Exemple #1
0
    def _get_streams(self):
        channelname = urlparse(self.url).path.rstrip("/").rpartition("/")[-1].lower()

        self.logger.debug("Fetching stream info")

        headers = {"Referer": self.url, "Accept-Encoding": "deflate"}

        options = dict(channel=channelname, vw="580", vh="390", domain="www.cast3d.tv")

        res = http.get(self.PlayerURL, headers=headers, params=options)

        match = re.search(".+?'streamer':'(.+?)'", res.text)
        if not match:
            raise NoStreamsError(self.url)

        streams = {}
        url = urlparse(match.group(1))
        if url.scheme.startswith("rtmp"):
            redirect = False
            rtmp = match.group(1)
            if "redirect" in rtmp:
                redirect = True

            streams["live"] = RTMPStream(
                self.session,
                {"rtmp": rtmp, "pageUrl": self.url, "swfVfy": self.SWFURL, "playpath": channelname, "live": True},
                redirect=redirect,
            )

        elif url.scheme.startswith("http"):
            streams["live"] = HTTPStream(self.session, match.group(1))
        else:
            raise PluginError(("Invalid stream type: {0}").format(url.scheme))

        return streams
Exemple #2
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
Exemple #3
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        video_id = match.group("video_id")
        res = http.get(ASSET_URL.format(video_id))
        assets = http.xml(res, schema=_asset_schema)

        streams = {}
        for asset in assets:
            base = asset["base"]
            url = asset["url"]

            if urlparse(url).path.endswith(".f4m"):
                streams.update(
                    HDSStream.parse_manifest(self.session, url, pvswf=SWF_URL)
                )
            elif base.startswith("rtmp"):
                name = "{0}k".format(asset["bitrate"])
                params = {
                    "rtmp": asset["base"],
                    "playpath": url,
                    "live": True
                }
                streams[name] = RTMPStream(self.session, params)

        return streams
Exemple #4
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)
        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
Exemple #5
0
    def _create_flv_playlist(self, template):
        res = http.get(template)
        json = http.json(res)

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

        parsed = urlparse(template)
        try:
            url_template = '{0}://{1}{2}'.format(parsed.scheme, parsed.netloc,
                                                 json['template'])
            segment_max = reduce(lambda i, j: i + j[0], json['fragments'], 0)
            duration = json['duration']
        except KeyError:
            raise PluginError('Unexpected JSON response')

        substreams = [
            HTTPStream(self.session,
                       url_template.replace('$fragment$', str(i)))
            for i in range(1, segment_max + 1)
        ]

        return FLVPlaylist(self.session,
                           streams=substreams,
                           duration=duration,
                           skip_header=True,
                           flatten_timestamps=True)
Exemple #6
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
Exemple #7
0
    def _get_streams(self):
        self.logger.debug("Fetching stream info")
        res = urlget(self.url)

        match = re.search("flashplayer: \"(.+.swf)\".+streamer: \"(.+)\""
                          ".+file: \"(.+).flv\"", res.text, re.DOTALL)
        if not match:
            raise NoStreamsError(self.url)

        rtmpurl = match.group(2).replace("\\/", "/")
        parsed = urlparse(rtmpurl)

        params = {
            "rtmp": rtmpurl,
            "app": "{0}?{1}".format(parsed.path[1:], parsed.query),
            "pageUrl": self.url,
            "swfVfy": match.group(1),
            "playpath" : match.group(3),
            "live": True
        }

        match = re.search("(http(s)?://.+/server.php\?id=\d+)",
                          res.text)
        if match:
            token_url = match.group(1)
            res = res_json(urlget(token_url, headers=dict(Referer=self.url)))
            token = res.get("token")
            if token:
                params["token"] = token

        streams = {}
        streams["live"] = RTMPStream(self.session, params)

        return streams
Exemple #8
0
    def _get_streams(self):
        channelid = urlparse(
            self.url).path.rstrip("/").rpartition("/")[-1].lower()

        self.logger.debug("Fetching stream info")
        headers = {"Referer": self.url}
        options = dict(id=channelid)
        res = urlget(self.StreamInfoURL, headers=headers, params=options)
        json = res_json(res, "stream info JSON")

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

        if not ("rtmp" in json and "streamname" in json):
            raise NoStreamsError(self.url)

        if not RTMPStream.is_usable(self.session):
            raise PluginError(
                "rtmpdump is not usable and required by Owncast plugin")

        rtmp = json["rtmp"]
        playpath = json["streamname"]

        streams = {}
        streams["live"] = RTMPStream(
            self.session, {
                "rtmp": rtmp,
                "pageUrl": self.url,
                "swfUrl": self.SWFURL,
                "playpath": playpath,
                "live": True
            })

        return streams
