Пример #1
0
    def _get_live_streams(self):
        stream_id = _id_map[self.channel_path]

        if stream_id == "ruv":
            qualities_rtmp = ["720p", "480p", "360p", "240p"]

            for i, quality in enumerate(qualities_rtmp):
                yield quality, RTMPStream(
                    self.session, {
                        "rtmp": RTMP_LIVE_URL.format(stream_id, i + 1),
                        "pageUrl": self.url,
                        "live": True
                    })

            qualities_hls = ["240p", "360p", "480p", "720p"]
            for i, quality_hls in enumerate(qualities_hls):
                yield quality_hls, HLSStream(self.session,
                                             HLS_RUV_LIVE_URL.format(i + 1))

        else:
            yield "audio", RTMPStream(
                self.session, {
                    "rtmp": RTMP_LIVE_URL.format(stream_id, 1),
                    "pageUrl": self.url,
                    "live": True
                })

            yield "audio", HLSStream(self.session,
                                     HLS_RADIO_LIVE_URL.format(stream_id))
Пример #2
0
    def _get_streams(self):
        """
        Find the streams for web.tv
        :return:
        """
        headers = {}
        res = http.get(self.url, headers=headers)
        headers["Referer"] = self.url

        sources = self._sources_re.findall(res.text)
        if len(sources):
            sdata = parse_json(sources[0], schema=self._sources_schema)
            for source in sdata:
                self.logger.debug("Found stream of type: {}", source[u'type'])
                if source[u'type'] == u"application/vnd.apple.mpegurl":
                    # if the url has no protocol, assume it is http
                    url = source[u"src"]
                    if url.startswith("//"):
                        url = "http:" + url

                    try:
                        # try to parse the stream as a variant playlist
                        variant = HLSStream.parse_variant_playlist(self.session, url, headers=headers)
                        if variant:
                            for q, s in variant.items():
                                yield q, s
                        else:
                            # and if that fails, try it as a plain HLS stream
                            yield 'live', HLSStream(self.session, url, headers=headers)
                    except IOError:
                        self.logger.warning("Could not open the stream, perhaps the channel is offline")
Пример #3
0
    def _create_hls_streams(self, bitrate):
        url = bitrate["url"]
        quality = self._get_quality(bitrate["label"])

        if not url.startswith("http"):
            url = HLS_PLAYLIST_BASE.format(url)

        if bitrate["label"] == "Auto":
            try:
                streams = HLSStream.parse_variant_playlist(self.session, url)
                return streams.items()
            except IOError as err:
                self.logger.warning("Failed to extract HLS streams: {0}", err)
        else:
            return quality, HLSStream(self.session, url)
Пример #4
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)
Пример #5
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        videoid = match.group('id')
        
        streams = {}

        # Set header data for user-agent
        hdr = {'User-Agent': USER_AGENT}
        
        # Parse video ID from data received from supplied URL
        res = http.get(VK_VIDEO_URL + videoid.strip(), headers=hdr)

        for match in re.findall(SINGLE_VIDEO_URL, res.text):
            url = match[0].replace("\\/", "/")
            streams[match[2]] = HTTPStream(self.session, url)

        if not streams:
            # try to check is live
            match = VK_LIVE_HASH.search(res.text)
            params = videoid.split('_')

            if match and match.group('hash'):
                url = VK_EXT_URL.format(params[0].replace('video', "").replace('-', ""), params[1], match.group('hash'))
                res = http.get(url, headers=hdr)

                match = SINGLE_HLS_URL.search(res.text)

                if match and match.group('playlist'):
                    hls_streams = HLSStream.parse_variant_playlist(self.session, match.group('playlist').replace("\\/", "/"), namekey="pixels")
                    streams.update(hls_streams)

        return streams
Пример #6
0
    def _get_streams(self):
        # get the HLS xml from the same sub domain as the main url, defaulting to www
        sdomain = _url_re.match(self.url).group(1) or "www"
        res = http.get(API_URL.format(sdomain))

        stream_url = http.xml(res, schema=_schema)
        return HLSStream.parse_variant_playlist(self.session, stream_url)
Пример #7
0
    def _create_stream(self, stream, is_live):
        stream_name = "{0}p".format(stream["height"])
        stream_type = stream["mediaType"]
        stream_url = stream["url"]

        if stream_type in ("hls", "mp4"):
            if urlparse(stream_url).path.endswith("m3u8"):
                try:
                    streams = HLSStream.parse_variant_playlist(
                        self.session, stream_url)

                    # TODO: Replace with "yield from" when dropping Python 2.
                    for stream in streams.items():
                        yield stream
                except IOError as err:
                    self.logger.error("Failed to extract HLS streams: {0}",
                                      err)
            else:
                yield stream_name, HTTPStream(self.session, stream_url)

        elif stream_type == "rtmp":
            params = {
                "rtmp": stream["streamer"],
                "playpath": stream["url"],
                "swfVfy": SWF_URL,
                "pageUrl": self.url,
            }

            if is_live:
                params["live"] = True
            else:
                params["playpath"] = "mp4:{0}".format(params["playpath"])

            stream = RTMPStream(self.session, params)
            yield stream_name, stream
