当前位置: 首页>>代码示例>>Python>>正文


Python HLSStream.parse_variant_playlist方法代码示例

本文整理汇总了Python中livestreamer.stream.HLSStream.parse_variant_playlist方法的典型用法代码示例。如果您正苦于以下问题:Python HLSStream.parse_variant_playlist方法的具体用法?Python HLSStream.parse_variant_playlist怎么用?Python HLSStream.parse_variant_playlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在livestreamer.stream.HLSStream的用法示例。


在下文中一共展示了HLSStream.parse_variant_playlist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_live_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    def _get_live_streams(self):
        self._authenticate()
        sig, token = self._access_token()
        url = self.usher.select(self.channel, password=self.options.get("password"), nauthsig=sig, nauth=token)

        try:
            streams = HLSStream.parse_variant_playlist(self.session, url)
        except ValueError:
            return
        except IOError as err:
            if "404 Client Error" in str(err):
                return
            else:
                raise PluginError(err)

        try:
            token = parse_json(token)
            chansub = verifyjson(token, "chansub")
            restricted_bitrates = verifyjson(chansub, "restricted_bitrates")

            for name in filter(lambda n: n not in ("archives", "live"), restricted_bitrates):
                self.logger.warning("The quality '{0}' is not available " "since it requires a subscription.", name)
        except PluginError:
            pass

        return dict(starmap(self._check_stream_name, streams.items()))
开发者ID:reduced111,项目名称:livestreamer,代码行数:28,代码来源:justintv_common.py

示例2: _get_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    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
开发者ID:492580195,项目名称:livestreamer,代码行数:29,代码来源:dmcloud.py

示例3: _get_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    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)
        streams = defaultdict(list)
        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)
            streams[stream_name].append(stream)

        if ios_url:
            if urlparse(ios_url).path.endswith(".m3u8"):
                hls_streams = HLSStream.parse_variant_playlist(
                    self.session, ios_url
                )
                for name, stream in hls_streams.items():
                    streams[name].append(stream)

        if swf_url:
            stream = self._get_rtmp_streams(swf_url)
            if stream:
                streams[stream_name].append(stream)

        return streams
开发者ID:Agataosa,项目名称:livestreamer,代码行数:33,代码来源:dmcloud.py

示例4: _get_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    def _get_streams(self):
        self.logger.debug("Fetching stream info")
        res = urlget(self.url, params=dict(output="json"))
        json = res_json(res)

        if not isinstance(json, dict):
            raise PluginError("Invalid JSON response")

        streams = {}
        video = verifyjson(json, "video")
        videos = verifyjson(video, "videoReferences")

        for video in videos:
            if not ("url" in video and "playerType" in video):
                continue

            if video["playerType"] == "flash":
                if video["url"].startswith("rtmp"):
                    stream = RTMPStream(
                        self.session,
                        {"rtmp": video["url"], "pageUrl": self.PageURL, "swfVfy": self.SWFURL, "live": True},
                    )
                    streams[str(video["bitrate"]) + "k"] = stream
            elif video["playerType"] == "ios":
                try:
                    hlsstreams = HLSStream.parse_variant_playlist(self.session, video["url"])
                    streams.update(hlsstreams)
                except IOError as err:
                    self.logger.warning("Failed to get variant playlist: {0}", err)

        return streams
开发者ID:hugolp,项目名称:livestreamer,代码行数:33,代码来源:svtplay.py

示例5: _get_streams_from_id

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    def _get_streams_from_id(self, stream_id):
        res = urlget(CONFIG_URL, params=dict(id=stream_id))
        config = res_json(res)
        media = verifyjson(config, "media")

        if not (media and isinstance(media, list)):
            return

        streams = {}
        media = media[0]
        hds_manifest = media.get("name")
        hls_manifest = media.get("hlsUrl")

        if hds_manifest:
            try:
                hds_streams = HDSStream.parse_manifest(self.session,
                                                       hds_manifest)
                streams.update(hds_streams)
            except IOError as err:
                if not re.search(r"(404|400) Client Error", str(err)):
                    self.logger.error("Failed to parse HDS manifest: {0}", err)

        if hls_manifest:
            try:
                hls_streams = HLSStream.parse_variant_playlist(self.session,
                                                               hls_manifest,
                                                               nameprefix="mobile_")
                streams.update(hls_streams)
            except IOError as err:
                if not re.search(r"(404|400) Client Error", str(err)):
                    self.logger.error("Failed to parse HLS playlist: {0}", err)

        return streams
