def _parse_smil(self, url, swf_url): res = http.get(url) smil = http.xml(res, "SMIL config", schema=_smil_schema) for src, bitrate in smil["videos"]: url = urljoin(smil["http_base"], src) yield bitrate, AkamaiHDStream(self.session, url, swf=swf_url)
def _get_streams(self): match = _url_re.match(self.url) video_id = match.group("video_id") res = http.get(API_URL, params=dict(ak="web", id=video_id)) fmts = http.xml(res, schema=_schema) streams = {} for fmt in fmts: if fmt["type"] in STREAMING_TYPES: name, parser = STREAMING_TYPES[fmt["type"]] try: streams.update(parser(self.session, fmt["url"])) except IOError as err: self.logger.error("Failed to extract {0} streams: {1}", name, err) elif fmt["type"] == "h264_aac_mp4_rtmp_zdfmeta_http": name = fmt["quality"] try: streams[name] = self._create_rtmp_stream(fmt["url"]) except IOError as err: self.logger.error("Failed to extract RTMP stream '{0}': {1}", name, err) return streams
def _get_streams(self): match = _url_re.match(self.url) video_id = match.group("video_id") res = http.get(ASSET_URL.format(video_id)) assets = http.xml(res, schema=_asset_schema) streams = {} for asset in assets: base = asset["base"] url = asset["url"] if urlparse(url).path.endswith(".f4m"): streams.update( HDSStream.parse_manifest(self.session, url, pvswf=SWF_URL) ) elif base.startswith("rtmp"): name = "{0}k".format(asset["bitrate"]) params = { "rtmp": asset["base"], "playpath": url, "live": True } streams[name] = RTMPStream(self.session, params) return streams
def _find_broadcast(self, username): res = http.get(CHANNEL_URL, headers=HEADERS, params=dict(szBjId=username)) liveinfo = http.xml(res) thumb = liveinfo.findtext("thumb") if not thumb: return match = _broadcast_re.match(thumb) if match: return match.group(1)
def _get_streams(self): """ Find all the streams for the ITV url :return: Mapping of quality to stream """ soap_message = self._soap_request() headers = { 'Content-Length': '{0:d}'.format(len(soap_message)), 'Content-Type': 'text/xml; charset=utf-8', 'Host': 'mercury.itv.com', 'Origin': 'http://www.itv.com', 'Referer': 'http://www.itv.com/Mercury/Mercury_VideoPlayer.swf?v=null', 'SOAPAction': "http://tempuri.org/PlaylistService/GetPlaylist", 'User-Agent': ITV_PLAYER_USER_AGENT, "X-Requested-With": "ShockwaveFlash/16.0.0.305" } res = http.post("http://mercury.itv.com/PlaylistService.svc?wsdl", headers=headers, data=soap_message) # looking for the <MediaFiles> tag xmldoc = http.xml(res) mediafiles = xmldoc.find(".//VideoEntries//MediaFiles") # No mediafiles, no streams if not mediafiles: return None rtmp = mediafiles.attrib['base'] streams = {} for mediafile in mediafiles.findall("MediaFile"): playpath = mediafile.find("URL").text rtmp_url = urlparse(rtmp) app = (rtmp_url.path[1:] + '?' + rtmp_url.query).rstrip('?') live = app == "live" params = dict( rtmp="{u.scheme}://{u.netloc}{u.path}".format(u=rtmp_url), app=app.rstrip('?'), playpath=playpath, swfVfy=LIVE_SWF_URL if live else ONDEMAND_SWF_URL, timeout=10) if live: params['live'] = True bitrate = int(mediafile.attrib['bitrate']) / 1000 quality = "{0}k".format(bitrate) streams[quality] = RTMPStream(self.session, params) return streams
def _get_smil_streams(self, info): res = http.get(info["_stream"]) smil = http.xml(res, "SMIL config", schema=_smil_schema) streams = {} for video in smil["videos"]: url = "{0}/{1}{2}".format(smil["base"], video, HDCORE_PARAMETER) streams.update( HDSStream.parse_manifest(self.session, url, pvswf=SWF_URL)) return streams
def _get_smil_streams(self, info): res = http.get(info["_stream"]) smil = http.xml(res, "SMIL config", schema=_smil_schema) for video in smil["videos"]: url = "{0}/{1}{2}".format(smil["base"], video, HDCORE_PARAMETER) streams = HDSStream.parse_manifest(self.session, url, pvswf=SWF_URL) # TODO: Replace with "yield from" when dropping Python 2. for stream in streams.items(): yield stream
def _get_smil_streams(self, info): res = http.get(info["_stream"]) smil = http.xml(res, "SMIL config", schema=_smil_schema) streams = {} for video in smil["videos"]: url = "{0}/{1}{2}".format(smil["base"], video, HDCORE_PARAMETER) streams.update( HDSStream.parse_manifest(self.session, url, pvswf=SWF_URL) ) return streams
def _get_streams(self): """ Find all the streams for the ITV url :return: Mapping of quality to stream """ soap_message = self._soap_request() headers = { "Content-Length": "{0:d}".format(len(soap_message)), "Content-Type": "text/xml; charset=utf-8", "Host": "mercury.itv.com", "Origin": "http://www.itv.com", "Referer": "http://www.itv.com/Mercury/Mercury_VideoPlayer.swf?v=null", "SOAPAction": "http://tempuri.org/PlaylistService/GetPlaylist", "User-Agent": ITV_PLAYER_USER_AGENT, "X-Requested-With": "ShockwaveFlash/16.0.0.305", } res = http.post("http://mercury.itv.com/PlaylistService.svc?wsdl", headers=headers, data=soap_message) # looking for the <MediaFiles> tag xmldoc = http.xml(res) mediafiles = xmldoc.find(".//VideoEntries//MediaFiles") # No mediafiles, no streams if not mediafiles: return None rtmp = mediafiles.attrib["base"] streams = {} for mediafile in mediafiles.findall("MediaFile"): playpath = mediafile.find("URL").text rtmp_url = urlparse(rtmp) app = (rtmp_url.path[1:] + "?" + rtmp_url.query).rstrip("?") live = app == "live" params = dict( rtmp="{u.scheme}://{u.netloc}{u.path}".format(u=rtmp_url), app=app.rstrip("?"), playpath=playpath, swfVfy=LIVE_SWF_URL if live else ONDEMAND_SWF_URL, timeout=10, ) if live: params["live"] = True bitrate = int(mediafile.attrib["bitrate"]) / 1000 quality = "{0}k".format(bitrate) streams[quality] = RTMPStream(self.session, params) return streams
def _get_streams(self): res = http.get(self.url) match = _meta_xmlurl_id_re.search(res.text) if not match: return xml_info_url = STREAMS_INFO_URL.format(match.group(1)) video_info_res = http.get(xml_info_url) parsed_info = http.xml(video_info_res) live_el = parsed_info.find("live") live = live_el is not None and live_el.text == "1" streams = {} hdsurl_el = parsed_info.find("hdsurl") if hdsurl_el is not None and hdsurl_el.text is not None: hdsurl = hdsurl_el.text streams.update(HDSStream.parse_manifest(self.session, hdsurl)) if live: vurls_el = parsed_info.find("vurls") if vurls_el is not None: for i, vurl_el in enumerate(vurls_el): bitrate = vurl_el.get("bitrate") name = bitrate + "k" if bitrate is not None else "rtmp{0}".format( i) params = { "rtmp": vurl_el.text, } streams[name] = RTMPStream(self.session, params) parsed_urls = set() mobileurls_el = parsed_info.find("mobileurls") if mobileurls_el is not None: for mobileurl_el in mobileurls_el: text = mobileurl_el.text if not text: continue if text in parsed_urls: continue parsed_urls.add(text) url = urlparse(text) if url[0] == "http" and url[2].endswith("m3u8"): streams.update( HLSStream.parse_variant_playlist(self.session, text)) return streams
def _get_smil_streams(self, url): res = http.get(url, verify=False) smil = http.xml(res, schema=_smil_schema) for video in smil["videos"]: stream = RTMPStream(self.session, { "rtmp": smil["base"], "playpath": video, "swfVfy": SWF_URL, "pageUrl": self.url, "live": True }) yield "live", stream
def _get_smil_streams(self, url): res = http.get(url, verify=False) smil = http.xml(res, schema=_smil_schema) for video in smil["videos"]: stream = RTMPStream( self.session, { "rtmp": smil["base"], "playpath": video, "swfVfy": SWF_URL, "pageUrl": self.url, "live": True }) yield "live", stream
def _get_streams(self): res = http.get(self.url) match = _meta_xmlurl_id_re.search(res.text) if not match: return; xml_info_url = STREAMS_INFO_URL.format(match.group(1)) video_info_res = http.get(xml_info_url) parsed_info = http.xml(video_info_res) live_el = parsed_info.find("live"); live = live_el is not None and live_el.text == "1" streams = { } hdsurl_el = parsed_info.find("hdsurl"); if hdsurl_el is not None and hdsurl_el.text is not None: hdsurl = hdsurl_el.text streams.update(HDSStream.parse_manifest(self.session, hdsurl)) if live: vurls_el = parsed_info.find("vurls"); if vurls_el is not None: for i, vurl_el in enumerate(vurls_el): bitrate = vurl_el.get("bitrate") name = bitrate + "k" if bitrate is not None else "rtmp{0}".format(i) params = { "rtmp": vurl_el.text, } streams[name] = RTMPStream(self.session, params) parsed_urls = set() mobileurls_el = parsed_info.find("mobileurls"); if mobileurls_el is not None: for mobileurl_el in mobileurls_el: text = mobileurl_el.text if not text: continue if text in parsed_urls: continue parsed_urls.add(text) url = urlparse(text) if url[0] == "http" and url[2].endswith("m3u8"): streams.update(HLSStream.parse_variant_playlist(self.session, text)) return streams
def _get_streams(self): match = _url_re.match(self.url) channel = match.group("channel") res = http.get(STREAM_INFO_URL.format(channel)) urls = http.xml(res, schema=_livestream_schema) streams = {} for (name, parser), url in urls.items(): try: streams.update(parser(self.session, url)) except IOError as err: self.logger.warning("Unable to extract {0} streams: {1}", name, err) return streams
def _get_rtmp_stream(self, channel_name): params = { "l": "info", "a": "xmlClipPath", "clip_id": channel_name, "rid": time() } res = http.get(API_URL, params=params) rtmp_url = http.xml(res, schema=_rtmp_schema) return RTMPStream(self.session, { "rtmp": rtmp_url, "swfVfy": SWF_URL, "live": True })
def _get_streams(self): cubeid = self._get_live_cubeid() if not cubeid: return res = http.get(API_URL_LIVE, params=dict(cubeid=cubeid)) entries = http.xml(res, schema=_entries_schema) streams = {} for url in entries: try: streams.update( HLSStream.parse_variant_playlist(self.session, url)) except IOError as err: self.logger.error("Failed to open playlist: {0}", err) return streams
def _get_playlist(self, **params): res = http.get(PLAYLIST_URL, params=params) playlist = http.xml(res, schema=_playlist_schema) streams = {} for video in playlist["videos"]: name = "{0}p".format(video["height"]) stream = RTMPStream(self.session, { "rtmp": "{0}/{1}".format(playlist["base"], video["src"]), "app": urlparse(playlist["base"]).path[1:], "pageUrl": self.url, "rtmp": playlist["base"], "playpath": video["src"], "live": True }) streams[name] = stream return streams
def _get_streams(self): cubeid = self._get_live_cubeid() if not cubeid: return res = http.get(API_URL_LIVE, params=dict(cubeid=cubeid)) entries = http.xml(res, schema=_entries_schema) streams = {} for url in entries: try: streams.update( HLSStream.parse_variant_playlist(self.session, url) ) except IOError as err: self.logger.error("Failed to open playlist: {0}", err) return streams
def call(self, path, format="json", host=None, schema=None, **extra_params): params = dict(as3="t", **extra_params) if self.oauth_token: params["oauth_token"] = self.oauth_token url = "https://{0}.{1}{2}.{3}".format(self.subdomain, host or self.host, path, format) # The certificate used by Twitch cannot be verified in some environments. res = http.get(url, params=params, verify=False) if format == "json": return http.json(res, schema=schema) elif format == "xml": return http.xml(res, schema=schema) else: return res
def _get_playlist(self, **params): res = http.get(PLAYLIST_URL, params=params) playlist = http.xml(res, schema=_playlist_schema) streams = {} for video in playlist["videos"]: name = "{0}p".format(video["height"]) stream = RTMPStream( self.session, { "rtmp": "{0}/{1}".format(playlist["base"], video["src"]), "app": urlparse(playlist["base"]).path[1:], "pageUrl": self.url, "rtmp": playlist["base"], "playpath": video["src"], "live": True }) streams[name] = stream return streams
def _get_rtmp_streams(self, channelname): options = dict(l="info", a="xmlClipPath", clip_id=channelname, rid=time()) res = http.get(self.APIURL, params=options) clip = http.xml(res) rtmpurl = clip.findtext("./info/url") if rtmpurl is None: raise PluginError(("No RTMP Streams found on URL {0}").format(self.url)) rtmplist = {} rtmplist["live"] = RTMPStream(self.session, { "rtmp": rtmpurl, "swfVfy": self.SWFURL, "live": True }) return rtmplist
def _get_streams(self): match = _url_re.match(self.url) channel = match.group("channel") res = http.get(CHANNEL_INFO.format(channel)) channel_info = http.json(res) if not channel_info["online"]: return res = http.get(CHANNEL_MANIFEST.format(channel_info["id"])) assets = http.xml(res, schema=_assets_schema) streams = {} for video in assets["videos"]: name = "{0}p".format(video["height"]) stream = RTMPStream(self.session,{ "rtmp" : "{0}/{1}".format(assets["base"], video["src"]) }) streams[name] = stream return streams
def _get_streams(self): match = _url_re.match(self.url) video_id = match.group("video_id") res = http.get(ASSET_URL.format(video_id)) assets = http.xml(res, schema=_asset_schema) streams = {} for asset in assets: base = asset["base"] url = asset["url"] if urlparse(url).path.endswith(".f4m"): streams.update( HDSStream.parse_manifest(self.session, url, pvswf=SWF_URL)) elif base.startswith("rtmp"): name = "{0}k".format(asset["bitrate"]) params = {"rtmp": asset["base"], "playpath": url, "live": True} streams[name] = RTMPStream(self.session, params) return streams
def _get_rtmp_streams(self, params, alternative=""): res = http.get(PLAYLIST_URL, params=params) root = http.xml(res) rtmp = root.find("./head/meta").attrib.get("base") if not rtmp: raise NoStreamsError(self.url) tmpsteams = {} videos = root.findall("./body/switch/video") or root.findall("./body/video") for video in videos: src = video.attrib.get("src") height = video.attrib.get("height") quality = "{0}p{1}".format(height, alternative) tmpsteams[quality] = RTMPStream(self.session, { "rtmp": "{0}/{1}".format(rtmp,src), "pageUrl": self.url, "live": True }) return tmpsteams
def _get_rtmp_streams(self, channelname): options = dict(l="info", a="xmlClipPath", clip_id=channelname, rid=time()) res = http.get(self.APIURL, params=options) clip = http.xml(res) rtmpurl = clip.findtext("./info/url") if rtmpurl is None: raise PluginError( ("No RTMP Streams found on URL {0}").format(self.url)) rtmplist = {} rtmplist["live"] = RTMPStream(self.session, { "rtmp": rtmpurl, "swfVfy": self.SWFURL, "live": True }) return rtmplist
def _get_smil_streams(self, url): res = http.get(url, verify=False) smil = http.xml(res, schema=_smil_schema) streams = {} for video in smil["videos"]: stream = RTMPStream(self.session, { "rtmp": smil["base"], "playpath": video, "swfVfy": SWF_URL, "pageUrl": self.url, "live": True }) if streams: name = "live_alt" else: name = "live" streams[name] = stream return streams
def _get_rtmp_streams(self, params, alternative=""): res = http.get(PLAYLIST_URL, params=params) root = http.xml(res) rtmp = root.find("./head/meta").attrib.get("base") if not rtmp: raise NoStreamsError(self.url) tmpsteams = {} videos = root.findall("./body/switch/video") or root.findall( "./body/video") for video in videos: src = video.attrib.get("src") height = video.attrib.get("height") quality = "{0}p{1}".format(height, alternative) tmpsteams[quality] = RTMPStream( self.session, { "rtmp": "{0}/{1}".format(rtmp, src), "pageUrl": self.url, "live": True }) return tmpsteams
def _parse_smil(self, url, swfurl): res = http.get(url) smil = http.xml(res, "SMIL config") streams = {} httpbase = smil.find("{http://www.w3.org/2001/SMIL20/Language}head/" "{http://www.w3.org/2001/SMIL20/Language}meta[@name='httpBase']") if not (httpbase is not None and httpbase.attrib.get("content")): raise PluginError("Missing HTTP base in SMIL") httpbase = httpbase.attrib.get("content") videos = smil.findall("{http://www.w3.org/2001/SMIL20/Language}body/" "{http://www.w3.org/2001/SMIL20/Language}switch/" "{http://www.w3.org/2001/SMIL20/Language}video") for video in videos: url = urljoin(httpbase, video.attrib.get("src")) bitrate = int(video.attrib.get("system-bitrate")) streams[bitrate] = AkamaiHDStream(self.session, url, swf=swfurl) return streams
def _parse_smil(self, url, swfurl): res = http.get(url) smil = http.xml(res, "SMIL config") streams = {} httpbase = smil.find( "{http://www.w3.org/2001/SMIL20/Language}head/" "{http://www.w3.org/2001/SMIL20/Language}meta[@name='httpBase']") if not (httpbase is not None and httpbase.attrib.get("content")): raise PluginError("Missing HTTP base in SMIL") httpbase = httpbase.attrib.get("content") videos = smil.findall("{http://www.w3.org/2001/SMIL20/Language}body/" "{http://www.w3.org/2001/SMIL20/Language}switch/" "{http://www.w3.org/2001/SMIL20/Language}video") for video in videos: url = urljoin(httpbase, video.attrib.get("src")) bitrate = int(video.attrib.get("system-bitrate")) streams[bitrate] = AkamaiHDStream(self.session, url, swf=swfurl) return streams
def _get_live_cubeid(self): res = http.get(API_URL_APP, params=dict(mode="get_live")) root = http.xml(res) return root.findtext("./cube/cubeid")
def _get_meta_url(self, url): res = http.get(url, exception=IOError) root = http.xml(res, exception=IOError) return root.findtext("default-stream-url")