Exemple #1
0
    def _login(self, username, password):
        '''login and update cached cookies'''
        self.logger.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)
        for cookie in http.cookies:
            self._session_attributes.set(cookie.name,
                                         cookie.value,
                                         expires=3600 * 24)

        if (self._session_attributes.get('fcu')
                and self._session_attributes.get('fgcv')
                and self._session_attributes.get('FCSID')
                and self._session_attributes.get('login_status')
                and self._session_attributes.get('glgd_val')
                and self._session_attributes.get('PHPSESSID')
                and self._session_attributes.get('secure_check_fc2')):

            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
Exemple #2
0
    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)
Exemple #3
0
    def _hello(self):
        self.logger.debug('_hello ...')
        headers = {
            'User-Agent': useragents.CHROME,
            'Referer': self.base_url
        }
        res = requests.get("{0}/login".format(self.base_url), headers=headers)
        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=3600 * 24)

        params = {
            'client_app_token': app_token,
            'uuid': __uuid,
            'lang': 'en',
            'format': 'json'
        }
        res = http.post(hello_url, headers=self.headers, data=params)
        return res
Exemple #4
0
    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
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
    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")})
Exemple #8
0
    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
Exemple #9
0
    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"
            )
Exemple #10
0
    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
Exemple #11
0
    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
Exemple #12
0
 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)
Exemple #13
0
 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)
Exemple #14
0
    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)
Exemple #15
0
    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)
Exemple #16
0
    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
Exemple #17
0
 def login(self, username, password):
     res = http.post(self.login_url,
                     data={
                         "username": username,
                         "password": password
                     })
     if "success_logged_in" in res.text:
         return True
     else:
         return False
Exemple #18
0
    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"] is not 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
Exemple #19
0
 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
Exemple #20
0
    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
Exemple #21
0
    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)
Exemple #22
0
 def _login(self, username, password):
     res = http.post(self.auth_url.format(self._domain),
                     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"
Exemple #23
0
    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
Exemple #24
0
    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"]
Exemple #25
0
    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
Exemple #26
0
    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")
Exemple #27
0
    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
Exemple #28
0
    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
Exemple #29
0
    def _resolve_stream(self):
        res = http.get(self.url)
        match = _data_stream_re.search(res.text)
        if not match:
            return
        data_stream = match.group(1)

        resolve_data = {'stream': data_stream}
        res = http.post('http://www-ipv4.nos.nl/livestream/resolve/',
                        data=json.dumps(resolve_data))
        data = http.json(res)

        res = http.get(data['url'])
        match = _js_re.search(res.text)
        if not match:
            return

        stream_url = parse_json(match.group(1))

        return HLSStream.parse_variant_playlist(self.session, stream_url)
Exemple #30
0
    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