开发者ID:alletti,项目名称:livestreamer,代码行数:35,代码来源:mlgtv.py

示例6: _get_hls_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    def _get_hls_streams(self):
        url = self.HLSStreamTokenURL.format(self.channelname)

        try:
            res = urlget(url, params=dict(type="any", connection="wifi"),
                         exception=IOError)
        except IOError:
            self.logger.debug("HLS streams not available")
            return {}

        json = res_json(res, "stream token JSON")

        if not isinstance(json, list):
            raise PluginError("Invalid JSON response")

        if len(json) == 0:
            raise PluginError("No stream token in JSON")

        streams = {}

        token = verifyjson(json[0], "token")
        hashed = hmac.new(self.HLSStreamTokenKey, bytes(token, "utf8"), sha1)
        fulltoken = hashed.hexdigest() + ":" + token
        url = self.HLSSPlaylistURL.format(self.channelname)

        try:
            params = dict(token=fulltoken, hd="true")
            playlist = HLSStream.parse_variant_playlist(self.session, url,
                                                        params=params)
        except IOError as err:
            raise PluginError(err)

        return playlist
开发者ID:ToadKing,项目名称:livestreamer,代码行数:35,代码来源:justintv.py

示例7: _create_stream

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    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
开发者ID:dafuk,项目名称:xbmc-israel,代码行数:30,代码来源:artetv.py

示例8: _get_hls_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    def _get_hls_streams(self, type="live"):
        self._authenticate()
        sig, token = self._access_token(type)
        if type == "live":
            url = self.usher.select(self.channel, nauthsig=sig, nauth=token)
        elif type == "video":
            url = self.usher.vod(self.video_id, nauthsig=sig, nauth=token)

        try:
            streams = HLSStream.parse_variant_playlist(self.session, url)
        except IOError as err:
            err = str(err)
            if "404 Client Error" in err or "Failed to parse playlist" in err:
                return
            else:
                raise PluginError(err)

        try:
            token = parse_json(token, schema=_token_schema)
            for name in token["restricted_bitrates"]:
                if name not in streams:
                    self.logger.warning("The quality '{0}' is not available "
                                        "since it requires a subscription.",
                                        name)
        except PluginError:
            pass

        return streams
开发者ID:SqTerror,项目名称:livestreamer,代码行数:30,代码来源:twitch.py

示例9: _get_live_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    def _get_live_streams(self):
        self._authenticate()
        sig, token = self._access_token()
        url = self.usher.select(self.channel,
                                password=self.options.get("password"),
                                nauthsig=sig,
                                nauth=token)

        try:
            streams = HLSStream.parse_variant_playlist(self.session, url)
        except IOError as err:
            err = str(err)
            if "404 Client Error" in err or "Failed to parse playlist" in err:
                return
            else:
                raise PluginError(err)

        try:
            token = parse_json(token, schema=_token_schema)
            for name in token["restricted_bitrates"]:
                if name not in streams:
                    self.logger.warning("The quality '{0}' is not available "
                                        "since it requires a subscription.",
                                        name)
        except PluginError:
            pass

        return dict(starmap(self._check_stream_name, streams.items()))
开发者ID:OliverWS,项目名称:livestreamer,代码行数:30,代码来源:justintv_common.py

示例10: _get_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    def _get_streams(self):
        info = self._get_stream_info()
        if not info:
            return

        stream_info = info["event"]["stream_info"]
        if not (stream_info and stream_info["is_live"]):
            # Stream is not live
            return

        play_url = stream_info.get("play_url")
        if play_url:
            swf_url = info.get("viewerPlusSwfUrl") or info.get("hdPlayerSwfUrl")
            if not swf_url.startswith("http"):
                swf_url = "http://" + swf_url

            qualities = stream_info["qualities"]
            for bitrate, stream in self._parse_smil(play_url, swf_url):
                name = "{0}k".format(bitrate / 1000)
                for quality in qualities:
                    if quality["bitrate"] == bitrate:
                        name = "{0}p".format(quality["height"])

                yield name, stream

        m3u8_url = stream_info.get("m3u8_url")
        if m3u8_url:
            streams = HLSStream.parse_variant_playlist(self.session, m3u8_url,
                                                       namekey="pixels")
            # TODO: Replace with "yield from" when dropping Python 2.
            for stream in streams.items():
                yield stream
