def _get_streams(self): if "empty" in self.url: return 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): """ Get the config object from the page source and call the API to get the list of streams :return: """ # attempt a login self.login() res = http.get(self.url) # decode the config for the page matches = self.config_re.finditer(res.text) try: config = self.config_schema.validate( dict([m.group("key", "value") for m in matches])) except PluginError: return if config["selectedVideoHID"]: self.logger.debug("Found video hash ID: {0}", config["selectedVideoHID"]) api_url = urljoin( self.url, urljoin(config["videosURL"], config["selectedVideoHID"])) elif config["livestreamURL"]: self.logger.debug("Found live stream URL: {0}", config["livestreamURL"]) api_url = urljoin(self.url, config["livestreamURL"]) else: return ares = http.get(api_url) data = http.json(ares, schema=self.api_schema) viewing_urls = data["viewing_urls"] if "error" in viewing_urls: self.logger.error("Failed to load streams: {0}", viewing_urls["error"]) else: for url in viewing_urls["urls"]: try: label = "{0}p".format(url.get("res", url["label"])) except KeyError: label = "live" if url["type"] == "rtmp/mp4" and RTMPStream.is_usable( self.session): params = { "rtmp": url["src"], "pageUrl": self.url, "live": True, } yield label, RTMPStream(self.session, params) elif url["type"] == "application/x-mpegURL": for s in HLSStream.parse_variant_playlist( self.session, url["src"]).items(): yield s
def test_rtmp_stream(self): stream = RTMPStream( self.session, { "rtmp": "rtmp://test.se/app/play_path", "swfVfy": "http://test.se/player.swf", "swfhash": "test", "swfsize": 123456, "playPath": "play_path" }) expected = "rtmp://test.se/app/play_path playPath=play_path swfUrl=http://test.se/player.swf swfVfy=1" self.assertEqual(expected, stream_to_url(stream)) self.assertEqual(expected, stream.to_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"] is 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 _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) 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, 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): url, params = parse_url_params(self.url) params["rtmp"] = url for boolkey in ("live", "realtime", "quiet", "verbose", "debug"): if boolkey in params: params[boolkey] = bool(params[boolkey]) self.logger.debug("params={0}", params) return {"live": RTMPStream(self.session, params)}
def _get_rtmp_streams(self, server, domain, channel, token): rtmp_server = self.rtmp_server_map.get(server, server) url = "rtmp://{0}/live?{1}".format(rtmp_server, token) yield "live", RTMPStream(self.session, params={ "rtmp": url, "pageUrl": self.url, "playpath": "{0}_{1}".format(self.name_remap.get(domain, "live"), channel), "live": True })
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 _create_rtmp_stream(self, rtmp, swf_url, bitrate): quality = self._get_quality(bitrate["label"]) url = bitrate["url"] stream = RTMPStream( self.session, { "rtmp": rtmp, "pageUrl": self.url, "playpath": url, "swfVfy": swf_url, "live": True }) return quality, stream
def _get_streams(self): match = _url_re.match(self.url) channel_name = match.group("channel") form = { "cid": channel_name, "watchTime": 0, "firstConnect": 1, "ip": "NaN" } res = http.post(API_URL, data=form, headers=HEADERS) params = parse_query(res.text, schema=_schema) if params["status"] <= 0: return if params["block_type"] != 0: if params["block_type"] == BLOCK_TYPE_VIEWING_LIMIT: msg = BLOCKED_MSG_FORMAT.format( params.get("block_time", "UNKNOWN"), params.get("reconnect_time", "UNKNOWN")) raise PluginError(msg) elif params["block_type"] == BLOCK_TYPE_NO_SLOTS: raise PluginError("No free slots available") else: raise PluginError("Blocked for unknown reasons") if "token" not in params: raise PluginError("Server seems busy, retry again later") streams = {} stream_names = ["sd"] if params["multibitrate"]: stream_names += ["hd"] for stream_name in stream_names: playpath = params["playpath"] if stream_name == "hd": playpath += "HI" stream = RTMPStream( self.session, { "rtmp": "{0}/{1}".format(params["rtmp"], playpath), "pageUrl": self.url, "swfVfy": SWF_URL, "weeb": params["token"], "live": True }) streams[stream_name] = stream return streams
def _get_plu_streams(self, cid): res = http.get(PLU_STREAM_INFO_URL % cid) info = http.json(res, schema=_plu_schema) for source in info["playLines"][0]["urls"]: quality = self._get_quality(source["resolution"]) if source["ext"] == "m3u8": yield quality, HLSStream(self.session, source["securityUrl"]) elif source["ext"] == "flv": yield quality, HTTPStream(self.session, source["securityUrl"]) elif source["ext"] == "rtmp": yield quality, RTMPStream(self.session, { "rtmp": source["securityUrl"], "live": True })
def _get_streams(self): match = _url_re.match(self.url) channel = match.group("channel") streamurl = getStreamURL(channel) if not streamurl: return streams = {} streams["live"] = RTMPStream(self.session, { "rtmp": streamurl, "live": True }) 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): res = http.get(self.url) match = self._videos_re.search(res.text) if match is not None: videos = self._videos_schema.validate(match.group('videos')) else: videos = self._get_embed_streams(res.text) for url in videos: if '.m3u8' in url: for stream in HLSStream.parse_variant_playlist( self.session, url).items(): yield stream elif 'rtmp' in url: yield 'vod', RTMPStream(self.session, {'rtmp': url}) elif '.mp4' in url: yield 'vod', HTTPStream(self.session, url)
def _get_streams(self): res = http.get(self.url, schema=_schema) streams = {} for url in res["urls"]: parsed = urlparse(url) if parsed.scheme.startswith("rtmp"): params = {"rtmp": url, "pageUrl": self.url, "live": True} if res["swf"]: params["swfVfy"] = res["swf"] stream = RTMPStream(self.session, params) streams["live"] = stream elif parsed.scheme.startswith("http"): name = splitext(parsed.path)[1][1:] stream = HTTPStream(self.session, url) streams[name] = stream return streams
def _get_rtmp(self, data): self.logger.debug('_get_rtmp ...') app = filter_urlquery(data['application'], new_dict={'media_token': data['media_token']}) host = data['host'] params = { 'app': app, 'flashVer': 'WIN 29,0,0,140', 'swfUrl': 'https://live.fc2.com/swf/liveVideo.swf', 'tcUrl': 'rtmp://{0}/{1}'.format(host, app), 'live': 'yes', 'pageUrl': self.url, 'playpath': data['play_rtmp_stream'], 'host': host, } yield 'live', RTMPStream(self.session, params)
def _get_streams(self): match = self._url_re.match(self.url) channel = match.group("channel") res = http.get(self.api_url.format(channel)) data = http.json(res) if data.get("errorCode") == 0: media = data.get("media") if media: rtmp_url = "rtmp://{host}{app}/{stream}".format( host=media["host"], app=media["app"], stream=media["stream"], ) params = {"rtmp": rtmp_url, "live": True} yield "live", RTMPStream(self.session, params=params)
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_live_streams(self, params, swf_url): for key, quality in QUALITY_MAP.items(): key_url = "{0}URL".format(key) url = params.get(key_url) if not url: continue try: res = http.get(url, exception=IOError) except IOError: continue if quality == "hds": self.logger.debug('PLAYLIST URL: {0}'.format(res.url)) try: streams = HDSStream.parse_manifest(self.session, res.url) except BaseException: streams = HLSStream.parse_variant_playlist( self.session, res.url) for name, stream in streams.items(): if key == "source": name += "+" yield name, stream elif res.text.startswith("rtmp"): match = _rtmp_re.match(res.text) if not match: continue stream = RTMPStream( self.session, { "rtmp": match.group("host"), "app": match.group("app"), "playpath": match.group("playpath"), "swfVfy": swf_url, "live": True }) yield quality, stream
def _get_streams(self): res = http.get(self.url) stream_urls = self.stream_schema.validate(res.text) self.logger.debug("Found {0} stream URL{1}", len(stream_urls), "" if len(stream_urls) == 1 else "s") for stream_url in stream_urls: if "m3u8" in stream_url: for _, s in HLSStream.parse_variant_playlist( self.session, stream_url).items(): yield "live", s if stream_url.startswith("rtmp://"): a = stream_url.split("///") s = RTMPStream( self.session, { "rtmp": a[0], "playpath": "live", "swfVfy": "http://www.tvr.by/plugines/uppod/uppod.swf", "pageUrl": self.url }) yield "live", s
def _create_rtmp_stream(self, video): swf_url = self._get_swf_url() if not swf_url: self.logger.debug("Unable to find SWF URL in the HTML") return name, stream_url = video params = { "rtmp": stream_url, "pageUrl": self.url, "swfVfy": swf_url, } if stream_url.endswith(".mp4"): tcurl, playpath = rtmpparse(stream_url) params["rtmp"] = tcurl params["playpath"] = playpath else: params["live"] = True return name, RTMPStream(self.session, params)
def _get_streams(self): res = http.get(self.live_iframe) britecove_url = self._find_iframe(res) if britecove_url: self.logger.debug("Found britecove embed url: {0}", britecove_url) params = self._britecove_params(britecove_url) self.logger.debug("Got britecode params: {0}", params) stream_info = self._get_stream_data(**params) for source in stream_info.get("sources"): if source.get("src"): for s in HLSStream.parse_variant_playlist( self.session, source.get("src")).items(): yield s else: q = "{0}p".format(source.get("height")) s = RTMPStream( self.session, { "rtmp": source.get("app_name"), "playpath": source.get("stream_name") }) yield q, s
def _get_streams(self): res = http.get(self.url) match = _playlist_url_re.search(res.text) if match is None: return res = http.get(match.group(1) + RUURL) sources = http.json(res, schema=_playlist_schema) streams = {} for source in sources: if source["type"] == "rtmp": streams["rtmp_live"] = RTMPStream(self.session, { "rtmp": source["streamer"], "pageUrl": self.url, "live": True }) elif source["type"] == "hls": streams.update(HLSStream.parse_variant_playlist(self.session, source["file"])) return streams
def _get_streams(self): res = http.get(self.url, headers={'User-Agent': useragents.ANDROID}) match = self._video_data_re.search(res.text) if match is None: return hls_streams = HLSStream.parse_variant_playlist( self.session, match.group('hls_url'), headers={'Referer': self.url}) for s in hls_streams.items(): yield s rtmp_video = self._flash_data_schema.validate( match.group('flash_data')) rtmp_stream = RTMPStream( self.session, { 'rtmp': rtmp_video['flashVars']['videoAppUrl'], 'playpath': rtmp_video['flashVars']['videoPlayUrl'], 'swfUrl': rtmp_video['playerUrl'] }) yield 'live', rtmp_stream
def _get_streams(self): match = _url_re.match(self.url) if not match: return channel_name = match.group(1) res = http.get(STREAMS_URL.format(channel_name)) streams = http.json(res, schema=_streams_schema) if streams["type"] not in ("multi", "stream"): return for stream in streams["data"]: if stream["slug"] != channel_name: continue if not stream["live"]: return streams = {} try: streams.update(HLSStream.parse_variant_playlist(self.session, HLS_URL.format(stream["id"]))) except IOError as e: # fix for hosted offline streams if "404 Client Error" in str(e): return raise streams["rtmp"] = RTMPStream(self.session, { "rtmp": RTMP_URL.format(stream["id"]), "pageUrl": self.url, "live": True }) return streams return
def _get_streams(self): match = _url_re.match(self.url) video_id = match.group("video_id") params = { "client_name": API_CLIENT_NAME, "context": API_CONTEXT, "raw_user_input": 1, "api_key": API_KEY, "vid": video_id, "r": random() } res = http.get(API_URL_VIDEO, params=params) video = http.json(res, schema=_video_schema) error = video.get("error") if error: raise PluginError(error) result = video.get("result") if not result: return url = result["url"] if url.startswith("http"): stream = HTTPStream(self.session, url) elif url.startswith("rtmp"): stream = RTMPStream( self.session, { "rtmp": url, "playpath": result["id"], "pageUrl": self.url, "live": True }) width, height = result["size"].split("x") name = "{0}p".format(height) return {name: stream}
def _get_streams(self): match = _url_re.match(self.url) channel = match.group("channel") headers = {"Referer": self.url} url = PLAYER_URL.format(channel) res = http.get(url, headers=headers, schema=_schema) if not res or "s" not in res: return streams = {} server = http.get(BALANCER_URL, headers=headers, schema=_rtmp_schema) playpath = "{0}?{1}".format(res["s"], res["id"]) streams["live"] = RTMPStream( self.session, { "rtmp": "rtmp://{0}/live/{1}".format(server, playpath), "pageUrl": self.url, "swfVfy": SWF_URL, "conn": "S:OK", "live": True }) return streams
def _get_live_stream(self, export_url): res = http.get(export_url) match = _live_json_re.search(res.text) if not match: return json = parse_json(match.group(1), schema=_live_schema) streams = {} for stream in json["streams"]: stream_name = stream["quality"] parsed = urlparse(stream["url"]) stream = RTMPStream( self.session, { "rtmp": stream["url"], "app": "{0}?{1}".format(parsed.path[1:], parsed.query), "playpath": stream["name"], "swfVfy": SWF_LIVE_URL, "pageUrl": self.url, "live": True }) streams[stream_name] = stream return streams