Ejemplo n.º 1
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        title = self.url.rsplit('/', 1)[-1]
        if title.endswith(".html"):
            title = title[:-5]

        request_url = "https://api.zdf.de/content/documents/%s.json?profile=player" % title
        res = http.get(request_url,
                       headers={
                           "Api-Auth":
                           "Bearer d2726b6c8c655e42b68b0db26131b15b22bd1a32"
                       })
        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)
        res = http.json(res, schema=_schema)

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

        return streams
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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_http", HLSStream(self.session, info)
Ejemplo n.º 4
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")

        http.headers.update({'User-Agent': USER_AGENT})
        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:
            return

        if room["show_status"] != SHOW_STATUS_ONLINE:
            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
Ejemplo n.º 5
0
 def _get_live_streams(self, language):
     """
     Get the live stream in a particular language
     :param language:
     :return:
     """
     res = http.get(self._live_api_url)
     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)
     # find the stream in the requested language
     if language in stream_data[u'primary']:
         playlist_url = stream_data[u'primary'][language][u"hls"]
         return HLSStream.parse_variant_playlist(self.session, playlist_url)
Ejemplo n.º 6
0
    def _get_streams(self):
        flashvars = http.get(self.url, schema=_flashvars_schema)
        if not flashvars:
            return

        params = {
            "rt": "json",
            "lc": "en_US",
            "pt": "view",
            "bpw": "",
            "bid": flashvars["id"],
            "adok": "",
            "bno": ""
        }

        if re.search(_url_re_tw, self.url):
            res = http.get(VIEW_LIVE_API_URL_TW, params=params)
        elif re.search(_url_re_jp, self.url):
            res = http.get(VIEW_LIVE_API_URL_JP, params=params)
        else:
            res = http.get(VIEW_LIVE_API_URL, params=params)

        streams = http.json(res, schema=_view_live_schema)

        for stream in streams:
            stream_name = "{0}p".format(stream["bps"])
            stream_params = {"rtmp": stream["purl"], "live": True}
            yield stream_name, RTMPStream(self.session, stream_params)
Ejemplo n.º 7
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 = 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", {})

        if not params:
            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)
Ejemplo n.º 8
0
    def _get_streams(self):
        # get the page
        res = http.get(self.url, headers={"User-Agent": self._user_agent})
        # find the big blob of stream info in the page
        stream_data = self._stream_data_re.match(res.text)
        stream_name = AdultSwim._url_re.match(
            self.url).group(1) or "live-stream"

        if stream_data:
            # parse the stream info as json
            stream_info = parse_json(stream_data.group(1),
                                     schema=self._page_data_schema)
            # get the stream ID
            stream_id = stream_info[u"streams"][stream_name][u"stream"]

            if stream_id:
                api_url = self.API_URL.format(id=stream_id)

                res = http.get(api_url,
                               headers={"User-Agent": self._user_agent})
                stream_data = http.json(res, schema=self._api_schema)

                for asset in stream_data[u'data'][u'stream'][u'assets']:
                    for n, s in HLSStream.parse_variant_playlist(
                            self.session, asset[u"url"]).items():
                        yield n, s

            else:
                self.logger.error(
                    "Couldn't find the stream ID for this stream: {}".format(
                        stream_name))
        else:
            self.logger.error(
                "Couldn't find the stream data for this stream: {}".format(
                    stream_name))
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
    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']
Ejemplo n.º 11
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
Ejemplo n.º 12
0
    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"])
Ejemplo n.º 13
0
    def _get_streams(self):
        self.url = http.resolve_url(self.url)
        match = _url_re.match(self.url)
        parsed = urlparse(self.url)
        if parsed.fragment:
            channel_id = parsed.fragment
        elif parsed.path[:3] == '/v/':
            channel_id = parsed.path.split('/')[-1]
        else:
            channel_id = match.group("channel")

        if not channel_id:
            return

        channel_id = channel_id.lower().replace("/", "_")
        res = http.get(API_URL.format(channel_id))
        info = http.json(res, schema=_schema)

        if not info["success"]:
            return

        if info.get("isLive"):
            name = "live"
        else:
            name = "vod"

        stream = HTTPStream(self.session, info["payload"])
        # Wrap the stream in a FLVPlaylist to verify the FLV tags
        stream = FLVPlaylist(self.session, [stream])

        return {name: stream}
