예제 #1
0
    def get(self):
        parse = urlparse(self.url)
        try:
            other = parse.fragment
        except KeyError:
            log.error("Something wrong with that url")
            return

        match = re.search("^/(.*).html", other)
        if not match:
            log.error("Cant find video file")
            return
        url = "http://www.hbo.com/data/content/{0}.xml".format(match.group(1))
        data = self.http.request("get", url).content
        xml = ET.XML(data)
        videoid = xml.find("content")[1].find("videoId").text
        url = "http://render.cdn.hbo.com/data/content/global/videos/data/{0}.xml".format(
            videoid)
        data = self.http.request("get", url).content
        xml = ET.XML(data)
        ss = xml.find("videos")
        sa = list(ss.iter("size"))

        for i in sa:
            videourl = i.find("tv14").find("path").text
            match = re.search("/([a-z0-9]+:[a-z0-9]+)/", videourl)
            self.options.other = "-y {0}".format(
                videourl[videourl.index(match.group(1)):])
            yield RTMP(copy.copy(self.options),
                       videourl[:videourl.index(match.group(1))],
                       i.attrib["width"])
예제 #2
0
 def find_stream(self, config, resource):
     tempresource = resource['Data'][0]['Assets']
     # To find the VideoResource, they have Images as well
     for resources in tempresource:
         if resources['Kind'] == 'VideoResource':
             links = resources['Links']
             break
     for i in links:
         if i["Target"] == "Ios" or i["Target"] == "HLS":
             streams = hlsparse(config,
                                self.http.request("get", i["Uri"]),
                                i["Uri"],
                                output=self.output)
             for n in list(streams.keys()):
                 yield streams[n]
         else:
             if i["Target"] == "Streaming":
                 config.set(
                     "other", "-y '{0}'".format(i["Uri"].replace(
                         "rtmp://vod.dr.dk/cms/", "")))
                 rtmp = "rtmp://vod.dr.dk/cms/"
                 yield RTMP(copy.copy(config),
                            rtmp,
                            i["Bitrate"],
                            output=self.output)
예제 #3
0
    def get(self, options):
        match = re.search("xmlUrl=([^ ]+)\" ", self.get_urldata())
        if match:
            xmlurl = unquote_plus(match.group(1))
        else:
            match = re.search(r"moviesList: \[\{\"VideoId\":\"(\d+)\"",
                              self.get_urldata())
            if not match:
                log.error("Can't find video id")
                sys.exit(2)
            vid = match.group(1)
            xmlurl = "http://www.expressen.se/Handlers/WebTvHandler.ashx?id=%s" % vid
        data = get_http_data(xmlurl)

        xml = ET.XML(data)
        live = xml.find("live").text
        if live != "0":
            options.live = True
        ss = xml.find("vurls")
        if is_py2_old:
            sa = list(ss.getiterator("vurl"))
        else:
            sa = list(ss.iter("vurl"))

        for i in sa:
            options2 = copy.copy(options)
            match = re.search(r"rtmp://([-0-9a-z\.]+/[-a-z0-9]+/)(.*)", i.text)
            filename = "rtmp://%s" % match.group(1)
            options2.other = "-y %s" % match.group(2)
            yield RTMP(options2, filename, int(i.attrib["bitrate"]))

        ipadurl = xml.find("mobileurls").find("ipadurl").text
        streams = hlsparse(ipadurl)
        for n in list(streams.keys()):
            yield HLS(copy.copy(options), streams[n], n)
예제 #4
0
파일: mtvnn.py 프로젝트: carlba/svtplay-dl
    def get(self, options):
        match = re.search(r'mrss\s+:\s+"([^"]+)"', self.get_urldata())
        if not match:
            log.error("Can't find id for the video")
            sys.exit(2)
        swfurl = re.search(r'embedSWF\( "([^"]+)"', self.get_urldata())
        options.other = "-W %s" % swfurl.group(1)
        data = get_http_data(match.group(1))
        xml = ET.XML(data)
        mediagen = xml.find("channel").find("item").find(
            "{http://search.yahoo.com/mrss/}group")
        title = xml.find("channel").find("item").find("title").text
        if options.output_auto:
            directory = os.path.dirname(options.output)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title
        contenturl = mediagen.find(
            "{http://search.yahoo.com/mrss/}content").attrib["url"]
        content = get_http_data(contenturl)
        xml = ET.XML(content)
        ss = xml.find("video").find("item")
        if is_py2_old:
            sa = list(ss.getiterator("rendition"))
        else:
            sa = list(ss.iter("rendition"))

        for i in sa:
            yield RTMP(options, i.find("src").text, i.attrib["bitrate"])
예제 #5
0
    def get(self, options):
        parse = urlparse(self.url)
        try:
            other = parse.fragment
        except KeyError:
            log.error("Something wrong with that url")
            sys.exit(2)
        match = re.search("^/(.*).html", other)
        if not match:
            log.error("Cant find video file")
            sys.exit(2)
        url = "http://www.hbo.com/data/content/%s.xml" % match.group(1)
        data = get_http_data(url)
        xml = ET.XML(data)
        videoid = xml.find("content")[1].find("videoId").text
        url = "http://render.cdn.hbo.com/data/content/global/videos/data/%s.xml" % videoid
        data = get_http_data(url)
        xml = ET.XML(data)
        ss = xml.find("videos")
        if is_py2_old:
            sa = list(ss.getiterator("size"))
        else:
            sa = list(ss.iter("size"))

        for i in sa:
            videourl = i.find("tv14").find("path").text
            match = re.search("/([a-z0-9]+:[a-z0-9]+)/", videourl)
            options.other = "-y %s" % videourl[videourl.index(match.group(1)):]
            yield RTMP(copy.copy(options),
                       videourl[:videourl.index(match.group(1))],
                       i.attrib["width"])
