示例#1
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"])
示例#2
0
    def get(self, options, url):
        parse = urlparse(url)
        data = get_http_data(url)
        match = re.search("abTvArticlePlayer-player-(.*)-[0-9]+-[0-9]+-clickOverlay", data)
        if not match:
            log.error("Can't find video file")
            sys.exit(2)
        try:
            start = parse_qs(parse[4])["start"][0]
        except KeyError:
            start = 0
        url = "http://www.aftonbladet.se/resource/webbtv/article/%s/player" % match.group(1)
        data = get_http_data(url)
        xml = ET.XML(data)
        url = xml.find("articleElement").find("mediaElement").find("baseUrl").text
        path = xml.find("articleElement").find("mediaElement").find("media").attrib["url"]
        live = xml.find("articleElement").find("mediaElement").find("isLive").text
        options.other = "-y %s" % path

        if start > 0:
            options.other = "%s -A %s" % (options.other, str(start))

        if live == "true":
            options.live = True

        if url == None:
            log.error("Can't find any video on that page")
            sys.exit(3)

        if url[0:4] == "rtmp":
            download_rtmp(options, url)
        else:
            filename = url + path
            download_http(options, filename)
示例#3
0
    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"])
示例#4
0
文件: hds.py 项目: drtobbe/svtplay-dl
def download_hds(options, url, swf=None):
    data = get_http_data(url)
    streams = {}
    bootstrap = {}
    xml = ET.XML(data)
    prefix = xml.find("{http://ns.adobe.com/f4m/1.0}id").text

    if sys.version_info < (2, 7):
        bootstrapIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
        mediaIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}media")
    else:
        bootstrapIter = xml.iter("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
        mediaIter = xml.iter("{http://ns.adobe.com/f4m/1.0}media")

    for i in bootstrapIter:
        bootstrap[i.attrib["id"]] = i.text

    for i in mediaIter:
        streams[int(i.attrib["bitrate"])] = {"url": i.attrib["url"], "bootstrapInfoId": i.attrib["bootstrapInfoId"], "metadata": i.find("{http://ns.adobe.com/f4m/1.0}metadata").text}

    test = select_quality(options, streams)

    bootstrap = base64.b64decode(bootstrap[test["bootstrapInfoId"]])
    box = readboxtype(bootstrap, 0)
    if box[2] == "abst":
        antal = readbox(bootstrap, box[0])

    baseurl = url[0:url.rfind("/")]
    i = 1

    if options.output != "-":
        extension = re.search("(\.[a-z0-9]+)$", options.output)
        if not extension:
            options.output = "%s.flv" % options.output
        log.info("Outfile: %s", options.output)
        file_d = open(options.output, "wb")
    else:
        file_d = sys.stdout

    metasize = struct.pack(">L", len(base64.b64decode(test["metadata"])))[1:]
    file_d.write(binascii.a2b_hex(b"464c560105000000090000000012"))
    file_d.write(metasize)
    file_d.write(binascii.a2b_hex(b"00000000000000"))
    file_d.write(base64.b64decode(test["metadata"]))
    file_d.write(binascii.a2b_hex(b"00000000"))
    total = antal[1]["total"]
    eta = ETA(total)
    while i <= total:
        url = "%s/%sSeg1-Frag%s" % (baseurl, test["url"], i)
        if options.output != "-":
            eta.update(i)
            progressbar(total, i, ''.join(["ETA: ", str(eta)]))
        data = get_http_data(url)
        number = decode_f4f(i, data)
        file_d.write(data[number:])
        i += 1

    if options.output != "-":
        file_d.close()
        progress_stream.write('\n')
示例#5
0
    def get(self, options):
        data = self.get_urldata()
        match = re.search('data-aptomaId="([-0-9a-z]+)"', data)
        if not match:
            log.error("Can't find video info")
            sys.exit(2)
        videoId = match.group(1)
        match = re.search(r'data-isLive="(\w+)"', data)
        if not match:
            log.error("Can't find live info")
            sys.exit(2)
        if match.group(1) == "true":
            options.live = True
        if not options.live:
            dataurl = "http://aftonbladet-play-metadata.cdn.drvideo.aptoma.no/video/%s.json" % videoId
            data = get_http_data(dataurl)
            data = json.loads(data)
            videoId = data["videoId"]

        streamsurl = "http://aftonbladet-play-static-ext.cdn.drvideo.aptoma.no/actions/video/?id=%s&formats&callback=" % videoId
        streams = json.loads(get_http_data(streamsurl))
        hlsstreams = streams["formats"]["hls"]
        if "level3" in hlsstreams.keys():
            hls = hlsstreams["level3"]["csmil"][0]
        else:
            hls = hlsstreams["akamai"]["m3u8"][0]
        address = hls["address"]
        path = hls["path"]

        for i in hls["files"]:
            if "filename" in i.keys():
                playlist = "http://%s/%s/%s/master.m3u8" % (address, path, i["filename"])
            else:
                playlist = "http://%s/%s/%s/master.m3u8" % (address, path, hls["filename"])
            yield HLS(copy.copy(options), playlist, i["bitrate"])
示例#6
0
    def get(self, options, url):
        data = get_http_data(url)
        match = re.search("xmlUrl: '(http://www.expressen.*)'", data)
        if not match:
            log.error("Can't find video file")
            sys.exit(2)
        url = "http://tv.expressen.se/%s/?standAlone=true&output=xml" % quote_plus(match.group(1))
        url = match.group(1)
        data = get_http_data(url)
        xml = ET.XML(data)
        ss = xml.find("vurls")
        if sys.version_info < (2, 7):
            sa = list(ss.getiterator("vurl"))
        else:
            sa = list(ss.iter("vurl"))
        streams = {}

        for i in sa:
            streams[int(i.attrib["bitrate"])] = i.text

        test = select_quality(options, streams)

        filename = test
        match = re.search("rtmp://([0-9a-z\.]+/[0-9]+/)(.*)", filename)

        filename = "rtmp://%s" % match.group(1)
        options.other = "-y %s" % match.group(2)

        download_rtmp(options, filename)
示例#7
0
    def get(self, options):
        vid = None
        data = self.get_urldata()
        match = re.search(r'video url-([^"]+)', data)
        if not match:
            match = re.search(r'embed.jsp\?id=([^&]+)&', data)
            if not match:
                log.error("Cant find video id")
                sys.exit(2)
            vid = match.group(1)
        if not vid:
            path = unquote_plus(match.group(1))
            data = get_http_data("http://www.svd.se%s" % path)
            match = re.search(r'embed.jsp\?id=([^&]+)&', data)
            if not match:
                log.error("Cant find video id2")
                sys.exit(2)
            vid = match.group(1)

        url = "http://amz.lwcdn.com/api/cache/VideoCache.jsp?id=%s" % vid
        data = get_http_data(url)
        xml = ET.XML(data)
        videofile = xml.find("{http://www.lemonwhale.com/xml11}VideoFile")
        mediafiles = videofile.find(
            "{http://www.lemonwhale.com/xml11}MediaFiles")
        high = mediafiles.find("{http://www.lemonwhale.com/xml11}VideoURLHigh")
        if high.text:
            yield HTTP(copy.copy(options), high.text, 720)
        videourl = mediafiles.find(
            "{http://www.lemonwhale.com/xml11}VideoURL").text
        yield HTTP(copy.copy(options), videourl, 480)
示例#8
0
    def get(self, options):
        vid = None
        data = self.get_urldata()
        match = re.search(r'video url-([^"]+)', data)
        if not match:
            match = re.search(r'embed.jsp\?id=([^&]+)&', data)
            if not match:
                log.error("Cant find video id")
                sys.exit(2)
            vid = match.group(1)
        if not vid:
            path = unquote_plus(match.group(1))
            data = get_http_data("http://www.svd.se%s" % path)
            match = re.search(r'embed.jsp\?id=([^&]+)&', data)
            if not match:
                log.error("Cant find video id2")
                sys.exit(2)
            vid = match.group(1)

        url = "http://amz.lwcdn.com/api/cache/VideoCache.jsp?id=%s" % vid
        data = get_http_data(url)
        xml = ET.XML(data)
        videofile = xml.find("{http://www.lemonwhale.com/xml11}VideoFile")
        mediafiles = videofile.find("{http://www.lemonwhale.com/xml11}MediaFiles")
        high = mediafiles.find("{http://www.lemonwhale.com/xml11}VideoURLHigh")
        if high.text:
            yield HTTP(copy.copy(options), high.text, 720)
        file = mediafiles.find("{http://www.lemonwhale.com/xml11}VideoURL").text
        yield HTTP(copy.copy(options), file, 480)
示例#9
0
文件: hbo.py 项目: drtobbe/svtplay-dl
    def get(self, options, url):
        parse = urlparse(url)
        try:
            other = parse[5]
        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 sys.version_info < (2, 7):
            sa = list(ss.getiterator("size"))
        else:
            sa = list(ss.iter("size"))
        streams = {}
        for i in sa:
            stream = {}
            stream["path"] = i.find("tv14").find("path").text
            streams[int(i.attrib["width"])] = stream

        test = select_quality(options, streams)

        download_rtmp(options, test["path"])
示例#10
0
文件: hbo.py 项目: Cybjit/svtplay-dl
    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"])
示例#11
0
    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"])
示例#12
0
    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"])
示例#13
0
    def get(self, options, url):
        if re.findall("dn.se", url):
            data = get_http_data(url)
            match = re.search("data-qbrick-mcid=\"([0-9A-F]+)\"", data)
            if not match:
                match = re.search("mediaId = \'([0-9A-F]+)\';", data)
                if not match:
                    log.error("Can't find video file")
                    sys.exit(2)
                mcid = "%sDE1BA107" % match.group(1)
            else:
                mcid = match.group(1)
            host = "http://vms.api.qbrick.com/rest/v3/getsingleplayer/%s" % mcid
        elif re.findall("di.se", url):
            data = get_http_data(url)
            match = re.search("ccid: \"(.*)\"\,", 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("svd.se", url):
            match = re.search("_([0-9]+)\.svd", url)
            if not match:
                log.error("Can't find video file")
                sys.exit(2)
            data = get_http_data("http://www.svd.se/?service=ajax&type=webTvClip&articleId=%s" % match.group(1))
            match = re.search("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)

        data = get_http_data(url)
        xml = ET.XML(data)
        server = xml.find("head").find("meta").attrib["base"]
        streams = xml.find("body").find("switch")
        if sys.version_info < (2, 7):
            sa = list(streams.getiterator("video"))
        else:
            sa = list(streams.iter("video"))
        streams = {}
        for i in sa:
            streams[int(i.attrib["system-bitrate"])] = i.attrib["src"]

        path = select_quality(options, streams)

        options.other = "-y %s" % path
        download_rtmp(options, server)
示例#14
0
    def get(self, options):
        match = re.search(r".*video/([0-9]+)", self.url)
        if not match:
            log.error("Can't find video file")
            sys.exit(2)

        video_id = match.group(1)
        if options.username and options.password:
            #bogus
            cc = Cookie(None, 'asdf', None, '80', '80', 'www.kanal5play.se', None, None, '/', None, False, False, 'TestCookie', None, None, None)
            self.cj.set_cookie(cc)
            #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"] == False:
                log.error(jsondata["message"])
                sys.exit(2)
            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))
        if not options.live:
            options.live = data["isLive"]
        if data["hasSubtitle"]:
            yield subtitle_json("http://www.kanal5play.se/api/subtitles/%s" % video_id)

        for i in data["streams"]:
            if i["drmProtected"]:
                log.error("We cant download drm files for this site.")
                sys.exit(2)
            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))
        for i in data["streams"]:
                streams = hlsparse(i["source"])
                for n in list(streams.keys()):
                    yield HLS(copy.copy(options), streams[n], n)