Ejemplo n.º 14
0
    def _get_star_streams(self, desktop_url, mobile_url, token=""):
        if token:
            self.logger.debug("Opening stream with token: {}", token)

        if mobile_url:
            for _, s in HLSStream.parse_variant_playlist(self.session,
                                                         mobile_url + token,
                                                         headers={
                                                             "Referer":
                                                             self.url
                                                         }).items():
                yield "live", s
        if desktop_url:
            # get the HDS stream URL
            res = http.get(desktop_url + token)
            stream_data = http.json(res, schema=self.hds_schema)
            for _, s in HDSStream.parse_manifest(
                    self.session,
                    stream_data["url"],
                    pvswf=self.SWF_URL,
                    is_akamai=stream_data["use_akamai"],
                    headers={
                        "Referer": self.url
                    }).items():
                yield "live", s
Ejemplo n.º 15
0
    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"])
Ejemplo n.º 16
0
    def _get_vod_streams(self, movie_id):
        for stream_type in STREAM_TYPES:
            cookies = {"flash-player-type": stream_type}
            res = ajax(VODINFO_URL.format(movie_id), cookies=cookies)
            vod = http.json(res, schema=_vod_schema)

            # TODO: Replace with "yield from" when dropping Python 2.
            for stream in self._parse_vod_streams(vod):
                yield stream
Ejemplo n.º 17
0
def get_json(url):
    """Fetch page for given URL and return json Python object.

    :param url: URL to fetch

    """
    res = http.get(url)

    return http.json(res)
