コード例 #1
0
ファイル: svtplay.py プロジェクト: persianpros/livecli
    def _get_streams(self):
        # Retrieve URL page and search for new type of video ID
        res = http.get(self.url)
        match = _id_re.search(res.text)

        # Use API if match, otherwise resort to old method
        if match:
            vid = match.group("id")
            res = http.get(API_URL.format(vid))

            videos = http.json(res, schema=_video_schema)
            mapper = StreamMapper(
                cmp=lambda format, video: video["format"] == format)
            mapper.map("hls", self._create_streams, "HLS",
                       HLSStream.parse_variant_playlist)
            mapper.map("hds", self._create_streams, "HDS",
                       HDSStream.parse_manifest)
        else:
            res = http.get(self.url, params=dict(output="json"))
            videos = http.json(res, schema=_old_video_schema)

            mapper = StreamMapper(
                cmp=lambda type, video: video["playerType"] == type)
            mapper.map("ios", self._create_streams, "HLS",
                       HLSStream.parse_variant_playlist)
            mapper.map("flash", self._create_streams, "HDS",
                       HDSStream.parse_manifest)

        return mapper(videos)
コード例 #2
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        if not match:
            return

        channel, media_id = match.group("channel", "media_id")
        self.logger.debug("Matched URL: channel={0}, media_id={1}".format(
            channel, media_id))
        if not media_id:
            res = http.get(LIVE_API.format(channel))
            livestream = http.json(res, schema=_live_schema)
            if livestream.get("media_hosted_media"):
                hosted = _live_schema.validate(
                    livestream["media_hosted_media"])
                self.logger.info("{0} is hosting {1}",
                                 livestream["media_user_name"],
                                 hosted["media_user_name"])
                livestream = hosted

            if not livestream["media_is_live"]:
                return

            media_id = livestream["media_id"]
            media_type = "live"
        else:
            media_type = "video"

        res = http.get(PLAYER_API.format(media_type, media_id))
        player = http.json(res, schema=_player_schema)

        if media_type == "live":
            return self._get_live_streams(player)
        else:
            return self._get_video_streams(player)
コード例 #3
0
ファイル: zdf_mediathek.py プロジェクト: persianpros/livecli
    def _get_streams(self):
        zdf_json = http.get(self.url, schema=_api_schema)
        if zdf_json is None:
            return

        headers = {
            "Api-Auth": "Bearer {0}".format(zdf_json['apiToken']),
            "Referer": self.url
        }

        res = http.get(zdf_json['content'], headers=headers)
        document = http.json(res, schema=_documents_schema)

        stream_request_url = document["mainVideoContent"][
            "http://zdf.de/rels/target"]["http://zdf.de/rels/streams/ptmd"]
        stream_request_url = API_URL + stream_request_url

        res = http.get(stream_request_url, headers=headers)
        res = http.json(res, schema=_schema)

        streams = {}
        for format_ in self._extract_streams(res):
            streams.update(format_)

        return streams
コード例 #4
0
ファイル: tga.py プロジェクト: longsack/livecli
    def _get_qq_streams(self, vid):
        res = http.get(QQ_STREAM_INFO_URL % (vid, 1))
        info = http.json(res, schema=_qq_schema)
        yield "live", HTTPStream(self.session, info)

        res = http.get(QQ_STREAM_INFO_URL % (vid, 2))
        info = http.json(res, schema=_qq_schema)
        yield "live", HLSStream(self.session, info)
コード例 #5
0
ファイル: euronews.py プロジェクト: persianpros/livecli
 def _get_live_streams(self, subdomain):
     """
     Get the live stream in a particular language
     :param subdomain:
     :return:
     """
     res = http.get(self._live_api_url.format(subdomain))
     live_res = http.json(res, schema=self._live_schema)
     api_res = http.get(live_res[u"url"])
     stream_data = http.json(api_res, schema=self._stream_api_schema)
     return HLSStream.parse_variant_playlist(self.session,
                                             stream_data[u'primary'])
コード例 #6
0
ファイル: chaturbate.py プロジェクト: persianpros/livecli
    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
コード例 #7
0
    def _get_live_streams(self, slug):
        res = http.get(LIVE_CHANNELS_API_URL)
        res = http.json(res, schema=_channels_schema)

        for channel in filter(lambda c: c["Slug"] == slug, res):
            servers = channel["StreamingServers"]
            return self._parse_streaming_servers(servers)
