コード例 #1
0
ファイル: svtplay.py プロジェクト: wirretheman/svtplay-dl
    def _get_video(self, janson):
        if "subtitleReferences" in janson:
            for i in janson["subtitleReferences"]:
                if i["format"] == "websrt" and "url" in i:
                    yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output)

        if "videoReferences" in janson:
            if len(janson["videoReferences"]) == 0:
                yield ServiceError("Media doesn't have any associated videos.")
                return

            for i in janson["videoReferences"]:
                streams = None
                alt_streams = None
                alt = None
                query = parse_qs(urlparse(i["url"]).query)
                if "alt" in query and len(query["alt"]) > 0:
                    alt = self.http.get(query["alt"][0])

                if i["format"] == "hls":
                    streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
                    if alt:
                        alt_streams = hlsparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output)
                elif i["format"] == "dash264" or i["format"] == "dashhbbtv":
                    streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
                    if alt:
                        alt_streams = dashparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output)

                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
                if alt_streams:
                    for n in list(alt_streams.keys()):
                        yield alt_streams[n]
コード例 #2
0
    def get(self):
        if not self.config.get("username") or not self.config.get("password"):
            yield ServiceError(
                "You need username and password to download things from this site."
            )
            return

        token, message = self._login()
        if not token:
            yield ServiceError(message)
            return

        res = self.http.get(self.url)
        match = re.search('data-asset-id="([^"]+)"', res.text)
        if not match:
            yield ServiceError("Can't find video id")
            return

        tld = self._gettld()
        url = "https://restapi.cmore.{0}/api/tve_web/asset/{1}/play.json?protocol=VUDASH".format(
            tld, match.group(1))
        res = self.http.get(
            url, headers={"authorization": "Bearer {0}".format(token)})
        janson = res.json()
        if "error" in janson:
            yield ServiceError("This video is geoblocked")
            return

        basename = self._autoname(match.group(1))
        self.output["id"] = match.group(1)
        if basename is None:
            yield ServiceError("Cant find vid id for autonaming")
            return

        if "drmProtected" in janson["playback"]:
            if janson["playback"]["drmProtected"]:
                yield ServiceError("DRM protected. Can't do anything")
                return

        if isinstance(janson["playback"]["items"]["item"], list):
            for i in janson["playback"]["items"]["item"]:
                if i["mediaFormat"] == "ism":
                    streams = dashparse(self.config,
                                        self.http.request("get", i["url"]),
                                        i["url"],
                                        output=self.output)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
                if i["mediaFormat"] == "webvtt":
                    yield subtitle(copy.copy(self.config), "wrst", i["url"])
        else:
            i = janson["playback"]["items"]["item"]
            if i["mediaFormat"] == "ism":
                streams = dashparse(self.config,
                                    self.http.request("get", i["url"]),
                                    i["url"],
                                    output=self.output)
                for n in list(streams.keys()):
                    yield streams[n]
コード例 #3
0
    def _get_video(self, janson):
        if "live" in janson:
            self.options.live = janson["live"]
        if "subtitleReferences" in janson:
            for i in janson["subtitleReferences"]:
                if i["format"] == "websrt" and "url" in i:
                    yield subtitle(copy.copy(self.options), "wrst", i["url"])

        if "videoReferences" in janson:
            if len(janson["videoReferences"]) == 0:
                yield ServiceError("Media doesn't have any associated videos (yet?)")
                return

            for i in janson["videoReferences"]:
                parse = urlparse(i["url"])
                query = parse_qs(parse.query)
                if i["format"] == "hls":
                    streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
                    if "alt" in query and len(query["alt"]) > 0:
                        alt = self.http.get(query["alt"][0])
                        if alt:
                            streams = hlsparse(self.options, self.http.request("get", alt.request.url), alt.request.url)
                            if streams:
                                for n in list(streams.keys()):
                                    yield streams[n]
                if i["format"] == "hds":
                    match = re.search(r"\/se\/secure\/", i["url"])
                    if not match:
                        streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"])
                        if streams:
                            for n in list(streams.keys()):
                                yield streams[n]
                        if "alt" in query and len(query["alt"]) > 0:
                            alt = self.http.get(query["alt"][0])
                            if alt:
                                streams = hdsparse(self.options, self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}), alt.request.url)
                                if streams:
                                    for n in list(streams.keys()):
                                        yield streams[n]
                if i["format"] == "dash264" or i["format"] == "dashhbbtv":
                    streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]

                    if "alt" in query and len(query["alt"]) > 0:
                        alt = self.http.get(query["alt"][0])
                        if alt:
                            streams = dashparse(self.options, self.http.request("get", alt.request.url), alt.request.url)
                            if streams:
                                for n in list(streams.keys()):
                                    yield streams[n]
