Exemplo n.º 1
0
def getMovieUrl(url):
    req = Request(url, None, std_headers)
    try:
        txt = urlopen2(req).read()
    except (URLError, HTTPException, error) as err:
        print(
            "[ZDFMediaThek] Error: Unable to retrieve videopage - Error code: ",
            str(err))
        return ""

    if ('rtsp' in txt) and ('.mp4' in txt):
        idx = txt.index('rtsp')
        idx2 = txt.index('.mp4')
        return txt[idx:idx2 + 4]
    if ('rtsp' in txt) and ('.sdp' in txt):
        idx = txt.index('rtsp')
        idx2 = txt.index('.sdp')
        return txt[idx:idx2 + 4]
    elif ('mms' in txt) and ('.wmv' in txt):
        idx = txt.index('mms')
        idx2 = txt.index('.wmv')
        return txt[idx:idx2 + 4]
    elif ('http' in txt) and ('.asx?' in txt):
        idx = txt.index('http')
        idx2 = txt.index('.asx?')
        return txt[idx:idx2 + 4]
    elif ('mms' in txt) and ('reflector:' in txt):
        idx = txt.index('mms')
        idx2 = txt.index('" />')
        return txt[idx:idx2]
    else:
        return None
Exemplo n.º 2
0
def wgetUrl(target):
    std_headers = {
        'User-Agent':
        'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.6) Gecko/20100627 Firefox/3.6.6',
        'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
        'Accept':
        'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language': 'en-us,en;q=0.5',
    }
    outtxt = Request(target, None, std_headers)
    try:
        #outtxt = urlopen2(target, timeout = 5).read()
        outtxt = urlopen2(target).read()
    except (URLError, HTTPException, socket.error):
        return ''
    return outtxt
Exemplo n.º 3
0
    def downloadThumbnail(self, thumbUrl):
        if thumbUrl is not None:
            thumbID = thumbUrl.rsplit("/", 1)[1]
            thumbFile = None
            if not thumbUrl.startswith("http://"):
                thumbUrl = "%s%s" % (MAIN_PAGE, thumbUrl)
            try:
                req = Request(thumbUrl)
                url_handle = urlopen2(req)
                headers = url_handle.info()
                contentType = headers.getheader("content-type")
            except:
                contentType = None

            if contentType:
                if 'image/jpeg' in contentType:
                    thumbFile = "/tmp/" + thumbID + ".jpg"
                elif 'image/gif' in contentType:
                    thumbID = None
                #	thumbFile = "/tmp/" + thumbID + ".gif"
                elif 'image/png' in contentType:
                    thumbFile = "/tmp/" + thumbID + ".png"
                else:
                    print("[ZDF Mediathek] Unknown thumbnail content-type:",
                          contentType)
            if thumbFile is not None:
                if (os_path.exists(thumbFile) == True):  #already downloaded
                    self.downloadThumbnailCallback(None, thumbFile, thumbID)
                else:
                    if self.png_cache.get(thumbID, None) is None:
                        downloadPage(six.ensure_binary(thumbUrl),
                                     thumbFile).addCallback(
                                         self.downloadThumbnailCallback,
                                         thumbFile, thumbID).addErrback(
                                             self.downloadThumbnailError,
                                             thumbID)
                    else:
                        self.updateEntry(thumbID, thumbFile)