コード例 #8
0
ファイル: zattoo.py プロジェクト: persianpros/livecli
    def _watch_live(self, channel, cookies):
        self.logger.debug('_watch_live ... Channel: {0}'.format(channel))
        watch_url = self.API_WATCH.format(self.base_url)

        channels_url = self.API_CHANNELS.format(self.base_url, self._session_attributes.get('power_guide_hash'))
        res = http.get(channels_url, headers=self.headers, cookies=cookies)
        data = http.json(res, schema=self._channels_schema)

        c_list = []
        for d in data:
            for c in d['channels']:
                c_list.append(c)

        cid = []
        zattoo_list = []
        for c in c_list:
            zattoo_list.append(c['display_alias'])
            if c['display_alias'] == channel:
                cid = c['cid']

        self.logger.debug('Available zattoo channels in this country: {0}'.format(', '.join(sorted(zattoo_list))))

        if not cid:
            cid = channel

        self.logger.debug('CHANNEL ID: {0}'.format(cid))

        params = {
            'cid': cid,
            'https_watch_urls': True,
            'stream_type': 'hls'
        }
        return params, watch_url
コード例 #9
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
コード例 #10
0
ファイル: vrtbe.py プロジェクト: persianpros/livecli
    def _get_vod_stream(self):
        vod_url = self.url
        if vod_url.endswith('/'):
            vod_url = vod_url[:-1]

        json_url = '{0}.securevideo.json'.format(vod_url)

        res = http.get(json_url)
        match = _json_re.search(res.text)
        if not match:
            return
        data = parse_json(match.group(1))

        res = http.get(API_VOD.format(data['clientid'], data['mzid']))
        data = http.json(res, schema=_stream_schema)

        for d in data['targetUrls']:
            if d['type'] == 'HDS':
                hds_url = d['url']
                for s in HDSStream.parse_manifest(self.session,
                                                  hds_url).items():
                    yield s

            if d['type'] == 'HLS':
                hls_url = d['url']
                for s in HLSStream.parse_variant_playlist(
                        self.session, hls_url).items():
                    yield s
コード例 #11
0
    def _get_streams_from_media(self, media_id):
        res = http.get(STREAM_INFO_URL.format(media_id), cookies=COOKIES)
        media = http.json(res, schema=_media_schema)

        params = extra_params = swf_url = message = None
        for __ in media:
            for __ in __["layerList"]:
                for __ in __.get("sequenceList", []):
                    for layer in __["layerList"]:
                        name = layer["name"]
                        if name == "video":
                            params = layer.get("param")
                        elif name == "reporting":
                            extra_params = layer.get("param", {})
                            extra_params = extra_params.get("extraParams", {})
                        elif name == "message":
                            message = layer.get("param")

        if not params:
            self.logger.error(message.get("title"))
            return []

        if extra_params:
            swf_url = extra_params.get("videoSwfURL")

        mode = params.get("mode")
        if mode == "live":
            return self._get_live_streams(params, swf_url)
        elif mode == "vod":
            return self._get_vod_streams(params)
コード例 #12
0
    def _get_streams(self):
        headers = {"Referer": self.url, "User-Agent": useragents.FIREFOX}

        res = http.get(self.url, headers=headers)

        m = self._playlist_re.search(res.text)
        if not m:
            return

        res = http.get(m.group("url"), headers=headers)
        if not res.text.startswith("#EXTM3U"):
            hls_url = http.json(res).get("redir")
        else:
            hls_url = m.group("url")

        if hls_url is not None:
            self.logger.debug("HLS URL: {0}".format(hls_url))
            streams = HLSStream.parse_variant_playlist(self.session,
                                                       hls_url,
                                                       headers=headers)
            if not streams:
                return {
                    "live": HLSStream(self.session, hls_url, headers=headers)
                }
            else:
                return streams
コード例 #13
0
ファイル: tga.py プロジェクト: longsack/livecli
    def _get_channel_id(self, domain):
        channel_info = http.get(CHANNEL_INFO_URL % str(domain))
        info = http.json(channel_info, schema=_channel_schema)
        if info is None:
            return 0, 0

        return info['channel']['vid'], info['channel']['id']
コード例 #14
0
    def _get_streams(self):
        headers = {"User-Agent": useragents.FIREFOX, "Referer": self.url}
        res = http.get(self.url, headers=headers)
        files = self._files_re.findall(res.text)
        if files is None:
            return

        files = list(set(files))
        for url in files:
            if ".m3u8" in url:
                if url.startswith("https://weltmediathek-vh."):
                    url = "https://www.welt.de/video/services/token/{0}".format(
                        quote(url, safe=""))
                    res = http.get(url, headers=headers)
                    r_json = http.json(res)
                    url = r_json["urlWithToken"]
                for s in HLSStream.parse_variant_playlist(
                        self.session, url, headers=headers).items():
                    yield s
            elif url.endswith(".mp4"):
                m = self._mp4_bitrate_re.search(url)
                bitrate = m.group("bitrate")
                if bitrate:
                    name = "{0}k".format(bitrate)
                else:
                    name = "mp4"
                yield name, HTTPStream(self.session, url, headers=headers)