コード例 #4
0
    def get(self):
        filename = os.path.basename(self.url[:self.url.rfind("/")])
        self.output["title"] = filename

        streams = []
        if re.search(".f4m", self.url):
            self.output["ext"] = "flv"
            streams.append(
                hdsparse(self.config,
                         self.http.request("get",
                                           self.url,
                                           params={"hdcore": "3.7.0"}),
                         self.url,
                         output=self.output))

        if re.search(".m3u8", self.url):
            streams.append(
                hlsparse(self.config,
                         self.http.request("get", self.url),
                         self.url,
                         output=self.output))

        if re.search(".mpd", self.url):
            streams.append(
                dashparse(self.config,
                          self.http.request("get", self.url),
                          self.url,
                          output=self.output))

        for stream in streams:
            if stream:
                for n in list(stream.keys()):
                    yield stream[n]
コード例 #5
0
ファイル: raw.py プロジェクト: olof/svtplay-dl
    def get(self):
        if self.exclude():
            return

        extention = False
        filename = os.path.basename(self.url[:self.url.rfind("/")])
        if self.options.output and os.path.isdir(self.options.output):
            self.options.output = os.path.join(os.path.dirname(self.options.output), filename)
            extention = True
        elif self.options.output is None:
            self.options.output = filename
            extention = True

        streams = []
        if re.search(".f4m", self.url):
            if extention:
                self.options.output = "{0}.flv".format(self.options.output)

            streams.append(hdsparse(self.options, self.http.request("get", self.url, params={"hdcore": "3.7.0"}), self.url))

        if re.search(".m3u8", self.url):
            streams.append(hlsparse(self.options, self.http.request("get", self.url), self.url))

        if re.search(".mpd", self.url):
            streams.append(dashparse(self.options, self.http.request("get", self.url), self.url))

        for stream in streams:
            if stream:
                for n in list(stream.keys()):
                    yield stream[n]
コード例 #6
0
ファイル: svtplay.py プロジェクト: spaam/svtplay-dl
    def _get_video(self, janson):
        if "subtitleReferences" in janson:
            for i in janson["subtitleReferences"]:
                if i["format"] == "websrt" and "url" in i:
                    yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output)

        if "videoReferences" in janson:
            if len(janson["videoReferences"]) == 0:
                yield ServiceError("Media doesn't have any associated videos.")
                return

            for i in janson["videoReferences"]:
                streams = None
                alt_streams = None
                alt = None
                query = parse_qs(urlparse(i["url"]).query)
                if "alt" in query and len(query["alt"]) > 0:
                    alt = self.http.get(query["alt"][0])

                if i["format"] == "hls":
                    streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
                    if alt:
                        alt_streams = hlsparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output)

                elif i["format"] == "hds":
                    match = re.search(r"\/se\/secure\/", i["url"])
                    if not match:
                        streams = hdsparse(self.config, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}),
                                           i["url"], output=self.output)
                        if alt:
                            alt_streams = hdsparse(self.config, self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}),
                                                   alt.request.url, output=self.output)
                elif i["format"] == "dash264" or i["format"] == "dashhbbtv":
                    streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
                    if alt:
                        alt_streams = dashparse(self.config, self.http.request("get", alt.request.url),
                                                alt.request.url, output=self.output)

                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
                if alt_streams:
                    for n in list(alt_streams.keys()):
                        yield alt_streams[n]