예제 #6
0
    def get(self):
        if self.exclude():
            yield ServiceError("Excluding video")
            return

        ajax_auth = self.get_auth()
        if not ajax_auth:
            yield ServiceError("Cant find token for video")
            return

        mediaid = self.get_mediaid()
        if not mediaid:
            yield ServiceError("Cant find media id")
            return
        if not isinstance(mediaid, str):
            mediaid = mediaid.group(1)

        jsondata = self.http.request(
            "get",
            "http://csp.picsearch.com/rest?jsonp=&eventParam=1&auth=%s&method=embed&mediaid=%s"
            % (ajax_auth.group(1), mediaid)).text
        jsondata = json.loads(jsondata)
        if "playerconfig" not in jsondata["media"]:
            yield ServiceError(jsondata["error"])
            return
        if "live" in jsondata["media"]["playerconfig"]["clip"]:
            self.options.live = jsondata["media"]["playerconfig"]["clip"]
        playlist = jsondata["media"]["playerconfig"]["playlist"][1]
        if "bitrates" in playlist:
            files = playlist["bitrates"]
            server = jsondata["media"]["playerconfig"]["plugins"]["bwcheck"][
                "netConnectionUrl"]

            for i in files:
                self.options.other = "-y '%s'" % i["url"]
                yield RTMP(copy.copy(self.options), server, i["height"])
        if "provider" in playlist:
            if playlist["provider"] != "rtmp":
                if "live" in playlist:
                    self.options.live = playlist["live"]
                if playlist["url"].endswith(".f4m"):
                    streams = hdsparse(
                        self.options,
                        self.http.request("get",
                                          playlist["url"],
                                          params={"hdcore": "3.7.0"}),
                        playlist["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
                if ".m3u8" in playlist["url"]:
                    streams = hlsparse(
                        self.options,
                        self.http.request("get",
                                          playlist["url"]), playlist["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
예제 #7
0
    def get(self, options):
        vid = self._get_video_id()
        if vid is None:
            log.error("Cant find video file")
            sys.exit(2)

        url = "http://playapi.mtgx.tv/v3/videos/%s" % vid
        options.other = ""
        data = get_http_data(url)
        dataj = json.loads(data)
        if "msg" in dataj:
            log.error("%s" % dataj["msg"])
            return

        if dataj["type"] == "live":
            options.live = True

        if dataj["sami_path"]:
            yield subtitle_sami(dataj["sami_path"])

        streams = get_http_data("http://playapi.mtgx.tv/v3/videos/stream/%s" %
                                vid)
        streamj = json.loads(streams)

        if "msg" in streamj:
            log.error(
                "Can't play this because the video is either not found or geoblocked."
            )
            return

        if streamj["streams"]["medium"]:
            filename = streamj["streams"]["medium"]
            if filename[len(filename) - 3:] == "f4m":
                manifest = "%s?hdcore=2.8.0&g=hejsan" % filename
                streams = hdsparse(copy.copy(options), manifest)
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
            else:
                parse = urlparse(filename)
                match = re.search("^(/[^/]+)/(.*)", parse.path)
                if not match:
                    log.error("Somthing wrong with rtmpparse")
                    sys.exit(2)
                filename = "%s://%s:%s%s" % (parse.scheme, parse.hostname,
                                             parse.port, match.group(1))
                path = "-y %s" % match.group(2)
                options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf %s" % path
                yield RTMP(copy.copy(options), filename, 800)

        if streamj["streams"]["hls"]:
            streams = hlsparse(streamj["streams"]["hls"])
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
예제 #8
0
파일: dr.py 프로젝트: vikekh/svtplay-dl
    def get(self):
        data = self.get_urldata()

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

        match = re.search(r'resource:[ ]*"([^"]*)",', data)
        if match:
            resource_url = match.group(1)
            resource_data = self.http.request("get", resource_url).content
            resource = json.loads(resource_data)
            streams = self.find_stream(self.options, resource)
            for i in streams:
                yield i
        else:
            match = re.search(r'resource="([^"]*)"', data)
            if not match:
                yield ServiceError("Cant find resource info for this video")
                return
            if match.group(1)[:4] != "http":
                resource_url = "http:{0}".format(match.group(1))
            else:
                resource_url = match.group(1)
            resource_data = self.http.request("get", resource_url).text
            resource = json.loads(resource_data)

            if "Links" not in resource:
                yield ServiceError("Cant access this video. its geoblocked.")
                return
            if "SubtitlesList" in resource and len(resource["SubtitlesList"]) > 0:
                suburl = resource["SubtitlesList"][0]["Uri"]
                yield subtitle(copy.copy(self.options), "wrst", suburl)
            if "Data" in resource:
                streams = self.find_stream(self.options, resource)
                for i in streams:
                    yield i
            else:
                for stream in resource['Links']:
                    if stream["Target"] == "HDS":
                        streams = hdsparse(copy.copy(self.options), self.http.request("get", stream["Uri"], params={"hdcore": "3.7.0"}), stream["Uri"])
                        if streams:
                            for n in list(streams.keys()):
                                yield streams[n]
                    if stream["Target"] == "HLS":
                        streams = hlsparse(self.options, self.http.request("get", stream["Uri"]), stream["Uri"])
                        for n in list(streams.keys()):
                            yield streams[n]
                    if stream["Target"] == "Streaming":
                        self.options.other = "-v -y '{0}'".format(stream['Uri'].replace("rtmp://vod.dr.dk/cms/", ""))
                        rtmp = "rtmp://vod.dr.dk/cms/"
                        yield RTMP(copy.copy(self.options), rtmp, stream['Bitrate'])
예제 #9
0
    def get(self):
        data = self.get_urldata()
        match = re.search(
            r'data-mrss=[\'"](http://gakusei-cluster.mtvnn.com/v2/mrss.xml[^\'"]+)[\'"]',
            data)
        if not match:
            yield ServiceError("Can't find id for the video")
            return

        data = self.http.request("get", match.group(1)).content
        xml = ET.XML(data)
        mediagen = xml.find("channel").find("item").find(
            "{http://search.yahoo.com/mrss/}group")
        title = xml.find("channel").find("item").find("title").text
        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

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

        swfurl = mediagen.find(
            "{http://search.yahoo.com/mrss/}player").attrib["url"]
        self.options.other = "-W %s" % self.http.check_redirect(swfurl)

        contenturl = mediagen.find(
            "{http://search.yahoo.com/mrss/}content").attrib["url"]
        filename = os.path.basename(contenturl)
        data = self.http.request(
            "get", "http://videos.mtvnn.com/api/v2/%s.js?video_format=hls" %
            filename).text
        dataj = json.loads(data)
        content = self.http.request("get", contenturl).content
        xml = ET.XML(content)
        ss = xml.find("video").find("item")
        if is_py2_old:
            sa = list(ss.getiterator("rendition"))
        else:
            sa = list(ss.iter("rendition"))

        for i in sa:
            yield RTMP(self.options, i.find("src").text, i.attrib["bitrate"])
        streams = hlsparse(self.options,
                           self.http.request("get",
                                             dataj["src"]), dataj["src"])
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
예제 #10
0
 def get(self, options):
     match = re.search(r"urPlayer.init\((.*)\);", self.get_urldata())
     if not match:
         log.error("Can't find json info")
         sys.exit(2)
     data = match.group(1)
     jsondata = json.loads(data)
     yield subtitle_tt(jsondata["subtitles"].split(",")[0])
     basedomain = jsondata["streaming_config"]["streamer"]["redirect"]
     http = "http://%s/%s" % (basedomain, jsondata["file_html5"])
     hd = None
     if len(jsondata["file_html5_hd"]) > 0:
         http_hd = "http://%s/%s" % (basedomain, jsondata["file_html5_hd"])
         hls_hd = "%s%s" % (http_hd, jsondata["streaming_config"]
                            ["http_streaming"]["hls_file"])
         tmp = jsondata["file_html5_hd"]
         match = re.search(".*(mp[34]:.*$)", tmp)
         path_hd = match.group(1)
         hd = True
     hls = "%s%s" % (
         http, jsondata["streaming_config"]["http_streaming"]["hls_file"])
     rtmp = "rtmp://%s/%s" % (
         basedomain, jsondata["streaming_config"]["rtmp"]["application"])
     path = "mp%s:%s" % (jsondata["file_flash"][-1], jsondata["file_flash"])
     streams = hlsparse(hls)
     for n in list(streams.keys()):
         yield HLS(options, streams[n], n)
     options.other = "-v -a %s -y %s" % (
         jsondata["streaming_config"]["rtmp"]["application"], path)
     yield RTMP(options, rtmp, "480")
     if hd:
         streams = hlsparse(hls_hd)
         for n in list(streams.keys()):
             yield HLS(copy.copy(options), streams[n], n)
         options.other = "-v -a %s -y %s" % (
             jsondata["streaming_config"]["rtmp"]["application"], path_hd)
         yield RTMP(copy.copy(options), rtmp, "720")
예제 #11
0
    def get(self):
        data = self.get_urldata()

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

        if re.findall(r"di.se", self.url):
            match = re.search("src=\"(http://qstream.*)\"></iframe", data)
            if not match:
                yield ServiceError("Can't find video info for: %s" % self.url)
                return
            data = self.http.request("get", match.group(1)).content
            match = re.search(r"data-qbrick-ccid=\"([0-9A-Z]+)\"", data)
            if not match:
                yield ServiceError("Can't find video file for: %s" % self.url)
                return
            host = "http://vms.api.qbrick.com/rest/v3/getplayer/%s" % match.group(
                1)
        else:
            yield ServiceError("Can't find any info for %s" % self.url)
            return

        data = self.http.request("get", host).content
        xml = ET.XML(data)
        try:
            url = xml.find("media").find("item").find("playlist").find(
                "stream").find("format").find("substream").text
        except AttributeError:
            yield ServiceError("Can't find video file")
            return
        live = xml.find("media").find("item").find("playlist").find(
            "stream").attrib["isLive"]
        if live == "true":
            self.options.live = True
        data = self.http.request("get", url).content
        xml = ET.XML(data)
        server = xml.find("head").find("meta").attrib["base"]
        streams = xml.find("body").find("switch")
        if is_py2_old:
            sa = list(streams.getiterator("video"))
        else:
            sa = list(streams.iter("video"))

        for i in sa:
            self.options.other = "-y '%s'" % i.attrib["src"]
            yield RTMP(copy.copy(self.options), server,
                       i.attrib["system-bitrate"])
예제 #12
0
 def get(self, options):
     match = re.search(r"v/(\d+)", self.url)
     if not match:
         log.error("Can't find video id in url")
         sys.exit(2)
     json_url = "http://player-c.api.bambuser.com/getVideo.json?api_key=005f64509e19a868399060af746a00aa&vid=%s" % match.group(1)
     data = get_http_data(json_url)
     info = json.loads(data)["result"]
     video = info["url"]
     if video[:4] == "rtmp":
         playpath = info["id"][len(info["id"])-36:]
         options.other = "-y %s" % playpath
         if info["type"] == "live":
             options.live = True
         yield RTMP(copy.copy(options), video, "0")
     else:
         yield HTTP(copy.copy(options), video, "0")
예제 #13
0
    def get(self):
        data = self.get_urldata()

        if re.findall(r"di.se", self.url):
            match = re.search("src=\"(http://qstream.*)\"></iframe", data)
            if not match:
                yield ServiceError("Can't find video info for: {0}".format(
                    self.url))
                return
            data = self.http.request("get", match.group(1)).content
            match = re.search(r"data-qbrick-ccid=\"([0-9A-Z]+)\"", data)
            if not match:
                yield ServiceError("Can't find video file for: {0}".format(
                    self.url))
                return
            host = "http://vms.api.qbrick.com/rest/v3/getplayer/{0}".format(
                match.group(1))
        else:
            yield ServiceError("Can't find any info for {0}".format(self.url))
            return

        data = self.http.request("get", host).content
        xml = ET.XML(data)
        try:
            url = xml.find("media").find("item").find("playlist").find(
                "stream").find("format").find("substream").text
        except AttributeError:
            yield ServiceError("Can't find video file")
            return
        live = xml.find("media").find("item").find("playlist").find(
            "stream").attrib["isLive"]
        if live == "true":
            self.config.set("live", True)
        data = self.http.request("get", url).content
        xml = ET.XML(data)
        server = xml.find("head").find("meta").attrib["base"]
        streams = xml.find("body").find("switch")
        sa = list(streams.iter("video"))

        for i in sa:
            yield RTMP(copy.copy(self.config),
                       server,
                       i.attrib["system-bitrate"],
                       output=self.output,
                       other="-y '{0}'".format(i.attrib["src"]))
예제 #14
0
파일: dr.py 프로젝트: carlba/svtplay-dl
def find_stream(options, resource):
    tempresource = resource['Data'][0]['Assets']
    # To find the VideoResource, they have Images as well
    for resources in tempresource:
        if resources['Kind'] == 'VideoResource':
            links = resources['Links']
            break
    for i in links:
        if i["Target"] == "Ios" or i["Target"] == "HLS":
            streams = hlsparse(i["Uri"])
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
        else:
            if i["Target"] == "Streaming":
                options.other = "-y '%s'" % i["Uri"].replace(
                    "rtmp://vod.dr.dk/cms/", "")
                rtmp = "rtmp://vod.dr.dk/cms/"
                yield RTMP(copy.copy(options), rtmp, i["Bitrate"])
예제 #15
0
    def get(self):
        match = re.search(r"v/(\d+)", self.url)
        if not match:
            yield ServiceError("Can't find video id in url")
            return

        json_url = "http://player-c.api.bambuser.com/getVideo.json?api_key=005f64509e19a868399060af746a00aa&vid={0}".format(
            match.group(1))
        data = self.http.request("get", json_url).text

        info = json.loads(data)["result"]
        video = info["url"]
        if video[:4] == "rtmp":
            playpath = info["id"][len(info["id"]) - 36:]
            other = "-y {0}".format(playpath)
            if info["type"] == "live":
                self.config.set("live", True)
            yield RTMP(copy.copy(self.config), video, "0", other=other)
        else:
            yield HTTP(copy.copy(self.config), video, "0")
예제 #16
0
    def get(self, options):
        data = self.get_urldata()
        ajax_auth = re.search(r"picsearch_ajax_auth = '(\w+)'", data)
        if not ajax_auth:
            log.error("Cant find token for video")
            sys.exit(2)
        mediaid = re.search(r"mediaId = '([^']+)';", data)
        if not mediaid:
            mediaid = re.search(r'media-id="([^"]+)"', data)
            if not mediaid:
                log.error("Cant find media id")
                sys.exit(2)
        jsondata = get_http_data("http://csp.picsearch.com/rest?jsonp=&eventParam=1&auth=%s&method=embed&mediaid=%s" % (ajax_auth.group(1), mediaid.group(1)))
        jsondata = json.loads(jsondata)
        files = jsondata["media"]["playerconfig"]["playlist"][1]["bitrates"]
        server = jsondata["media"]["playerconfig"]["plugins"]["bwcheck"]["netConnectionUrl"]

        for i in files:
            options.other = "-y '%s'" % i["url"]
            yield RTMP(copy.copy(options), server, i["height"])
예제 #17
0
파일: dr.py 프로젝트: carlba/svtplay-dl
    def get(self, options):
        data = self.get_urldata()
        match = re.search(r'resource:[ ]*"([^"]*)",', data)
        if match:
            resource_url = match.group(1)
            resource_data = get_http_data(resource_url)
            resource = json.loads(resource_data)
            streams = find_stream(options, resource)
            for i in streams:
                yield i
        else:
            match = re.search(r'resource="([^"]*)"', data)
            if not match:
                log.error("Cant find resource info for this video")
                sys.exit(2)
            resource_url = "%s" % match.group(1)
            resource_data = get_http_data(resource_url)
            resource = json.loads(resource_data)

            if "Data" in resource:
                streams = find_stream(options, resource)
                for i in streams:
                    yield i
            else:
                for stream in resource['Links']:
                    if stream["Target"] == "HDS":
                        manifest = "%s?hdcore=2.8.0&g=hejsan" % stream["Uri"]
                        streams = hdsparse(copy.copy(options), manifest)
                        if streams:
                            for n in list(streams.keys()):
                                yield streams[n]
                    if stream["Target"] == "HLS":
                        streams = hlsparse(stream["Uri"])
                        for n in list(streams.keys()):
                            yield HLS(copy.copy(options), streams[n], n)
                    if stream["Target"] == "Streaming":
                        options.other = "-v -y '%s'" % stream['Uri'].replace(
                            "rtmp://vod.dr.dk/cms/", "")
                        rtmp = "rtmp://vod.dr.dk/cms/"
                        yield RTMP(copy.copy(options), rtmp, stream['Bitrate'])
예제 #18
0
    def get(self):
        match = re.search(r"v/(\d+)", self.url)
        if not match:
            yield ServiceError("Can't find video id in url")
            return

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

        json_url = "http://player-c.api.bambuser.com/getVideo.json?api_key=005f64509e19a868399060af746a00aa&vid=%s" % match.group(
            1)
        data = self.http.request("get", json_url).text

        info = json.loads(data)["result"]
        video = info["url"]
        if video[:4] == "rtmp":
            playpath = info["id"][len(info["id"]) - 36:]
            self.options.other = "-y %s" % playpath
            if info["type"] == "live":
                self.options.live = True
            yield RTMP(copy.copy(self.options), video, "0")
        else:
            yield HTTP(copy.copy(self.options), video, "0")
예제 #19
0
파일: viaplay.py 프로젝트: zozs/svtplay-dl
    def get(self):
        vid = self._get_video_id()
        if vid is None:
            yield ServiceError("Can't find video file for: %s" % self.url)
            return

        url = "http://playapi.mtgx.tv/v3/videos/%s" % vid
        self.options.other = ""
        data = self.http.request("get", url)
        if data.status_code == 403:
            yield ServiceError(
                "Can't play this because the video is geoblocked.")
            return
        dataj = json.loads(data.text)
        if "msg" in dataj:
            yield ServiceError(dataj["msg"])
            return

        if dataj["type"] == "live":
            self.options.live = True

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

        streams = self.http.request(
            "get", "http://playapi.mtgx.tv/v3/videos/stream/%s" % vid)
        if streams.status_code == 403:
            yield ServiceError(
                "Can't play this because the video is geoblocked.")
            return
        streamj = json.loads(streams.text)

        if "msg" in streamj:
            yield ServiceError(
                "Can't play this because the video is either not found or geoblocked."
            )
            return

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            self.options.service = "tv3play"
            basename = self._autoname(dataj)
            title = "%s-%s-%s" % (basename, vid, self.options.service)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        if dataj["sami_path"]:
            yield subtitle(copy.copy(self.options), "sami", dataj["sami_path"])
        if dataj["subtitles_for_hearing_impaired"]:
            yield subtitle(copy.copy(self.options), "sami",
                           dataj["subtitles_for_hearing_impaired"])

        if streamj["streams"]["medium"]:
            filename = streamj["streams"]["medium"]
            if ".f4m" in filename:
                streams = hdsparse(
                    self.options,
                    self.http.request("get",
                                      filename,
                                      params={"hdcore": "3.7.0"}), filename)
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
            else:
                parse = urlparse(filename)
                match = re.search("^(/[^/]+)/(.*)", parse.path)
                if not match:
                    yield ServiceError("Can't get rtmpparse info")
                    return
                filename = "%s://%s:%s%s" % (parse.scheme, parse.hostname,
                                             parse.port, match.group(1))
                path = "-y %s" % match.group(2)
                self.options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf %s" % path
                yield RTMP(copy.copy(self.options), filename, 800)

        if streamj["streams"]["hls"]:
            streams = hlsparse(
                self.options,
                self.http.request("get", streamj["streams"]["hls"]),
                streamj["streams"]["hls"])
            if streams:
                for n in list(streams.keys()):
                    yield streams[n]
예제 #20
0
    def get(self):
        data = self.get_urldata()
        match = re.search(
            r'data-mrss=[\'"](http://gakusei-cluster.mtvnn.com/v2/mrss.xml[^\'"]+)[\'"]',
            data)
        if not match:
            yield ServiceError("Can't find id for the video")
            return

        mrssxmlurl = match.group(1)
        data = self.http.request("get", mrssxmlurl).content
        xml = ET.XML(data)
        mediagen = xml.find("channel").find("item").find(
            "{http://search.yahoo.com/mrss/}group")
        title = xml.find("channel").find("item").find("title").text
        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

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

        swfurl = mediagen.find(
            "{http://search.yahoo.com/mrss/}player").attrib["url"]
        self.options.other = "-W %s" % self.http.check_redirect(swfurl)

        contenturl = mediagen.find(
            "{http://search.yahoo.com/mrss/}content").attrib["url"]
        content = self.http.request("get", contenturl).content
        xml = ET.XML(content)
        ss = xml.find("video").find("item")
        if is_py2_old:
            sa = list(ss.getiterator("rendition"))
        else:
            sa = list(ss.iter("rendition"))

        for i in sa:
            yield RTMP(self.options, i.find("src").text, i.attrib["bitrate"])

        match = re.search("gon.viacom_config=([^;]+);", self.get_urldata())
        if match:
            countrycode = json.loads(match.group(1))["country_code"].replace(
                "_", "/")

            match = re.search("mtvnn.com:([^&]+)", mrssxmlurl)
            if match:
                urlpart = match.group(1).replace("-", "/").replace(
                    "playlist", "playlists"
                )  # it use playlists dunno from where it gets it
                hlsapi = "http://api.mtvnn.com/v2/{0}/{1}.json?video_format=m3u8&callback=&".format(
                    countrycode, urlpart)
                data = self.http.request("get", hlsapi).text

                dataj = json.loads(data)
                for i in dataj["local_playlist_videos"]:
                    streams = hlsparse(self.options,
                                       self.http.request("get", i["url"]),
                                       i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
예제 #21
0
    def get(self, options):
        if re.findall("svt.se", self.url):
            match = re.search(r"data-json-href=\"(.*)\"", self.get_urldata())
            if match:
                filename = match.group(1).replace("&amp;", "&").replace(
                    "&format=json", "")
                url = "http://www.svt.se%s" % filename
            else:
                log.error("Can't find video file")
                sys.exit(2)
        else:
            url = self.url

        pos = url.find("?")
        if pos < 0:
            dataurl = "%s?&output=json&format=json" % url
        else:
            dataurl = "%s&output=json&format=json" % url
        data = json.loads(get_http_data(dataurl))
        if "live" in data["video"]:
            options.live = data["video"]["live"]
        else:
            options.live = False

        if data["video"]["subtitleReferences"]:
            subtitle = None
            try:
                subtitle = data["video"]["subtitleReferences"][0]["url"]
            except KeyError:
                pass
            if subtitle and len(subtitle) > 0:
                yield subtitle_wsrt(subtitle)

        if options.output_auto:
            directory = os.path.dirname(options.output)
            options.service = "svtplay"

            name = data["statistics"]["folderStructure"]
            if name.find(".") > 0:
                title = "%s-%s-%s-%s" % (name[:name.find(".")],
                                         data["statistics"]["title"],
                                         data["videoId"], options.service)
            else:
                title = "%s-%s-%s-%s" % (name, data["statistics"]["title"],
                                         data["videoId"], options.service)
            title = filenamify(title)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title

        if options.force_subtitle:
            return

        for i in data["video"]["videoReferences"]:
            parse = urlparse(i["url"])

            if parse.path.find("m3u8") > 0:
                streams = hlsparse(i["url"])
                for n in list(streams.keys()):
                    yield HLS(copy.copy(options), streams[n], n)
            elif parse.path.find("f4m") > 0:
                match = re.search(r"\/se\/secure\/", i["url"])
                if not match:
                    parse = urlparse(i["url"])
                    manifest = "%s://%s%s?%s&hdcore=3.3.0" % (
                        parse.scheme, parse.netloc, parse.path, parse.query)
                    streams = hdsparse(copy.copy(options), manifest)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            elif parse.scheme == "rtmp":
                embedurl = "%s?type=embed" % url
                data = get_http_data(embedurl)
                match = re.search(
                    r"value=\"(/(public)?(statiskt)?/swf(/video)?/svtplayer-[0-9\.a-f]+swf)\"",
                    data)
                swf = "http://www.svtplay.se%s" % match.group(1)
                options.other = "-W %s" % swf
                yield RTMP(copy.copy(options), i["url"], i["bitrate"])
            else:
                yield HTTP(copy.copy(options), i["url"], "0")
예제 #22
0
파일: qbrick.py 프로젝트: carlba/svtplay-dl
    def get(self, options):
        if re.findall(r"sydsvenskan.se", self.url):
            data = self.get_urldata()
            match = re.search(r"data-qbrick-mcid=\"([0-9A-F]+)\"", data)
            if not match:
                log.error("Can't find video file")
                sys.exit(2)
            mcid = match.group(1)
            host = "http://vms.api.qbrick.com/rest/v3/getsingleplayer/%s" % mcid
        elif re.findall(r"di.se", self.url):
            data = self.get_urldata()
            match = re.search("src=\"(http://qstream.*)\"></iframe", data)
            if not match:
                log.error("Can't find video info")
                sys.exit(2)
            data = get_http_data(match.group(1))
            match = re.search(r"data-qbrick-ccid=\"([0-9A-Z]+)\"", data)
            if not match:
                log.error("Can't find video file")
                sys.exit(2)
            host = "http://vms.api.qbrick.com/rest/v3/getplayer/%s" % match.group(
                1)
        elif re.findall(r"svd.se", self.url):
            match = re.search(r'video url-([^"]*)\"', self.get_urldata())
            if not match:
                log.error("Can't find video file")
                sys.exit(2)
            path = unquote_plus(match.group(1))
            data = get_http_data("http://www.svd.se%s" % path)
            match = re.search(r"mcid=([A-F0-9]+)\&width=", data)
            if not match:
                log.error("Can't find video file")
                sys.exit(2)
            host = "http://vms.api.qbrick.com/rest/v3/getsingleplayer/%s" % match.group(
                1)
        else:
            log.error("Can't find site")
            sys.exit(2)

        data = get_http_data(host)
        xml = ET.XML(data)
        try:
            url = xml.find("media").find("item").find("playlist").find(
                "stream").find("format").find("substream").text
        except AttributeError:
            log.error("Can't find video file")
            sys.exit(2)
        live = xml.find("media").find("item").find("playlist").find(
            "stream").attrib["isLive"]
        if live == "true":
            options.live = True
        data = get_http_data(url)
        xml = ET.XML(data)
        server = xml.find("head").find("meta").attrib["base"]
        streams = xml.find("body").find("switch")
        if is_py2_old:
            sa = list(streams.getiterator("video"))
        else:
            sa = list(streams.iter("video"))

        for i in sa:
            options.other = "-y '%s'" % i.attrib["src"]
            yield RTMP(copy.copy(options), server, i.attrib["system-bitrate"])
예제 #23
0
    def get(self):
        data = self.get_urldata()

        vid = findvid(self.url, data)
        if vid is None:
            yield ServiceError("Can't find video id for %s" % self.url)
            return

        # if self.options.username and self.options.password:
        # work = self._login(self.options.username, self.options.password)
        # if isinstance(work, Exception):
        # yield work
        # return

        url = "http://prima.tv4play.se/api/web/asset/%s/play" % vid
        data = self.http.request("get", url, cookies=self.cookies)
        if data.status_code == 401:
            xml = ET.XML(data.content)
            code = xml.find("code").text
            if code == "SESSION_NOT_AUTHENTICATED":
                yield ServiceError("Can't access premium content")
            elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION":
                yield ServiceError(
                    "Can't download this video because of geoblock.")
            else:
                yield ServiceError("Can't find any info for that video")
            return
        if data.status_code == 404:
            yield ServiceError("Can't find the video api")
            return
        xml = ET.XML(data.content)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))

        if xml.find("live").text:
            if xml.find("live").text != "false":
                self.options.live = True
        if xml.find("drmProtected").text == "true":
            yield ServiceError(
                "We cant download DRM protected content from this site.")
            return
        if xml.find("playbackStatus").text == "NOT_STARTED":
            yield ServiceError("Can't download something that is not started")
            return

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            self.options.service = "tv4play"
            basename = self._autoname(vid)
            if basename is None:
                yield ServiceError("Cant find vid id for autonaming")
                return
            title = "%s-%s-%s" % (basename, vid, 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

        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                base = urlparse(i.find("base").text)
                parse = urlparse(i.find("url").text)
                if "rtmp" in base.scheme:
                    swf = "http://www.tv4play.se/flash/tv4playflashlets.swf"
                    self.options.other = "-W %s -y %s" % (swf,
                                                          i.find("url").text)
                    yield RTMP(copy.copy(self.options),
                               i.find("base").text,
                               i.find("bitrate").text)
                elif parse.path[len(parse.path) - 3:len(parse.path)] == "f4m":
                    streams = hdsparse(
                        self.options,
                        self.http.request("get",
                                          i.find("url").text,
                                          params={"hdcore": "3.7.0"}),
                        i.find("url").text)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            elif i.find("mediaFormat").text == "webvtt":
                yield subtitle(copy.copy(self.options), "wrst",
                               i.find("url").text)

        url = "https://prima.tv4play.se/api/web/asset/%s/play?protocol=hls3" % vid
        data = self.http.request("get", url, cookies=self.cookies).content
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))
        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                parse = urlparse(i.find("url").text)
                if parse.path.endswith("m3u8"):
                    streams = hlsparse(
                        self.options,
                        self.http.request("get",
                                          i.find("url").text),
                        i.find("url").text)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
예제 #24
0
    def get(self, options):
        parse = urlparse(self.url)
        if "tv4play.se" in self.url:
            try:
                vid = parse_qs(parse.query)["video_id"][0]
            except KeyError:
                log.error("Can't find video file")
                sys.exit(2)
        else:
            match = re.search(r"\"vid\":\"(\d+)\",", self.get_urldata())
            if match:
                vid = match.group(1)
            else:
                match = re.search(r"-(\d+)$", self.url)
                if match:
                    vid = match.group(1)
                else:
                    log.error("Can't find video id")
                    sys.exit(2)

        url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid
        data = get_http_data(url)
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))

        if xml.find("live").text:
            if xml.find("live").text != "false":
                options.live = True
        if xml.find("drmProtected").text == "true":
            log.error("DRM protected content.")
            sys.exit(2)

        if options.output_auto:
            directory = os.path.dirname(options.output)
            options.service = "tv4play"
            title = "%s-%s-%s" % (options.output, vid, options.service)
            title = filenamify(title)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title

        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                base = urlparse(i.find("base").text)
                parse = urlparse(i.find("url").text)
                if base.scheme == "rtmp":
                    swf = "http://www.tv4play.se/flash/tv4playflashlets.swf"
                    options.other = "-W %s -y %s" % (swf, i.find("url").text)
                    yield RTMP(copy.copy(options), i.find("base").text, i.find("bitrate").text)
                elif parse.path[len(parse.path)-3:len(parse.path)] == "f4m":
                    query = ""
                    if i.find("url").text[-1] != "?":
                        query = "?"
                    manifest = "%s%shdcore=2.8.0&g=hejsan" % (i.find("url").text, query)
                    streams = hdsparse(copy.copy(options), manifest)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            elif i.find("mediaFormat").text == "smi":
                yield subtitle_smi(i.find("url").text)

        url = "http://premium.tv4play.se/api/web/asset/%s/play?protocol=hls" % vid
        data = get_http_data(url)
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))
        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                parse = urlparse(i.find("url").text)
                if parse.path.endswith("m3u8"):
                    streams = hlsparse(i.find("url").text)
                    for n in list(streams.keys()):
                        yield HLS(copy.copy(options), streams[n], n)