Ejemplo n.º 18
0
    def _get_stream_info(self, url):
        res = http.get(url, headers=HEADERS)
        match = re.search("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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
    def _get_live_streams(self, channel_id):
        params = {"channel_id": channel_id}
        for stream_type in STREAM_TYPES:
            cookies = {"flash-player-type": stream_type}
            res = ajax(CHINFO_URL, cookies=cookies, data=params)
            channel = http.json(res, schema=_channel_schema)

            # TODO: Replace with "yield from" when dropping Python 2.
            for stream in self._parse_live_streams(channel):
                yield stream
Ejemplo n.º 21
0
 def _get_stream_info(self, broadcast, type):
     params = {
         "return_type": "gs_cdn",
         "use_cors": "true",
         "cors_origin_url": "m.afreeca.com",
         "broad_no": "{broadcast}-mobile-hd-{type}".format(**locals()),
         "broad_key": "{broadcast}-flash-hd-{type}".format(**locals())
     }
     res = http.get(STREAM_INFO_URLS[type], params=params)
     return http.json(res, schema=_stream_schema)
Ejemplo n.º 22
0
    def _get_vod_streams(self, name):
        res = http.get(API_URL.format("videos", name))
        json = http.json(res, schema=_vod_schema)
        if not json:
            return

        streams = {}
        streams["source"] = self._create_rtmp_stream(
            VOD_RTMP_URL.format(json["channel_slug"]), json["name"], True)

        return streams
Ejemplo n.º 23
0
    def _get_streams(self):
        match = self._url_re.match(self.url)
        film_id, episode_id = match.groups()

        headers = {"Referer": self.url, "User-Agent": self._user_agent}

        # Get the info about the Episode, including the Grabber API URL
        info_res = http.get(self._episode_info_url,
                            params=dict(update=0, film=film_id, id=episode_id),
                            headers=headers)
        info = http.json(info_res, schema=self._info_schema)

        # Get the data about the streams from the Grabber API
        stream_list_res = http.get(info["grabber"],
                                   params=info["params"],
                                   headers=headers)
        stream_data = http.json(stream_list_res, schema=self._streams_schema)

        for stream in stream_data["data"]:
            yield stream["label"], HTTPStream(self.session, stream["file"])
Ejemplo n.º 24
0
    def _get_live_streams(self, name):
        res = http.get(API_URL.format("channels", name))
        json = http.json(res, schema=_channel_schema)
        if not json:
            return

        streams = {}
        for quality in json["stream"]["qualities"]:
            streams[self._get_quality(quality)] = self._create_rtmp_stream(
                json["stream"]["rootUrl"], quality, True)

        return streams
Ejemplo n.º 25
0
    def _get_streams(self):
        url_params = dict(parse_qsl(urlparse(self.url).query))
        video_id = url_params.get("videoid")

        if video_id:
            self.logger.debug("Found Video ID: {}", video_id)
            res = http.get(self.api_url.format(id=video_id))
            data = http.json(res, schema=self.api_schema)
            hls = self._make_stream(data["video_info"]["hlsvideosource"])
            video = self._make_stream(data["video_info"]["videosource"])
            if hls:
                yield "live", hls
            if video:
                yield "live", video
Ejemplo n.º 26
0
    def _get_channel_video(self, channel_id):
        query = {
            "channelId": channel_id,
            "type": "video",
            "eventType": "live",
            "part": "id",
            "key": API_KEY
        }
        res = http.get(API_SEARCH_URL, params=query)
        videos = http.json(res, schema=_search_schema)

        for video in videos:
            video_id = video["id"]["videoId"]
            return video_id
Ejemplo n.º 27
0
 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["urls"]:
         quality = self._get_quality(source["resolution"])
         if source["ext"] == "m3u8":
             yield quality, HLSStream(self.session, source["securityUrl"])
         elif source["ext"] == "flv":
             yield quality, HTTPStream(self.session, source["securityUrl"])
         elif source["ext"] == "rtmp":
             yield quality, RTMPStream(self.session, {
                 "rtmp": source["securityUrl"],
                 "live": True
             })
Ejemplo n.º 28
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        if not match:
            return

        channel, media_id = match.group("channel", "media_id")
        if channel != "video":
            res = http.get(LIVE_API.format(channel))
            livestream = http.json(res, schema=_live_schema)
            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)
Ejemplo n.º 29
0
    def _get_hls_url(self, content_id):
        # make the api url relative to the current domain
        if "cnnturk" in self.url:
            self.logger.debug("Using alternative content API url")
            api_url = urljoin(self.url,
                              self.alt_content_api.format(id=content_id))
        else:
            api_url = urljoin(self.url, self.content_api.format(id=content_id))

        apires = http.get(api_url)

        stream_data = http.json(apires, schema=self.content_api_schema)
        d = stream_data["Media"]["Link"]
        return urljoin((d["ServiceUrl"] or d["DefaultServiceUrl"]),
                       d["SecurePath"])
Ejemplo n.º 30
0
    def _get_streams(self):
        res = http.get(self.url)
        match = _embed_re.search(res.text)
        if match:
            res = http.get(match.group(1))

        match = _aptoma_id_re.search(res.text)
        if not match:
            return

        aptoma_id = match.group(1)
        if not _live_re.search(res.text):
            res = http.get(METADATA_URL.format(aptoma_id))
            metadata = http.json(res)
            video_id = metadata["videoId"]
        else:
            video_id = aptoma_id

        res = http.get(VIDEO_INFO_URL, params=dict(id=video_id))
        video = http.json(res, schema=_video_schema)
        streams = {}
        for fmt, providers in video["formats"].items():
            for name, provider in providers.items():
                for ext, playlists in provider.items():
                    for playlist in playlists:
                        url = PLAYLIST_URL_FORMAT.format(**playlist)
                        parser = STREAM_TYPES[fmt]

                        try:
                            streams.update(parser(self.session, url))
                        except IOError as err:
                            self.logger.error(
                                "Failed to extract {0} streams: {1}",
                                fmt.upper(), err)

        return streams