コード例 #7
0
ファイル: raw.py プロジェクト: olof/debian-svtplay-dl
    def get(self):
        filename = os.path.basename(self.url[:self.url.rfind("/")])
        self.output["title"] = filename

        streams = []
        if re.search(".f4m", self.url):
            self.output["ext"] = "flv"
            streams.append(hdsparse(self.config, self.http.request("get", self.url, params={"hdcore": "3.7.0"}), self.url, output=self.output))

        if re.search(".m3u8", self.url):
            streams.append(hlsparse(self.config, self.http.request("get", self.url), self.url, output=self.output))

        if re.search(".mpd", self.url):
            streams.append(dashparse(self.config, self.http.request("get", self.url), self.url, output=self.output))

        for stream in streams:
            if stream:
                for n in list(stream.keys()):
                    yield stream[n]
コード例 #8
0
ファイル: vidme.py プロジェクト: magic75/svtplay-dl
    def _get_video(self, janson):

        if "video" in janson and "formats" in janson["video"]:
            janson_v = janson["video"]
            if len(janson_v["formats"]) == 0:
                yield ServiceError("Media doesn't have any associated videos.")
                return

            for i in janson_v["formats"]:
                streams = None

                if i["type"] == "hls":
                    streams = hlsparse(self.options, self.http.request("get", i["uri"]), i["uri"])

                elif i["type"] == "dash":
                    streams = dashparse(self.options, self.http.request("get", i["uri"]), i["uri"])

                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
コード例 #9
0
ファイル: raw.py プロジェクト: crapmaster/svtplay-dl
    def get(self):
        if self.exclude():
            return

        extention = False
        filename = os.path.basename(self.url[:self.url.rfind("/")])
        if self.options.output and os.path.isdir(self.options.output):
            self.options.output = os.path.join(
                os.path.dirname(self.options.output), filename)
            extention = True
        elif self.options.output is None:
            self.options.output = filename
            extention = True

        streams = []
        if re.search(".f4m", self.url):
            if extention:
                self.options.output = "{0}.flv".format(self.options.output)

            streams.append(
                hdsparse(
                    self.options,
                    self.http.request("get",
                                      self.url,
                                      params={"hdcore": "3.7.0"}), self.url))

        if re.search(".m3u8", self.url):
            streams.append(
                hlsparse(self.options, self.http.request("get", self.url),
                         self.url))

        if re.search(".mpd", self.url):
            streams.append(
                dashparse(self.options, self.http.request("get", self.url),
                          self.url))

        for stream in streams:
            if stream:
                for n in list(stream.keys()):
                    yield stream[n]
コード例 #10
0
    def _get_video(self, janson):

        if "video" in janson and "formats" in janson["video"]:
            janson_v = janson["video"]
            if len(janson_v["formats"]) == 0:
                yield ServiceError("Media doesn't have any associated videos.")
                return

            for i in janson_v["formats"]:
                streams = None

                if i["type"] == "hls":
                    streams = hlsparse(self.options,
                                       self.http.request("get", i["uri"]),
                                       i["uri"])

                elif i["type"] == "dash":
                    streams = dashparse(self.options,
                                        self.http.request("get", i["uri"]),
                                        i["uri"])

                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