示例#15
0
文件: ruv.py 项目: drtobbe/svtplay-dl
 def get(self, options, url):
     data = get_http_data(url)
     match = re.search(r'(http://load.cache.is/vodruv.*)"', data)
     js_url = match.group(1)
     js = get_http_data(js_url)
     tengipunktur = js.split('"')[1]
     match = re.search(r"http.*tengipunktur [+] '([:]1935.*)'", data)
     m3u8_url = "http://" + tengipunktur + match.group(1)
     base_url = m3u8_url.rsplit("/", 1)[0]
     download_hls(options, m3u8_url, base_url)
示例#16
0
    def download(self):
        if self.options.live and not self.options.force:
            raise LiveHLSException(self.url)

        error, m3u8 = get_http_data(self.url)
        if error:
            log.error("Cant get m3u8 file.")
            return
        globaldata, files = parsem3u(m3u8)
        encrypted = False
        key = None
        if "KEY" in globaldata:
            keydata = globaldata["KEY"]
            encrypted = True

        if encrypted:
            try:
                from Crypto.Cipher import AES
            except ImportError:
                log.error("You need to install pycrypto to download encrypted HLS streams")
                sys.exit(2)

            match = re.search(r'URI="(https?://.*?)"', keydata)
            error, key = get_http_data(match.group(1))
            if error:
                log.error("Can't get crypto key to decode files.")
                return
            rand = os.urandom(16)
            decryptor = AES.new(key, AES.MODE_CBC, rand)

        file_d = output(self.options, "ts")
        if hasattr(file_d, "read") is False:
            return

        n = 1
        eta = ETA(len(files))
        for i in files:
            item = _get_full_url(i[0], self.url)

            if self.options.output != "-":
                eta.increment()
                progressbar(len(files), n, "".join(["ETA: ", str(eta)]))
                n += 1

            error, data = get_http_data(item)
            if error:
                log.error("Missing segment in playlist")
                return
            if encrypted:
                data = decryptor.decrypt(data)
            file_d.write(data)

        if self.options.output != "-":
            file_d.close()
            progress_stream.write("\n")