Exemple #9
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)
        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
Exemple #10
0
    def _create_rtmp_stream(self, cdn, stream_name):
        parsed = urlparse(cdn)
        options = dict(rtmp=cdn, app=parsed.path[1:],
                       playpath=stream_name, pageUrl=self.url,
                       swfUrl=SWF_URL, live=True)

        return RTMPStream(self.session, options)
Exemple #11
0
    def _get_streams(self):
        parsed = urlparse(self.url)

        if parsed.fragment:
            channelid = parsed.fragment
        else:
            channelid = parsed.path.rpartition("view/")[-1]

        if not channelid:
            raise NoStreamsError(self.url)

        channelid = channelid.lower().replace("/", "_")

        self.logger.debug("Fetching stream info")
        res = urlget(self.APIURL.format(channelid))
        json = res_json(res)

        if not isinstance(json, dict):
            raise PluginError("Invalid JSON response")
        elif not ("success" in json and "payload" in json):
            raise PluginError("Invalid JSON response")
        elif json["success"] == False:
            raise NoStreamsError(self.url)

        streams = {}
        streams["live"] = HTTPStream(self.session, json["payload"])

        return streams
Exemple #12
0
    def _get_streams(self):
        parsed = urlparse(self.url)
        cls = PROTOCOL_MAP.get(parsed.scheme)

        if not cls:
            return

        split = self.url.split(" ")
        url = split[0]
        urlnoproto = re.match("^\w+://(.+)", url).group(1)

        # Prepend http:// if needed.
        if cls != RTMPStream and not re.match("^http(s)?://", urlnoproto):
            urlnoproto = "http://{0}".format(urlnoproto)

        params = (" ").join(split[1:])
        params = self._parse_params(params)

        if cls == RTMPStream:
            params["rtmp"] = url

            for boolkey in ("live", "realtime", "quiet", "verbose", "debug"):
                if boolkey in params:
                    params[boolkey] = bool(params[boolkey])

            stream = cls(self.session, params)
        elif cls == HLSStream.parse_variant_playlist or cls == HDSStream.parse_manifest:
            return cls(self.session, urlnoproto, **params)
        else:
            stream = cls(self.session, urlnoproto, **params)

        return dict(live=stream)
Exemple #13
0
    def _get_streams(self):
        channelid = urlparse(self.url).path.rstrip("/").rpartition("/")[-1].lower()

        self.logger.debug("Fetching stream info")
        headers = {"Referer": self.url}
        options = dict(id=channelid)
        res = urlget(self.StreamInfoURL, headers=headers, params=options)
        json = res_json(res, "stream info JSON")

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

        if not ("rtmp" in json and "streamname" in json):
            raise NoStreamsError(self.url)

        if not RTMPStream.is_usable(self.session):
            raise PluginError("rtmpdump is not usable and required by Owncast plugin")

        rtmp = json["rtmp"]
        playpath = json["streamname"]

        streams = {}
        streams["live"] = RTMPStream(
            self.session, {"rtmp": rtmp, "pageUrl": self.url, "swfUrl": self.SWFURL, "playpath": playpath, "live": True}
        )

        return streams
Exemple #14
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":
            swf_url = SWF_URL
            for playlist in player.get("playlist", []):
                bitrates = playlist.get("bitrates")
                provider = playlist.get("connectionProvider")
                rtmp = None

                if bitrates:
                    rtmp = playlist.get("netConnectionUrl")
                elif provider and provider in player["plugins"]:
                    provider = player["plugins"][provider]
                    swf_name = provider["url"]
                    swf_url = SWF_BASE + swf_name
                    rtmp = provider["netConnectionUrl"]
                    bitrates = player["clip"]["bitrates"]
                else:
                    continue

                for bitrate in bitrates:
                    quality = self._get_quality(bitrate["label"])
                    url = bitrate["url"]
                    stream = RTMPStream(self.session, {
                        "rtmp": rtmp,
                        "pageUrl": self.url,
                        "playpath": url,
                        "swfVfy": swf_url,
                        "live": True
                    })
                    yield quality, stream
        else:
            base_url = player["clip"]["baseUrl"] or VOD_BASE_URL
            for bitrate in player["clip"]["bitrates"]:
                url = base_url + "/" + bitrate["url"]
                quality = self._get_quality(bitrate["label"])

                if urlparse(url).path.endswith("m3u8"):
                    stream = HLSStream(self.session, url)
                else:
                    stream = HTTPStream(self.session, url)

                yield quality, stream