Пример #8
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        videoid = match.group('id')

        # Set header data for user-agent
        hdr = {'User-Agent': USER_AGENT}

        # Parse video ID from data received from supplied URL
        res = http.get(self.url, headers=hdr)

        if not res:
            return {}

        for match in re.findall(_player_params, res.text):
            try:
                params = json.loads(base64.b64decode(match))
                video_url = params.get("url")
                res = http.get(video_url, headers=hdr)

                video_url = res.text.split('=')[1]

                return HLSStream.parse_variant_playlist(
                    self.session, video_url)
            except Exception as e:
                self.logger.error("Failed to decode player params: {0}", e)

                return {}
Пример #9
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
Пример #10
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
Пример #11
0
 def _get_streams(self):
     res = http.get(self.url)
     data_m = self.data_re.search(res.text)
     if data_m:
         stream_url = data_m.group(1)
         self.logger.debug("Found stream: {}", stream_url)
         yield "live", HLSStream(self.session, stream_url)
Пример #12
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        video = match.group("video_id")

        playlist = _playlist_url.format(video)

        return HLSStream.parse_variant_playlist(self.session, playlist)
Пример #13
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))
Пример #14
0
    def _get_streams(self):
        res = http.get(self.url)
        match = _info_re.search(res.text)
        if not match:
            return

        info = parse_json(match.group(1), schema=_schema)
        stream_name = info["mode"]
        mp4_url = info.get("mp4_url")
        ios_url = info.get("ios_url")
        swf_url = info.get("swf_url")

        if mp4_url:
            stream = HTTPStream(self.session, mp4_url)
            yield stream_name, stream

        if ios_url:
            if urlparse(ios_url).path.endswith(".m3u8"):
                streams = HLSStream.parse_variant_playlist(
                    self.session, ios_url)
                # TODO: Replace with "yield from" when dropping Python 2.
                for stream in streams.items():
                    yield stream

        if swf_url:
            stream = self._get_rtmp_stream(swf_url)
            if stream:
                yield stream_name, stream
Пример #15
0
    def _get_streams(self):
        streams = {}

        # streaming.media.ccc.de
        match = _url_streaming_media_re.match(self.url)
        if match:
            query_url = API_URL_STREAMING_MEDIA
            live_streams = parse_streaming_media_json(get_json(query_url),\
                                                      match.group('room'))

            for stream_name, stream_url in live_streams.items():
                if re.search(r"m3u8", live_streams[stream_name]):
                    streams[stream_name] = HLSStream(self.session,\
                                                        stream_url)
                else:
                    streams[stream_name] = HTTPStream(self.session,\
                                                        stream_url)

        # media.ccc.de
        elif _url_media_re.search(self.url):
            event_id = get_event_id(self.url)
            query_url = "%s/public/events/%i" % (API_URL_MEDIA, event_id)
            recordings = parse_media_json(get_json(query_url))

            for name, stream_url in recordings.items():
                streams[name] = HTTPStream(self.session, stream_url)

        if not streams:
            raise PluginError("This plugin does not support your "
                              "selected video.")

        return streams
Пример #16
0
 def _get_streams(self):
     res = http.get(self.url)
     text = res.text
     cdn = _RE_CDN.search(text).group(1)
     playlist_url = _RE_PLAYLIST.search(text).group(1)
     url = 'http://{}{}'.format(cdn, playlist_url)
     return dict(source=HLSStream(self.session, url))
Пример #17
0
    def _get_sarpurinn_streams(self):
        res = http.get(self.url)
        match = _rtmp_url_re.search(res.text)

        if not match:
            yield

        token = match.group("id")
        status = match.group("status")
        extension = match.group("ext")
        date = match.group("date")
        if not date:
            date = ""

        if extension == "mp3":
            key = "audio"
        else:
            key = "576p"

            # HLS on Sarpurinn is currently only available on videos
            yield key, HLSStream(
                self.session,
                HLS_SARPURINN_URL.format(status, date, token, extension))

        yield key, RTMPStream(
            self.session, {
                "rtmp": RTMP_SARPURINN_URL.format(status, date, token,
                                                  extension),
                "pageUrl": self.url,
                "live": True
            })