示例#17
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"]:
            try:
                subtitle = data["video"]["subtitleReferences"][0]["url"]
            except KeyError:
                pass
            if len(subtitle) > 0:
                yield subtitle_wsrt(subtitle)

        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)
                    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")
示例#18
0
    def download(self):
        if self.options.live and not self.options.force:
            raise LiveHLSException(self.url)

        m3u8 = get_http_data(self.url)
        globaldata, files = parsem3u(m3u8)
        encrypted = False
        key = None
        try:
            keydata = globaldata["KEY"]
            encrypted = True
        except KeyError:
            pass

        if encrypted:
            try:
                from Crypto.Cipher import AES
            except ImportError:
                log.error("You need to install pycrypto to download encrypted HLS streams")
                sys.exit(2)

            match = re.search(r'URI="(https?://.*?)"', keydata)
            key = get_http_data(match.group(1))
            rand = os.urandom(16)
            decryptor = AES.new(key, AES.MODE_CBC, rand)
        if self.options.output != "-":
            extension = re.search(r"(\.[a-z0-9]+)$", self.options.output)
            if not extension:
                self.options.output = "%s.ts" % self.options.output
            log.info("Outfile: %s", self.options.output)
            if os.path.isfile(self.options.output) and not self.options.force:
                log.info("File already exists. use --force to overwrite")
                return
            file_d = open(self.options.output, "wb")
        else:
            file_d = sys.stdout

        n = 0
        eta = ETA(len(files))
        for i in files:
            item = _get_full_url(i[0], self.url)

            if self.options.output != "-":
                eta.increment()
                progressbar(len(files), n, ''.join(['ETA: ', str(eta)]))
                n += 1

            data = get_http_data(item)
            if encrypted:
                data = decryptor.decrypt(data)
            file_d.write(data)

        if self.options.output != "-":
            file_d.close()
            progress_stream.write('\n')
示例#19
0
文件: dr.py 项目: dapstr/svtplay-dl
    def get(self, options):
        error, data = self.get_urldata()
        if error:
            log.error("Can't download page.")
            return

        if self.exclude(options):
            return

        match = re.search(r'resource:[ ]*"([^"]*)",', data)
        if match:
            resource_url = match.group(1)
            error, resource_data = get_http_data(resource_url)
            if error:
                log.error("Can't get resource data")
                return
            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")
                return
            resource_url = "%s" % match.group(1)
            error, resource_data = get_http_data(resource_url)
            if error:
                log.error("Can't get resource data")
                return
            resource = json.loads(resource_data)

            if "SubtitlesList" in resource:
                suburl = resource["SubtitlesList"][0]["Uri"]
                yield subtitle(copy.copy(options), "wrst", suburl)
            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":
                        streams = hdsparse(copy.copy(options), stream["Uri"])
                        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'])
示例#20
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)
示例#21
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)
示例#22
0
    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)
            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":
                    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"])

        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)

            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)
                    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'])
示例#23
0
文件: hls.py 项目: carlba/svtplay-dl
    def download(self):
        if self.options.live and not self.options.force:
            raise LiveHLSException(self.url)

        m3u8 = get_http_data(self.url)
        globaldata, files = parsem3u(m3u8)
        encrypted = False
        key = None
        try:
            keydata = globaldata["KEY"]
            encrypted = True
        except KeyError:
            pass

        if encrypted:
            try:
                from Crypto.Cipher import AES
            except ImportError:
                log.error("You need to install pycrypto to download encrypted HLS streams")
                sys.exit(2)

            match = re.search(r'URI="(https?://.*?)"', keydata)
            key = get_http_data(match.group(1))
            rand = os.urandom(16)
            decryptor = AES.new(key, AES.MODE_CBC, rand)

        file_d = output(self.options, self.options.output, "ts")
        if hasattr(file_d, "read") is False:
            return

        n = 1
        eta = ETA(len(files))
        for i in files:
            item = _get_full_url(i[0], self.url)

            if self.options.output != "-":
                eta.increment()
                progressbar(len(files), n, ''.join(['ETA: ', str(eta)]))
                n += 1

            data = get_http_data(item)
            if encrypted:
                data = decryptor.decrypt(data)
            file_d.write(data)

        if self.options.output != "-":
            file_d.close()
            progress_stream.write('\n')
