Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    def get_live_streams(self):
        res = self._get_live_page(self.res)

        match = re.search("this\.playObj = ({.+?})", res.text, re.DOTALL)
        if not match:
            raise NoStreamsError(self.url)

        flashvars = parse_json(match.group(1), "playObj JSON")

        match = re.search("goxkey=([A-z0-9]+)", res.text)
        if not match:
            raise NoStreamsError(self.url)

        flashvars["goxkey"] = match.group(1)
        flashvars["target"] = "live"

        streams = {}

        for strlevel in self.LiveQualityLevels:
            params = self._create_gox_params(flashvars, strlevel, "live")
            res = urlget(self.GOXURL, params=params, session=self.rsession)

            gox = GOXFile(res.text)

            for entry in gox.entries:
                streams[strlevel.lower()] = HTTPStream(self.session, entry.ref[0],
                                                       headers=self.StreamHeaders)

                break

        return streams
Ejemplo n.º 8
0
    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()))
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
    def get_live_streams(self):
        res = self._get_live_page(self.res)

        match = re.search("flashvars\s+=\s+({.+?});", res.text)

        if not match:
            raise NoStreamsError(self.url)

        flashvars = parse_json(match.group(1), "flashvars JSON")
        flashvars["uip"] = self._get_user_ip()

        levels = re.findall("setFlashLevel\((\d+)\);", res.text)
        streams = {}

        for level in levels:
            params = self._create_gox_params(flashvars, level)

            res = urlget(self.GOXLiveURL, params=params,
                         session=self.rsession)
            gox = GOXFile(res.text)

            for entry in gox.filter_entries("live"):
                try:
                    s = HDSStream.parse_manifest(self.session, entry.ref[0])
                    streams.update(s)
                except IOError:
                    self.logger.warning("Unable to parse manifest")

                break

        return streams
Ejemplo n.º 11
0
    def get_live_streams(self):
        res = self._get_live_page(self.res)

        match = re.search("flashvars\s+=\s+({.+?});", res.text)

        if not match:
            raise NoStreamsError(self.url)

        flashvars = parse_json(match.group(1), "flashvars JSON")
        flashvars["uip"] = self._get_user_ip()

        levels = re.findall("setFlashLevel\((\d+)\);", res.text)
        streams = {}

        for level in levels:
            params = self._create_gox_params(flashvars, level)

            res = urlget(self.GOXLiveURL, params=params, session=self.rsession)
            gox = GOXFile(res.text)

            for entry in gox.filter_entries("live"):
                try:
                    s = HDSStream.parse_manifest(self.session, entry.ref[0])
                    streams.update(s)
                except IOError:
                    self.logger.warning("Unable to parse manifest")

                break

        return streams
Ejemplo n.º 12
0
    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)
            chansub = verifyjson(token, "chansub")
            restricted_bitrates = verifyjson(chansub, "restricted_bitrates")

            for name in filter(
                    lambda n: not re.match(r"(.+_)?archives|live", n),
                    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()))
Ejemplo n.º 13
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
Ejemplo n.º 14
0
    def _get_stream_info(self):
        res = urlget(self.url)

        match = re.search("var initialData = ({.+})", res.text)

        if match:
            config = match.group(1)

            return parse_json(config, "config JSON")
Ejemplo n.º 15
0
    def _get_stream_info(self):
        res = urlget(self.url)

        match = re.search("initialData : ({.+})", res.text)

        if match:
            config = match.group(1)

            return parse_json(config, "config JSON")
Ejemplo n.º 16
0
    def _get_stream_info(self, url):
        res = urlget(url)
        config = self._find_config(res.text)

        if not config:
            watch_match = re.search("href=\"/(watch\?v=.+?)\"", res.text)
            if watch_match:
                watch_url = "http://youtube.com/%s" % watch_match.group(1)
                res = urlget(watch_url)
                config = self._find_config(res.text)

        if config:
            return parse_json(config, "config JSON")
Ejemplo n.º 17
0
    def _get_stream_info(self, url):
        res = urlget(url)
        config = self._find_config(res.text)

        if not config:
            watch_match = re.search("href=\"/(watch\?v=.+?)\"", res.text)
            if watch_match:
                watch_url = "http://youtube.com/{0}".format(watch_match.group(1))
                res = urlget(watch_url)
                config = self._find_config(res.text)

        if config:
            return parse_json(config, "config JSON")
Ejemplo n.º 18
0
    def _get_stream_info(self, url):
        match = re.search("/(embed|v)/([^?]+)", url)
        if match:
            url = "http://youtube.com/watch?v={0}".format(match.group(2))

        res = http.get(url)
        match = re.search("/user/([^?/]+)", res.url)
        if match:
            return self._find_channel_config(res.text)
        else:
            config = self._find_config(res.text)

        if config:
            return parse_json(config, "config JSON")
Ejemplo n.º 19
0
    def _get_stream_info(self, url):
        res = urlget(url)
        data = res.text
        config = None

        match = re.search("'PLAYER_CONFIG': (.+)\n.+}\);", data)
        if match:
            config = match.group(1)

        match = re.search("yt.playerConfig = (.+)\;\n", data)
        if match:
            config = match.group(1)

        if config:
            return parse_json(config, "config JSON")