开发者ID:A-StadLabs,项目名称:citylive,代码行数:34,代码来源:livestream.py

示例11: _get_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    def _get_streams(self):
        channelid = self._get_channel_id(self.url)

        if not channelid:
            raise NoStreamsError(self.url)


        self.logger.debug("Fetching stream info")
        res = urlget(self.AMFURL.format(channelid))

        try:
            packet = AMF0Packet.deserialize(BytesIO(res.content))
        except (IOError, AMFError) as err:
            raise PluginError(("Failed to parse AMF packet: {0}").format(str(err)))

        result = None
        for message in packet.messages:
            if message.target_uri == "/1/onResult":
                result = message.value
                break

        if not result:
            raise PluginError("No result found in AMF packet")

        streams = {}

        if "liveHttpUrl" in result:
            try:
                hlsstreams = HLSStream.parse_variant_playlist(self.session,
                                                              result["liveHttpUrl"])
                streams.update(hlsstreams)
            except IOError as err:
                self.logger.warning("Failed to get variant playlist: {0}", err)

        if "streamName" in result:
            if "cdnUrl" in result:
                cdn = result["cdnUrl"]
            elif "fmsUrl" in result:
                cdn = result["fmsUrl"]
            else:
                self.logger.warning("Missing cdnUrl and fmsUrl from result")
                return streams

            if "videoCodec" in result and result["videoCodec"]["height"] > 0:
                streamname = "{0}p".format(int(result["videoCodec"]["height"]))
            else:
                streamname = "live"

            streams[streamname] = self._create_stream(cdn, result["streamName"])

        if "streamVersions" in result:
            for version, info in result["streamVersions"].items():
                if "streamVersionCdn" in info:
                    for name, cdn in info["streamVersionCdn"].items():
                        if "cdnStreamUrl" in cdn and "cdnStreamName" in cdn:
                            streams["cdn_" + name] = self._create_stream(cdn["cdnStreamUrl"],
                                                                         cdn["cdnStreamName"])


        return streams
开发者ID:buttsKramer,项目名称:livestreamer,代码行数:62,代码来源:ustreamtv.py

示例12: _get_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    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)
开发者ID:A-StadLabs,项目名称:citylive,代码行数:9,代码来源:oldlivestream.py

示例13: _get_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
    def _get_streams(self):
        self.logger.debug("Fetching stream info")
        res = http.get(self.url)

        match = re.search("var info = (.*);", res.text)
        if not match:
            raise NoStreamsError(self.url)

        json = parse_json(match.group(1))
        if not isinstance(json, dict):
            return

        ios_url = json.get("ios_url")
        swf_url = json.get("swf_url")
        streams = {}

        if ios_url:
            hls = HLSStream.parse_variant_playlist(self.session, ios_url)
            streams.update(hls)

        if swf_url:
            try:
                streams["live"] = self._get_rtmp_streams(swf_url)
            except NoStreamsError:
                pass

        return streams
开发者ID:3cky,项目名称:livestreamer,代码行数:29,代码来源:dmcloud.py

示例14: _get_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
 def _get_streams(self):
     self.logger.debug('Extracting media URL')
     res = urlget(self.url, cookies = {'NRK_PLAYER_SETTINGS_TV':
         'devicetype=desktop&preferred-player-odm=hlslink&preferred-player-live=hlslink'})
     m = re.search(r'<div[^>]*?id="playerelement"[^>]+data-media="([^"]+)"', res.text)
     if not m:
         raise NoStreamsError(self.url)
     return HLSStream.parse_variant_playlist(self.session, m.group(1))
开发者ID:Am2k,项目名称:livestreamer,代码行数:10,代码来源:nrk.py

示例15: _get_streams

# 需要导入模块: from livestreamer.stream import HLSStream [as 别名]
# 或者: from livestreamer.stream.HLSStream import parse_variant_playlist [as 别名]
 def _get_streams(self):
     url_match = _url_re.match(self.url)
     if url_match:
         _id = url_match.group(1)
         url = 'https://rtctw-rtcp-tw-1.livehouse.in/%s/video/playlist.m3u8' % (_id)
         streams = HLSStream.parse_variant_playlist(self.session, url)
         return streams
     else:
          raise StreamError("Error open playlist, maybe it's not live stream ")         
开发者ID:nitpicker,项目名称:livestreamer.plugin.livehouse.in,代码行数:11,代码来源:livehouse.py


注:本文中的livestreamer.stream.HLSStream.parse_variant_playlist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。