示例#24
0
    def download(self, options):
        self.subtitle = get_http_data(self.url)
        i = 1
        data = ""
        tree = ET.ElementTree(ET.fromstring(self.subtitle))
        xml = tree.find("{http://www.w3.org/2006/10/ttaf1}body").find(
            "{http://www.w3.org/2006/10/ttaf1}div")
        plist = list(xml.findall("{http://www.w3.org/2006/10/ttaf1}p"))
        for node in plist:
            tag = norm(node.tag)
            if tag == "p" or tag == "span":
                begin = node.attrib["begin"]
                if not ("dur" in node.attrib):
                    duration = node.attrib["duration"]
                else:
                    duration = node.attrib["dur"]
                if not ("end" in node.attrib):
                    begin2 = begin.split(":")
                    duration2 = duration.split(":")
                    sec = float(begin2[2]) + float(duration2[2])
                    end = "%02d:%02d:%06.3f" % (int(begin[0]), int(
                        begin[1]), sec)
                else:
                    end = node.attrib["end"]
                data += '%s\n%s --> %s\n' % (i, begin.replace(
                    ".", ","), end.replace(".", ","))
                data = tt_text(node, data)
                data += "\n"
                i += 1

        if is_py2:
            data = data.encode('utf8')
        save(options, data)
示例#25
0
    def download(self, options):
        self.subtitle = get_http_data(self.url)
        recomp = re.compile(
            r"(\d+)\r\n([\d:\.]+ --> [\d:\.]+)?([^\r\n]+)?\r\n([^\r\n]+)\r\n(([^\r\n]*)\r\n)?"
        )
        srt = ""
        subtract = False
        for i in recomp.finditer(self.subtitle):
            number = int(i.group(1))
            match = re.search(
                r'(\d+):(\d+):([\d\.]+) --> (\d+):(\d+):([\d\.]+)', i.group(2))
            hour1 = int(match.group(1))
            hour2 = int(match.group(4))
            if number == 1:
                if hour1 > 9:
                    subtract = True
            if subtract:
                hour1 -= 10
                hour2 -= 10
            time = "%s:%s:%s --> %s:%s:%s" % (
                hour1, match.group(2), match.group(3).replace(".", ","), hour2,
                match.group(5), match.group(6).replace(".", ","))
            sub = "%s\n%s\n%s\n" % (i.group(1), time, i.group(4))
            if len(i.group(6)) > 0:
                sub += "%s\n" % i.group(6)
            sub += "\n"
            sub = re.sub('<[^>]*>', '', sub)
            srt += sub

        save(options, srt)
示例#26
0
    def get(self, options, url):
        data = get_http_data(url)
        match = re.search("liveStationsRedundancy = ({.*});</script>", data)
        parse = urlparse(url)
        station = parse.path[1:]
        streams = None
        if match:
            data = json.loads(match.group(1))
            for i in data["stations"]:
                if station == i["name"].lower().replace(" ", ""):
                    streams = i["streams"]
                    break
        else:
            log.error("Can't find any streams.")
            sys.exit(2)
        if streams:
            if options.hls:
                try:
                    m3u8_url = streams["hls"]
                    base_url = m3u8_url.rsplit("/", 1)[0]
                    download_hls(options, m3u8_url, base_url)
                except KeyError:
                    log.error("Can't find any streams.")
                    sys.exit(2)
            else:
                try:
                    rtmp = streams["rtmp"]
                    download_rtmp(options, rtmp)
                except KeyError:
                    mp3 = streams["mp3"]
                    download_http(options, mp3)

        else:
            log.error("Can't find any streams.")
            sys.exit(2)
示例#27
0
    def find_all_episodes(self, options):
        parse = urlparse(self.url)
        show = parse.path[parse.path.find("/", 1)+1:]
        if not re.search("%", show):
            show = quote_plus(show)
        error, data = get_http_data("http://webapi.tv4play.se/play/video_assets?type=episode&is_live=false&platform=web&node_nids=%s&per_page=99999" % show)
        if error:
            log.error("Can't get api page")
            return
        jsondata = json.loads(data)
        episodes = []
        n = 1
        for i in jsondata["results"]:
            try:
                days = int(i["availability"]["availability_group_free"])
            except (ValueError, TypeError):
                days = 999
            if days > 0:
                video_id = i["id"]
                url = "http://www.tv4play.se/program/%s?video_id=%s" % (
                    show, video_id)
                episodes.append(url)
                if n == options.all_last:
                    break
                n += 1

        return episodes
示例#28
0
    def get(self, options, url):
        data = get_http_data(url, referer="")
        match = data.split(' = {config:')[1].split(',assets:')[0]
        if match:
            jsondata = json.loads(match)
            sig = jsondata['request']['signature']
            vidid = jsondata["video"]["id"]
            timestamp = jsondata['request']['timestamp']
            referer = jsondata["request"]["referrer"]
            avail_quality = jsondata["video"]["files"]["h264"]
            selected_quality = None
            for i in avail_quality:
                if options.quality == i:
                    selected_quality = i

            if options.quality and selected_quality is None:
                log.error("Can't find that quality. (Try one of: %s)",
                      ", ".join(map(str, avail_quality)))
                sys.exit(4)
            elif options.quality is None and selected_quality is None:
                selected_quality = avail_quality[0]
            url = "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=H264,VP8,VP6&type=moogaloop_local&embed_location=%s" % (vidid, sig, timestamp, selected_quality, referer)
            download_http(options, url)
        else:
            log.error("Can't find any streams.")
            sys.exit(2)
示例#29
0
    def get(self, options):
        data = self.get_urldata()
        match = re.search('data-subtitlesurl = "(/.*)"', data)
        if match:
            parse = urlparse(self.url)
            subtitle = "%s://%s%s" % (parse.scheme, parse.netloc, match.group(1))
            yield subtitle_tt(subtitle)
        match = re.search(r'data-media="(.*manifest.f4m)"', data)
        if match:
            manifest_url = match.group(1)
        else:
            match = re.search(r'data-video-id="(\d+)"', data)
            if match is None:
                log.error("Can't find video id.")
                sys.exit(2)
            vid = match.group(1)
            match = re.search(r"PS_VIDEO_API_URL : '([^']*)',", data)
            if match is None:
                log.error("Can't find server address with media info")
                sys.exit(2)
            dataurl = "%smediaelement/%s" % (match.group(1), vid)
            data = json.loads(get_http_data(dataurl))
            manifest_url = data["mediaUrl"]
            options.live = data["isLive"]

        hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8")
        streams = hlsparse(hlsurl)
        for n in list(streams.keys()):
            yield HLS(copy.copy(options), streams[n], n)

        manifest_url = "%s?hdcore=2.8.0&g=hejsan" % manifest_url
        streams = hdsparse(copy.copy(options), manifest_url)
        for n in list(streams.keys()):
            yield streams[n]
