def _get_streams(self): username = self.get_option('username') password = self.get_option('password') if username is None or password is None: self.logger.error( "PC-YourFreeTV requires authentication, use --pcyourfreetv-username " "and --pcyourfreetv-password to set your username/password combination" ) return if self.login(username, password): self.logger.info("Successfully logged in as {0}", username) # Retrieve URL iframe res = http.get(self.url) match = self._iframe_re.search(res.text) if match is None: return res = http.get(match.group('iframe')) players = self._player_re.findall(res.text) if len(players) == 0 is None: return while len(players) > 0: player = unquote(players[-1]) players = self._player_re.findall(player) match = self._video_url_re.search(player) if match is None: return video_url = match.group('video_url') if '.m3u8' in video_url: streams = HLSStream.parse_variant_playlist(self.session, video_url) if len(streams) != 0: for stream in streams.items(): yield stream else: # Not a HLS playlist yield 'live', HLSStream(self.session, video_url)
def _get_streams(self): if "empty" in self.url: return if "UnsortableStreamNames" in self.url: def gen(): for i in range(3): yield "vod", HTTPStream(self.session, "http://test.se/stream") return gen() if "NoStreamsError" in self.url: raise NoStreamsError(self.url) streams = {} streams["test"] = TestStream(self.session) streams["rtmp"] = RTMPStream(self.session, dict(rtmp="rtmp://test.se")) streams["hls"] = HLSStream(self.session, "http://test.se/playlist.m3u8") streams["http"] = HTTPStream(self.session, "http://test.se/stream") streams["akamaihd"] = AkamaiHDStream(self.session, "http://test.se/stream") streams["240p"] = HTTPStream(self.session, "http://test.se/stream") streams["360p"] = HTTPStream(self.session, "http://test.se/stream") streams["1080p"] = HTTPStream(self.session, "http://test.se/stream") streams["350k"] = HTTPStream(self.session, "http://test.se/stream") streams["800k"] = HTTPStream(self.session, "http://test.se/stream") streams["1500k"] = HTTPStream(self.session, "http://test.se/stream") streams["3000k"] = HTTPStream(self.session, "http://test.se/stream") streams["480p"] = [ HTTPStream(self.session, "http://test.se/stream"), RTMPStream(self.session, dict(rtmp="rtmp://test.se")) ] streams.update(testplugin_support.get_streams(self.session)) return streams
def _get_streams(self): res = self.session.http.get(self.url) m = self._roomid_re.search(res.text) if m: room_id = m.group(1) else: room_id = self.match.group("room_id") res = self.session.http.get( "https://fx2.service.kugou.com/video/pc/live/pull/v3/streamaddr", params={ "ch": "fx", "version": "1.0", # 1=rtmp, 2=httpflv, 3=hls, 5=httpsflv, 6=httpshls "streamType": "1-2-5-6", "ua": "fx-flash", "kugouId": "0", "roomId": room_id, "_": int(time.time()), }) stream_data_json = self.session.http.json( res, schema=self._stream_data_schema) log.trace("{0!r}".format(stream_data_json)) if stream_data_json["code"] != 0 or stream_data_json["data"][ "status"] != 1: return h = stream_data_json["data"]["horizontal"] v = stream_data_json["data"]["vertical"] stream_data = h[0] if h else v[0] if stream_data.get("httpshls"): for hls_url in stream_data["httpshls"]: s = HLSStream.parse_variant_playlist(self.session, hls_url) if not s: yield "live", HLSStream(self.session, hls_url) else: yield from s.items() if stream_data.get("httpsflv"): for http_url in stream_data["httpsflv"]: yield "live", HTTPStream(self.session, http_url)
def _get_streams(self): url_m = self.url_re.match(self.url) channel = url_m and url_m.group("channel") vod_id = url_m and url_m.group("vod_id") is_group = url_m and url_m.group("is_group") if vod_id: data = self.api.vod(vod_id) for _, stream in data["streams"].items(): streams = HLSStream.parse_variant_playlist(self.session, stream["url"]) if not streams: yield stream["quality"], HLSStream(self.session, stream["url"]) else: yield from streams.items() else: if channel and not channel.isdigit(): _id = self.cache.get(channel) if _id is None: _id = self.session.http.get(self.url, schema=self._channel_id_schema) log.debug(f"Found channel ID: {_id}") # do not cache a group url if _id and not is_group: self.cache.set(channel, _id, expires=self.TIME_CHANNEL) else: log.debug(f"Found cached channel ID: {_id}") else: _id = channel if _id is None: raise PluginError("Unable to find channel ID: {0}".format(channel)) try: data = self.api.channel(_id) for stream in data["streams"]: yield stream["quality"], FilmOnHLS(self.session, channel=_id, quality=stream["quality"]) except Exception: if channel and not channel.isdigit(): self.cache.set(channel, None, expires=0) log.debug(f"Reset cached channel: {channel}") raise
def _get_streams(self): api_urls = self.session.http.get(self.url, schema=self.channel_id_schema) _api_url = list(api_urls)[0] log.debug("API URL: {0}".format(_api_url)) player_api_url = self.session.http.get(_api_url, schema=self.player_api_schema) for api_url in player_api_url: log.debug("Player API URL: {0}".format(api_url)) for source in self.session.http.get(api_url, schema=self.stream_schema): log.debug("Stream source: {0} ({1})".format(source['src'], source.get("type", "n/a"))) if "type" not in source or source["type"] == "application/vnd.apple.mpegurl": streams = HLSStream.parse_variant_playlist(self.session, source["src"]) if not streams: yield "live", HLSStream(self.session, source["src"]) else: for s in streams.items(): yield s elif source["type"] == "application/dash+xml": for s in DASHStream.parse_manifest(self.session, source["src"]).items(): yield s
def _get_streams(self): streams = self.session.http.get(self.url, schema=self._stream_schema) for stream in streams: if stream["stream-type"] == "hls": streams = HLSStream.parse_variant_playlist(self.session, stream["url"]).items() if streams: for s in streams: yield s else: yield "live", HLSStream(self.session, stream["url"]) elif stream["stream-type"] == "rtmp": yield "0_live", RTMPStream(self.session, {"rtmp": stream["url"]}) elif stream["stream-type"] == "endpoint": res = self.session.http.get(stream["url"]) files = self.session.http.json(res, schema=self._endpoint_schema) for f in files: s = HTTPStream(self.session, f["file"]) yield "vod", s elif stream["stream-type"] == "mp4": yield "vod", HTTPStream(self.session, stream["url"])
def _get_streams(self): channel = self.match.group("channel") res = self.session.http.get(API_URL.format(channel)) room = self.session.http.json(res, schema=_room_schema) if not room: log.info("Not a valid room url.") return if room["status"] != STATUS_ONLINE: log.info("Stream currently unavailable.") return url = "http://wshdl.load.cdn.zhanqi.tv/zqlive/{room[videoId]}.flv?get_url=".format(room=room) stream = HTTPStream(self.session, url) yield "live", stream url = "http://dlhls.cdn.zhanqi.tv/zqlive/{room[videoId]}_1024/index.m3u8?Dnion_vsnae={room[videoId]}".format(room=room) stream = HLSStream(self.session, url) yield "live", stream
def test_get_streams(self, hlsstream, mock_get_stream_data): mock_get_stream_data.return_value = { "stream": "http://test.se/stream1" } page_resp = Mock() page_resp.text = u""" <div class="video-js theoplayer-skin theo-seekbar-above-controls content-box vjs-fluid" data-resource= "bbcone" data-token = "1324567894561268987948596154656418448489159" data-content-type="live" data-environment="live" data-subscription="free" data-channel-id="89"> <div id="channel-info" class="channel-info"> <div class="row visible-xs visible-sm"> """ self.session.http.get.return_value = page_resp hlsstream.parse_variant_playlist.return_value = { "test": HLSStream(self.session, "http://test.se/stream1") } TVPlayer.bind(self.session, "test.tvplayer") plugin = TVPlayer("http://tvplayer.com/watch/dave") streams = plugin.get_streams() self.assertTrue("test" in streams) # test the url is used correctly self.session.http.get.assert_called_with( "http://tvplayer.com/watch/dave") # test that the correct API call is made mock_get_stream_data.assert_called_with( resource="bbcone", channel_id="89", token="1324567894561268987948596154656418448489159") # test that the correct URL is used for the HLSStream hlsstream.parse_variant_playlist.assert_called_with( ANY, "http://test.se/stream1")
def _get_streams(self): is_live = False if not self.video_id: self.video_id, self.pl_id = self._find_video_id(self.url) info = self._get_stream_info(self.video_id, self.pl_id) if not info: log.error("Could not get video info") return if info.get("is_live"): log.debug("This video is live.") is_live = True streams = {} for stream_info in info.get("formats", []): itag = int(stream_info["format_id"]) if itag not in self.video: if is_live: log.debug( "Skipped format:{}, Codecs: v {} a {}", stream_info["format"], stream_info["vcodec"], stream_info["acodec"], ) continue url = stream_info["url"] name = self.video[itag] if stream_info.get("protocol", "") != "m3u8": stream = HTTPStream(self.session, url) streams[name] = stream else: stream = HLSStream(self.session, url) streams[name] = stream if not is_live and not self.get_option("no-adaptive-streams"): streams = self._create_adaptive_streams(info, streams) else: log.info("Adaptive streams are skipped") return streams
def _get_streams(self): log.debug('Version 2018-07-12') log.info('This is a custom plugin. ' 'For support visit https://github.com/back-to/plugins') headers = {'Referer': self.url, 'User-Agent': useragents.FIREFOX} self.session.http.headers.update(headers) match = self._url_re.match(self.url) channel = match.group('channel') if not channel: channel = (match.group('domain2') or match.group('channel2') or match.group('domain')) try: channel = self.channel_map[channel] except KeyError: log.error('This channel is currently not supported.') cdn = random.choice(['cdn8', 'edge1', 'edge3']) query_e = 'e={0}'.format(int(time.time())) server = random.choice(['9', '10']) hls_url = 'https://mobdrm.1tv.ru/hls-live{server}/streams/{channel}/{channel}.m3u8?cdn=https://{cdn}.1internet.tv&{query}'.format( cdn=cdn, channel=channel, query=query_e, server=server, ) res = self.session.http.get(self.API_HLS_SESSION) json_session = self.session.http.json(res, schema=self._session_schema) hls_url = '{url}&s={session}'.format(url=hls_url, session=json_session['s']) if hls_url: log.debug('HLS URL: {0}'.format(hls_url)) streams = HLSStream.parse_variant_playlist( self.session, hls_url, name_fmt='{pixels}_{bitrate}') if not streams: return {'live': HLSStream(self.session, hls_url)} else: return streams
def test_get_streams(self, hlsstream, mock_http): api_data = { "tvplayer": { "status": "200 OK", "response": { "stream": "http://test.se/stream1" } } } page_resp = Mock() page_resp.text = u""" var validate = "foo"; var resourceId = "1234"; var platform = "test"; """ api_resp = Mock() api_resp.text = json.dumps(api_data) mock_http.get.return_value = page_resp mock_http.post.return_value = api_resp mock_http.json.return_value = api_data hlsstream.parse_variant_playlist.return_value = { "test": HLSStream(None, "http://test.se/stream1") } plugin = TVPlayer("http://tvplayer.com/watch/dave") streams = plugin.get_streams() self.assertTrue("test" in streams) # test the url is used correctly mock_http.get.assert_called_with("http://tvplayer.com/watch/dave", headers=ANY) # test that the correct API call is made mock_http.post.assert_called_with( "http://api.tvplayer.com/api/v2/stream/live", data=dict(id=u"1234", validate=u"foo", platform=u"test")) # test that the correct URL is used for the HLSStream hlsstream.parse_variant_playlist.assert_called_with( ANY, "http://test.se/stream1", headers=ANY)
def _get_streams(self): api = self._create_api() match = _url_re.match(self.url) media_id = int(match.group("media_id")) try: # the media.stream_data field is required, no stream data is returned otherwise 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 = self.session.http.get(self.url) m = self._source_re.search(res.text) or self._yt_source_re.search( res.text) if m: if ".m3u8" in m.group(2): url = urljoin(self._HD_AUTH_BASE, m.group(2)) url = url.replace("livee.", "live.") log.debug(url) streams = HLSStream.parse_variant_playlist(self.session, url) if not streams: return {"live": HLSStream(self.session, url)} else: return streams elif m.group(1) == "videoId": url = "youtube.com/embed/{0}".format(m.group(2)) return self.session.streams(url) elif m: raise PluginError("Unexpected source format: {0}".format( m.group(1))) else: raise PluginError("Could not extract source.")
def _get_streams(self): headers = {"User-Agent": useragents.CHROME} res = http.get(self.url, headers=headers) url_match = RTPPlay._m3u8_re.search(res.text) if url_match: hls_url = url_match.group("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): channel = self.match.group("channel") self.session.http.headers.update({"User-Agent": USER_AGENT}) self.session.http.verify = False feed_json = self.session.http.get(HUAJIAO_URL.format(channel), schema=_feed_json_schema) if feed_json['feed']['m3u8']: stream = HLSStream(self.session, feed_json['feed']['m3u8']) else: sn = feed_json['feed']['sn'] channel_sid = feed_json['relay']['channel'] sid = uuid.uuid4().hex.upper() encoded_json = self.session.http.get( LAPI_URL.format(channel_sid, sn, sid, time.time(), random.random())).content decoded_json = base64.decodestring( encoded_json[0:3] + encoded_json[6:]).decode('utf-8') video_data = json.loads(decoded_json) stream = HTTPStream(self.session, video_data['main']) yield "live", stream
def _get_streams(self): match = _url_re.match(self.url) if not match: return channel_name = match.group(1) res = self.session.http.get(STREAMS_URL) streams = self.session.http.json(res, schema=_streams_schema) for stream in streams: if stream["slug"] != channel_name: continue if not stream["live"]: return log.debug("HLS stream URL: {}", HLS_URL.format(stream["id"])) return { "live": HLSStream(self.session, HLS_URL.format(stream["id"])) }
def _get_streams(self): headers = {"Referer": self.url} res = http.get(self.url, headers=headers) match = _ddos_re.search(res.text) if (match): headers["Cookie"] = match.group(1) res = http.get(self.url, headers=headers) match = _stream_re.search(res.text) if not match: return stream_id = match.group(1) streams = {} for name, url_suffix in QUALITIES.items(): url = HLS_URL_FORMAT.format(stream_id, url_suffix) if not self._check_stream(url): continue streams[name] = HLSStream(self.session, url) return streams
def _get_streams(self): self.session.http.headers.update({'User-Agent': useragents.IPHONE_6}) self.follow_vk_redirect() video_id = self.match.group('video_id') log.debug('video ID: {0}'.format(video_id)) params = { 'act': 'show_inline', 'al': '1', 'video': video_id, } res = self.session.http.post(self.API_URL, params=params) for _i in itertags(res.text, 'iframe'): if _i.attributes.get('src'): iframe_url = update_scheme(self.url, _i.attributes['src']) log.debug('Found iframe: {0}'.format(iframe_url)) yield from self.session.streams(iframe_url).items() for _i in itertags(res.text.replace('\\', ''), 'source'): if _i.attributes.get('type') == 'application/vnd.apple.mpegurl': video_url = html_unescape(_i.attributes['src']) streams = HLSStream.parse_variant_playlist( self.session, video_url) if not streams: yield 'live', HLSStream(self.session, video_url) else: yield from streams.items() elif _i.attributes.get('type') == 'video/mp4': q = 'vod' video_url = _i.attributes['src'] m = self._vod_quality_re.search(video_url) if m: q = '{0}p'.format(m.group(1)) yield q, HTTPStream(self.session, video_url)
def _get_streams(self): res = self.url streamname = _url_re.search(res).group(1) ci = http.get(API_URL.format(channel=streamname)) api_json = json.loads(ci.text) if not api_json or len(api_json) == 0: self.logger.error( "The channel {0} does not exist or is marked private".format( streamname)) return if api_json[0]["online"] == False: self.logger.error( "The channel {0} is not online".format(streamname)) return streams = {} stream = RTMPStream( self.session, { "rtmp": ROOT_URL.format(streamname), "pageUrl": PAGE_URL, "live": True, "app": "live", "flashVer": "LNX 11,2,202,280", "swfVfy": "https://www.tigerdile.com/wp-content/jwplayer.flash.swf", "playpath": streamname, }) streams["live"] = stream stream_hls = HLSStream(self.session, HLS_URL.format(channel=streamname)) streams["live_hls"] = stream_hls return streams
def __parse_video_stream(self, url): html = self.session.http.get(url) vid = Douyutv.__valid_address(html.text, '"vid":"([^"]*)"', str) if not vid: self.logger.warn( "{target} is recognized by Douyutv, but not valid.".format( target=url)) return pid = Douyutv.simple_re_validate(html.text, "point_id", r'"point_id":(\d+)', 1, int) # self.logger.debug("vid: %s pid: %s"%(vid, pid)) sign = self.__generate_sign(html.text, pid) sign['vid'] = vid res = self.session.http.post(VAPI_URL, data=sign, cookies={"dy_did": sign['did']}) # self.logger.debug(res.json()) video = self.session.http.json(res, schema=_video_schema) for source, addr in video.items(): self.logger.debug("m3u8: name:{name}, addres:{address}".format( name=source, address=addr)) yield source, HLSStream(self.session, addr)
def _get_streams(self): res = self.session.http.get(self.url) # some pages have embedded players iframe_m = self.iframe_re.search(res.text) if iframe_m: url = urljoin(self.url, iframe_m.group("url")) res = self.session.http.get(url) video = self.src_re.search(res.text) stream_src = video and video.group("url") if stream_src and stream_src.endswith("m3u8"): # do not open empty m3u8 files if len(self.session.http.get(stream_src).text) <= 10: log.error("This stream is currently offline") return log.debug("URL={0}".format(stream_src)) streams = HLSStream.parse_variant_playlist(self.session, stream_src) if not streams: return {"live": HLSStream(self.session, stream_src)} else: return streams
def _get_streams(self): self.session.http.headers = { "Referer": self.url, "User-Agent": "Mozilla" } # This cookie encodes the user agent above. Don't change them! self.session.http.cookies.set('STC', 'a4f963d2c0680cb534f626ae56a4609d') html = self.session.http.get(self.url).text if html: body = get_js(html) if body: for item in body: if item.expression and item.expression.arguments: for item in item.expression.arguments: if item.body and item.body.body: for item in item.body.body: if item.expression and item.expression.arguments: for item in item.expression.arguments: if item.properties: for item in item.properties: if item.key.name and item.key.name == 'source': stream_url = item.value.value log.debug("Stream URL: {0}".format(stream_url)) yield "live", HLSStream(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_streams(self): match = _url_re.match(self.url) channel = match.group("channel") self.session.http.headers.update({'User-Agent': useragents.CHROME, 'Referer': self.url}) payload = '{"liveStreamID": "%s"}' % (channel) res = self.session.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) https_url = http_url.replace("http:", "https:") yield "live", HTTPStream(self.session, https_url) if 'pull-rtmp' in http_url: rtmp_url = http_url.replace("http:", "rtmp:").replace(".flv", "") stream = RTMPStream(self.session, { "rtmp": rtmp_url, "live": True, "pageUrl": self.url, }) yield "live", stream if 'wansu-' in http_url: hls_url = http_url.replace(".flv", "/playlist.m3u8") else: hls_url = http_url.replace("live-hdl", "live-hls").replace(".flv", ".m3u8") 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)
def _make_stream(self, url): if url and url.endswith("flv"): return HTTPStream(self.session, url) elif url and url.endswith("m3u8"): return HLSStream(self.session, url)
def _get_streams(self): match = _url_re.match(self.url) page = match.group("page") channel = match.group("channel") http.headers.update({'User-Agent': useragents.CHROME}) if page == 'user': res = http.get(self.url) userid = _userid_re.search(res.text).group(1) api = http.post(API_URL, data={"targetUserID": userid}) data = http.json(api, schema=_user_api_schema) rid = data["liveStreamID"] if rid == 0: self.logger.info("Stream currently unavailable.") return url = ROOM_URL.format(rid) res = http.get(url) elif page == 'profile': api = http.post(API_URL, data={"targetUserID": channel}) data = http.json(api, schema=_user_api_schema) rid = data["liveStreamID"] if rid == 0: self.logger.info("Stream currently unavailable.") return url = ROOM_URL.format(rid) res = http.get(url) else: res = http.get(self.url) status = _status_re.search(res.text) if not status: return if status.group(1) != 'true': self.logger.info("Stream currently unavailable.") return url = _rtmp_re.search(res.text).group(1) if 'rtmp:' in url: stream = RTMPStream(self.session, { "rtmp": url, "live": True }) yield "live", stream else: yield "live", HTTPStream(self.session, url) if '17app.co' in url: prefix = url.replace("rtmp:", "http:").replace(".flv", "/playlist.m3u8") if '/playlist.m3u8' not in prefix: url = prefix + "/playlist.m3u8" else: url = prefix for stream in HLSStream.parse_variant_playlist(self.session, url).items(): yield stream else: url = url.replace(".flv", ".m3u8") yield "live", HLSStream(self.session, url)
def test_hls_stream(self): expected = "http://test.se/stream.m3u8" stream = HLSStream(self.session, expected) self.assertEqual(expected, stream_to_url(stream)) self.assertEqual(expected, stream.to_url())
def ytdl_fallback(self): '''Basic support for m3u8 URLs with youtube-dl''' log.debug(f'Fallback {youtube_dl.__name__} {youtube_dl.version.__version__}') class YTDL_Logger(object): def debug(self, msg): log.debug(msg) def warning(self, msg): log.warning(msg) def error(self, msg): log.trace(msg) ydl_opts = { 'call_home': False, 'forcejson': True, 'logger': YTDL_Logger(), 'no_color': True, 'noplaylist': True, 'no_warnings': True, 'verbose': False, 'quiet': True, } with youtube_dl.YoutubeDL(ydl_opts) as ydl: try: info = ydl.extract_info(self.url, download=False) except Exception: return if not info or not info.get('formats'): return self.title = info['title'] streams = [] for stream in info['formats']: if stream['protocol'] in ['m3u8', 'm3u8_native'] and stream['ext'] == 'mp4': log.trace('{0!r}'.format(stream)) name = stream.get('height') or stream.get('width') if name: name = '{0}p'.format(name) streams.append((name, HLSStream(self.session, stream['url'], headers=stream['http_headers']))) if not streams: if ('youtube.com' in self.url and info.get('requested_formats') and len(info.get('requested_formats')) == 2 and MuxedStream.is_usable(self.session)): audio_url = audio_format = video_url = video_format = video_name = None for stream in info.get('requested_formats'): if stream.get('format_id') == '135': url = stream.get('manifest_url') if not url: return return DASHStream.parse_manifest(self.session, url).items() if not stream.get('height'): audio_url = stream.get('url') audio_format = stream.get('format_id') if stream.get('height'): video_url = stream.get('url') video_format = stream.get('format_id') video_name = '{0}p'.format(stream.get('height')) log.debug('MuxedStream: v {video} a {audio} = {name}'.format( audio=audio_format, name=video_name, video=video_format, )) streams.append((video_name, MuxedStream(self.session, HTTPStream(self.session, video_url, headers=stream['http_headers']), HTTPStream(self.session, audio_url, headers=stream['http_headers'])) )) return streams
def _resolve_playlist(self, playlist_all): playlist_referer = self.get_option('playlist_referer') or self.url self.session.http.headers.update({'Referer': playlist_referer}) playlist_max = self.get_option('playlist_max') or 5 count_playlist = { 'dash': 0, 'hls': 0, 'http': 0, } o = urlparse(self.url) origin_tuple = ( '.cloudfront.net', ) for url in playlist_all: parsed_url = urlparse(url) if parsed_url.netloc.endswith(origin_tuple): self.session.http.headers.update({ 'Origin': '{0}://{1}'.format(o.scheme, o.netloc), }) if (parsed_url.path.endswith(('.m3u8')) or parsed_url.query.endswith(('.m3u8'))): if count_playlist['hls'] >= playlist_max: log.debug('Skip - {0}'.format(url)) continue try: streams = HLSStream.parse_variant_playlist(self.session, url).items() if not streams: yield 'live', HLSStream(self.session, url) for s in streams: yield s log.debug('HLS URL - {0}'.format(url)) count_playlist['hls'] += 1 except Exception as e: log.error('Skip HLS with error {0}'.format(str(e))) elif (parsed_url.path.endswith(('.mp3', '.mp4')) or parsed_url.query.endswith(('.mp3', '.mp4'))): if count_playlist['http'] >= playlist_max: log.debug('Skip - {0}'.format(url)) continue try: name = 'vod' m = self._httpstream_bitrate_re.search(url) if m: bitrate = m.group('bitrate') resolution = m.group('resolution') if bitrate: if bitrate in self._httpstream_common_resolution_list: name = '{0}p'.format(m.group('bitrate')) else: name = '{0}k'.format(m.group('bitrate')) elif resolution: name = resolution yield name, HTTPStream(self.session, url) log.debug('HTTP URL - {0}'.format(url)) count_playlist['http'] += 1 except Exception as e: log.error('Skip HTTP with error {0}'.format(str(e))) elif (parsed_url.path.endswith(('.mpd')) or parsed_url.query.endswith(('.mpd'))): if count_playlist['dash'] >= playlist_max: log.debug('Skip - {0}'.format(url)) continue try: for s in DASHStream.parse_manifest(self.session, url).items(): yield s log.debug('DASH URL - {0}'.format(url)) count_playlist['dash'] += 1 except Exception as e: log.error('Skip DASH with error {0}'.format(str(e))) else: log.error('parsed URL - {0}'.format(url))
def _get_streams(self): """ Find the streams for vk.com :return: """ # If this is a 'videos' catalog URL with an video ID in the GET request, get that instead url = self.follow_vk_redirect(self.url) if url != self.url: self.logger.debug('Grabbing data from real video page at {}', url) headers = {} res = http.get(url, headers=headers) headers["Referer"] = url # Try and find an HLS source (livestream) stream_urls = self._livestream_sources_re.findall(res.text) if len(stream_urls): stream_url = stream_urls[0].replace('\/', '/') self.logger.debug("Found live stream at {}", stream_url) try: # try to parse the stream as a variant playlist variant = HLSStream.parse_variant_playlist(self.session, stream_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, stream_url, headers=headers) except IOError: self.logger.warning( "Could not open the stream, perhaps the channel is offline" ) return # Try and find a set of MP4 sources (VOD) vod_urls = self._vod_sources_re.findall(res.text) if len(vod_urls): vod_urls = [v.replace('\/', '/') for v in vod_urls] # Try to get quality from URL qualities = {} for s in vod_urls: q = self._vod_quality_re.findall(s) if not len(q): break qualities[s] = q[0] try: if len(qualities) == len(vod_urls): for s in vod_urls: yield qualities[s] + 'p', HTTPStream(self.session, s) else: # Fall back to numerical ranking for q, s in enumerate(vod_urls): yield str(q), HTTPStream(self.session, s) except IOError: self.logger.warning( "Could not open the stream, perhaps the channel is offline" )