コード例 #15
0
ファイル: afreeca.py プロジェクト: persianpros/livecli
 def _get_stream_info(self, broadcast, quality, cdn, rmd):
     params = {
         "return_type": cdn,
         "broad_key": "{broadcast}-flash-{quality}-hls".format(**locals())
     }
     res = http.get(STREAM_INFO_URLS.format(rmd=rmd), params=params)
     return http.json(res, schema=_stream_schema)
コード例 #16
0
ファイル: npo.py プロジェクト: persianpros/livecli
    def _get_streams(self):
        asset_id = self._get_prid(self.get_option("subtitles"))

        if asset_id:
            self.logger.debug("Found asset id: {0}", asset_id)
            streams = self.api_call(asset_id,
                                    params=dict(adaptive="yes",
                                                token=self.token),
                                    schema=self.streams_schema)

            for stream in streams:
                if stream["format"] in ("adaptive", "hls", "mp4"):
                    if stream["contentType"] == "url":
                        stream_url = stream["url"]
                    else:
                        # using type=json removes the javascript function wrapper
                        info_url = stream["url"].replace(
                            "type=jsonp", "type=json")

                        # find the actual stream URL
                        stream_url = http.json(http.get(info_url),
                                               schema=self.stream_info_schema)

                    if stream["format"] in ("adaptive", "hls"):
                        for s in HLSStream.parse_variant_playlist(
                                self.session, stream_url).items():
                            yield s
                    elif stream["format"] in ("mp3", "mp4"):
                        yield "vod", HTTPStream(self.session, stream_url)
コード例 #17
0
    def _get_vod_streams(self, params):
        manifest_url = params.get("autoURL")
        if not manifest_url:
            return

        res = http.get(manifest_url)
        if res.headers.get("Content-Type") == "application/f4m+xml":
            streams = HDSStream.parse_manifest(self.session, res.url)

            # TODO: Replace with "yield from" when dropping Python 2.
            for __ in streams.items():
                yield __
        elif res.headers.get(
                "Content-Type") == "application/vnd.apple.mpegurl":
            streams = HLSStream.parse_variant_playlist(self.session, res.url)

            # TODO: Replace with "yield from" when dropping Python 2.
            for __ in streams.items():
                yield __
        else:
            manifest = http.json(res, schema=_vod_manifest_schema)
            for params in manifest["alternates"]:
                name = "{0}p".format(params["height"])
                stream = self._create_flv_playlist(params["template"])
                yield name, stream

                failovers = params.get("failover", [])
                for failover in failovers:
                    stream = self._create_flv_playlist(failover)
                    yield name, stream
コード例 #18
0
ファイル: zattoo.py プロジェクト: NghiemTrung/livecli
    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
コード例 #19
0
    def _get_streams(self):
        http.headers.update({
            "User-Agent": useragents.CHROME,
            "Referer": self.referer
        })
        fragment = dict(parse_qsl(urlparse(self.url).fragment))
        link = fragment.get("link")
        if not link:
            link = self._get_tv_link()

        if not link:
            self.logger.error("Missing link fragment: stream unavailable")
            return

        player_url = self._api_url.format(link)
        self.logger.debug("Requesting player API: {0} (referer={1})",
                          player_url, self.referer)
        res = http.get(player_url,
                       params={"_": int(time.time() * 1000)},
                       headers={"X-Requested-With": "XMLHttpRequest"})

        try:
            data = http.json(res, schema=self.api_schema)
        except PluginError as e:
            print(e)
            self.logger.error("Cannot play this stream type")
        else:
            if data["status"]:
                if data["file"].startswith("<"):
                    self.logger.error("Cannot play embedded streams")
                else:
                    return HLSStream.parse_variant_playlist(
                        self.session, data["file"])
            else:
                self.logger.error(data["text"])
コード例 #20
0
ファイル: dplay.py プロジェクト: persianpros/livecli
    def _get_streams(self):
        m_url = self._url_re.match(self.url)

        host = m_url.group('host')
        id_url = m_url.group('id')

        api_url = self._api_url.format(host)
        headers = {'User-Agent': useragents.FIREFOX}

        res = http.get(self.url, headers=headers)
        m = self._videoid_re.search(res.text)
        if m:
            video_id = m.group('id')
        else:
            http.get('{0}/token'.format(api_url), params={'realm': host.replace('.', '')})
            headers2 = {
                'User-Agent': useragents.FIREFOX,
                'Referer': self.url,
                'x-disco-client': 'WEB:UNKNOWN:dplay-client:0.0.1'
            }
            try:
                res = http.get('{0}/content/videos/{1}'.format(api_url, id_url), headers=headers2)
            except Exception as e:
                if '404' in str(e):
                    self.logger.error('No video found on this url.')
                return
            data = http.json(res)
            if data:
                video_id = data['data']['id']

        if not video_id:
            self.logger.error('Found no video id')
            return

        res = http.get('{0}/playback/videoPlaybackInfo/{1}'.format(api_url, video_id), headers=headers)
        data = http.json(res, schema=_api_schema)

        if not data:
            return

        hls_url = data['hls']['url']

        streams = HLSStream.parse_variant_playlist(self.session, hls_url, headers=headers)
        if not streams:
            return {'live': HLSStream(self.session, hls_url, headers=headers)}
        else:
            return streams