示例#30
0
    def get(self, options):
        match = re.search("xmlUrl=([^ ]+)\" ", self.get_urldata())
        if match:
            xmlurl = unquote_plus(match.group(1))
        else:
            match = re.search("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)
示例#31
0
    def find_all_episodes(self, options):
        page = 1
        match = re.search(r'"http://www.oppetarkiv.se/etikett/titel/([^"/]+)',
                          self.get_urldata())
        if match is None:
            match = re.search(
                r'"http://www.oppetarkiv.se/etikett/titel/([^"/]+)', self.url)
            if match is None:
                log.error("Couldn't find title")
                sys.exit(2)
        program = match.group(1)
        more = True
        episodes = []
        while more:
            url = "http://www.oppetarkiv.se/etikett/titel/%s/?sida=%s&sort=tid_stigande&embed=true" % (
                program, page)
            data = get_http_data(url)
            visa = re.search(r'svtXColorDarkLightGrey', data)
            if not visa:
                more = False
            regex = re.compile(r'(http://www.oppetarkiv.se/video/[^"]+)')
            for match in regex.finditer(data):
                episodes.append(match.group(1))
            page += 1

        return episodes
示例#32
0
    def find_all_episodes(self, options):
        match = re.search(r'<link rel="alternate" type="application/rss\+xml" [^>]*href="([^"]+)"',
                          self.get_urldata()[1])
        if match is None:
            match = re.findall(r'a class="play[^"]+"\s+href="(/video[^"]+)"', self.get_urldata()[1])
            if not match:
                log.error("Couldn't retrieve episode list")
                return
            episodes = [urljoin("http://www.svtplay.se", x) for x in match]
        else:
            error, data = get_http_data(match.group(1))
            if error:
                log.error("Cant get rss page")
                return
            xml = ET.XML(data)

            episodes = [x.text for x in xml.findall(".//item/link")]
        episodes_new = []
        n = 1
        for i in episodes:
            episodes_new.append(i)
            if n == options.all_last:
                break
            n += 1
        return sorted(episodes_new)
示例#33
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)
示例#34
0
文件: vg.py 项目: carlba/svtplay-dl
    def get(self, options):
        match = re.search(r'data-videoid="([^"]+)"', self.get_urldata())
        if not match:
            parse = urlparse(self.url)
            match = re.search(r'video/(\d+)/', parse.fragment)
            if not match:
                log.error("Can't find video id")
                sys.exit(2)
        videoid = match.group(1)
        data = get_http_data("http://svp.vg.no/svp/api/v1/vgtv/assets/%s?appName=vgtv-website" % videoid)
        jsondata = json.loads(data)

        if options.output_auto:
            directory = os.path.dirname(options.output)
            title = "%s" % jsondata["title"]
            title = filenamify(title)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title
        if "hds" in jsondata["streamUrls"]:
            parse = urlparse(jsondata["streamUrls"]["hds"])
            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]
        if "hls" in jsondata["streamUrls"]:
            streams = hlsparse(jsondata["streamUrls"]["hls"])
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
        if "mp4" in jsondata["streamUrls"]:
            yield HTTP(copy.copy(options), jsondata["streamUrls"]["mp4"])
示例#35
0
    def get(self, options):
        error, data = self.get_urldata()
        if error:
            log.error("Cant get page")
            return
        match = re.search(r"mgid=\"(mgid.*[0-9]+)\" data-wi", data)
        if not match:
            log.error("Can't find video file")
            return
        url = "http://media.mtvnservices.com/player/html5/mediagen/?uri=%s" % match.group(1)
        error, data = get_http_data(url)
        if error:
            log.error("Cant get stream info")
            return
        start = data.index("<?xml version=")
        data = data[start:]
        xml = ET.XML(data)
        ss = xml.find("video").find("item")
        if is_py2_old:
            sa = list(ss.getiterator("rendition"))
        else:
            sa = list(ss.iter("rendition"))

        if self.exclude(options):
            return

        for i in sa:
            temp = i.find("src").text.index("gsp.comedystor")
            url = "http://mtvnmobile.vo.llnwd.net/kip0/_pxn=0+_pxK=18639+_pxE=mp4/44620/mtvnorigin/%s" % i.find("src").text[temp:]
            yield HTTP(copy.copy(options), url, i.attrib["height"])
示例#36
0
def get_media(url, options):
    stream = service_handler(url)
    if not stream:
        url, stream = Generic().get(url)
        url = url.replace("&amp;", "&")
    if not stream:
        log.error("That site is not supported. Make a ticket or send a message")
        sys.exit(2)

    if not options.output or os.path.isdir(options.output):
        data = get_http_data(url)
        match = re.search("(?i)<title.*>\s*(.*?)\s*</title>", data)
        if match:
            if sys.version_info > (3, 0):
                title = re.sub('[^\w\s-]', '', match.group(1)).strip().lower()
                if options.output:
                    options.output = options.output + re.sub('[-\s]+', '-', title)
                else:
                    options.output = re.sub('[-\s]+', '-', title)
            else:
                title = unicode(re.sub('[^\w\s-]', '', match.group(1)).strip().lower())
                if options.output:
                    options.output = unicode(options.output + re.sub('[-\s]+', '-', title))
                else:
                    options.output = unicode(re.sub('[-\s]+', '-', title))

    stream.get(options, url)
示例#37
0
文件: sr.py 项目: dapstr/svtplay-dl
    def get(self, options):
        error, data = self.get_urldata()
        if error:
            log.error("Can't get the page")
            return

        if self.exclude(options):
            return

        match = re.search(r'href="(/sida/[\.\/=a-z0-9&;\?]+\d+)" aria-label', data)
        if not match:
            log.error("Can't find audio info")
            return
        path = quote_plus(match.group(1))
        dataurl = "http://sverigesradio.se/sida/ajax/getplayerinfo?url=%s&isios=false&playertype=html5" % path
        error, data = get_http_data(dataurl)
        if error:
            log.error("Cant get stream info")
            return
        playerinfo = json.loads(data)["playerInfo"]
        for i in playerinfo["AudioSources"]:
            url = i["Url"]
            if not url.startswith('http'):
                url = 'http:%s' % url
            yield HTTP(copy.copy(options), url, i["Quality"]/1000)