예제 #25
0
파일: kanal5.py 프로젝트: carlba/svtplay-dl
    def get(self, options):
        match = re.search(r".*video/([0-9]+)", self.url)
        if not match:
            log.error("Can't find video file")
            return

        video_id = match.group(1)
        if options.username and options.password:
            # get session cookie
            data = get_http_data("http://www.kanal5play.se/", cookiejar=self.cj)
            authurl = "https://kanal5swe.appspot.com/api/user/login?callback=jQuery171029989&email=%s&password=%s&_=136250" % \
                      (options.username, options.password)
            data = get_http_data(authurl)
            match = re.search(r"({.*})\);", data)
            jsondata = json.loads(match.group(1))
            if jsondata["success"] is False:
                log.error(jsondata["message"])
                return
            authToken = jsondata["userData"]["auth"]
            cc = Cookie(version=0, name='authToken',
                        value=authToken,
                        port=None, port_specified=False,
                        domain='www.kanal5play.se',
                        domain_specified=True,
                        domain_initial_dot=True, path='/',
                        path_specified=True, secure=False,
                        expires=None, discard=True, comment=None,
                        comment_url=None, rest={'HttpOnly': None})
            self.cj.set_cookie(cc)

        url = "http://www.kanal5play.se/api/getVideo?format=FLASH&videoId=%s" % video_id
        data = json.loads(get_http_data(url, cookiejar=self.cj))
        options.cookiejar = self.cj
        if not options.live:
            options.live = data["isLive"]
        if data["hasSubtitle"]:
            yield subtitle_json("http://www.kanal5play.se/api/subtitles/%s" % video_id)

        if options.output_auto:
            directory = os.path.dirname(options.output)
            options.service = "kanal5"

            title = "%s-s%s-%s-%s-%s" % (data["program"]["name"], data["seasonNumber"], data["episodeText"], data["id"], options.service)
            title = filenamify(title)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title

        if options.force_subtitle:
            return

        if "streams" in data:
            for i in data["streams"]:
                if i["drmProtected"]:
                    log.error("We cant download drm files for this site.")
                    return
                steambaseurl = data["streamBaseUrl"]
                bitrate = i["bitrate"]
                if bitrate > 1000:
                    bitrate = bitrate / 1000
                options2 = copy.copy(options)
                options2.other = "-W %s -y %s " % ("http://www.kanal5play.se/flash/K5StandardPlayer.swf", i["source"])
                options2.live = True
                yield RTMP(options2, steambaseurl, bitrate)

            url = "http://www.kanal5play.se/api/getVideo?format=IPAD&videoId=%s" % video_id
            data = json.loads(get_http_data(url, cookiejar=self.cj))
            if "streams" in data.keys():
                for i in data["streams"]:
                    streams = hlsparse(i["source"])
                    for n in list(streams.keys()):
                        yield HLS(copy.copy(options), streams[n], n)
        if "reasonsForNoStreams" in data:
            log.error(data["reasonsForNoStreams"][0])