Exemplo n.º 4
0
    def getVideoUrl(self, entry):
        std_headers = {
            'User-Agent':
            'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.6) Gecko/20100627 Firefox/3.6.6',
            'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
            'Accept':
            'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Language': 'en-us,en;q=0.5',
        }

        VIDEO_FMT_PRIORITY_MAP = {
            '18': 4,  #MP4 360p
            '35': 5,  #FLV 480p
            '34': 6,  #FLV 360p
        }

        if int(config.plugins.yttrailer.best_resolution.value) <= 1:
            VIDEO_FMT_PRIORITY_MAP["38"] = 1  #MP4 Original (HD)
            VIDEO_FMT_PRIORITY_MAP["22"] = 3  #MP4 720p (HD)

            if int(config.plugins.yttrailer.best_resolution.value) == 0:
                VIDEO_FMT_PRIORITY_MAP["37"] = 2  #MP4 1080p (HD)

        video_url = None
        video_id = str(self.getTubeId(entry))

        # Getting video webpage
        #URLs for YouTube video pages will change from the format http://www.youtube.com/watch?v=ylLzyHk54Z0 to http://www.youtube.com/watch#!v=ylLzyHk54Z0.
        watch_url = 'http://www.youtube.com/watch?v=%s&gl=US&hl=en' % video_id
        watchrequest = Request(watch_url, None, std_headers)
        try:
            print("[YTTrailer] trying to find out if a HD Stream is available",
                  watch_url)
            watchvideopage = urlopen2(watchrequest).read()
        except (URLError, HTTPException, socket_error) as err:
            print(
                "[YTTrailer] Error: Unable to retrieve watchpage - Error code: ",
                str(err))
            return video_url

        # Get video info
        for el in ['&el=embedded', '&el=detailpage', '&el=vevo', '']:
            info_url = (
                'http://www.youtube.com/get_video_info?&video_id=%s%s&ps=default&eurl=&gl=US&hl=en'
                % (video_id, el))
            request = Request(info_url, None, std_headers)
            try:
                infopage = urlopen2(request).read()
                videoinfo = parse_qs(infopage)
                if ('url_encoded_fmt_stream_map'
                        or 'fmt_url_map') in videoinfo:
                    break
            except (URLError, HTTPException, socket_error) as err:
                print("[YTTrailer] Error: unable to download video infopage",
                      str(err))
                return video_url

        if ('url_encoded_fmt_stream_map' or 'fmt_url_map') not in videoinfo:
            # Attempt to see if YouTube has issued an error message
            if 'reason' not in videoinfo:
                print(
                    '[YTTrailer] Error: unable to extract "url_encoded_fmt_stream_map" or "fmt_url_map" parameter for unknown reason'
                )
            else:
                reason = unquote_plus(videoinfo['reason'][0])
                print('[YTTrailer] Error: YouTube said: %s' %
                      reason.decode('utf-8'))
            return video_url

        video_fmt_map = {}
        fmt_infomap = {}

        if 'url_encoded_fmt_stream_map' in videoinfo:
            tmp_fmtUrlDATA = videoinfo['url_encoded_fmt_stream_map'][0].split(
                ',')
        else:
            tmp_fmtUrlDATA = videoinfo['fmt_url_map'][0].split(',')
        for fmtstring in tmp_fmtUrlDATA:
            fmturl = fmtid = ""
            if 'url_encoded_fmt_stream_map' in videoinfo:
                try:
                    for arg in fmtstring.split('&'):
                        if arg.find('=') >= 0:
                            print(arg.split('='))
                            key, value = arg.split('=')
                            if key == 'itag':
                                if len(value) > 3:
                                    value = value[:2]
                                fmtid = value
                            elif key == 'url':
                                fmturl = value

                    if fmtid != "" and fmturl != "" and fmtid in VIDEO_FMT_PRIORITY_MAP:
                        video_fmt_map[VIDEO_FMT_PRIORITY_MAP[fmtid]] = {
                            'fmtid': fmtid,
                            'fmturl': unquote_plus(fmturl)
                        }
                        fmt_infomap[int(fmtid)] = "%s" % (unquote_plus(fmturl))
                    fmturl = fmtid = ""

                except:
                    print("error parsing fmtstring:", fmtstring)

            else:
                (fmtid, fmturl) = fmtstring.split('|')
            if fmtid in VIDEO_FMT_PRIORITY_MAP and fmtid != "":
                video_fmt_map[VIDEO_FMT_PRIORITY_MAP[fmtid]] = {
                    'fmtid': fmtid,
                    'fmturl': unquote_plus(fmturl)
                }
                fmt_infomap[int(fmtid)] = unquote_plus(fmturl)
        print("[YTTrailer] got", sorted(six.iterkeys(fmt_infomap)))
        if video_fmt_map and len(video_fmt_map):
            if self.l3cert:
                l3key = validate_cert(self.l3cert, l2key)
                if l3key:
                    rnd = read_random()
                    val = etpm.computeSignature(rnd)
                    result = decrypt_block(val, l3key)
                    if result[80:88] == rnd:
                        print(
                            "[YTTrailer] found best available video format:",
                            video_fmt_map[sorted(
                                six.iterkeys(video_fmt_map))[0]]['fmtid'])
                        best_video = video_fmt_map[sorted(
                            six.iterkeys(video_fmt_map))[0]]
                        video_url = "%s" % (best_video['fmturl'].split(';')[0])
                        print("[YTTrailer] found best available video url:",
                              video_url)

        return video_url