Exemple #15
0
    def _get_streams(self):
        channelname = urlparse(self.url).path.rstrip("/").rpartition("/")[-1].lower()

        self.logger.debug("Fetching stream info")

        headers = {
            "Referer": self.url
        }

        res = urlget(self.PlayerURL.format(channelname), headers=headers)
        match = re.search("'FlashVars', '(id=\d+)&s=(.+?)&", res.text)
        if not match:
            raise NoStreamsError(self.url)

        channelname = "{0}?{1}".format(match.group(2), match.group(1))
        res = urlget(self.BalancerURL, headers=headers)

        match = re.search("redirect=(.+)", res.text)
        if not match:
            raise PluginError("Error retrieving RTMP address from loadbalancer")

        rtmp = match.group(1)
        streams = {}
        streams["live"] = RTMPStream(self.session, {
            "rtmp": "rtmp://{0}/live/{1}".format(rtmp, channelname),
            "pageUrl": self.url,
            "swfVfy": self.SWFURL,
            "conn": "S:OK",
            "live": True
        })

        return streams
Exemple #16
0
    def _get_stream(self, channel_id, quality):
        params = dict(channel_id=channel_id, quality=quality)
        res = urlopen(CHINFO_URL, data=params, headers=AJAX_HEADERS,
                      session=self.rsession)
        json = res_json(res)

        if not json:
            raise NoStreamsError(self.url)
        elif not isinstance(json, list):
            raise PluginError("Invalid JSON response")

        info = json[0]
        rtmp = info.get("serverURL")
        playpath = info.get("streamName")
        if not (rtmp and playpath):
            raise NoStreamsError(self.url)

        parsed = urlparse(rtmp)
        if not parsed.scheme.startswith("rtmp"):
            raise NoStreamsError(self.url)

        if parsed.query:
            app = "{0}?{1}".format(parsed.path[1:], parsed.query)
        else:
            app = parsed.path[1:]

        return RTMPStream(self.session, {
            "rtmp": rtmp,
            "pageUrl": self.url,
            "swfUrl": SWF_URL,
            "playpath": playpath,
            "app": app,
            "live": True
        })
Exemple #17
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
Exemple #18
0
    def _create_rtmp_stream(self, cdn, stream_name):
        parsed = urlparse(cdn)
        options = dict(rtmp=cdn, app=parsed.path[1:],
                       playpath=stream_name, pageUrl=self.url,
                       swfUrl=SWF_URL, live=True)

        return RTMPStream(self.session, options)
Exemple #19
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
Exemple #20
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        parsed = urlparse(self.url)
        if parsed.fragment:
            channel_id = parsed.fragment
        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}
Exemple #21
0
    def _get_streams(self):
        parsed = urlparse(self.url)

        if not parsed.scheme in self.ProtocolMap:
            raise NoStreamsError(self.url)

        cls = self.ProtocolMap[parsed.scheme]
        split = self.url.split(" ")

        url = split[0]
        urlnoproto = re.match("^\w+://(.+)", url).group(1)

        params = (" ").join(split[1:])
        params = self._parse_params(params)

        if cls == RTMPStream:
            params["rtmp"] = url

            for boolkey in ("live", "realtime", "quiet", "verbose", "debug"):
                if boolkey in params:
                    params[boolkey] = bool(params[boolkey])

            stream = cls(self.session, params)
        elif cls == HLSStream.parse_variant_playlist or cls == HDSStream.parse_manifest:
            return cls(self.session, urlnoproto, **params)
        else:
            stream = cls(self.session, urlnoproto, **params)

        return dict(live=stream)
Exemple #22
0
    def get_alt_live_streams(self):
        res = self._get_live_page(self.res)

        match = re.search('jQuery.post\("/live/ajaxGetUrl.gom", ({.+?}),',
                          res.text)
        if not match:
            raise NoStreamsError(self.url)

        ajaxparams = match.group(1)
        ajaxparams = dict(re.findall("(\w+):(\d+)", ajaxparams))

        levels = re.findall("setFlashLevel\((\d+)\);.+?<span class=\"qtype\">(\w+)</span>", res.text)
        streams = {}

        for level, quality in levels:
            params = ajaxparams.copy()
            params["level"] = level
            quality = quality.lower()

            res = urlopen(self.GetStreamURL, data=params, session=self.rsession)
            url = unquote(res.text)

            if not urlparse(url).path.endswith(".f4m"):
                continue

            try:
                s = HDSStream.parse_manifest(self.session, url)
                if len(s) > 0:
                    bitrate, stream = list(s.items())[0]
                    streams[quality] = stream
            except IOError:
                self.logger.warning("Unable to parse manifest")

        return streams