Пример #18
0
    def _get_streams(self):
        if _stream_url_re.match(self.url):
            mode = MODE_STREAM
        else:
            mode = MODE_VOD

        res = http.get(self.url)
        match = _json_re.search(res.text)
        if match:
            data = json.loads(
                _json_re.search(res.text).group('json').replace('"', '"'))
        else:
            raise PluginError("Could not extract JSON metadata")

        streams = {}
        try:
            if mode == MODE_STREAM:
                sources = data['playlist']['videos'][0]['sources']
            elif mode == MODE_VOD:
                sources = data['selected_video']['sources']
        except (KeyError, IndexError):
            raise PluginError("Could not extract sources")

        for source in sources:
            try:
                if source['delivery'] != 'hls':
                    continue
                url = source['src'].replace('\/', '/')
            except KeyError:
                continue
            stream = HLSStream.parse_variant_playlist(self.session, url)
            streams.update(stream)

        return streams
Пример #19
0
    def _get_streams(self):
        res = http.get(self.url, schema=_live_schema)
        if not res:
            return

        if res["type"] == "hls" and urlparse(res["url"]).path.endswith("m3u8"):
            stream = HLSStream(self.session, res["url"])
            return dict(hls=stream)
Пример #20
0
    def _get_streams(self):
        clips = http.get(self.url, schema=_schema)
        if not clips:
            return

        for clip in clips:
            for source in clip["sources"]:
                return HLSStream.parse_variant_playlist(self.session, source["file"])
Пример #21
0
    def _parse_vod_streams(self, vod):
        for name, stream in vod["streams"].items():
            scheme = urlparse(stream["url"]).scheme

            if scheme == "http":
                yield name, HLSStream(self.session, stream["url"])
            elif scheme == "rtmp":
                yield name, self._create_rtmp_stream(stream, live=False)
Пример #22
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)
Пример #23
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"])
Пример #24
0
 def _get_streams(self):
     content_id = self._get_content_id()
     if content_id:
         self.logger.debug(u"Loading content: {}", content_id)
         hls_url = self._get_hls_url(content_id)
         return HLSStream.parse_variant_playlist(self.session, hls_url)
     else:
         self.logger.error(u"Could not find the contentId for this stream")
Пример #25
0
    def _get_streams(self):
        """
        Finds the streams from tvcatchup.com.
        """
        http.headers.update({"User-Agent": USER_AGENT})
        res = http.get(self.url)

        match = _stream_re.search(res.text, re.IGNORECASE | re.MULTILINE)

        if match:
            stream_url = match.group("stream_url")

            if stream_url:
                if "_adp" in stream_url:
                    return HLSStream.parse_variant_playlist(
                        self.session, stream_url)
                else:
                    return {'576p': HLSStream(self.session, stream_url)}
Пример #26
0
 def _get_streams(self):
     username = _RE_URL.match(self.url).group(1)
     url = 'https://www.stream.me/api-user/v1/{}/channel'.format(username)
     data = http.get(url).json()
     try:
         m3u8 = data['_embedded']['streams'][0]['_links']['hlsmp4']['href']
         return HLSStream.parse_variant_playlist(self.session, m3u8)
     except KeyError:
         return {}
Пример #27
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")
        channel = channel.replace("_", "-")
        playlist_url = PLAYLIST_URL.format(channel)

        return HLSStream.parse_variant_playlist(self.session,
                                                playlist_url,
                                                check_streams=True)
Пример #28
0
    def _get_streams(self):
        res = http.get(self.url)
        match = (_stream_hls_re.search(res.text) or
                 _stream_data_re.search(res.text))
        if not match:
            return

        stream_url = parse_json(match.group(1))

        return HLSStream.parse_variant_playlist(self.session, stream_url)
Пример #29
0
 def _get_hls_stream(self, broadcast, username):
     keyjson = self._get_hls_key(broadcast, username)
     if keyjson["result"] != CHANNEL_RESULT_OK:
         return
     key = keyjson["data"]["hls_authentication_key"]
     info = self._get_stream_info(broadcast, "hls")
     if "view_url" in info:
         return HLSStream(self.session,
                          info["view_url"],
                          params=dict(aid=key))
Пример #30
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        res = http.get(STREAM_INFO_URL,
                       params=match.groupdict(),
                       acceptable_status=STATUS_UNAVAILABLE)

        if res.status_code in STATUS_UNAVAILABLE:
            return

        playlist_url = http.json(res, schema=_stream_schema)
        if "hls_url" in playlist_url:
            return dict(
                replay=HLSStream(self.session, playlist_url["hls_url"]))
        elif "replay_url" in playlist_url:
            self.logger.info("Live Stream ended, using replay instead")
            return dict(
                replay=HLSStream(self.session, playlist_url["replay_url"]))
        else:
            return