示例#38
0
def hdsparse(options, manifest):
    data = get_http_data(manifest)
    streams = {}
    bootstrap = {}
    xml = ET.XML(data)

    if is_py2_old:
        bootstrapIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
        mediaIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}media")
    else:
        bootstrapIter = xml.iter("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
        mediaIter = xml.iter("{http://ns.adobe.com/f4m/1.0}media")

    if xml.find("{http://ns.adobe.com/f4m/1.0}drmAdditionalHeader") is not None:
        log.error("HDS DRM protected content.")
        return
    for i in bootstrapIter:
        if "id" in i.attrib:
            bootstrap[i.attrib["id"]] = i.text
        else:
            bootstrap["0"] = i.text
    parse = urlparse(manifest)
    querystring = parse.query
    for i in mediaIter:
        if len(bootstrap) == 1:
            bootstrapid = bootstrap["0"]
        else:
            bootstrapid = bootstrap[i.attrib["bootstrapInfoId"]]
        streams[int(i.attrib["bitrate"])] = HDS(options, i.attrib["url"], i.attrib["bitrate"], manifest=manifest, bootstrap=bootstrapid,
                                                metadata=i.find("{http://ns.adobe.com/f4m/1.0}metadata").text, querystring=querystring)
    return streams
示例#39
0
    def _get_static_video(self, vid, options, vidtype):
        url = "http://api.justin.tv/api/broadcast/by_%s/%s.xml?onsite=true" % (
            vidtype, vid)
        data = get_http_data(url)

        xml = ET.XML(data)
        url = xml.find("archive").find("video_file_url").text

        yield HTTP(copy.copy(options), url)
示例#40
0
    def get(self, options):
        parse = urlparse(self.url)
        if parse.hostname == "video.disney.se":
            match = re.search(r"Grill.burger=({.*}):", self.get_urldata())
            if not match:
                log.error("Can't find video info")
                return
            jsondata = json.loads(match.group(1))
            for n in jsondata["stack"]:
                if len(n["data"]) > 0:
                    for x in n["data"]:
                        if "flavors" in x:
                            for i in x["flavors"]:
                                if i["format"] == "mp4":
                                    yield HTTP(copy.copy(options), i["url"],
                                               i["bitrate"])
        else:
            match = re.search(r"uniqueId : '([^']+)'", self.get_urldata())
            if not match:
                log.error("Can't find video info")
                return
            uniq = match.group(1)
            match = re.search("entryId : '([^']+)'", self.get_urldata())
            entryid = match.group(1)
            match = re.search("partnerId : '([^']+)'", self.get_urldata())
            partnerid = match.group(1)
            match = re.search("uiConfId : '([^']+)'", self.get_urldata())
            uiconfid = match.group(1)


            url = "http://cdnapi.kaltura.com/html5/html5lib/v1.9.7.6/mwEmbedFrame.php?&wid=%s&uiconf_id=%s&entry_id=%s&playerId=%s&forceMobileHTML5=true&urid=1.9.7.6&callback=mwi" % \
            (partnerid, uiconfid, entryid, uniq)
            data = get_http_data(url)
            match = re.search(r"mwi\(({.*})\);", data)
            jsondata = json.loads(match.group(1))
            data = jsondata["content"]
            match = re.search(r"window.kalturaIframePackageData = ({.*});",
                              data)
            jsondata = json.loads(match.group(1))
            ks = jsondata["enviornmentConfig"]["ks"]
            if options.output_auto:
                name = jsondata["entryResult"]["meta"]["name"]
                directory = os.path.dirname(options.output)
                options.service = "disney"
                title = "%s-%s" % (name, options.service)
                title = filenamify(title)
                if len(directory):
                    options.output = "%s/%s" % (directory, title)
                else:
                    options.output = title

            url = "http://cdnapi.kaltura.com/p/%s/sp/%s00/playManifest/entryId/%s/format/applehttp/protocol/http/a.m3u8?ks=%s&referrer=aHR0cDovL3d3dy5kaXNuZXkuc2U=&" % (
                partnerid[1:], partnerid[1:], entryid, ks)
            redirect = check_redirect(url)
            streams = hlsparse(redirect)
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
示例#41
0
文件: hls.py 项目: carlba/svtplay-dl
def hlsparse(url):
    data = get_http_data(url)
    files = (parsem3u(data))[1]
    streams = {}

    for i in files:
        bitrate = float(i[1]["BANDWIDTH"])/1000
        streams[int(bitrate)] = _get_full_url(i[0], url)
    return streams
示例#42
0
    def get(self, options):
        data = self.get_urldata()
        match = re.search('data-aptomaId="([-0-9a-z]+)"', data)
        if not match:
            log.error("Can't find video info")
            sys.exit(2)
        videoId = match.group(1)
        match = re.search(r'data-isLive="(\w+)"', data)
        if not match:
            log.error("Can't find live info")
            sys.exit(2)
        if match.group(1) == "true":
            options.live = True
        if not options.live:
            dataurl = "http://aftonbladet-play-metadata.cdn.drvideo.aptoma.no/video/%s.json" % videoId
            data = get_http_data(dataurl)
            data = json.loads(data)
            videoId = data["videoId"]

        streamsurl = "http://aftonbladet-play-static-ext.cdn.drvideo.aptoma.no/actions/video/?id=%s&formats&callback=" % videoId
        streams = json.loads(get_http_data(streamsurl))
        hlsstreams = streams["formats"]["hls"]
        if "level3" in hlsstreams.keys():
            hls = hlsstreams["level3"]
        else:
            hls = hlsstreams["akamai"]
        if "csmil" in hls.keys():
            hls = hls["csmil"][0]
        else:
            hls = hls["m3u8"][0]
        address = hls["address"]
        path = hls["path"]

        for i in hls["files"]:
            if "filename" in i.keys():
                plist = "http://%s/%s/%s/master.m3u8" % (address, path,
                                                         i["filename"])
            else:
                plist = "http://%s/%s/%s" % (address, path, hls["filename"])

            streams = hlsparse(plist)
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
示例#43
0
    def find_all_episodes(self, options):
        match = re.search(
            r'<link rel="alternate" type="application/rss\+xml" [^>]*href="([^"]+)"',
            self.get_urldata())
        if match is None:
            log.error("Couldn't retrieve episode list")
            sys.exit(2)
        url = "http://urplay.se%s" % match.group(1).replace("&amp;", "&")
        xml = ET.XML(get_http_data(url))

        return sorted(x.text for x in xml.findall(".//item/link"))
示例#44
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'])
示例#45
0
    def find_all_episodes(self, options):
        format_id = re.search(r'data-format-id="(\d+)"', self.get_urldata())
        if not format_id:
            log.error("Can't find video info")
            sys.exit(2)
        data = get_http_data(
            "http://playapi.mtgx.tv/v1/sections?sections=videos.one,seasons.videolist&format=%s"
            % format_id.group(1))
        jsondata = json.loads(data)
        videos = jsondata["_embedded"]["sections"][1]["_embedded"]["seasons"][
            0]["_embedded"]["episodelist"]["_embedded"]["videos"]

        return sorted(x["sharing"]["url"] for x in videos)
示例#46
0
    def get(self, url):
        data = get_http_data(url)
        match = re.search(r"src=\"(http://www.svt.se/wd.*)\" height", data)
        stream = None
        if match:
            url = match.group(1)
            for i in sites:
                if i.handles(url):
                    url = url.replace("&amp;", "&")
                    return url, i(url)

        match = re.search(r"src=\"(http://player.vimeo.com/video/[0-9]+)\" ", data)
        if match:
            for i in sites:
                if i.handles(match.group(1)):
                    return match.group(1), i(url)
        match = re.search(r"tv4play.se/iframe/video/(\d+)?", data)
        if match:
            url = "http://www.tv4play.se/?video_id=%s" % match.group(1)
            for i in sites:
                if i.handles(url):
                    return url, i(url)
        match = re.search(r"embed.bambuser.com/broadcast/(\d+)", data)
        if match:
            url = "http://bambuser.com/v/%s" % match.group(1)
            for i in sites:
                if i.handles(url):
                    return url, i(url)
        match = re.search(r'iframe src="(http://tv.aftonbladet[^"]*)"', data)
        if match:
            url = match.group(1)
            for i in sites:
                if i.handles(url):
                    return url, i(url)
        match = re.search(r'a href="(http://tv.aftonbladet[^"]*)" class="abVi', data)
        if match:
            url = match.group(1)
            for i in sites:
                if i.handles(url):
                    return url, i(url)

        match = re.search(r"iframe src='(http://www.svtplay[^']*)'", data)
        if match:
            url = match.group(1)
            for i in sites:
                if i.handles(url):
                    return url, i(url)

        return url, stream
示例#47
0
 def get(self, options):
     match = re.search(r'href="(/sida/[\.\/=a-z0-9&;\?]+\d+)" aria-label',
                       self.get_urldata())
     if not match:
         log.error("Can't find audio info")
         sys.exit(2)
     path = quote_plus(match.group(1))
     dataurl = "http://sverigesradio.se/sida/ajax/getplayerinfo?url=%s&isios=false&playertype=html5" % path
     data = get_http_data(dataurl)
     playerinfo = json.loads(data)["playerInfo"]
     for i in playerinfo["AudioSources"]:
         url = i["Url"]
         if not url.startswith('http'):
             url = 'http:%s' % url
         yield HTTP(copy.copy(options), url, i["Quality"])
示例#48
0
    def download(self, options):
        self.subtitle = get_http_data(self.url, cookiejar=options.cookiejar)
        data = json.loads(self.subtitle)
        number = 1
        subs = ""
        for i in data:
            subs += "%s\n%s --> %s\n" % (number, timestr(int(
                i["startMillis"])), timestr(int(i["endMillis"])))
            if is_py2:
                subs += "%s\n\n" % i["text"].encode("utf-8")
            else:
                subs += "%s\n\n" % i["text"]
            number += 1

        save(options, subs)
示例#49
0
    def _ajax_get(self, method):
        url = "%s/%s" % (self.api_base_url, method)

        # Logic found in Twitch's global.js. Prepend /kraken/ to url
        # path unless the API method already is absolute.
        if method[0] != '/':
            method = '/kraken/%s' % method

        # There are references to a api_token in global.js; it's used
        # with the "Twitch-Api-Token" HTTP header. But it doesn't seem
        # to be necessary.
        payload = get_http_data(url, header={
            'Accept': 'application/vnd.twitchtv.v2+json'
        })
        return json.loads(payload)
示例#50
0
    def get(self, options):
        match = re.search(r'id="(bcPl[^"]+)"', self.get_urldata())
        if not match:
            log.error("Can't find flash id.")
            sys.exit(2)
        flashid = match.group(1)

        match = re.search(r'playerID" value="([^"]+)"', self.get_urldata())
        if not match:
            log.error("Can't find playerID")
            sys.exit(2)
        playerid = match.group(1)

        match = re.search(r'playerKey" value="([^"]+)"', self.get_urldata())
        if not match:
            log.error("Can't find playerKey")
            sys.exit(2)
        playerkey = match.group(1)

        match = re.search(r'videoPlayer" value="([^"]+)"', self.get_urldata())
        if not match:
            log.error("Can't find videoPlayer info")
            sys.exit(2)
        videoplayer = match.group(1)

        dataurl = "http://c.brightcove.com/services/viewer/htmlFederated?flashID=%s&playerID=%s&playerKey=%s&isVid=true&isUI=true&dynamicStreaming=true&@videoPlayer=%s" % (
            flashid, playerid, playerkey, videoplayer)
        data = get_http_data(dataurl)
        match = re.search(r'experienceJSON = ({.*});', data)
        if not match:
            log.error("Can't find json data")
            sys.exit(2)
        jsondata = json.loads(match.group(1))
        renditions = jsondata["data"]["programmedContent"]["videoPlayer"][
            "mediaDTO"]["renditions"]
        for i in renditions:
            if i["defaultURL"].endswith("f4m"):
                manifest = "%s?hdcore=3.3.0" % i["defaultURL"]
                streams = hdsparse(copy.copy(options), manifest)
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]

            if i["defaultURL"].endswith("m3u8"):
                streams = hlsparse(i["defaultURL"])
                for n in list(streams.keys()):
                    yield HLS(copy.copy(options), streams[n], n)