Exemple #23
0
    def _get_stream_live(self):
        self.logger.debug("Fetching room_id")
        res = http.get(self.url)
        match = re.search("room/id/(\d+)", res.text)
        if not match:
            return
        room_id = match.group(1)

        self.logger.debug("Comparing channel name with URL")
        match = re.search("<meta property=\"og:url\" content=\"http://www.filmon.us/(\w+)", res.text)
        if not match:
            return
        channel_name = match.group(1)
        base_name = self.url.rstrip("/").rpartition("/")[2]

        if (channel_name != base_name):
            return

        playpath = "mp4:bc_" + room_id
        if not playpath:
            raise NoStreamsError(self.url)

        rtmp = RTMP_URL
        parsed = urlparse(rtmp)
        app = parsed.path[1:]

        return RTMPStream(self.session, {
            "rtmp": RTMP_URL,
            "pageUrl": self.url,
            "swfUrl": SWF_URL,
            "playpath": playpath,
            "app": app,
            "live": True
        })
Exemple #24
0
    def _get_streams(self):
        parsed = urlparse(self.url)

        if not parsed.scheme in self.ProtocolMap:
            raise NoStreamsError(self.url)

        cls = self.ProtocolMap[parsed.scheme]
        split = self.url.split(" ")

        url = split[0]
        urlnoproto = re.match("^\w+://(.+)", url).group(1)

        params = (" ").join(split[1:])
        params = self._parse_params(params)

        if cls == RTMPStream:
            params["rtmp"] = url

            for boolkey in ("live", "realtime", "quiet", "verbose", "debug"):
                if boolkey in params:
                    params[boolkey] = bool(params[boolkey])

            stream = cls(self.session, params)
        elif cls == HLSStream.parse_variant_playlist or cls == HDSStream.parse_manifest:
            return cls(self.session, urlnoproto, **params)
        else:
            stream = cls(self.session, urlnoproto, **params)

        return dict(live=stream)
Exemple #25
0
    def _get_streams(self):
        channelname = urlparse(
            self.url).path.rstrip("/").rpartition("/")[-1].lower()

        self.logger.debug("Fetching stream info")

        headers = {"Referer": self.url}

        res = urlget(self.PlayerURL.format(channelname), headers=headers)
        match = re.search("'FlashVars', '(id=\d+)&", res.text)
        if not match:
            raise NoStreamsError(self.url)

        channelname += "?" + match.group(1)
        res = urlget(self.BalancerURL, headers=headers)

        match = re.search("redirect=(.+)", res.text)
        if not match:
            raise PluginError(
                "Error retrieving RTMP address from loadbalancer")

        rtmp = match.group(1)
        streams = {}
        streams["live"] = RTMPStream(
            self.session, {
                "rtmp": "rtmp://{0}/live/{1}".format(rtmp, channelname),
                "pageUrl": self.url,
                "swfVfy": self.SWFURL,
                "conn": "S:OK",
                "live": True
            })

        return streams
Exemple #26
0
    def _get_streams(self):
        info = http.get(self.url, schema=_schema)
        if not info:
            return

        headers = {"Referer": self.url}
        res = http.get(info["token_url"], headers=headers)
        token = http.json(res, schema=_token_schema)

        parsed = urlparse(info["rtmp_url"])
        if parsed.query:
            app = "{0}?{1}".format(parsed.path[1:], parsed.query)
        else:
            app = parsed.path[1:]

        params = {
            "rtmp": info["rtmp_url"],
            "app": app,
            "pageUrl": self.url,
            "swfVfy": info["swf_url"],
            "playpath": info["rtmp_playpath"],
            "token": token,
            "live": True
        }

        stream = RTMPStream(self.session, params)
        return dict(live=stream)
Exemple #27
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)
Exemple #28
0
    def __init__(self, url):
        parsed = urlparse(url)

        # Attempt to resolve current live URL if main page is passed
        if len(parsed.path) <= 1:
            url = self.LiveURL

        Plugin.__init__(self, url)