예제 #26
0
    def get(self):
        data = self.get_urldata()
        parse = urlparse(self.url)

        if parse.netloc.endswith("se"):
            match = re.search('<div class="video-player" (.*)>', data)

            if not match:
                yield ServiceError("Can't find video info")
                return

            match_id = re.search('data-id="([0-9a-fA-F|\-]+)" ',
                                 match.group(1))

            if not match_id:
                yield ServiceError("Can't find video info")
                return

            wanted_id = match_id.group(1)
            url_service = "http://feeds.mtvnservices.com/od/feed/intl-mrss-player-feed?mgid=mgid:arc:episode:nick.intl:{0}" \
                          "&arcEp=nickelodeon.se&imageEp=nickelodeon.se&stage=staging&accountOverride=intl.mtvi.com&ep=a9cc543c".format(wanted_id)
            service_asset = self.http.request("get", url_service)
            match_guid = re.search('<guid isPermaLink="false">(.*)</guid>',
                                   service_asset.text)

            if not match_guid:
                yield ServiceError("Can't find video info")
                return

            hls_url = "https://mediautilssvcs-a.akamaihd.net/services/MediaGenerator/{0}?arcStage=staging&accountOverride=intl.mtvi.com&" \
                      "billingSection=intl&ep=a9cc543c&acceptMethods=hls".format(match_guid.group(1))
            hls_asset = self.http.request("get", hls_url)
            xml = ET.XML(hls_asset.text)

            if xml.find("./video") is not None and xml.find("./video").find("item") is not None \
                    and xml.find("./video").find("item").find("rendition") is not None \
                    and xml.find("./video").find("item").find("rendition").find("src") is not None:

                hls_url = xml.find("./video").find("item").find(
                    "rendition").find("src").text
                stream = hlsparse(self.config,
                                  self.http.request("get", hls_url),
                                  hls_url,
                                  output=self.output)
                for key in list(stream.keys()):
                    yield stream[key]
            return

        match = re.search(
            r'data-mrss=[\'"](http://gakusei-cluster.mtvnn.com/v2/mrss.xml[^\'"]+)[\'"]',
            data)
        if not match:
            yield ServiceError("Can't find id for the video")
            return

        mrssxmlurl = match.group(1)
        data = self.http.request("get", mrssxmlurl).content
        xml = ET.XML(data)
        mediagen = xml.find("channel").find("item").find(
            "{http://search.yahoo.com/mrss/}group")
        title = xml.find("channel").find("item").find("title").text
        self.output["title"] = title

        swfurl = mediagen.find(
            "{http://search.yahoo.com/mrss/}player").attrib["url"]
        other = "-W {0}".format(self.http.check_redirect(swfurl))

        contenturl = mediagen.find(
            "{http://search.yahoo.com/mrss/}content").attrib["url"]
        content = self.http.request("get", contenturl).content
        xml = ET.XML(content)
        ss = xml.find("video").find("item")
        sa = list(ss.iter("rendition"))

        for i in sa:
            yield RTMP(self.config,
                       i.find("src").text,
                       i.attrib["bitrate"],
                       other=other,
                       output=self.output)

        match = re.search("gon.viacom_config=([^;]+);", self.get_urldata())
        if match:
            countrycode = json.loads(match.group(1))["country_code"].replace(
                "_", "/")

            match = re.search("mtvnn.com:([^&]+)", mrssxmlurl)
            if match:
                urlpart = match.group(1).replace("-", "/").replace(
                    "playlist", "playlists"
                )  # it use playlists dunno from where it gets it
                hlsapi = "http://api.mtvnn.com/v2/{0}/{1}.json?video_format=m3u8&callback=&".format(
                    countrycode, urlpart)
                data = self.http.request("get", hlsapi).text

                dataj = json.loads(data)
                for i in dataj["local_playlist_videos"]:
                    streams = hlsparse(self.config,
                                       self.http.request("get", i["url"]),
                                       i["url"],
                                       output=self.output)
                    for n in list(streams.keys()):
                        yield streams[n]
