def _get_rtmp_streams(self): def clean_tag(tag): if tag[0] == "_": return tag[1:] else: return tag chansub = self._authenticate() url = self.StreamInfoURL.format(self.channelname) params = dict(b_id="true", group="", private_code="null", p=int(random.random() * 999999), channel_subscription=chansub, type="any") self.logger.debug("Fetching stream info") res = urlget(url, params=params) data = res.text # fix invalid xml data = re.sub("<(\d+)", "<_\g<1>", data) data = re.sub("</(\d+)", "</_\g<1>", data) streams = {} try: dom = xml.dom.minidom.parseString(data) except Exception as err: raise PluginError(("Unable to parse config XML: {0})").format(err)) nodes = dom.getElementsByTagName("nodes")[0] if len(nodes.childNodes) == 0: return streams swfurl = urlresolve(self.SWFURL) for node in nodes.childNodes: info = {} for child in node.childNodes: info[child.tagName] = self._get_node_text(child) if not ("connect" in info and "play" in info): continue stream = RTMPStream(self.session, { "rtmp": ("{0}/{1}").format(info["connect"], info["play"]), "swfVfy": swfurl, "live": True }) sname = clean_tag(node.tagName) if "token" in info: stream.params["jtv"] = info["token"] else: self.logger.warning("No token found for stream {0}, this stream may fail to play", sname) streams[sname] = stream return streams
def _verify_swf(self): swfurl = urlresolve(self.SWFURL) cachekey = "swf:{0}".format(swfurl) swfhash, swfsize = self.cache.get(cachekey, (None, None)) if not (swfhash and swfsize): self.logger.debug("Verifying SWF") swfhash, swfsize = swfverify(swfurl) self.cache.set(cachekey, (swfhash, swfsize)) return swfurl, swfhash, swfsize
def _get_history(self): video_id = self.url.rstrip("/").rpartition("/")[2] self.logger.debug("Testing if video exist") history_url = 'http://www.filmon.us/video/history/hid/' + video_id if urlresolve(prepend_www(history_url)) == '/': raise PluginError("history number " + video_id + " don't exist") self.logger.debug("Fetching video URL") res = urlget(history_url) match = re.search("http://cloud.battlecam.com/([/\w]+).flv", res.text) if not match: return url = match.group(0) return HTTPStream(self.session, url)
def _verify_swf(self): swfurl = urlresolve(self.SWFURL) # For some reason the URL returned sometimes contain random # user-agent/referer query parameters, let's strip them # so we actually cache. if "?" in swfurl: swfurl = swfurl[:swfurl.find("?")] cachekey = "swf:{0}".format(swfurl) swfhash, swfsize = self.cache.get(cachekey, (None, None)) if not (swfhash and swfsize): self.logger.debug("Verifying SWF") swfhash, swfsize = swfverify(swfurl) self.cache.set(cachekey, (swfhash, swfsize)) return swfurl, swfhash, swfsize
def _get_stream_upload(self): video = urlparse(self.url).path if urlresolve(prepend_www(self.url)) == 'http://www.filmon.us/channels': raise PluginError(video + " don't exist") playpath = "mp4:resources" + video + '/v_3.mp4' rtmp = RTMP_UPLOAD_URL parsed = urlparse(rtmp) app = parsed.path[1:] return RTMPStream(self.session, { "rtmp": rtmp, "pageUrl": self.url, "swfUrl": SWF_UPLOAD_URL, "playpath": playpath, "app": app, "live": True })
def _get_stream_upload(self): video = urlparse(self.url).path if urlresolve(prepend_www( self.url)) == 'http://www.filmon.us/channels': raise PluginError(video + " don't exist") playpath = "mp4:resources" + video + '/v_3.mp4' rtmp = RTMP_UPLOAD_URL parsed = urlparse(rtmp) app = parsed.path[1:] return RTMPStream( self.session, { "rtmp": rtmp, "pageUrl": self.url, "swfUrl": SWF_UPLOAD_URL, "playpath": playpath, "app": app, "live": True })