Exemple #29
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)
Exemple #30
0
    def _get_rtmp_app(self, rtmp):
        parsed = urlparse(rtmp)
        if parsed.query:
            app = "{0}?{1}".format(parsed.path[1:], parsed.query)
        else:
            app = parsed.path[1:]

        return app
Exemple #31
0
    def __init__(self, url):
        parsed = urlparse(url)

        # Attempt to resolve current live URL if main page is passed
        if len(parsed.path) <= 1:
            url = self.LiveURL

        Plugin.__init__(self, url)
Exemple #32
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)
Exemple #33
0
    def _get_rtmp_app(self, rtmp):
        parsed = urlparse(rtmp)
        if parsed.query:
            app = "{0}?{1}".format(parsed.path[1:], parsed.query)
        else:
            app = parsed.path[1:]

        return app
Exemple #34
0
    def _get_video_streams(self, player):
        base_url = player["clip"]["baseUrl"] or VOD_BASE_URL
        mapper = StreamMapper(cmp=lambda ext, bitrate: urlparse(bitrate["url"])
                              .path.endswith(ext))
        mapper.map(".m3u8", self._create_video_stream, HLSStream, base_url)
        mapper.map(".mp4", self._create_video_stream, HTTPStream, base_url)
        mapper.map(".flv", self._create_video_stream, HTTPStream, base_url)

        return mapper(player["clip"]["bitrates"])
Exemple #35
0
    def _get_streams(self):
        res = http.get(self.url, schema=_schema)
        if not res:
            return

        if res["type"] == "channel" and urlparse(res["url"]).path.endswith("m3u8"):
            return HLSStream.parse_variant_playlist(self.session, res["url"])
        elif res["type"] == "video":
            stream = HTTPStream(self.session, res["url"])
            return dict(video=stream)
Exemple #36
0
    def _get_video_streams(self, player):
        base_url = player["clip"]["baseUrl"] or VOD_BASE_URL
        mapper = StreamMapper(
            cmp=lambda ext, bitrate: urlparse(bitrate["url"]).path.endswith(ext)
        )
        mapper.map(".m3u8", self._create_video_stream, HLSStream, base_url)
        mapper.map(".mp4", self._create_video_stream, HTTPStream, base_url)
        mapper.map(".flv", self._create_video_stream, HTTPStream, base_url)

        return mapper(player["clip"]["bitrates"])
Exemple #37
0
    def _get_streams(self):
        """
            Find all the streams for the ITV url
            :return: Mapping of quality to stream
        """
        soap_message = self._soap_request()

        headers = {
            'Content-Length': '{0:d}'.format(len(soap_message)),
            'Content-Type': 'text/xml; charset=utf-8',
            'Host': 'mercury.itv.com',
            'Origin': 'http://www.itv.com',
            'Referer':
            'http://www.itv.com/Mercury/Mercury_VideoPlayer.swf?v=null',
            'SOAPAction': "http://tempuri.org/PlaylistService/GetPlaylist",
            'User-Agent': ITV_PLAYER_USER_AGENT,
            "X-Requested-With": "ShockwaveFlash/16.0.0.305"
        }

        res = http.post("http://mercury.itv.com/PlaylistService.svc?wsdl",
                        headers=headers,
                        data=soap_message)

        # looking for the <MediaFiles> tag
        xmldoc = http.xml(res)

        mediafiles = xmldoc.find(".//VideoEntries//MediaFiles")
        # No mediafiles, no streams
        if not mediafiles:
            return None

        rtmp = mediafiles.attrib['base']
        streams = {}

        for mediafile in mediafiles.findall("MediaFile"):
            playpath = mediafile.find("URL").text

            rtmp_url = urlparse(rtmp)
            app = (rtmp_url.path[1:] + '?' + rtmp_url.query).rstrip('?')
            live = app == "live"

            params = dict(
                rtmp="{u.scheme}://{u.netloc}{u.path}".format(u=rtmp_url),
                app=app.rstrip('?'),
                playpath=playpath,
                swfVfy=LIVE_SWF_URL if live else ONDEMAND_SWF_URL,
                timeout=10)
            if live:
                params['live'] = True

            bitrate = int(mediafile.attrib['bitrate']) / 1000
            quality = "{0}k".format(bitrate)
            streams[quality] = RTMPStream(self.session, params)

        return streams