コード例 #11
0
ファイル: oppetarkiv.py プロジェクト: magic75/svtplay-dl
    def get(self):
        vid = self.find_video_id()
        if vid is None:
            yield ServiceError("Cant find video id for this video")
            return

        url = "http://api.svt.se/videoplayer-api/video/{0}".format(vid)
        data = self.http.request("get", url)
        if data.status_code == 404:
            yield ServiceError("Can't get the json file for {0}".format(url))
            return

        data = data.json()
        if "live" in data:
            self.options.live = data["live"]

        if self.options.output_auto:
            self.options.service = "svtplay"
            self.options.output = self.outputfilename(data, self.options.output, ensure_unicode(self.get_urldata()))

        if self.exclude():
            yield ServiceError("Excluding video")
            return
        if "subtitleReferences" in data:
            for i in data["subtitleReferences"]:
                if i["format"] == "websrt":
                    yield subtitle(copy.copy(self.options), "wrst", i["url"])

        if len(data["videoReferences"]) == 0:
            yield ServiceError("Media doesn't have any associated videos (yet?)")
            return

        for i in data["videoReferences"]:
            parse = urlparse(i["url"])
            query = parse_qs(parse.query)
            if i["format"] == "hls" or i["format"] == "ios":
                streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"])
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
                if "alt" in query and len(query["alt"]) > 0:
                    alt = self.http.get(query["alt"][0])
                    if alt:
                        streams = hlsparse(self.options, self.http.request("get", alt.request.url), alt.request.url)
                        if streams:
                            for n in list(streams.keys()):
                                yield streams[n]
            if i["format"] == "hds" or i["format"] == "flash":
                match = re.search(r"\/se\/secure\/", i["url"])
                if not match:
                    streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}),
                                       i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
                    if "alt" in query and len(query["alt"]) > 0:
                        alt = self.http.get(query["alt"][0])
                        if alt:
                            streams = hdsparse(self.options,
                                               self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}),
                                               alt.request.url)
                            if streams:
                                for n in list(streams.keys()):
                                    yield streams[n]
            if i["format"] == "dash264" or i["format"] == "dashhbbtv":
                streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"])
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]

                if "alt" in query and len(query["alt"]) > 0:
                    alt = self.http.get(query["alt"][0])
                    if alt:
                        streams = dashparse(self.options, self.http.request("get", alt.request.url), alt.request.url)
                        if streams:
                            for n in list(streams.keys()):
                                yield streams[n]