コード例 #21
0
    def _get_streams(self):
        # Get video ID and channel from URL
        match = self._url_re.match(self.url)
        video_id = match.group('video_id')
        if video_id is None:
            # Retrieve URL page and search for video ID
            res = http.get(self.url)
            match = self._video_id_re.search(res.text)
            if match is None:
                return
            video_id = match.group('video_id')

        res = http.get(self.API_URL.format(video_id))
        videos = http.json(res, schema=self._api_schema)
        parsed = []
        headers = {'User-Agent': self._user_agent}

        # Some videos may be also available on Dailymotion (especially on CNews)
        if videos['ID_DM'] != '':
            for stream in self.session.streams('https://www.dailymotion.com/video/' + videos['ID_DM']).items():
                yield stream

        for quality, video_url in list(videos['MEDIA']['VIDEOS'].items()):
            # Ignore empty URLs
            if video_url == '':
                continue

            # Ignore duplicate video URLs
            if video_url in parsed:
                continue
            parsed.append(video_url)

            try:
                # HDS streams don't seem to work for live videos
                if '.f4m' in video_url and 'LIVE' not in videos['TYPE']:
                    for stream in HDSStream.parse_manifest(self.session,
                                                           video_url,
                                                           params={'hdcore': self.HDCORE_VERSION},
                                                           headers=headers).items():
                        yield stream
                elif '.m3u8' in video_url:
                    for stream in HLSStream.parse_variant_playlist(self.session,
                                                                   video_url,
                                                                   headers=headers).items():
                        yield stream
                elif '.mp4' in video_url:
                    # Get bitrate from video filename
                    match = self._mp4_bitrate_re.match(video_url)
                    if match is not None:
                        bitrate = match.group('bitrate')
                    else:
                        bitrate = quality
                    yield bitrate, HTTPStream(self.session,
                                              video_url,
                                              params={'secret': self.SECRET},
                                              headers=headers)
            except IOError as err:
                if '403 Client Error' in str(err):
                    self.logger.error('Failed to access stream, may be due to geo-restriction')
コード例 #22
0
ファイル: powerapp.py プロジェクト: persianpros/livecli
    def _get_streams(self):
        channel = self.url_re.match(self.url).group(1)

        res = http.get(self.api_url.format(channel))
        data = http.json(res, schema=self.api_schema)

        return HLSStream.parse_variant_playlist(self.session,
                                                data["channel_stream_url"])
コード例 #23
0
ファイル: olympicchannel.py プロジェクト: persianpros/livecli
 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)
コード例 #24
0
ファイル: olympicchannel.py プロジェクト: persianpros/livecli
 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)
コード例 #25
0
ファイル: mixer.py プロジェクト: persianpros/livecli
    def _get_vod_stream(self, vod_id):
        res = self._get_api_res("recordings", vod_id)

        for sdata in http.json(res, schema=self._vod_schema):
            if sdata["format"] == "hls":
                hls_url = urljoin(sdata["url"], "manifest.m3u8")
                yield "{0}p".format(sdata["height"]), HLSStream(
                    self.session, hls_url)
コード例 #26
0
ファイル: liveedu.py プロジェクト: persianpros/livecli
    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
コード例 #27
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)
コード例 #28
0
ファイル: tga.py プロジェクト: longsack/livecli
 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"])
コード例 #29
0
    def _get_stream_info(self, url):
        res = http.get(url, headers=HEADERS)
        match = re.search(r"embed.swf\?p=(\d+)", res.text)
        if not match:
            return
        program = match.group(1)
        res = http.get(BEAT_PROGRAM.format(program), headers=HEADERS)

        return http.json(res, schema=_schema)
コード例 #30
0
    def _get_streams(self):
        res = http.get(DATA_URL)
        data = http.json(res, schema=_data_schema)
        video_id = data["channel"] or data["channel2"]
        if not video_id:
            return

        url = "http://youtu.be/{0}".format(video_id)
        return self.session.streams(url)