Exemple #38
0
    def _get_streams(self):
        channelname = urlparse(
            self.url).path.rstrip("/").rpartition("/")[-1].lower()

        self.logger.debug("Fetching stream info")

        headers = {"Referer": self.url, "Accept-Encoding": "deflate"}

        options = dict(channel=channelname,
                       vw="580",
                       vh="390",
                       domain="www.cast3d.tv")

        res = http.get(self.PlayerURL, headers=headers, params=options)

        match = re.search(".+?'streamer':'(.+?)'", res.text)
        if not match:
            raise NoStreamsError(self.url)

        streams = {}
        url = urlparse(match.group(1))
        if url.scheme.startswith("rtmp"):
            redirect = False
            rtmp = match.group(1)
            if "redirect" in rtmp:
                redirect = True

            streams["live"] = RTMPStream(self.session, {
                "rtmp": rtmp,
                "pageUrl": self.url,
                "swfVfy": self.SWFURL,
                "playpath": channelname,
                "live": True
            },
                                         redirect=redirect)

        elif url.scheme.startswith("http"):
            streams["live"] = HTTPStream(self.session, match.group(1))
        else:
            raise PluginError(("Invalid stream type: {0}").format(url.scheme))

        return streams
Exemple #39
0
    def _get_streams(self):
        res = http.get(self.url, schema=_schema)
        if not res:
            return

        if res["type"] == "channel" and urlparse(
                res["url"]).path.endswith("m3u8"):
            return HLSStream.parse_variant_playlist(self.session, res["url"])
        elif res["type"] == "video":
            stream = HTTPStream(self.session, res["url"])
            return dict(video=stream)
Exemple #40
0
    def _get_streams(self):
        channelname = urlparse(self.url).path.rstrip("/").rpartition("/")[-1].lower()
        channelname = channelname.replace("_", "-")

        try:
            streams = HLSStream.parse_variant_playlist(self.session,
                                                       self.PlaylistURL.format(channelname))
        except IOError:
            return

        return streams
Exemple #41
0
    def _get_rtmp_app(self, rtmp):
        parsed = urlparse(rtmp)
        if not parsed.scheme.startswith("rtmp"):
            return

        if parsed.query:
            app = "{0}?{1}".format(parsed.path[1:], parsed.query)
        else:
            app = parsed.path[1:]

        return app
Exemple #42
0
    def _create_rtmp_stream(self, url):
        parsed = urlparse(url)
        if parsed.query:
            app = "{0}?{1}".format(parsed.path[1:], parsed.query)
        else:
            app = parsed.path[1:]

        params = {"rtmp": url, "app": app, "pageUrl": self.url, "live": True}

        stream = RTMPStream(self.session, params)
        return "live", stream
def resolve_url(url):
    parsed = urlparse(url)

    if len(parsed.scheme) == 0:
        url = "http://" + url

    for name, plugin in plugins.get_plugins().items():
        if plugin.can_handle_url(url):
            obj = plugin(url)
            return obj
    return None
Exemple #44
0
    def _get_stream_upload(self):
        video = urlparse(self.url).path

        if http.resolve_url(prepend_www(self.url)) == 'http://www.filmon.us/channels':
            raise PluginError(video + " don't exist")

        playpath = "mp4:resources" + video + '/v_3.mp4'

        rtmp = RTMP_UPLOAD_URL
        parsed = urlparse(rtmp)
        app = parsed.path[1:]

        return RTMPStream(self.session, {
            "rtmp": rtmp,
            "pageUrl": self.url,
            "swfUrl": SWF_UPLOAD_URL,
            "playpath": playpath,
            "app": app,
            "live": True
        })
Exemple #45
0
    def _get_rtmp_app(self, rtmp):
        parsed = urlparse(rtmp)
        if not parsed.scheme.startswith("rtmp"):
            return

        if parsed.query:
            app = "{0}?{1}".format(parsed.path[1:], parsed.query)
        else:
            app = parsed.path[1:]

        return app
Exemple #46
0
    def _get_streams(self):
        self.logger.debug("Fetching stream info")
        res = urlget(self.url)

        match = re.search("var current_channel = (.*);", res.text)
        if match:
            json = parse_json(match.group(1))
        else:
            raise NoStreamsError(self.url)

        if not isinstance(json, dict):
            raise PluginError("Invalid JSON response")
        elif not "streams" in json:
            raise NoStreamsError(self.url)

        if not RTMPStream.is_usable(self.session):
            raise PluginError(
                "rtmpdump is not usable and required by Filmon plugin")

        match = re.search("var flash_config = (.*);", res.text)
        if match:
            config = parse_json(match.group(1))
            if "streamer" in config:
                self.SWFURL = urljoin(self.SWFURL, config["streamer"])

        streams = {}

        for stream in json["streams"]:
            if not ("url" in stream and "name" in stream):
                continue

            parsed = urlparse(stream["url"])

            if not parsed.scheme.startswith("rtmp"):
                continue

            if parsed.query:
                app = "{0}?{1}".format(parsed.path[1:], parsed.query)
            else:
                app = parsed.path[1:]

            name = stream["quality"]
            streams[name] = RTMPStream(
                self.session, {
                    "rtmp": stream["url"],
                    "pageUrl": self.url,
                    "swfUrl": self.SWFURL,
                    "playpath": stream["name"],
                    "app": app,
                    "live": True
                })

        return streams