コード例 #12
0
    def get(self):
        if not self.options.username or not self.options.password:
            yield ServiceError(
                "You need username and password to download things from this site."
            )
            return
        token, message = self._login()
        if not token:
            yield ServiceError(message)
            return
        res = self.http.get(self.url)
        match = re.search('data-asset-splash-section data-asset-id="([^"]+)"',
                          res.text)
        if not match:
            yield ServiceError("Can't find video id")
            return
        url = "https://restapi.cmore.se/api/tve_web/asset/{0}/play.json?protocol=VUDASH".format(
            match.group(1))
        res = self.http.get(
            url, headers={"authorization": "Bearer {0}".format(token)})
        janson = res.json()

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            self.options.service = "cmore"
            basename = self._autoname(match.group(1))
            if basename is None:
                yield ServiceError("Cant find vid id for autonaming")
                return
            title = "%s-%s-%s" % (basename, match.group(1),
                                  self.options.service)
            title = filenamify(title)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        if "drmProtected" in janson["playback"]:
            if janson["playback"]["drmProtected"]:
                yield ServiceError("DRM protected. Can't do anything")
                return

        if isinstance(janson["playback"]["items"]["item"], list):
            for i in janson["playback"]["items"]["item"]:
                if i["mediaFormat"] == "ism":
                    streams = dashparse(self.options,
                                        self.http.request("get", i["url"]),
                                        i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
                if i["mediaFormat"] == "webvtt":
                    yield subtitle(copy.copy(self.options), "wrst", i["url"])
        else:
            i = janson["playback"]["items"]["item"]
            if i["mediaFormat"] == "ism":
                streams = dashparse(self.options,
                                    self.http.request("get", i["url"]),
                                    i["url"])
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
コード例 #13
0
ファイル: svtplay.py プロジェクト: rabinv/svtplay-dl
    def get(self):
        old = False

        parse = urlparse(self.url)
        if parse.netloc == "www.svtplay.se" or parse.netloc == "svtplay.se":
            if parse.path[:6] != "/video" and parse.path[:6] != "/klipp":
                yield ServiceError("This mode is not supported anymore. need the url with the video")
                return

        vid = self.find_video_id()
        if vid is None:
            yield ServiceError("Cant find video id for this video")
            return
        if re.match("^[0-9]+$", vid):
            old = True

        url = "http://www.svt.se/videoplayer-api/video/%s" % vid
        data = self.http.request("get", url)
        if data.status_code == 404:
            yield ServiceError("Can't get the json file for %s" % url)
            return

        data = data.json()
        if "live" in data:
            self.options.live = data["live"]
        if old:
            params = {"output": "json"}
            try:
                dataj = self.http.request("get", self.url, params=params).json()
            except ValueError:
                dataj = data
                old = False
        else:
            dataj = data

        if self.options.output_auto:
            self.options.service = "svtplay"
            self.options.output = self.outputfilename(dataj, self.options.output, ensure_unicode(self.get_urldata()))

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        if "subtitleReferences" in data:
            for i in data["subtitleReferences"]:
                if i["format"] == "websrt":
                    yield subtitle(copy.copy(self.options), "wrst", i["url"])
        if old and dataj["video"]["subtitleReferences"]:
            try:
                suburl = dataj["video"]["subtitleReferences"][0]["url"]
            except KeyError:
                pass
            if suburl and len(suburl) > 0:
                yield subtitle(copy.copy(self.options), "wrst", suburl)

        if len(data["videoReferences"]) == 0:
            yield ServiceError("Media doesn't have any associated videos (yet?)")
            return

        for i in data["videoReferences"]:
            if i["format"] == "hls" or i["format"] == "ios":
                streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"])
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
            if i["format"] == "hds" or i["format"] == "flash":
                match = re.search(r"\/se\/secure\/", i["url"])
                if not match:
                    streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            if i["format"] == "dash264":
                streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"])
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
コード例 #14
0
    def get(self):
        vid = self.find_video_id()
        if vid is None:
            yield ServiceError("Cant find video id for this video")
            return

        url = "http://api.svt.se/videoplayer-api/video/{}".format(vid)
        data = self.http.request("get", url)
        if data.status_code == 404:
            yield ServiceError("Can't get the json file for {}".format(url))
            return

        data = data.json()
        if "live" in data:
            self.config.set("live", data["live"])

        self.outputfilename(data)

        if "subtitleReferences" in data:
            for i in data["subtitleReferences"]:
                if i["format"] == "websrt":
                    yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output)

        if len(data["videoReferences"]) == 0:
            yield ServiceError("Media doesn't have any associated videos (yet?)")
            return

        for i in data["videoReferences"]:
            parse = urlparse(i["url"])
            query = parse_qs(parse.query)
            if i["format"] == "hls" or i["format"] == "ios":
                streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
                for n in list(streams.keys()):
                    yield streams[n]
                if "alt" in query and len(query["alt"]) > 0:
                    alt = self.http.get(query["alt"][0])
                    if alt:
                        streams = hlsparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output)
                        for n in list(streams.keys()):
                            yield streams[n]
            if i["format"] == "hds" or i["format"] == "flash":
                match = re.search(r"\/se\/secure\/", i["url"])
                if not match:
                    streams = hdsparse(self.config, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"], output=self.output)
                    for n in list(streams.keys()):
                        yield streams[n]
                    if "alt" in query and len(query["alt"]) > 0:
                        alt = self.http.get(query["alt"][0])
                        if alt:
                            streams = hdsparse(
                                self.config,
                                self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}),
                                alt.request.url,
                                output=self.output,
                            )
                            for n in list(streams.keys()):
                                yield streams[n]
            if i["format"] == "dash264" or i["format"] == "dashhbbtv":
                streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
                for n in list(streams.keys()):
                    yield streams[n]

                if "alt" in query and len(query["alt"]) > 0:
                    alt = self.http.get(query["alt"][0])
                    if alt:
                        streams = dashparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output)
                        for n in list(streams.keys()):
                            yield streams[n]