Exemplo n.º 5
0
    def getVideoUrl(self, video_id):
        video_url = None

        if video_id is None or video_id == "":
            return video_url

        # Getting video webpage
        watch_url = 'http://www.youtube.com/watch?v=%s&gl=US&hl=en' % video_id
        watchrequest = Request(watch_url, None, std_headers)
        try:
            #print "trying to find out if a HD Stream is available",watch_url
            watchvideopage = urlopen2(watchrequest).read()
        except (URLError, HTTPException, socket.error) as err:
            print("Error: Unable to retrieve watchpage - Error code: ",
                  str(err))
            return video_url

        # Get video info
        for el in ['&el=embedded', '&el=detailpage', '&el=vevo', '']:
            info_url = (
                'http://www.youtube.com/get_video_info?&video_id=%s%s&ps=default&eurl=&gl=US&hl=en'
                % (video_id, el))
            request = Request(info_url, None, std_headers)
            try:
                infopage = urlopen2(request).read()
                videoinfo = parse_qs(infopage)
                if ('url_encoded_fmt_stream_map'
                        or 'fmt_url_map') in videoinfo:
                    break
            except (URLError, HTTPException, socket.error) as err:
                print("Error: unable to download video infopage", str(err))
                return video_url

        if ('url_encoded_fmt_stream_map' or 'fmt_url_map') not in videoinfo:
            if 'reason' not in videoinfo:
                print(
                    'Error: unable to extract "fmt_url_map" or "url_encoded_fmt_stream_map" parameter for unknown reason'
                )
            else:
                reason = unquote_plus(videoinfo['reason'][0])
                print('Error: YouTube said: %s' % reason.decode('utf-8'))
            return video_url

        video_fmt_map = {}
        fmt_infomap = {}
        if 'url_encoded_fmt_stream_map' in videoinfo:
            tmp_fmtUrlDATA = videoinfo['url_encoded_fmt_stream_map'][0].split(
                ',url=')
        else:
            tmp_fmtUrlDATA = videoinfo['fmt_url_map'][0].split(',')
        for fmtstring in tmp_fmtUrlDATA:
            if 'url_encoded_fmt_stream_map' in videoinfo:
                (fmturl, fmtid) = fmtstring.split('&itag=')
                if fmturl.find("url=") != -1:
                    fmturl = fmturl.replace("url=", "")
            else:
                (fmtid, fmturl) = fmtstring.split('|')
            if fmtid in VIDEO_FMT_PRIORITY_MAP:
                video_fmt_map[VIDEO_FMT_PRIORITY_MAP[fmtid]] = {
                    'fmtid': fmtid,
                    'fmturl': unquote_plus(fmturl)
                }
            fmt_infomap[int(fmtid)] = unquote_plus(fmturl)
        print("got", sorted(six.iterkeys(fmt_infomap)))
        if video_fmt_map and len(video_fmt_map):
            video_url = video_fmt_map[sorted(
                six.iterkeys(video_fmt_map))[0]]['fmturl'].split(';')[0]
            #print "found best available video format:",video_fmt_map[sorted(six.iterkeys(video_fmt_map))[0]]['fmtid']
            #print "found best available video url:",video_url
        return video_url