Exemple #47
0
    def _create_stream(self, source):
        url = source["file"]

        if urlparse(url).path.endswith("m3u8"):
            streams = HLSStream.parse_variant_playlist(self.session, url)

            # TODO: Replace with "yield from" when dropping Python 2.
            for stream in streams.items():
                yield stream
        else:
            name = source.get("label", "vod")
            yield name, HTTPStream(self.session, url)
Exemple #48
0
    def _create_rtmp_stream(self, cdn, stream_name):
        parsed = urlparse(cdn)
        params = {
            "rtmp": cdn,
            "app": parsed.path[1:],
            "playpath": stream_name,
            "pageUrl": self.url,
            "swfUrl": SWF_URL,
            "live": True
        }

        return RTMPStream(self.session, params)
Exemple #49
0
    def _get_streams(self):
        channelname = urlparse(
            self.url).path.rstrip("/").rpartition("/")[-1].lower()
        channelname = channelname.replace("_", "-")

        try:
            streams = HLSStream.parse_variant_playlist(
                self.session, self.PlaylistURL.format(channelname))
        except IOError:
            raise NoStreamsError(self.url)

        return streams
Exemple #50
0
    def _create_rtmp_stream(self, cdn, stream_name):
        parsed = urlparse(cdn)
        params = {
            "rtmp": cdn,
            "app": parsed.path[1:],
            "playpath": stream_name,
            "pageUrl": self.url,
            "swfUrl": SWF_URL,
            "live": True
        }

        return RTMPStream(self.session, params)
Exemple #51
0
    def _get_streams(self):
        """
            Find all the streams for the ITV url
            :return: Mapping of quality to stream
        """
        soap_message = self._soap_request()

        headers = {
            "Content-Length": "{0:d}".format(len(soap_message)),
            "Content-Type": "text/xml; charset=utf-8",
            "Host": "mercury.itv.com",
            "Origin": "http://www.itv.com",
            "Referer": "http://www.itv.com/Mercury/Mercury_VideoPlayer.swf?v=null",
            "SOAPAction": "http://tempuri.org/PlaylistService/GetPlaylist",
            "User-Agent": ITV_PLAYER_USER_AGENT,
            "X-Requested-With": "ShockwaveFlash/16.0.0.305",
        }

        res = http.post("http://mercury.itv.com/PlaylistService.svc?wsdl", headers=headers, data=soap_message)

        # looking for the <MediaFiles> tag
        xmldoc = http.xml(res)

        mediafiles = xmldoc.find(".//VideoEntries//MediaFiles")
        # No mediafiles, no streams
        if not mediafiles:
            return None

        rtmp = mediafiles.attrib["base"]
        streams = {}

        for mediafile in mediafiles.findall("MediaFile"):
            playpath = mediafile.find("URL").text

            rtmp_url = urlparse(rtmp)
            app = (rtmp_url.path[1:] + "?" + rtmp_url.query).rstrip("?")
            live = app == "live"

            params = dict(
                rtmp="{u.scheme}://{u.netloc}{u.path}".format(u=rtmp_url),
                app=app.rstrip("?"),
                playpath=playpath,
                swfVfy=LIVE_SWF_URL if live else ONDEMAND_SWF_URL,
                timeout=10,
            )
            if live:
                params["live"] = True

            bitrate = int(mediafile.attrib["bitrate"]) / 1000
            quality = "{0}k".format(bitrate)
            streams[quality] = RTMPStream(self.session, params)

        return streams