예제 #27
0
    def get(self):
        vid = self._get_video_id()
        if vid is None:
            yield ServiceError("Can't find video file for: {0}".format(
                self.url))
            return

        data = self._get_video_data(vid)
        if data.status_code == 403:
            yield ServiceError(
                "Can't play this because the video is geoblocked.")
            return
        dataj = json.loads(data.text)

        if "msg" in dataj:
            yield ServiceError(dataj["msg"])
            return

        if dataj["type"] == "live":
            self.options.live = True

        if self.options.output_auto:
            self.options.output = self.outputfilename(dataj, vid,
                                                      self.options.output)

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

        streams = self.http.request(
            "get", "http://playapi.mtgx.tv/v3/videos/stream/{0}".format(vid))
        if streams.status_code == 403:
            yield ServiceError(
                "Can't play this because the video is geoblocked.")
            return
        streamj = json.loads(streams.text)

        if "msg" in streamj:
            yield ServiceError(
                "Can't play this because the video is either not found or geoblocked."
            )
            return

        if dataj["sami_path"]:
            if dataj["sami_path"].endswith("vtt"):
                subtype = "wrst"
            else:
                subtype = "sami"
            yield subtitle(copy.copy(self.options), subtype,
                           dataj["sami_path"])
        if dataj["subtitles_webvtt"]:
            yield subtitle(copy.copy(self.options), "wrst",
                           dataj["subtitles_webvtt"])
        if dataj["subtitles_for_hearing_impaired"]:
            if dataj["subtitles_for_hearing_impaired"].endswith("vtt"):
                subtype = "wrst"
            else:
                subtype = "sami"
            if self.options.get_all_subtitles:
                yield subtitle(copy.copy(self.options), subtype,
                               dataj["subtitles_for_hearing_impaired"], "-SDH")
            else:
                yield subtitle(copy.copy(self.options), subtype,
                               dataj["subtitles_for_hearing_impaired"])

        if streamj["streams"]["medium"]:
            filename = streamj["streams"]["medium"]
            if ".f4m" in filename:
                streams = hdsparse(
                    self.options,
                    self.http.request("get",
                                      filename,
                                      params={"hdcore": "3.7.0"}), filename)
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
            else:
                parse = urlparse(filename)
                match = re.search("^(/[^/]+)/(.*)", parse.path)
                if not match:
                    yield ServiceError("Can't get rtmpparse info")
                    return
                filename = "{0}://{1}:{2}{3}".format(parse.scheme,
                                                     parse.hostname,
                                                     parse.port,
                                                     match.group(1))
                path = "-y {0}".format(match.group(2))
                self.options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf {0}".format(
                    path)
                yield RTMP(copy.copy(self.options), filename, 800)

        if streamj["streams"]["hls"]:
            streams = hlsparse(
                self.options,
                self.http.request("get", streamj["streams"]["hls"]),
                streamj["streams"]["hls"])
            if streams:
                for n in list(streams.keys()):
                    yield streams[n]
