def _get_streams(self): stype = _url_re.match(self.url).group(1) if stype.lower() == "live": self.logger.debug("Searching the page for live stream URLs") playlists = http.get(self.url, schema=_live_schema) for playlist in playlists: for q, s in HLSStream.parse_variant_playlist(self.session, playlist["url"]).items(): yield "source" if playlist["isSource"] else q, s elif stype.lower() == "movie": self.logger.debug("Searching the page for VOD stream URLs") playlist = http.get(self.url, schema=_movie_schema) if playlist: for s in HLSStream.parse_variant_playlist(self.session, playlist).items(): yield s
def handle_module_info(self, args, media_id, application, cluster="live", referrer=None, retries=3): has_results = False for streams in UHSClient.module_info_schema.validate(args): has_results = True if isinstance(streams, list): for stream in streams: for q, s in HLSStream.parse_variant_playlist( self.session, stream["url"]).items(): yield q, UStreamHLSStream(self.session, s.url, self.api) elif isinstance(streams, dict): for stream in streams.get("streams", []): name = "{0}k".format(stream["bitrate"]) for surl in stream["streamName"]: yield name, HTTPStream(self.session, surl) elif streams == "offline": self.logger.warning("This stream is currently offline") if not has_results: raise ModuleInfoNoStreams
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): http.headers.update({ "User-Agent": useragents.CHROME, "Referer": self.referer }) fragment = dict(parse_qsl(urlparse(self.url).fragment)) link = fragment.get("link") if not link: link = self._get_tv_link() if not link: self.logger.error("Missing link fragment: stream unavailable") return player_url = self._api_url.format(link) self.logger.debug("Requesting player API: {0} (referer={1})", player_url, self.referer) res = http.get(player_url, params={"_": int(time.time() * 1000)}, headers={"X-Requested-With": "XMLHttpRequest"}) try: data = http.json(res, schema=self.api_schema) except PluginError as e: print(e) self.logger.error("Cannot play this stream type") else: if data["status"]: if data["file"].startswith("<"): self.logger.error("Cannot play embedded streams") else: return HLSStream.parse_variant_playlist( self.session, data["file"]) else: self.logger.error(data["text"])
def _get_streams(self): stream_url = self.stream_schema.validate(http.get(self.url).text) if stream_url: headers = {"Referer": self.url} return HLSStream.parse_variant_playlist(self.session, stream_url, headers=headers)
def _get_streams(self): headers = { "User-Agent": useragents.FIREFOX, "Referer": self.url, } res = http.get(self.url, headers=headers) for id_re in (self._id_re, self._id_2_re): m = id_re.search(res.text) if not m: continue break if not m: self.logger.error("No video id found") return dvr_id = m.group("id") self.logger.debug("Found video id: {0}".format(dvr_id)) data = {"feed": "hd", "dvrId": dvr_id} res = http.post(self.api_url, headers=headers, data=data) if res.status_code == 200: for s in HLSStream.parse_variant_playlist(self.session, res.text, headers=headers).items(): yield s
def _get_streams(self): headers = {"User-Agent": useragents.FIREFOX, "Referer": self.url} res = http.get(self.url, headers=headers) files = self._files_re.findall(res.text) if files is None: return files = list(set(files)) for url in files: if ".m3u8" in url: if url.startswith("https://weltmediathek-vh."): url = "https://www.welt.de/video/services/token/{0}".format( quote(url, safe="")) res = http.get(url, headers=headers) r_json = http.json(res) url = r_json["urlWithToken"] for s in HLSStream.parse_variant_playlist( self.session, url, headers=headers).items(): yield s elif url.endswith(".mp4"): m = self._mp4_bitrate_re.search(url) bitrate = m.group("bitrate") if bitrate: name = "{0}k".format(bitrate) else: name = "mp4" yield name, HTTPStream(self.session, url, headers=headers)
def _get_streams(self): match = _url_re.match(self.url) channel = match.group("channel") http.headers.update({'User-Agent': useragents.CHROME}) payload = '{"liveStreamID": "%s"}' % (channel) res = http.post(API_URL, data=payload) status = _status_re.search(res.text) if not status: self.logger.info("Stream currently unavailable.") return http_url = _rtmp_re.search(res.text).group(1) http_url = http_url.replace("http:", "https:") yield "live", HTTPStream(self.session, http_url) if 'pull-rtmp' in http_url: url = http_url.replace("https:", "rtmp:").replace(".flv", "") stream = RTMPStream(self.session, {"rtmp": url, "live": True}) yield "live", stream if 'wansu-' in http_url: url = http_url.replace(".flv", "/playlist.m3u8") for stream in HLSStream.parse_variant_playlist(self.session, url).items(): yield stream else: url = http_url.replace("live-hdl", "live-hls").replace(".flv", ".m3u8") yield "live", HLSStream(self.session, url)
def _get_streams(self): asset_id = self._get_prid(self.get_option("subtitles")) if asset_id: self.logger.debug("Found asset id: {0}", asset_id) streams = self.api_call(asset_id, params=dict(adaptive="yes", token=self.token), schema=self.streams_schema) for stream in streams: if stream["format"] in ("adaptive", "hls", "mp4"): if stream["contentType"] == "url": stream_url = stream["url"] else: # using type=json removes the javascript function wrapper info_url = stream["url"].replace( "type=jsonp", "type=json") # find the actual stream URL stream_url = http.json(http.get(info_url), schema=self.stream_info_schema) if stream["format"] in ("adaptive", "hls"): for s in HLSStream.parse_variant_playlist( self.session, stream_url).items(): yield s elif stream["format"] in ("mp3", "mp4"): yield "vod", HTTPStream(self.session, stream_url)
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): match = _url_re.match(self.url) channel = match.group("channel") domain = match.group("domain") headers = {"Referer": self.url, "User-Agent": useragents.FIREFOX} if domain == "canlitv.plus": res = http.get(EMBED_URL_1.format(channel), headers=headers) elif domain == "ecanlitvizle.net": res = http.get(EMBED_URL_2.format(channel), headers=headers) else: res = http.get(self.url, headers=headers) url_match = _m3u8_re.search(res.text) if url_match: hls_url = url_match.group("url") if domain in ("canlitvlive.live", "canlitvlive.site"): hls_url = "http:" + hls_url self.logger.debug("Found URL: {0}".format(hls_url)) try: s = [] for s in HLSStream.parse_variant_playlist( self.session, hls_url).items(): yield s if not s: yield "live", HLSStream(self.session, hls_url) except IOError as err: self.logger.error("Failed to extract streams: {0}", err)
def _get_streams(self): res = http.get(self.url) data = self._data_re.search(res.text) if data: self.logger.debug("Found _data_re") data = self.js_to_json_regex(data.group(1)) res = http.post(self.api_url, data=data) m = self._hls_re.search(res.text) if m: self.logger.debug("Found _hls_re") hls_url = m.group("url") hls_url = update_scheme("http://", hls_url) self.logger.debug("URL={0}".format(hls_url)) streams = HLSStream.parse_variant_playlist(self.session, hls_url) if not streams: return {"live": HLSStream(self.session, hls_url)} else: return streams iframe = self._iframe_re.search(res.text) if iframe: self.logger.debug("Found _iframe_re") iframe_url = iframe.group("url") iframe_url = update_scheme("http://", iframe_url) self.logger.debug("URL={0}".format(iframe_url)) return self.session.streams(iframe_url)
def _get_streams(self): email = self.get_option("email") password = self.get_option("password") if not self._authed and (not email and not password): self.logger.error("A login for WWE Network is required, use --wwenetwork-email/" "--wwenetwork-password to set them") return if not self._authed: if not self.login(email, password): self.logger.error("Failed to login, check your username/password") return content_id = self._get_content_id() if content_id: self.logger.debug("Found content ID: {0}", content_id) info = self._get_media_info(content_id) if info["status"]["code"] == 1: # update the session attributes self._update_session_attribute("fprt", info.get("fingerprint")) for attr in info["session_attributes"]: self._update_session_attribute(attr["name"], attr["value"]) if info.get("session_key"): self.session_key = info.get("session_key") for url in info["urls"]: for s in HLSStream.parse_variant_playlist(self.session, url, name_fmt="{pixels}_{bitrate}").items(): yield s else: raise PluginError("Could not load streams: {message} ({code})".format(**info["status"]))
def _get_streams(self): match = _url_re.match(self.url) username = match.group("username") CSRFToken = str(uuid.uuid4().hex.upper()[0:32]) headers = { "Content-Type": "application/x-www-form-urlencoded", "X-CSRFToken": CSRFToken, "X-Requested-With": "XMLHttpRequest", "Referer": self.url, } cookies = { "csrftoken": CSRFToken, } post_data = "room_slug={0}&bandwidth=high".format(username) res = http.post(API_HLS, headers=headers, cookies=cookies, data=post_data) data = http.json(res, schema=_post_schema) if data["success"] is True and data["room_status"] == "public": for s in HLSStream.parse_variant_playlist(self.session, data["url"]).items(): yield s
def _get_streams(self): headers = {"User-Agent": useragents.FIREFOX, "Referer": self.url} data = http.get(self.url, headers=headers, schema=self._data_schema) metadata = data.get("metadata") metadata_url = data.get("metadataUrl") if metadata_url: metadata = http.post(metadata_url, headers=headers, schema=self._metadata_schema) if metadata: list_hls = [ metadata.get("hlsManifestUrl"), metadata.get("hlsMasterPlaylistUrl"), ] for hls_url in list_hls: if hls_url is not None: for s in HLSStream.parse_variant_playlist( self.session, hls_url, headers=headers).items(): yield s if metadata.get("videos"): for http_stream in metadata.get("videos"): http_name = http_stream["name"] http_url = http_stream["url"] yield http_name, HTTPStream(self.session, http_url, headers=headers) if metadata.get("rtmpUrl"): yield "live", RTMPStream( self.session, params={"rtmp": metadata.get("rtmpUrl")})
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): user = self.login(self.options.get("email"), self.options.get("password")) if user: self.logger.debug("Logged in to Schoolism as {0}", user) res = http.get(self.url, headers={"User-Agent": useragents.SAFARI_8}) lesson_playlist = self.playlist_schema.validate(res.text) part = self.options.get("part") self.logger.info("Attempting to play lesson Part {0}", part) found = False # make request to key-time api, to get key specific headers res = http.get(self.key_time_url, headers={"User-Agent": useragents.SAFARI_8}) for i, video in enumerate(lesson_playlist, 1): if video["sources"] and i == part: found = True for source in video["sources"]: for s in HLSStream.parse_variant_playlist( self.session, source["src"], headers={ "User-Agent": useragents.SAFARI_8, "Referer": self.url }).items(): yield s if not found: self.logger.error("Could not find lesson Part {0}", part)
def get_streams(self, video_id): self.logger.debug("Finding streams for video: {0}", video_id) policy_key = self.policy_key(video_id) self.logger.debug("Found policy key: {0}", policy_key) data = self.video_info(video_id, policy_key) for source in data.get("sources"): # determine quality name if source.get("height"): q = "{0}p".format(source.get("height")) elif source.get("avg_bitrate"): q = "{0}k".format(source.get("avg_bitrate") // 1000) else: q = "live" if ((source.get("type") == "application/x-mpegURL" and source.get("src")) or (source.get("src") and ".m3u8" in source.get("src"))): for s in HLSStream.parse_variant_playlist( self.session, source.get("src")).items(): yield s elif source.get("app_name"): s = RTMPStream( self.session, { "rtmp": source.get("app_name"), "playpath": source.get("stream_name") }) yield q, s elif source.get("src") and source.get("src").endswith(".mp4"): yield q, HTTPStream(self.session, source.get("src"))
def _get_streams(self): login_username = self.get_option("username") login_password = self.get_option("password") if login_username and login_password: self.logger.debug("Attempting login as {0}", login_username) if self._login(login_username, login_password): self.logger.info("Successfully logged in as {0}", login_username) else: self.logger.info("Failed to login as {0}", login_username) res = http.get(self.url) video = self._get_info(res.text) if not video: video = self._get_info_fallback(res.text) if video: self.logger.debug("Found {type}: {name}".format( type=video.get("type", self._vtype), name=video.get("name", "???"))) surl = self._get_stream_url(video["id"], video.get("type", self._vtype)) if surl: surl = surl.replace("_iphone", "") return HLSStream.parse_variant_playlist(self.session, surl) else: self.logger.error( "Could not get stream URL for video: {name} ({id})".format( id=video.get("id", "???"), name=video.get("name", "???"), )) else: self.logger.error("Could not find any video info on the page")
def _get_streams(self): headers = {"Referer": self.url, "User-Agent": useragents.FIREFOX} res = http.get(self.url, headers=headers) m = self._playlist_re.search(res.text) if not m: return res = http.get(m.group("url"), headers=headers) if not res.text.startswith("#EXTM3U"): hls_url = http.json(res).get("redir") else: hls_url = m.group("url") if hls_url is not None: self.logger.debug("HLS URL: {0}".format(hls_url)) streams = HLSStream.parse_variant_playlist(self.session, hls_url, headers=headers) if not streams: return { "live": HLSStream(self.session, hls_url, headers=headers) } else: return streams
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": url = update_scheme(self.url, source[u"src"]) 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_streams(self): data_url = http.get(self.url, schema=self._player_url_schema) if data_url: res = http.get(urljoin(self.url, data_url)) stream_info = http.xml(res, schema=self._livestream_schema) for stream in stream_info: url = stream["url"] try: if ".m3u8" in url: for s in HLSStream.parse_variant_playlist( self.session, url, name_key="bitrate").items(): yield s elif ".f4m" in url: for s in HDSStream.parse_manifest( self.session, url, pvswf=self.swf_url, is_akamai=True).items(): yield s elif ".mp4" in url: yield "{0}k".format(stream["bitrate"]), HTTPStream( self.session, url) except IOError as err: self.logger.warning("Error parsing stream: {0}", err)
def _get_vod_stream(self): vod_url = self.url if vod_url.endswith('/'): vod_url = vod_url[:-1] json_url = '{0}.securevideo.json'.format(vod_url) res = http.get(json_url) match = _json_re.search(res.text) if not match: return data = parse_json(match.group(1)) res = http.get(API_VOD.format(data['clientid'], data['mzid'])) data = http.json(res, schema=_stream_schema) for d in data['targetUrls']: if d['type'] == 'HDS': hds_url = d['url'] for s in HDSStream.parse_manifest(self.session, hds_url).items(): yield s if d['type'] == 'HLS': hls_url = d['url'] for s in HLSStream.parse_variant_playlist( self.session, hls_url).items(): yield s
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(r'\/', '/') except KeyError: continue stream = HLSStream.parse_variant_playlist(self.session, url) streams.update(stream) return streams
def _get_streams(self): res = http.get(self.url) match = self._video_id_re.search( res.text) or self._video_id_alt_re.search(res.text) if match is None: return broadcaster_id = match.group('broadcaster_id') video_type = match.group('video_type') video_id = match.group('video_id') videos = http.get(self.DACAST_API_URL.format(broadcaster_id, video_type, video_id), schema=self._api_schema) token = http.get(self.DACAST_TOKEN_URL.format(broadcaster_id, video_type, video_id), schema=self._token_schema) parsed = [] for video_url in videos: video_url += token # Ignore duplicate video URLs if video_url in parsed: continue parsed.append(video_url) # Ignore HDS streams (broken) if '.m3u8' in video_url: for s in HLSStream.parse_variant_playlist( self.session, video_url).items(): yield s
def _get_streams(self): http.headers = {"User-Agent": useragents.FIREFOX} login_username = self.get_option("username") login_password = self.get_option("password") if login_username and login_password: self.logger.debug("Attempting login as {0}".format(login_username)) if self._login(login_username, login_password): self.logger.info( "Successfully logged in as {0}".format(login_username)) else: self.logger.info( "Failed to login as {0}".format(login_username)) videopage = self._url_re.match(self.url).group("videopage") if not videopage: self.url = self.find_videopage() data = http.get(self.url, schema=self._data_schema) if not data.get("LiveStore"): self.logger.debug("No video url found, stream might be offline.") return data = data["LiveStore"]["lives"] # get the unknown user-id for _key in data.keys(): video_data = data.get(_key) owner = video_data["owner"] self.logger.info("Owner ID: {0}".format(owner["user_id"])) self.logger.debug("HLS URL: {0}".format(owner["hls_movie"])) for n, s in HLSStream.parse_variant_playlist( self.session, owner["hls_movie"]).items(): yield n, s performers = video_data.get("performers") if performers: for p in performers: self.logger.info("CO-HOST ID: {0}".format(p["user_id"])) hls_url = p["hls_movie"] self.logger.debug("HLS URL: {0}".format(hls_url)) for n, s in HLSStream.parse_variant_playlist( self.session, hls_url).items(): _n = "{0}_{1}".format(n, p["user_id"]) yield _n, s
def _get_streams(self): # Get video ID and channel from URL match = self._url_re.match(self.url) video_id = match.group('video_id') if video_id is None: # Retrieve URL page and search for video ID res = http.get(self.url) match = self._video_id_re.search(res.text) if match is None: return video_id = match.group('video_id') res = http.get(self.API_URL.format(video_id)) videos = http.json(res, schema=self._api_schema) parsed = [] headers = {'User-Agent': self._user_agent} # Some videos may be also available on Dailymotion (especially on CNews) if videos['ID_DM'] != '': for stream in self.session.streams('https://www.dailymotion.com/video/' + videos['ID_DM']).items(): yield stream for quality, video_url in list(videos['MEDIA']['VIDEOS'].items()): # Ignore empty URLs if video_url == '': continue # Ignore duplicate video URLs if video_url in parsed: continue parsed.append(video_url) try: # HDS streams don't seem to work for live videos if '.f4m' in video_url and 'LIVE' not in videos['TYPE']: for stream in HDSStream.parse_manifest(self.session, video_url, params={'hdcore': self.HDCORE_VERSION}, headers=headers).items(): yield stream elif '.m3u8' in video_url: for stream in HLSStream.parse_variant_playlist(self.session, video_url, headers=headers).items(): yield stream elif '.mp4' in video_url: # Get bitrate from video filename match = self._mp4_bitrate_re.match(video_url) if match is not None: bitrate = match.group('bitrate') else: bitrate = quality yield bitrate, HTTPStream(self.session, video_url, params={'secret': self.SECRET}, headers=headers) except IOError as err: if '403 Client Error' in str(err): self.logger.error('Failed to access stream, may be due to geo-restriction')
def _resolve_playlist(self, res, playlist_all): """ yield for _resolve_res Args: res: Content from self._res_text playlist_all: List of streams Returns: yield every stream """ # m_base is used for .f4m files that doesn't have a base_url m_base = self._stream_base_re.search(res) if m_base: stream_base = m_base.group("base") else: stream_base = "" playlist_list = self._make_url_list(playlist_all, self.url, stream_base) self.logger.debug("Found URL: {0}".format(", ".join(playlist_list))) endswith_blacklist = (".mp3", ".mp4", ".vtt") for url in playlist_list: if ".m3u8" in url and not url.endswith(endswith_blacklist): try: streams = HLSStream.parse_variant_playlist( self.session, url, headers=self.headers).items() if not streams: yield "live", HLSStream(self.session, url, headers=self.headers) for s in streams: yield s except Exception: self.logger.error("Skipping hls_url: {0}".format(url)) elif ".f4m" in url and not url.endswith(endswith_blacklist): try: for s in HDSStream.parse_manifest( self.session, url, headers=self.headers).items(): yield s except Exception: self.logger.error("Skipping hds_url: {0}".format(url)) elif self.list_in_item(url, [ ".mp3", ".mp4" ]) and not self.list_in_item(url, [".f4m", ".m3u8", ".mpd"]): try: name = "live" m = self._httpstream_bitrate_re.search(url) if m: name = "{0}k".format(m.group("bitrate")) yield name, HTTPStream(self.session, url, headers=self.headers) except Exception: self.logger.error("Skipping http_url: {0}".format(url)) elif ".mpd" in url and not url.endswith(endswith_blacklist): try: self.logger.info("Found mpd: {0}".format(url)) except Exception: self.logger.error("Skipping mpd_url: {0}".format(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): 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")