示例#51
0
    def find_all_episodes(self, options):
        match = re.search(
            r'<link rel="alternate" type="application/rss\+xml" [^>]*href="([^"]+)"',
            self.get_urldata())
        if match is None:
            log.error("Couldn't retrieve episode list")
            sys.exit(2)

        xml = ET.XML(get_http_data(match.group(1)))

        if options.episode_list_exclude_filter:
            episode_list = sorted(
                x.text for x in xml.findall(".//item/link")
                if options.episode_list_exclude_filter not in x.text)
        else:
            episode_list = sorted(x.text for x in xml.findall(".//item/link"))
        return episode_list
示例#52
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")
示例#53
0
    def get(self, options):
        match = re.search("data-config-url=\"(.*)\" data-fallback-url",
                          self.get_urldata())
        if not match:
            log.error("Can't find data")
            sys.exit(4)
        player_url = match.group(1).replace("&amp;", "&")
        player_data = get_http_data(player_url)

        if player_data:
            jsondata = json.loads(player_data)
            avail_quality = jsondata["request"]["files"]["h264"]
            for i in avail_quality.keys():
                yield HTTP(copy.copy(options), avail_quality[i]["url"],
                           avail_quality[i]["bitrate"])
        else:
            log.error("Can't find any streams.")
            sys.exit(2)