コード例 #15
0
    def get(self):
        parse = urlparse(self.url)
        if parse.netloc == "www.svtplay.se" or parse.netloc == "svtplay.se":
            if parse.path[:6] != "/video" and parse.path[:6] != "/klipp":
                yield ServiceError("This mode is not supported anymore. need the url with the video")
                return

        match = re.search("__svtplay'] = ({.*});", self.get_urldata())
        if not match:
            yield ServiceError("Cant find video info.")
            return
        janson = json.loads(match.group(1))["videoTitlePage"]

        if "live" in janson["video"]:
            self.optionslive = janson["video"]["live"]

        if self.options.output_auto:
            self.options.service = "svtplay"
            self.options.output = self.outputfilename(janson, self.options.output)

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        if "subtitles" in janson["video"]:
            for i in janson["video"]["subtitles"]:
                if i["format"] == "WebSRT":
                    yield subtitle(copy.copy(self.options), "wrst", i["url"])

        if "videoReferences" in janson["video"]:
            if len(janson["video"]["videoReferences"]) == 0:
                yield ServiceError("Media doesn't have any associated videos (yet?)")
                return

            for i in janson["video"]["videoReferences"]:
                parse = urlparse(i["url"])
                query = parse_qs(parse.query)
                if i["playerType"] == "hls" or i["playerType"] == "ios":
                    streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
                    if "alt" in query and len(query["alt"]) > 0:
                        alt = self.http.get(query["alt"][0])
                        if alt:
                            streams = hlsparse(self.options, self.http.request("get", alt.request.url), alt.request.url)
                            if streams:
                                for n in list(streams.keys()):
                                    yield streams[n]
                if i["playerType"] == "playerType" or i["playerType"] == "flash":
                    match = re.search(r"\/se\/secure\/", i["url"])
                    if not match:
                        streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"])
                        if streams:
                            for n in list(streams.keys()):
                                yield streams[n]
                        if "alt" in query and len(query["alt"]) > 0:
                            alt = self.http.get(query["alt"][0])
                            if alt:
                                streams = hdsparse(self.options, self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}), alt.request.url)
                                if streams:
                                    for n in list(streams.keys()):
                                        yield streams[n]
                if i["playerType"] == "dash264" or i["playerType"] == "dashhbbtv":
                    streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]

                    if "alt" in query and len(query["alt"]) > 0:
                        alt = self.http.get(query["alt"][0])
                        if alt:
                            streams = dashparse(self.options, self.http.request("get", alt.request.url), alt.request.url)
                            if streams:
                                for n in list(streams.keys()):
                                    yield streams[n]