Exemple #52
0
    def _get_streams(self):
        res = http.get(self.url)

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

        xml_info_url = STREAMS_INFO_URL.format(match.group(1))
        video_info_res = http.get(xml_info_url)
        parsed_info = http.xml(video_info_res)

        live_el = parsed_info.find("live")
        live = live_el is not None and live_el.text == "1"

        streams = {}

        hdsurl_el = parsed_info.find("hdsurl")
        if hdsurl_el is not None and hdsurl_el.text is not None:
            hdsurl = hdsurl_el.text
            streams.update(HDSStream.parse_manifest(self.session, hdsurl))

        if live:
            vurls_el = parsed_info.find("vurls")
            if vurls_el is not None:
                for i, vurl_el in enumerate(vurls_el):
                    bitrate = vurl_el.get("bitrate")
                    name = bitrate + "k" if bitrate is not None else "rtmp{0}".format(
                        i)
                    params = {
                        "rtmp": vurl_el.text,
                    }
                    streams[name] = RTMPStream(self.session, params)

        parsed_urls = set()
        mobileurls_el = parsed_info.find("mobileurls")
        if mobileurls_el is not None:
            for mobileurl_el in mobileurls_el:
                text = mobileurl_el.text
                if not text:
                    continue

                if text in parsed_urls:
                    continue

                parsed_urls.add(text)
                url = urlparse(text)

                if url[0] == "http" and url[2].endswith("m3u8"):
                    streams.update(
                        HLSStream.parse_variant_playlist(self.session, text))

        return streams
Exemple #53
0
    def _get_stream_upload(self):
        video = urlparse(self.url).path

        if http.resolve_url(prepend_www(
                self.url)) == 'http://www.filmon.us/channels':
            raise PluginError(video + " don't exist")

        playpath = "mp4:resources" + video + '/v_3.mp4'

        rtmp = RTMP_UPLOAD_URL
        parsed = urlparse(rtmp)
        app = parsed.path[1:]

        return RTMPStream(
            self.session, {
                "rtmp": rtmp,
                "pageUrl": self.url,
                "swfUrl": SWF_UPLOAD_URL,
                "playpath": playpath,
                "app": app,
                "live": True
            })
    def _get_channel_name(self, url):
        name = None
        if ("dailymotion.com" in url) or ("dai.ly" in url):
            rpart = urlparse(url).path.rstrip("/").rpartition("/")[-1].lower()
            name = re.sub("_.*", "", rpart)
        elif ("video.gamecreds.com" in url):
            res = urlget(url)
            # The HTML is broken (unclosed meta tags) and minidom fails to parse.
            # Since we are not manipulating the DOM, we get away with a simple grep instead of fixing it.
            match = re.search("<meta property=\"og:video\" content=\"http://www.dailymotion.com/swf/video/([a-z0-9]{6})", res.text)
            if match: name = match.group(1)

        return name
Exemple #55
0
    def _get_streams(self):
        country_code = urlparse(self.url).netloc.split(".")[0]

        self.logger.debug("Fetching stream info")
        res = urlget(self.APIURL)
        json = res_json(res)

        if not isinstance(json, dict):
            raise PluginError("Invalid JSON response")
        elif not ("primary" in json or "secondary" in json):
            raise PluginError("Invalid JSON response")

        if not RTMPStream.is_usable(self.session):
            raise PluginError(
                "rtmpdump is not usable and required by Euronews plugin")

        streams = {}

        self.logger.debug("Euronews Countries:{0}",
                          " ".join(json["primary"].keys()))

        if not (country_code in json["primary"]
                or country_code in json["secondary"]):
            res = urlget(self.GEOIPURL)
            geo = res_json(res)
            if isinstance(json, dict) and "country_code" in geo:
                country_code = geo["country_code"].lower()
                if not (country_code in json["primary"]
                        or country_code in json["secondary"]):
                    country_code = "en"
            else:
                country_code = "en"

        for site in ("primary", "secondary"):
            for quality in json[site][country_code]["rtmp_flash"]:
                stream = json[site][country_code]["rtmp_flash"][quality]
                name = quality + "k"
                if site == "secondary":
                    name += "_alt"
                streams[name] = RTMPStream(
                    self.session, {
                        "rtmp": stream["server"],
                        "playpath": stream["name"],
                        "swfUrl": self.SWFURL,
                        "live": True
                    })

        if len(streams) == 0:
            raise NoStreamsError(self.url)

        return streams
Exemple #56
0
    def __init__(self, url):
        Plugin.__init__(self, url)

        match = _url_re.match(url).groupdict()
        self.channel = match.get("channel").lower()
        self.subdomain = match.get("subdomain")
        self.video_type = match.get("video_type")
        self.video_id = match.get("video_id")

        parsed = urlparse(url)
        self.params = parse_query(parsed.query)

        self.api = TwitchAPI(beta=self.subdomain == "beta")
        self.usher = UsherService()