Ejemplo n.º 20
0
    def _get_stream_info(self, url):
        res = urlget(url)
        data = res.text
        config = None

        match = re.search("'PLAYER_CONFIG': (.+)\n.+}\);", data)
        if match:
            config = match.group(1)

        match = re.search("yt.playerConfig = (.+)\;\n", data)
        if match:
            config = match.group(1)

        if config:
            return parse_json(config, "config JSON")
Ejemplo n.º 21
0
 def _get_stream_info(self):
     res = http.get(self.url)
     match = re.search("window.config = ({.+})", res.text)
     if match:
         config = match.group(1)
         return parse_json(config, "config JSON")
Ejemplo n.º 22
0
    def _get_stream_info(self, url):
        res = urlget(url)
        config = self._find_config(res.text)

        if config:
            return parse_json(config, "config JSON")
Ejemplo n.º 23
0
    def get_vod_streams(self):
        match = re.search("flashvars\s+=\s+({.+?});", self.res.text)

        if not match:
            raise NoStreamsError(self.url)

        flashvars = parse_json(match.group(1), "flashvars JSON")

        match = re.search("var jsonData\s+= eval \((.+?)\);", self.res.text,
                          re.DOTALL)

        if not match:
            raise NoStreamsError(self.url)

        playlists = parse_json(match.group(1), "playlist JSON")

        self.logger.info("Playlist items found:")
        for i, playlist in enumerate(playlists):
            for fvars in playlist:
                if self.url[-1] != "/":
                    url = self.url + "/"
                else:
                    url = self.url

                url = urljoin(url, "?set={1}&lang={0}".format(i, fvars["set"]))

                self.logger.info("[Set {1} ({0})] {2}", self.Lang[i],
                                 fvars["set"], url)

        params = parse_qsd(urlparse(self.url).query)
        currentset = int(params.get("set", "1"))
        lang = int(params.get("lang", "0"))

        flashvars.update(playlists[lang][currentset - 1])
        flashvars["uip"] = self._get_user_ip()

        streams = {}

        for level, levelname in self.VODQualityLevels.items():
            params = self._create_gox_params(flashvars, level)

            res = urlget(self.GOXVODURL, params=params, session=self.rsession)

            gox = GOXFile(res.text)
            entries = gox.filter_entries("vod")

            for entry in entries:
                streamurl = entry.ref[0]
                params = {}

                try:
                    params["key"] = self._create_stream_key(streamurl)
                except PluginError as err:
                    self.logger.warning("{0}", str(err))
                    continue

                streams[levelname] = HTTPStream(self.session,
                                                streamurl,
                                                params=params)

        if len(streams) == 0:
            self.logger.warning(("Unable to access any streams, "
                                 "make sure you have access to this VOD"))

        return streams
Ejemplo n.º 24
0
    def get_vod_streams(self):
        match = re.search("flashvars\s+=\s+({.+?});", self.res.text)

        if not match:
            raise NoStreamsError(self.url)

        flashvars = parse_json(match.group(1), "flashvars JSON")

        match = re.search("var jsonData\s+= eval \((.+?)\);",
                             self.res.text, re.DOTALL)

        if not match:
            raise NoStreamsError(self.url)

        playlists = parse_json(match.group(1), "playlist JSON")

        self.logger.info("Playlist items found:")
        for i, playlist in enumerate(playlists):
            for fvars in playlist:
                if self.url[-1] != "/":
                    url = self.url + "/"
                else:
                    url = self.url

                url = urljoin(url, "?set={1}&lang={0}".format(i,
                              fvars["set"]))

                self.logger.info("[Set {1} ({0})] {2}", self.Lang[i],
                                                        fvars["set"],
                                                        url)

        params = parse_qsd(urlparse(self.url).query)
        currentset = int(params.get("set", "1"))
        lang = int(params.get("lang", "0"))

        flashvars.update(playlists[lang][currentset - 1])
        flashvars["uip"] = self._get_user_ip()

        streams = {}

        for level, levelname in self.VODQualityLevels.items():
            params = self._create_gox_params(flashvars, level)

            res = urlget(self.GOXVODURL, params=params,
                         session=self.rsession)

            gox = GOXFile(res.text)
            entries = gox.filter_entries("vod")

            for entry in entries:
                streamurl = entry.ref[0]
                params = {}

                try:
                    params["key"] = self._create_stream_key(streamurl)
                except PluginError as err:
                    self.logger.warning("{0}", str(err))
                    continue

                streams[levelname] = HTTPStream(self.session, streamurl,
                                                params=params)

        if len(streams) == 0:
            self.logger.warning(("Unable to access any streams, "
                                 "make sure you have access to this VOD"))

        return streams
Ejemplo n.º 25
0
 def _get_stream_info(self):
     res = http.get(self.url)
     match = re.search("window.config = ({.+})", res.text)
     if match:
         config = match.group(1)
         return parse_json(config, "config JSON")