コード例 #16
0
ファイル: svtplay.py プロジェクト: qnorsten/svtplay-dl
    def get(self):
        parse = urlparse(self.url)
        if parse.netloc == "www.svtplay.se" or parse.netloc == "svtplay.se":
            if parse.path[:6] != "/video" and parse.path[:6] != "/klipp":
                yield ServiceError(
                    "This mode is not supported anymore. need the url with the video"
                )
                return

        match = re.search("__svtplay'] = ({.*});", self.get_urldata())
        if not match:
            yield ServiceError("Cant find video info.")
            return
        janson = json.loads(match.group(1))["videoTitlePage"]

        if "live" in janson["video"]:
            self.options.live = janson["video"]["live"]

        if not "programTitle" in janson["video"]:
            yield ServiceError("Can't find any video on that page")
            return

        if self.options.output_auto:
            self.options.service = "svtplay"
            self.options.output = self.outputfilename(janson["video"],
                                                      self.options.output)

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        if "programVersionId" in janson["video"]:
            vid = janson["video"]["programVersionId"]
        else:
            vid = janson["video"]["id"]
        res = self.http.get(
            "http://api.svt.se/videoplayer-api/video/{0}".format(vid))
        janson = res.json()
        if "live" in janson:
            self.options.live = janson["live"]
        if "subtitleReferences" in janson:
            for i in janson["subtitleReferences"]:
                if i["format"] == "websrt" and "url" in i:
                    yield subtitle(copy.copy(self.options), "wrst", i["url"])

        if "videoReferences" in janson:
            if len(janson["videoReferences"]) == 0:
                yield ServiceError(
                    "Media doesn't have any associated videos (yet?)")
                return

            for i in janson["videoReferences"]:
                parse = urlparse(i["url"])
                query = parse_qs(parse.query)
                if i["format"] == "hls":
                    streams = hlsparse(self.options,
                                       self.http.request("get", i["url"]),
                                       i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
                    if "alt" in query and len(query["alt"]) > 0:
                        alt = self.http.get(query["alt"][0])
                        if alt:
                            streams = hlsparse(
                                self.options,
                                self.http.request("get", alt.request.url),
                                alt.request.url)
                            if streams:
                                for n in list(streams.keys()):
                                    yield streams[n]
                if i["format"] == "hds":
                    match = re.search(r"\/se\/secure\/", i["url"])
                    if not match:
                        streams = hdsparse(
                            self.options,
                            self.http.request("get",
                                              i["url"],
                                              params={"hdcore": "3.7.0"}),
                            i["url"])
                        if streams:
                            for n in list(streams.keys()):
                                yield streams[n]
                        if "alt" in query and len(query["alt"]) > 0:
                            alt = self.http.get(query["alt"][0])
                            if alt:
                                streams = hdsparse(
                                    self.options,
                                    self.http.request(
                                        "get",
                                        alt.request.url,
                                        params={"hdcore": "3.7.0"}),
                                    alt.request.url)
                                if streams:
                                    for n in list(streams.keys()):
                                        yield streams[n]
                if i["format"] == "dash264" or i["format"] == "dashhbbtv":
                    streams = dashparse(self.options,
                                        self.http.request("get", i["url"]),
                                        i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]

                    if "alt" in query and len(query["alt"]) > 0:
                        alt = self.http.get(query["alt"][0])
                        if alt:
                            streams = dashparse(
                                self.options,
                                self.http.request("get", alt.request.url),
                                alt.request.url)
                            if streams:
                                for n in list(streams.keys()):
                                    yield streams[n]
コード例 #17
0
    def get(self):
        old = False

        parse = urlparse(self.url)
        if parse.netloc == "www.svtplay.se" or parse.netloc == "svtplay.se":
            if parse.path[:6] != "/video" and parse.path[:6] != "/klipp":
                yield ServiceError(
                    "This mode is not supported anymore. need the url with the video"
                )
                return

        vid = self.find_video_id()
        if vid is None:
            yield ServiceError("Cant find video id for this video")
            return
        if re.match("^[0-9]+$", vid):
            old = True

        url = "http://www.svt.se/videoplayer-api/video/%s" % vid
        data = self.http.request("get", url)
        if data.status_code == 404:
            yield ServiceError("Can't get the json file for %s" % url)
            return

        data = data.json()
        if "live" in data:
            self.options.live = data["live"]
        if old:
            params = {"output": "json"}
            try:
                dataj = self.http.request("get", self.url,
                                          params=params).json()
            except ValueError:
                dataj = data
                old = False
        else:
            dataj = data

        if self.options.output_auto:
            self.options.service = "svtplay"
            self.options.output = self.outputfilename(
                dataj, self.options.output, ensure_unicode(self.get_urldata()))

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        if "subtitleReferences" in data:
            for i in data["subtitleReferences"]:
                if i["format"] == "websrt":
                    yield subtitle(copy.copy(self.options), "wrst", i["url"])
        if old and dataj["video"]["subtitleReferences"]:
            try:
                suburl = dataj["video"]["subtitleReferences"][0]["url"]
            except KeyError:
                pass
            if suburl and len(suburl) > 0:
                yield subtitle(copy.copy(self.options), "wrst", suburl)

        if len(data["videoReferences"]) == 0:
            yield ServiceError(
                "Media doesn't have any associated videos (yet?)")
            return

        for i in data["videoReferences"]:
            if i["format"] == "hls" or i["format"] == "ios":
                streams = hlsparse(self.options,
                                   self.http.request("get", i["url"]),
                                   i["url"])
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
            if i["format"] == "hds" or i["format"] == "flash":
                match = re.search(r"\/se\/secure\/", i["url"])
                if not match:
                    streams = hdsparse(
                        self.options,
                        self.http.request("get",
                                          i["url"],
                                          params={"hdcore": "3.7.0"}),
                        i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            if i["format"] == "dash264":
                streams = dashparse(self.options,
                                    self.http.request("get", i["url"]),
                                    i["url"])
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]