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 _get_streams(self): http.headers.update({'User-Agent': useragents.FIREFOX}) log.debug('Version 2018-07-01') log.info('This is a custom plugin. ' 'For support visit https://github.com/back-to/plugins') res = http.get(self.url) m = self._token_re.search(res.text) if not m: raise PluginError('No token found.') data = { '_method': 'PATCH', '_token': m.group('data') } http.post(self.verify_url, data=data) res = http.get(self.url) m = self._hls_re.search(res.text) if not m: log.debug('No video url found.') return hls_url = m.group('url') log.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
def _get_streams(self): match = _url_re.match(self.url) channel = match.group("channel") http.headers.update({'User-Agent': useragents.CHROME}) http.verify = False http.mount('https://', HTTPAdapter(max_retries=99)) #Thanks to @ximellon for providing method. try: channel = int(channel) except ValueError: channel = http.get(self.url, schema=_room_id_schema) if channel == 0: channel = http.get(self.url, schema=_room_id_alt_schema) res = http.get(MAPI_URL.format(channel)) room = http.json(res, schema=_room_schema) if not room: self.logger.info("Not a valid room url.") return if room["show_status"] != SHOW_STATUS_ONLINE: self.logger.info("Stream currently unavailable.") return ts = int(time.time() / 60) did = uuid.uuid4().hex.upper() sign = hashlib.md5( ("{0}{1}{2}{3}".format(channel, did, LAPI_SECRET, ts)).encode("utf-8")).hexdigest() data = {"cdn": "ws", "rate": "0", "tt": ts, "did": did, "sign": sign} res = http.post(LAPI_URL.format(channel), data=data) room = http.json(res, schema=_lapi_schema) url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room) stream = HTTPStream(self.session, url) yield "source", stream data = {"cdn": "ws", "rate": "2", "tt": ts, "did": did, "sign": sign} res = http.post(LAPI_URL.format(channel), data=data) room = http.json(res, schema=_lapi_schema) url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room) stream = HTTPStream(self.session, url) yield "middle", stream data = {"cdn": "ws", "rate": "1", "tt": ts, "did": did, "sign": sign} res = http.post(LAPI_URL.format(channel), data=data) room = http.json(res, schema=_lapi_schema) url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room) stream = HTTPStream(self.session, url) yield "low", stream
def _login(self, username, password): '''login and update cached cookies''' log.debug('login ...') http.get(self.url) data = { 'pass': password, 'email': username, 'done': 'livechat', 'keep_login': 1 } http.post(self.url_login, data=data, allow_redirects=True) cookies_list = self.save_cookies() return self.cmp_cookies_list(cookies_list)
def _get_live_streams(self, lang, path): """ Get the live stream in a particular language :param lang: :param path: :return: """ res = http.get(self._live_api_url.format(lang, path)) live_res = http.json(res)['default']['uid'] post_data = '{"channel_url":"/api/channels/%s/"}' % live_res try: stream_data = http.json(http.post(self._stream_get_url, data=post_data))['stream_url'] except: stream_data = http.json(http.post(self._stream_get_url, data=post_data))['channel_url'] return HLSStream.parse_variant_playlist(self.session, stream_data)
def _get_live_streams(self, lang, path): """ Get the live stream in a particular language :param lang: :param path: :return: """ res = http.get(self._live_api_url.format(lang, path)) live_res = http.json(res)['default']['uid'] post_data = '{"channel_url":"/api/channels/%s/"}' % live_res try: stream_data = http.json(http.post(self._stream_get_url, data=post_data))['stream_url'] except BaseException: stream_data = http.json(http.post(self._stream_get_url, data=post_data))['channel_url'] return HLSStream.parse_variant_playlist(self.session, stream_data)
def _get_streams(self): if self.get_option("email") and self.get_option("password"): self.logger.debug("Logging in as {0}".format(self.get_option("email"))) if not self.authenticate(self.get_option("email"), self.get_option("password")): self.logger.warning("Failed to login as {0}".format(self.get_option("email"))) # find the list of channels from the html in the page self.url = self.url.replace("https", "http") # https redirects to http res = http.get(self.url) if "enter your postcode" in res.text: self.logger.info("Setting your postcode to: {0}. " "This can be changed in the settings on tvplayer.com", self.dummy_postcode) res = http.post(self.update_url, data=dict(postcode=self.dummy_postcode), params=dict(return_url=self.url)) stream_attrs = self._get_stream_attrs(res) if stream_attrs: stream_data = self._get_stream_data(**stream_attrs) if stream_data: if stream_data.get("drmToken"): self.logger.error("This stream is protected by DRM can cannot be played") return else: return HLSStream.parse_variant_playlist(self.session, stream_data["stream"]) else: if "need to login" in res.text: self.logger.error( "You need to login using --tvplayer-email/--tvplayer-password to view this stream")
def login(self, ptrt_url): """ Create session using BBC ID. See https://www.bbc.co.uk/usingthebbc/account/ :param ptrt_url: The snapback URL to redirect to after successful authentication :type ptrt_url: string :return: Whether authentication was successful :rtype: bool """ session_res = http.get( self.session_url, params=dict(ptrt=ptrt_url) ) http_nonce = self._extract_nonce(session_res) res = http.post( self.auth_url, params=dict( ptrt=ptrt_url, nonce=http_nonce ), data=dict( jsEnabled=True, username=self.get_option("username"), password=self.get_option('password'), attempts=0 ), headers={"Referer": self.url}) return len(res.history) != 0
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_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): 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(".flv", ".m3u8") yield "live", HLSStream(self.session, url)
def _login(self, email, password, _hello): self.logger.debug('_login ... Attempting login as {0}'.format(email)) login_url = self.API_LOGIN.format(self.base_url) params = {'login': email, 'password': password, 'remember': 'true'} res = http.post(login_url, headers=self.headers, data=params, cookies=_hello.cookies) data = http.json(res) self._authed = data['success'] if self._authed: self.logger.debug('New Session Data') self._session_attributes.set('beaker.session.id', res.cookies.get('beaker.session.id'), expires=3600 * 24) self._session_attributes.set('pzuid', res.cookies.get('pzuid'), expires=3600 * 24) self._session_attributes.set('power_guide_hash', data['session']['power_guide_hash'], expires=3600 * 24) return self._authed else: return None
def _post_api(self, api, payload, schema): res = http.post(api, json=payload) data = http.json(res, schema=schema) if data["result"] == "success": post_data = data["reply"] return post_data
def login(self, username, password): res = http.post(self.login_url, data={ "username": username, "password": password }) return res.text.startswith("success")
def from_player_key(cls, session, player_id, player_key, video_id, url=None): amf_message = AMFMessage("com.brightcove.experience.ExperienceRuntimeFacade.getDataForExperience", "/1", [ ''.join(["{0:02x}".format(random.randint(0, 255)) for _ in range(20)]), # random id ViewerExperienceRequest(experienceId=int(player_id), URL=url or "", playerKey=player_key, deliveryType=float('nan'), TTLToken="", contentOverrides=[ContentOverride( featuredRefId=None, contentRefIds=None, contentId=int(video_id) )]) ]) amf_packet = AMFPacket(version=3) amf_packet.messages.append(amf_message) res = http.post(cls.amf_broker, headers={"Content-Type": "application/x-amf"}, data=amf_packet.serialize(), params=dict(playerKey=player_key), raise_for_status=False) data = AMFPacket.deserialize(BytesIO(res.content)) result = data.messages[0].value bp = cls(session=session, account_id=int(result.publisherId)) return bp.get_streams(video_id)
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 login(self, ptrt_url, context="tvandiplayer"): # get the site config, to find the signin url config = http.get(self.config_url, params=dict(ptrt=ptrt_url), schema=self.config_schema) res = http.get(config["signin_url"], params=dict(userOrigin=context, context=context), headers={"Referer": self.url}) m = self.account_locals_re.search(res.text) if m: auth_data = parse_json(m.group(1)) res = http.post(self.auth_url, params=dict(context=auth_data["userOrigin"], ptrt=auth_data["ptrt"]["value"], userOrigin=auth_data["userOrigin"], nonce=auth_data["nonce"]), data=dict(jsEnabled="false", attempts=0, username=self.get_option("username"), password=self.get_option("password"))) # redirects to ptrt_url on successful login if res.url == ptrt_url: return res else: self.logger.error( "Could not authenticate, could not find the authentication nonce" )
def _get_vod_streams(self): page = http.get(self.url) asset = re.search(r'asse_.{32}', str(page._content)).group(0) post_data = '{"asset_url":"/api/assets/%s/"}' % asset stream_data = http.json(http.post(self._stream_get_url, data=post_data))['objects'][0]['level3'][ 'streaming_url'] return HLSStream.parse_variant_playlist(self.session, stream_data)
def _get_streams(self): http.headers.update({'User-Agent': useragents.FIREFOX}) log.debug('Version 2018-07-01') log.info('This is a custom plugin. ' 'For support visit https://github.com/back-to/plugins') res = http.get(self.url) data = self._data_re.search(res.text) if data: log.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: log.debug('Found _hls_re') hls_url = m.group('url') hls_url = update_scheme('http://', hls_url) log.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: log.debug('Found _iframe_re') iframe_url = iframe.group('url') iframe_url = update_scheme('http://', iframe_url) log.debug('URL={0}'.format(iframe_url)) return self.session.streams(iframe_url)
def login(self): """ Attempt a login to LiveEdu.tv """ email = self.get_option("email") password = self.get_option("password") if email and password: res = http.get(self.login_url) csrf_match = self.csrf_re.search(res.text) token = csrf_match and csrf_match.group(1) self.logger.debug("Attempting login as {0} (token={1})", email, token) res = http.post(self.login_url, data=dict(login=email, password=password, csrfmiddlewaretoken=token), allow_redirects=False, raise_for_status=False, headers={"Referer": self.login_url}) if res.status_code != 302: self.logger.error("Failed to login to LiveEdu account: {0}", email)
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): """ Find all the streams for the ITV url :return: Mapping of quality to stream """ http.headers.update({"User-Agent": useragents.FIREFOX}) video_info = self.video_info() video_info_url = video_info.get( "data-html5-playlist") or video_info.get("data-video-id") res = http.post(video_info_url, data=json.dumps(self.device_info), headers={"hmac": video_info.get("data-video-hmac")}) data = http.json(res, schema=self._video_info_schema) log.debug("Video ID info response: {0}".format(data)) stype = data['Playlist']['VideoType'] for media in data['Playlist']['Video']['MediaFiles']: url = urljoin(data['Playlist']['Video']['Base'], media['Href']) name_fmt = "{pixels}_{bitrate}" if stype == "CATCHUP" else None for s in HLSStream.parse_variant_playlist( self.session, url, name_fmt=name_fmt).items(): yield s
def _get_streams(self): if self.get_option("email") and self.get_option("password"): if not self.authenticate(self.get_option("email"), self.get_option("password")): self.logger.warning("Failed to login as {0}".format(self.get_option("email"))) # find the list of channels from the html in the page self.url = self.url.replace("https", "http") # https redirects to http res = http.get(self.url) if "enter your postcode" in res.text: self.logger.info("Setting your postcode to: {0}. " "This can be changed in the settings on tvplayer.com", self.dummy_postcode) res = http.post(self.update_url, data=dict(postcode=self.dummy_postcode), params=dict(return_url=self.url)) stream_attrs = self._get_stream_attrs(res) if stream_attrs: stream_data = self._get_stream_data(**stream_attrs) if stream_data: if stream_data.get("drmToken"): self.logger.error("This stream is protected by DRM can cannot be played") return else: return HLSStream.parse_variant_playlist(self.session, stream_data["stream"]) else: if "need to login" in res.text: self.logger.error( "You need to login using --tvplayer-email/--tvplayer-password to view this stream")
def login(self, email, password): """ Login to the schoolism account and return the users account :param email: (str) email for account :param password: (str) password for account :return: (str) users email """ if self.options.get("email") and self.options.get("password"): res = http.post(self.login_url, data={ "email": email, "password": password, "redirect": None, "submit": "Login" }) if res.cookies.get("password") and res.cookies.get("email"): return res.cookies.get("email") else: self.logger.error( "Failed to login to Schoolism, incorrect email/password combination" ) else: self.logger.error( "An email and password are required to access Schoolism streams" )
def _authenticate(self, email, password): csrf_token = http.get(LOGIN_PAGE_URL, schema=_csrf_token_schema) if not csrf_token: raise PluginError("Unable to find CSRF token") data = { "authenticity_token": csrf_token, "channel_id": "", "commit": "Login", "plan_id": "", "session[email]": email, "session[password]": password, "utf8": "\xE2\x9C\x93", # Check Mark Character } res = http.post(LOGIN_POST_URL, data=data, acceptable_status=(200, 422)) result = http.json(res, schema=_login_schema) errors = result.get("errors") if errors: errors = ", ".join(errors) raise PluginError("Unable to authenticate: {0}".format(errors)) self.logger.info("Successfully logged in as {0}", result["email"])
def _hello(self): log.debug('_hello ...') # a new session is required for the app_token http.cookies = cookiejar_from_dict({}) res = http.get(self.base_url) match = self._app_token_re.search(res.text) app_token = match.group(1) hello_url = self.API_HELLO.format(self.base_url) if self._uuid: __uuid = self._uuid else: __uuid = str(uuid.uuid4()) self._session_attributes.set('uuid', __uuid, expires=self.TIME_SESSION) params = { 'client_app_token': app_token, 'uuid': __uuid, 'lang': 'en', 'format': 'json' } res = http.post(hello_url, headers=self.headers, data=params)
def get_url_tokens(self, stream_id): self.logger.debug("Getting stream tokens") csrf_token = self.get_csrf_tokens() return http.post(self.tokens_url.format(id=stream_id), files={"authenticity_token": (None, csrf_token)}, headers={"User-Agent": useragents.CHROME, "Referer": self.url}, schema=self.token_schema)
def authenticate(self, username, password): res = http.get(self.login_url) match = self.login_token_re.search(res.text) token = match and match.group(1) res2 = http.post(self.login_url, data=dict(email=username, password=password, token=token), allow_redirects=False) # there is a 302 redirect on a successful login return res2.status_code == 302
def _get_streams(self): # fetch requested url and find playlist info response = http.get(self.url) info = _find_playlist_info(response) if not info: # playlist info not found, let's try to find player url player_url = _find_player_url(response) if not player_url: raise PluginError('Cannot find playlist info or player url!') # get player url and try to find playlist info in it response = http.get(player_url) info = _find_playlist_info(response) if not info: raise PluginError('Cannot find playlist info in the player url!') data = { 'playlist[0][type]': info['type'], 'playlist[0][id]': info['id'], 'requestUrl': '/ivysilani/embed/iFramePlayerCT24.php', 'requestSource': 'iVysilani', 'type': 'html' } headers = { 'x-addr': '127.0.0.1', } # fetch playlist url response = http.post( 'http://www.ceskatelevize.cz/ivysilani/ajax/get-client-playlist', data=data, headers=headers ) json_data = http.json(response, schema=_playlist_url_schema) if json_data['url'] == "error_region": self.logger.error("This stream is not available in your territory") return # fetch playlist response = http.post(json_data['url']) json_data = http.json(response, schema=_playlist_schema) playlist = json_data['playlist'][0]['streamUrls']['main'] return HLSStream.parse_variant_playlist(self.session, playlist)
def _get_streams(self): page = http.get(self.url) page_channel = self._url_re.match(self.url).group(1) if page_channel.endswith(".flv"): self.logger.debug("Possible VOD stream...") vod_streams = self._get_vod_stream(page) if vod_streams: for s in vod_streams.items(): yield s return if "does not exist" in page.text: self.logger.error( "The channel {0} does not exist".format(page_channel)) return if not self._stream_online(page): self.logger.error( "The channel {0} is currently offline".format(page_channel)) return server = None streams = list(self._get_steam_list(page)) multi = False for args in streams: channel, tech, token = args["channel"], args["tech"], args["token"] if channel.lower() != page_channel.lower(): if not multi: self.logger.info( "Skipping multi-channel stream for: {0}".format( channel)) multi = True continue self.logger.debug( "Found stream for {channel}; tech=\"{tech}\", token=\"{token}\"", **args) # cache the load balancing info if not server: channel_server_res = http.post( self.API_CHANNEL_INFO, data={"loadbalancinginfo": channel}) server = channel_server_res.text self.logger.debug( "Using load balancing server {0} for channel {1}", server, channel) # generate all the streams, for multi-channel streams also append the channel name if tech == "hls": for s in self._create_hls_stream(server, args).items(): yield s elif tech == "flash": stream = self._create_flash_stream(server, args) yield "live", stream
def get_token(self, **config): pdata = dict(arg1=base64.b64encode("www.ellobo106.com".encode("utf8")), arg2=base64.b64encode(self.time.encode("utf8"))) res = http.post(self.token_url.format(deviceId=self.device_id, **config), data=pdata) data = http.json(res) return data["token"]
def _get_channel_info(self, username): data = { "bid": username, "mode": "landing", "player_type": "html5" } res = http.post(CHANNEL_API_URL, data=data) return http.json(res, schema=_channel_schema)
def login(self, username, password): res = http.post(self._login_url, data={ 'user_name': username, 'user_pass': password, 'login': '******' }) return username in res.text
def _watch(self): self.logger.debug('_watch ...') match = self._url_re.match(self.url) if not match: self.logger.debug('_watch ... no match') return channel = match.group('channel') vod_id = match.group('vod_id') recording_id = match.group('recording_id') cookies = { 'beaker.session.id': self._session_attributes.get('beaker.session.id'), 'pzuid': self._session_attributes.get('pzuid') } watch_url = [] if channel: params, watch_url = self._watch_live(channel, cookies) elif vod_id: params, watch_url = self._watch_vod(vod_id) elif recording_id: params, watch_url = self._watch_recording(recording_id) if not watch_url: self.logger.debug('Missing watch_url') return res = [] try: res = http.post(watch_url, headers=self.headers, data=params, cookies=cookies) except Exception as e: if '404 Client Error' in str(e): self.logger.error( 'Unfortunately streaming is not permitted in this country or this channel does not exist.' ) elif '402 Client Error: Payment Required' in str(e): self.logger.error( 'Paid subscription required for this channel.') self.logger.info( 'If paid subscription exist, use --zattoo-purge-credentials to start a new session.' ) else: self.logger.error(str(e)) return self.logger.debug('Found post data') data = http.json(res) if data['success']: for hls_url in data['stream']['watch_urls']: for s in HLSStream.parse_variant_playlist( self.session, hls_url['url']).items(): yield s
def login(self, username, password): self.logger.debug("Logging in as {0}".format(username)) redirect_to = "https://home.bt.com/ss/Satellite/secure/loginforward?redirectURL={0}".format( quote(self.url)) data = { "cookieExpp": "30", "Switch": "yes", "SMPostLoginUrl": "/appsyouraccount/secure/postlogin", "loginforward": "https://home.bt.com/ss/Satellite/secure/loginforward", "smauthreason": "0", "TARGET": redirect_to, "USER": username, "PASSWORD": password } res = http.post(self.login_url, data=data) self.logger.debug("Redirected to: {0}".format(res.url)) if url_equal(res.url, self.url, ignore_scheme=True): self.logger.debug("Login successful, getting SAML token") res = http.get( "https://samlfed.bt.com/sportgetfedwebhls?bt.cid={0}".format( self.acid())) d = self.saml_re.search(res.text) if d: saml_data = d.group(1) self.logger.debug("BT Sports federated login...") res = http.post(self.api_url, params={ "action": "LoginBT", "channel": "WEBHLS", "bt.cid": self.acid }, data={"SAMLResponse": saml_data}) fed_json = http.json(res) success = fed_json['resultCode'] == "OK" if not success: self.logger.error("Failed to login: {0} - {1}".format( fed_json['errorDescription'], fed_json['message'])) return success return False
def _get_streams(self): if self.get_option("email") and self.get_option("password"): self.authenticate(self.get_option("email"), self.get_option("password")) # find the list of channels from the html in the page self.url = self.url.replace("https", "http") # https redirects to http res = http.get(self.url) if "enter your postcode" in res.text: self.logger.info( "Setting your postcode to: {0}. " "This can be changed in the settings on tvplayer.com", self.dummy_postcode) res = http.post(self.update_url, data=dict(postcode=self.dummy_postcode), params=dict(return_url=self.url)) stream_attrs = dict((k, v.strip('"')) for k, v in self.stream_attrs_re.findall(res.text)) if "resourceId" in stream_attrs and "validate" in stream_attrs and "platform" in stream_attrs: # get the stream urls res = http.post(self.api_url, data=dict(service=1, id=stream_attrs["resourceId"], validate=stream_attrs["validate"], platform=stream_attrs["platform"], token=stream_attrs.get("token"))) stream_data = http.json(res, schema=self.stream_schema) if stream_data.get("drmToken"): self.logger.error( "This stream is protected by DRM can cannot be played") return else: return HLSStream.parse_variant_playlist( self.session, stream_data["stream"]) else: if "need to login" in res.text: self.logger.error( "You need to login using --tvplayer-email/--tvplayer-password to view this stream" )
def _get_stream_url(self, video_id, vtype="video"): res = http.post(self.stream_api_url, data={ "id": video_id, "type": vtype, "format": "json" }, headers={ "User-Agent": useragents.IPHONE_6 }) data = http.json(res) return data.get("path")
def _get_hls_key(self, broadcast, username): headers = { "Referer": self.url } data = { "bj_id": username, "broad_no": broadcast } res = http.post(HLS_KEY_URL, data=data, headers=headers) return http.json(res)
def _login(self, username, password): res = http.post(self.auth_url, data={ "username": username, "password": password, "cookielink": False }) login_status = http.xml(res, schema=self.auth_schema) self.logger.debug("Login status for {0}: {1}", username, login_status) if login_status == "loginlocked": self.logger.error("The account {0} has been locked, the password needs to be reset") return login_status == "loginsuccess"
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_streams(self): url_channel_name = self._url_re.match(self.url).group(1) # Handle VODs first, since their "channel name" is different if url_channel_name.endswith(".flv"): self.logger.debug("Possible VOD stream...") page = http.get(self.url) vod_streams = self._get_vod_stream(page) if vod_streams: for s in vod_streams.items(): yield s return else: self.logger.warning("Probably a VOD stream but no VOD found?") ci = http.get(self.CHANNEL_API_URL.format(channel=url_channel_name), raise_for_status=False) if ci.status_code == 404: self.logger.error("The channel {0} does not exist".format(url_channel_name)) return channel_api_json = json.loads(ci.text) if channel_api_json["online"] != True: self.logger.error("The channel {0} is currently offline".format(url_channel_name)) return server = None token = "public" channel = channel_api_json["name"] # Extract preferred edge server and available techs from the undocumented channel API channel_server_res = http.post(self.VIDEO_API_URL, data={"loadbalancinginfo": channel}) info_json = json.loads(channel_server_res.text) pref = info_json["preferedEdge"] for i in info_json["edges"]: if i["id"] == pref: server = i["ep"] break self.logger.debug("Using load balancing server {0} : {1} for channel {2}", pref, server, channel) for i in info_json["techs"]: if i["label"] == "HLS": for s in self._create_hls_stream(server, channel, token).items(): yield s elif i["label"] == "RTMP Flash": stream = self._create_flash_stream(server, channel, token) yield "live", stream
def _get_hls_key(self, broadcast, username, quality): headers = { "Referer": self.url } data = { "bid": username, "bno": broadcast, "pwd": "", "quality": quality, "type": "pwd" } res = http.post(CHANNEL_API_URL, data=data, headers=headers) return http.json(res, schema=_channel_schema)
def login(self, email, password): self.logger.debug("Attempting to log in as {0}", email) res = http.post(self.login_url, data=dict(email=email, password=password), allow_redirects=False, raise_for_status=False) loc = res.headers.get("Location", "") if "geoblocked" in loc.lower(): self.logger.error("AnimeLab is not available in your territory") elif res.status_code >= 400: self.logger.error("Failed to login to AnimeLab, check your email/password combination") else: return True return False
def login(self, username, password): self.logger.debug("Logging in as {0}".format(username)) redirect_to = "https://home.bt.com/ss/Satellite/secure/loginforward?redirectURL={0}".format(quote(self.url)) data = { "cookieExpp": "30", "Switch": "yes", "SMPostLoginUrl": "/appsyouraccount/secure/postlogin", "loginforward": "https://home.bt.com/ss/Satellite/secure/loginforward", "smauthreason": "0", "TARGET": redirect_to, "USER": username, "PASSWORD": password} res = http.post(self.login_url, data=data) self.logger.debug("Redirected to: {0}".format(res.url)) if url_equal(res.url, self.url, ignore_scheme=True): self.logger.debug("Login successful, getting SAML token") res = http.get("https://samlfed.bt.com/sportgetfedwebhls?bt.cid={0}".format(self.acid())) d = self.saml_re.search(res.text) if d: saml_data = d.group(1) self.logger.debug("BT Sports federated login...") res = http.post(self.api_url, params={"action": "LoginBT", "channel": "WEBHLS", "bt.cid": self.acid}, data={"SAMLResponse": saml_data}) fed_json = http.json(res) success = fed_json['resultCode'] == "OK" if not success: self.logger.error("Failed to login: {0} - {1}".format(fed_json['errorDescription'], fed_json['message'])) return success return False
def get_token(self, **config): pdata = dict(arg1=base64.b64encode("www.ellobo106.com".encode("utf8")), arg2=base64.b64encode(self.time.encode("utf8"))) headers = { "User-Agent": useragents.FIREFOX, "Referer": self.url, "X-Requested-With": "XMLHttpRequest", "Content-Type": "application/x-www-form-urlencoded" } res = http.post(self.token_url.format(deviceId=self.device_id, **config), data=pdata, headers=headers) data = http.json(res) return data["token"]
def _watch(self): self.logger.debug('_watch ...') match = self._url_re.match(self.url) if not match: self.logger.debug('_watch ... no match') return channel = match.group('channel') vod_id = match.group('vod_id') recording_id = match.group('recording_id') cookies = { 'beaker.session.id': self._session_attributes.get('beaker.session.id'), 'pzuid': self._session_attributes.get('pzuid') } watch_url = [] if channel: params, watch_url = self._watch_live(channel, cookies) elif vod_id: params, watch_url = self._watch_vod(vod_id) elif recording_id: params, watch_url = self._watch_recording(recording_id) if not watch_url: self.logger.debug('Missing watch_url') return res = [] try: res = http.post(watch_url, headers=self.headers, data=params, cookies=cookies) except Exception as e: if '404 Client Error' in str(e): self.logger.error( 'Unfortunately streaming is not permitted in this country or this channel does not exist.') elif '402 Client Error: Payment Required' in str(e): self.logger.error('Paid subscription required for this channel.') self.logger.info('If paid subscription exist, use --zattoo-purge-credentials to start a new session.') else: self.logger.error(str(e)) return self.logger.debug('Found post data') data = http.json(res) if data['success']: for hls_url in data['stream']['watch_urls']: for s in HLSStream.parse_variant_playlist(self.session, hls_url['url']).items(): yield s
def login(self, username, password): r = http.get(self._signin_url) csrf = None for input in itertags(r.text, "input"): if input.attributes['name'] == "csrf_ustvnow": csrf = input.attributes['value'] self.logger.debug("CSRF: {0}", csrf) r = http.post(self._login_url, data={'csrf_ustvnow': csrf, 'signin_email': username, 'signin_password': password, 'signin_remember': '1'}) m = self._token_re.search(r.text) return m and m.group(1)
def _login(self, username, password): data = { "szWork": "login", "szType": "json", "szUid": username, "szPassword": password, "isSaveId": "true", "isSavePw": "false", "isSaveJoin": "false" } res = http.post(self.login_url, data=data) res = http.json(res) if res["RESULT"] == 1: return True else: return False
def login(self, email, password): self.logger.debug("Attempting login as {0}", email) # sets some required cookies to login http.get(self.login_page_url) # login res = http.post(self.login_url, data=dict(registrationAction='identify', emailAddress=email, password=password, submitButton=""), headers={"Referer": self.login_page_url}, allow_redirects=False) self._authed = "Authentication Error" not in res.text if self._authed: self._session_attributes.set("ipid", res.cookies.get("ipid"), expires=3600 * 1.5) self._session_attributes.set("fprt", res.cookies.get("fprt"), expires=3600 * 1.5) return self._authed
def _get_stream_url(self, video_id, vtype): try: res = http.post(self.stream_api_url.format(self._domain), data={ "id": video_id, "type": vtype, "format": "json" }, headers={ "User-Agent": useragents.IPHONE_6 }) except Exception as e: if "400 Client Error" in str(e): self.logger.error("Login required") return else: raise e data = http.json(res) return data.get("path")
def _get_stream_data(self, resource, channel_id, token, service=1): # Get the context info (validation token and platform) self.logger.debug("Getting stream information for resource={0}".format(resource)) context_res = http.get(self.context_url, params={"resource": resource, "gen": token}) context_data = http.json(context_res, schema=self.context_schema) self.logger.debug("Context data: {0}", str(context_data)) # get the stream urls res = http.post(self.api_url, data=dict( service=service, id=channel_id, validate=context_data["validate"], token=context_data.get("token"), platform=context_data["platform"]["key"]), raise_for_status=False) return http.json(res, schema=self.stream_schema)
def login(self, email, password): """ Login to the schoolism account and return the users account :param email: (str) email for account :param password: (str) password for account :return: (str) users email """ if self.options.get("email") and self.options.get("password"): res = http.post(self.login_url, data={"email": email, "password": password, "redirect": None, "submit": "Login"}) if res.cookies.get("password") and res.cookies.get("email"): return res.cookies.get("email") else: self.logger.error("Failed to login to Schoolism, incorrect email/password combination") else: self.logger.error("An email and password are required to access Schoolism streams")
def _login(self, username, password): '''login and update cached cookies''' self.logger.debug('login ...') res = http.get(self.login_url) input_list = self._input_re.findall(res.text) if not input_list: raise PluginError('Missing input data on login website.') data = {} for _input_data in input_list: try: _input_name = self._name_re.search(_input_data).group(1) except AttributeError: continue try: _input_value = self._value_re.search(_input_data).group(1) except AttributeError: _input_value = '' data[_input_name] = _input_value login_data = { 'ctl00$Login1$UserName': username, 'ctl00$Login1$Password': password, 'ctl00$Login1$LoginButton.x': '0', 'ctl00$Login1$LoginButton.y': '0' } data.update(login_data) res = http.post(self.login_url, data=data) for cookie in http.cookies: self._session_attributes.set(cookie.name, cookie.value, expires=3600 * 24) if self._session_attributes.get('ASP.NET_SessionId') and self._session_attributes.get('.abportail1'): self.logger.debug('New session data') self.set_expires_time_cache() return True else: self.logger.error('Failed to login, check your username/password') return False
def get_stream_url(self, data): """ Get the hls_url from the post request :param data: dict with "gcp" and "ogn" :return: hls_url """ try: res = http.post(self.gate_url, headers=self.headers, data=data) except Exception as e: if "403" in str(e): self.logger.error("This Video is Not Available in Your Country.") raise NoStreamsError(self.url) r_data = parse_json(res.text) hls_url = r_data.get("stream") suffix = r_data.get("suffix") if hls_url is None and suffix: hls_url = self.create_hls_url(suffix) return hls_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")