예제 #28
0
    def get(self):

        parse = urlparse(self.url)
        if parse.path[:8] == "/kanaler":

            end_time_stamp = (datetime.utcnow() - timedelta(seconds=20)).replace(microsecond=0)
            start_time_stamp = end_time_stamp - timedelta(minutes=1)

            url = "https://bbr-l2v.akamaized.net/live/{0}/master.m3u8?in={1}&out={2}?".format(parse.path[9:],
                                                                                              start_time_stamp.isoformat(),
                                                                                              end_time_stamp.isoformat())

            self.options.live = True
            self.options.hls_time_stamp = True
            streams = hlsparse(self.options, self.http.request("get", url), url)
            if streams:
                for n in list(streams.keys()):
                    yield streams[n]
            return

        data = self.get_urldata()

        vid = findvid(self.url, data)
        if not vid:
            yield ServiceError("Can't find video id for {0}.".format(self.url))
            return

        url = "http://prima.tv4play.se/api/web/asset/{0}/play".format(vid)
        data = self.http.request("get", url, cookies=self.cookies)
        if data.status_code == 401:
            xml = ET.XML(data.content)
            code = xml.find("code").text
            if code == "SESSION_NOT_AUTHENTICATED":
                yield ServiceError("Can't access premium content")
            elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION":
                yield ServiceError("Can't download this video because of geoblock.")
            else:
                yield ServiceError("Can't find any info for that video.")
            return
        if data.status_code == 404:
            yield ServiceError("Can't find the video api.")
            return
        xml = ET.XML(data.content)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))

        if xml.find("live").text:
            self.options.live = (xml.find("live").text != "false")
        if xml.find("drmProtected").text == "true":
            yield ServiceError("We can't download DRM protected content from this site.")
            return
        if xml.find("playbackStatus").text == "NOT_STARTED":
            yield ServiceError("Can't download something that is not started.")
            return

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            self.options.service = "tv4play"
            basename = self._autoname(vid)
            if not basename:
                yield ServiceError("Cant find vid id for autonaming.")
                return
            title = "{0}-{1}-{2}".format(basename, vid, 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

        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                base = urlparse(i.find("base").text)
                parse = urlparse(i.find("url").text)
                if "rtmp" in base.scheme:
                    swf = "http://www.tv4play.se/flash/tv4playflashlets.swf"
                    self.options.other = "-W {0} -y {1}".format(swf, i.find("url").text)
                    yield RTMP(copy.copy(self.options), i.find("base").text, i.find("bitrate").text)
                elif parse.path[len(parse.path) - 3:len(parse.path)] == "f4m":
                    streams = hdsparse(self.options, self.http.request("get", i.find("url").text,
                                                                       params={"hdcore": "3.7.0"}), i.find("url").text)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            elif i.find("mediaFormat").text == "webvtt":
                yield subtitle(copy.copy(self.options), "wrst", i.find("url").text)

        url = "https://prima.tv4play.se/api/web/asset/{0}/play?protocol=hls3".format(vid)
        data = self.http.request("get", url, cookies=self.cookies).content
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))
        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                parse = urlparse(i.find("url").text)
                if parse.path.endswith("m3u8"):
                    streams = hlsparse(self.options, self.http.request("get", i.find("url").text), i.find("url").text)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]