示例#54
0
文件: hds.py 项目: carlba/svtplay-dl
    def download(self):
        if self.options.live and not self.options.force:
            raise LiveHDSException(self.url)

        querystring = self.kwargs["querystring"]
        bootstrap = base64.b64decode(self.kwargs["bootstrap"])
        box = readboxtype(bootstrap, 0)
        antal = None
        if box[2] == b"abst":
            antal = readbox(bootstrap, box[0])
        baseurl = self.kwargs["manifest"][0:self.kwargs["manifest"].rfind("/")]

        file_d = output(self.options, self.options.output, "flv")
        if hasattr(file_d, "read") is False:
            return

        metasize = struct.pack(">L",
                               len(base64.b64decode(
                                   self.kwargs["metadata"])))[1:]
        file_d.write(binascii.a2b_hex(b"464c560105000000090000000012"))
        file_d.write(metasize)
        file_d.write(binascii.a2b_hex(b"00000000000000"))
        file_d.write(base64.b64decode(self.kwargs["metadata"]))
        file_d.write(binascii.a2b_hex(b"00000000"))
        i = 1
        start = antal[1]["first"]
        total = antal[1]["total"]
        eta = ETA(total)
        while i <= total:
            url = "%s/%sSeg1-Frag%s?%s" % (baseurl, self.url, start,
                                           querystring)
            if self.options.output != "-":
                eta.update(i)
                progressbar(total, i, ''.join(["ETA: ", str(eta)]))
            data = get_http_data(url)
            number = decode_f4f(i, data)
            file_d.write(data[number:])
            i += 1
            start += 1

        if self.options.output != "-":
            file_d.close()
            progress_stream.write('\n')
示例#55
0
 def find_all_episodes(self, options):
     parse =  urlparse(self.url)
     show = parse.path[parse.path.find("/", 1)+1:]
     if not re.search("%", show):
         show = quote_plus(show)
     data = get_http_data("http://webapi.tv4play.se/play/video_assets?type=episode&is_live=false&platform=web&node_nids=%s&per_page=99999" % show)
     jsondata = json.loads(data)
     episodes = []
     for i in jsondata["results"]:
         try:
             days = int(i["availability"]["availability_group_free"])
         except ValueError:
             days = 999
         if  days > 0:
             video_id = i["id"]
             url = "http://www.tv4play.se/program/%s?video_id=%s" % (
                 show, video_id)
             episodes.append(url)
     return sorted(episodes)
示例#56
0
文件: nrk.py 项目: carlba/svtplay-dl
    def get(self, options):
        data = self.get_urldata()
        match = re.search("data-subtitlesurl = \"(/.*)\"", data)
        if match:
            parse = urlparse(self.url)
            subtitle = "%s://%s%s" % (parse.scheme, parse.netloc,
                                      match.group(1))
            yield subtitle_tt(subtitle)

        if options.force_subtitle:
            return

        match = re.search(r'data-media="(.*manifest.f4m)"', data)
        if match:
            manifest_url = match.group(1)
        else:
            match = re.search(r'data-video-id="(\d+)"', data)
            if match is None:
                log.error("Can't find video id.")
                sys.exit(2)
            vid = match.group(1)
            match = re.search(r"PS_VIDEO_API_URL : '([^']*)',", data)
            if match is None:
                log.error("Can't find server address with media info")
                sys.exit(2)
            dataurl = "%smediaelement/%s" % (match.group(1), vid)
            data = json.loads(get_http_data(dataurl))
            manifest_url = data["mediaUrl"]
            options.live = data["isLive"]

        hlsurl = manifest_url.replace("/z/",
                                      "/i/").replace("manifest.f4m",
                                                     "master.m3u8")
        streams = hlsparse(hlsurl)
        for n in list(streams.keys()):
            yield HLS(copy.copy(options), streams[n], n)

        manifest_url = "%s?hdcore=2.8.0&g=hejsan" % manifest_url
        streams = hdsparse(copy.copy(options), manifest_url)
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
示例#57
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"])
示例#58
0
 def get(self, options):
     match = re.search(r'"([^"]+geo.php)"', self.get_urldata())
     if match:
         data = get_http_data(match.group(1))
         match = re.search(r'punktur=\(([^ ]+)\)', data)
         if match:
             janson = json.loads(match.group(1))
             options.live = checklive(janson["result"][1])
             streams = hlsparse(janson["result"][1])
             for n in list(streams.keys()):
                 yield HLS(copy.copy(options), streams[n], n)
     else:
         match = re.search(r'<source [^ ]*[ ]*src="([^"]+)" ',
                           self.get_urldata())
         if not match:
             log.error("Can't find video info")
             sys.exit(2)
         m3u8_url = match.group(1)
         options.live = checklive(m3u8_url)
         yield HLS(copy.copy(options), m3u8_url, 800)