def _create_stream(self, stream, is_live): stream_name = "{0}p".format(stream["height"]) stream_type = stream["mediaType"] stream_url = stream["url"] if stream_type in ("hls", "mp4"): if urlparse(stream_url).path.endswith("m3u8"): try: streams = HLSStream.parse_variant_playlist( self.session, stream_url) # TODO: Replace with "yield from" when dropping Python 2. for stream in streams.items(): yield stream except IOError as err: self.logger.error("Failed to extract HLS streams: {0}", err) else: yield stream_name, HTTPStream(self.session, stream_url) elif stream_type == "rtmp": params = { "rtmp": stream["streamer"], "playpath": stream["url"], "swfVfy": SWF_URL, "pageUrl": self.url, } if is_live: params["live"] = True else: params["playpath"] = "mp4:{0}".format(params["playpath"]) stream = RTMPStream(self.session, params) yield stream_name, stream
def _get_streams(self): # get the HLS xml from the same sub domain as the main url, defaulting to www sdomain = _url_re.match(self.url).group(1) or "www" res = http.get(API_URL.format(sdomain)) stream_url = http.xml(res, schema=_schema) return HLSStream.parse_variant_playlist(self.session, stream_url)
def _get_streams(self): """ Find the streams for web.tv :return: """ headers = {} res = http.get(self.url, headers=headers) headers["Referer"] = self.url sources = self._sources_re.findall(res.text) if len(sources): sdata = parse_json(sources[0], schema=self._sources_schema) for source in sdata: self.logger.debug("Found stream of type: {}", source[u'type']) if source[u'type'] == u"application/vnd.apple.mpegurl": # if the url has no protocol, assume it is http url = source[u"src"] if url.startswith("//"): url = "http:" + url try: # try to parse the stream as a variant playlist variant = HLSStream.parse_variant_playlist(self.session, url, headers=headers) if variant: for q, s in variant.items(): yield q, s else: # and if that fails, try it as a plain HLS stream yield 'live', HLSStream(self.session, url, headers=headers) except IOError: self.logger.warning("Could not open the stream, perhaps the channel is offline")
def _get_star_streams(self, desktop_url, mobile_url, token=""): if token: self.logger.debug("Opening stream with token: {}", token) if mobile_url: for _, s in HLSStream.parse_variant_playlist(self.session, mobile_url + token, headers={ "Referer": self.url }).items(): yield "live", s if desktop_url: # get the HDS stream URL res = http.get(desktop_url + token) stream_data = http.json(res, schema=self.hds_schema) for _, s in HDSStream.parse_manifest( self.session, stream_data["url"], pvswf=self.SWF_URL, is_akamai=stream_data["use_akamai"], headers={ "Referer": self.url }).items(): yield "live", s
def _get_streams(self): match = _url_re.match(self.url) video = match.group("video_id") playlist = _playlist_url.format(video) return HLSStream.parse_variant_playlist(self.session, playlist)
def _get_streams(self): match = _url_re.match(self.url) videoid = match.group('id') streams = {} # Set header data for user-agent hdr = {'User-Agent': USER_AGENT} # Parse video ID from data received from supplied URL res = http.get(VK_VIDEO_URL + videoid.strip(), headers=hdr) for match in re.findall(SINGLE_VIDEO_URL, res.text): url = match[0].replace("\\/", "/") streams[match[2]] = HTTPStream(self.session, url) if not streams: # try to check is live match = VK_LIVE_HASH.search(res.text) params = videoid.split('_') if match and match.group('hash'): url = VK_EXT_URL.format(params[0].replace('video', "").replace('-', ""), params[1], match.group('hash')) res = http.get(url, headers=hdr) match = SINGLE_HLS_URL.search(res.text) if match and match.group('playlist'): hls_streams = HLSStream.parse_variant_playlist(self.session, match.group('playlist').replace("\\/", "/"), namekey="pixels") streams.update(hls_streams) return streams
def _get_streams(self): page = http.get(self.url) try: channel, _, _, _, online, visibility, is_flash = self._get_stream_arguments( page) except ValueError: return if not online: self.logger.error("This stream is currently offline") return channel_server_res = http.post(API_CHANNEL_INFO, data={"loadbalancinginfo": channel}) if is_flash: return { "live": RTMPStream( self.session, { "rtmp": RTMP_URL.format(channel_server_res.text), "playpath": RTMP_PLAYPATH.format(channel, visibility), "pageUrl": self.url, "live": True }) } else: return HLSStream.parse_variant_playlist( self.session, HLS_URL.format(channel_server_res.text, channel, visibility), verify=False)
def _get_vod_streams(self, params): manifest_url = params.get("autoURL") if not manifest_url: return res = http.get(manifest_url) if res.headers.get("Content-Type") == "application/f4m+xml": streams = HDSStream.parse_manifest(self.session, res.url) # TODO: Replace with "yield from" when dropping Python 2. for __ in streams.items(): yield __ elif res.headers.get( "Content-Type") == "application/vnd.apple.mpegurl": streams = HLSStream.parse_variant_playlist(self.session, res.url) # TODO: Replace with "yield from" when dropping Python 2. for __ in streams.items(): yield __ else: manifest = http.json(res, schema=_vod_manifest_schema) for params in manifest["alternates"]: name = "{0}p".format(params["height"]) stream = self._create_flv_playlist(params["template"]) yield name, stream failovers = params.get("failover", []) for failover in failovers: stream = self._create_flv_playlist(failover) yield name, stream
def _get_streams(self): if _stream_url_re.match(self.url): mode = MODE_STREAM else: mode = MODE_VOD res = http.get(self.url) match = _json_re.search(res.text) if match: data = json.loads( _json_re.search(res.text).group('json').replace('"', '"')) else: raise PluginError("Could not extract JSON metadata") streams = {} try: if mode == MODE_STREAM: sources = data['playlist']['videos'][0]['sources'] elif mode == MODE_VOD: sources = data['selected_video']['sources'] except (KeyError, IndexError): raise PluginError("Could not extract sources") for source in sources: try: if source['delivery'] != 'hls': continue url = source['src'].replace('\/', '/') except KeyError: continue stream = HLSStream.parse_variant_playlist(self.session, url) streams.update(stream) return streams
def _get_streams(self): # get the page res = http.get(self.url, headers={"User-Agent": self._user_agent}) # find the big blob of stream info in the page stream_data = self._stream_data_re.match(res.text) stream_name = AdultSwim._url_re.match( self.url).group(1) or "live-stream" if stream_data: # parse the stream info as json stream_info = parse_json(stream_data.group(1), schema=self._page_data_schema) # get the stream ID stream_id = stream_info[u"streams"][stream_name][u"stream"] if stream_id: api_url = self.API_URL.format(id=stream_id) res = http.get(api_url, headers={"User-Agent": self._user_agent}) stream_data = http.json(res, schema=self._api_schema) for asset in stream_data[u'data'][u'stream'][u'assets']: for n, s in HLSStream.parse_variant_playlist( self.session, asset[u"url"]).items(): yield n, s else: self.logger.error( "Couldn't find the stream ID for this stream: {}".format( stream_name)) else: self.logger.error( "Couldn't find the stream data for this stream: {}".format( stream_name))
def _get_streams(self): res = http.get(self.url) match = _info_re.search(res.text) if not match: return info = parse_json(match.group(1), schema=_schema) stream_name = info["mode"] mp4_url = info.get("mp4_url") ios_url = info.get("ios_url") swf_url = info.get("swf_url") if mp4_url: stream = HTTPStream(self.session, mp4_url) yield stream_name, stream if ios_url: if urlparse(ios_url).path.endswith(".m3u8"): streams = HLSStream.parse_variant_playlist( self.session, ios_url) # TODO: Replace with "yield from" when dropping Python 2. for stream in streams.items(): yield stream if swf_url: stream = self._get_rtmp_stream(swf_url) if stream: yield stream_name, stream
def _get_streams(self): match = _url_re.match(self.url) videoid = match.group('id') # Set header data for user-agent hdr = {'User-Agent': USER_AGENT} # Parse video ID from data received from supplied URL res = http.get(self.url, headers=hdr) if not res: return {} for match in re.findall(_player_params, res.text): try: params = json.loads(base64.b64decode(match)) video_url = params.get("url") res = http.get(video_url, headers=hdr) video_url = res.text.split('=')[1] return HLSStream.parse_variant_playlist( self.session, video_url) except Exception as e: self.logger.error("Failed to decode player params: {0}", e) return {}
def _get_streams(self): content_id = self._get_content_id() if content_id: self.logger.debug(u"Loading content: {}", content_id) hls_url = self._get_hls_url(content_id) return HLSStream.parse_variant_playlist(self.session, hls_url) else: self.logger.error(u"Could not find the contentId for this stream")
def _get_streams(self): clips = http.get(self.url, schema=_schema) if not clips: return for clip in clips: for source in clip["sources"]: return HLSStream.parse_variant_playlist(self.session, source["file"])
def _get_streams(self): channel = self.url_re.match(self.url).group(1) res = http.get(self.api_url.format(channel)) data = http.json(res, schema=self.api_schema) return HLSStream.parse_variant_playlist(self.session, data["channel_stream_url"])
def _get_streams(self): username = _RE_URL.match(self.url).group(1) url = 'https://www.stream.me/api-user/v1/{}/channel'.format(username) data = http.get(url).json() try: m3u8 = data['_embedded']['streams'][0]['_links']['hlsmp4']['href'] return HLSStream.parse_variant_playlist(self.session, m3u8) except KeyError: return {}
def _get_streams(self): match = _url_re.match(self.url) channel = match.group("channel") channel = channel.replace("_", "-") playlist_url = PLAYLIST_URL.format(channel) return HLSStream.parse_variant_playlist(self.session, playlist_url, check_streams=True)
def _get_streams(self): res = http.get(self.url) match = (_stream_hls_re.search(res.text) or _stream_data_re.search(res.text)) if not match: return stream_url = parse_json(match.group(1)) return HLSStream.parse_variant_playlist(self.session, stream_url)
def _get_streams(self): login_email = self.options.get("email") login_password = self.options.get("password") if login_email and login_password: self._authenticate(login_email, login_password) hls_playlist = http.get(self.url, schema=_hls_playlist_schema) if not hls_playlist: return return HLSStream.parse_variant_playlist(self.session, hls_playlist)
def _get_streams(self): info = self._get_stream_info(self.url) if not info: return formats = info.get("fmt_list") streams = {} protected = False for stream_info in info.get("url_encoded_fmt_stream_map", []): if stream_info.get("s"): protected = True continue stream = HTTPStream(self.session, stream_info["url"]) name = formats.get(stream_info["itag"]) or stream_info["quality"] if stream_info.get("stereo3d"): name += "_3d" streams[name] = stream # Extract audio streams from the DASH format list for stream_info in info.get("adaptive_fmts", []): if stream_info.get("s"): protected = True continue stream_type, stream_format = stream_info["type"] if stream_type != "audio": continue stream = HTTPStream(self.session, stream_info["url"]) name = "audio_{0}".format(stream_format) streams[name] = stream hls_playlist = info.get("hlsvp") if hls_playlist: try: hls_streams = HLSStream.parse_variant_playlist( self.session, hls_playlist, headers=HLS_HEADERS, namekey="pixels") streams.update(hls_streams) except IOError as err: self.logger.warning("Failed to extract HLS streams: {0}", err) if not streams and protected: raise AccessDeniedError( "This plugin does not support protected videos, " "try youtube-dl instead") return streams
def _get_streams(self): res = http.get(self.url, schema=_schema) if not res: return if res["type"] == "channel" and urlparse( res["url"]).path.endswith("m3u8"): return HLSStream.parse_variant_playlist(self.session, res["url"]) elif res["type"] == "video": stream = HTTPStream(self.session, res["url"]) return dict(video=stream)
def _get_streams(self): match = _url_re.match(self.url) uuid = match.group("uuid") html = http.get( 'http://www.rtl.nl/system/s4m/vfd/version=2/uuid={}/d=pc/fmt=adaptive/' .format(uuid)).text playlist_url = "http://manifest.us.rtl.nl" + re.compile( 'videopath":"(?P<playlist_url>.*?)",', re.IGNORECASE).search(html).group("playlist_url") return HLSStream.parse_variant_playlist(self.session, playlist_url)
def _get_streams(self): match = self.url_re.match(self.url) res = http.post(self.flashvars_url, data=dict( broadcaster=match.group("broadcaster") or "Verm", stream_id=match.group("channel_id") or match.group("highlight_id"))) flashvars = http.json(res, schema=self.flashvars_schema) if flashvars.get("pereakaurl"): url = self.pereakaurl.format(flashvars.get("pereakaurl").strip("/")) return HLSStream.parse_variant_playlist(self.session, url) elif flashvars.get("akaurl"): url = self.akaurl.format(flashvars.get("akaurl").strip("/")) return HLSStream.parse_variant_playlist(self.session, url) elif flashvars.get("stream"): self.logger.error("OctoStreams are not currently supported")
def _get_live_streams(self): meta = self._get_meta() stream = [x for x in meta['streams'] if x['type'] == 'hls'][0]['url'] url = 'http://ida.omroep.nl/aapi/?type=jsonp&stream={}&token={}'.format( stream, self.get_token()) streamdata = http.get(url, headers=HTTP_HEADERS).json() deeplink = http.get(streamdata['stream'], headers=HTTP_HEADERS).text deeplink = re.compile('"(.*?)"', re.DOTALL + re.IGNORECASE).search(deeplink).group(1) playlist_url = deeplink.replace("\\/", "/") return HLSStream.parse_variant_playlist(self.session, playlist_url)
def _get_streams(self): stream_id = _id_map[self.channel_path] hls_url = "http://iphonelive.rtve.es/{0}_LV3_IPH/{0}_LV3_IPH.m3u8".format( stream_id) # Check if the stream is available res = http.head(hls_url, raise_for_status=False) if res.status_code == 404: raise PluginError( "The program is not available due to rights restrictions") return HLSStream.parse_variant_playlist(self.session, hls_url)
def _get_streams(self): api = self._create_api() match = _url_re.match(self.url) media_id = int(match.group("media_id")) try: info = api.get_info(media_id, fields=["media.stream_data"], schema=_media_schema) except CrunchyrollAPIError as err: raise PluginError(u"Media lookup error: {0}".format(err.msg)) if not info: return streams = {} # The adaptive quality stream sometimes a subset of all the other streams listed, ultra is no included has_adaptive = any([s[u"quality"] == u"adaptive" for s in info[u"streams"]]) if has_adaptive: self.logger.debug(u"Loading streams from adaptive playlist") for stream in filter(lambda x: x[u"quality"] == u"adaptive", info[u"streams"]): for q, s in HLSStream.parse_variant_playlist(self.session, stream[u"url"]).items(): # rename the bitrates to low, mid, or high. ultra doesn't seem to appear in the adaptive streams name = STREAM_NAMES.get(q, q) streams[name] = s # If there is no adaptive quality stream then parse each individual result for stream in info[u"streams"]: if stream[u"quality"] != u"adaptive": # the video_encode_id indicates that the stream is not a variant playlist if u"video_encode_id" in stream: streams[stream[u"quality"]] = HLSStream(self.session, stream[u"url"]) else: # otherwise the stream url is actually a list of stream qualities for q, s in HLSStream.parse_variant_playlist(self.session, stream[u"url"]).items(): # rename the bitrates to low, mid, or high. ultra doesn't seem to appear in the adaptive streams name = STREAM_NAMES.get(q, q) streams[name] = s 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_hls_streams(self, stream_type="live"): self.logger.debug("Getting {0} HLS streams for {1}".format(stream_type, self.channel)) self._authenticate() self._hosted_chain.append(self.channel) if stream_type == "live": hosted_channel = self._check_for_host() if hosted_channel and self.options.get("disable_hosting"): self.logger.info("hosting was disabled by command line option") elif hosted_channel: self.logger.info("switching to {0}", hosted_channel) if hosted_channel in self._hosted_chain: self.logger.error(u"A loop of hosted channels has been detected, " "cannot find a playable stream. ({0})".format(u" -> ".join(self._hosted_chain + [hosted_channel]))) return {} self.channel = hosted_channel return self._get_hls_streams(stream_type) # only get the token once the channel has been resolved sig, token = self._access_token(stream_type) url = self.usher.channel(self.channel, sig=sig, token=token) elif stream_type == "video": sig, token = self._access_token(stream_type) url = self.usher.video(self.video_id, nauthsig=sig, nauth=token) else: self.logger.debug("Unknown HLS stream type: {0}".format(stream_type)) return {} try: # If the stream is a VOD that is still being recorded the stream should start at the # beginning of the recording streams = HLSStream.parse_variant_playlist(self.session, url, force_restart=not stream_type == "live") except IOError as err: err = str(err) if "404 Client Error" in err or "Failed to parse playlist" in err: return else: raise PluginError(err) try: token = parse_json(token, schema=_token_schema) for name in token["restricted_bitrates"]: if name not in streams: self.logger.warning("The quality '{0}' is not available " "since it requires a subscription.", name) except PluginError: pass return streams
def _get_live_streams(self, language): """ Get the live stream in a particular language :param language: :return: """ res = http.get(self._live_api_url) live_res = http.json(res, schema=self._live_schema) api_res = http.get(live_res[u"url"]) stream_data = http.json(api_res, schema=self._stream_api_schema) # find the stream in the requested language if language in stream_data[u'primary']: playlist_url = stream_data[u'primary'][language][u"hls"] return HLSStream.parse_variant_playlist(self.session, playlist_url)
def _get_streams(self): vid = self.url_re.match(self.url).group(1) self.logger.debug("Found video ID: {}", vid) page = http.get(self.play_url.format(vid=vid)) js_url_m = self.js_re.search(page.text) if js_url_m: js_url = js_url_m.group(1) self.logger.debug("Loading player JS: {}", js_url) res = http.get(js_url) data = self.setup_schema.validate(res.text) for source in data["playlist"][0]["sources"]: if source["type"] == "hls": return HLSStream.parse_variant_playlist(self.session, "https:" + source["file"])