Exemplo n.º 1
0
 def parse_vurl(self, content, options):
     # Read urls of all qualities
     root = json.loads(content)
     vs = root[u'tkl'][0][u'vs']
     bids = [None] * 5
     for v in vs:
         bid = int(v[u'bid']) - 1
         if bid < 5:
             bids[bid] = ['http://data.video.qiyi.com/videos' + item[u'l'] for item in v[u'fs']]
     # Select quality
     if options & moonplayer.OPT_QL_SUPER:
         q = 3
     elif options & moonplayer.OPT_QL_HIGH:
         q = 1
     else:
         q = 0
     for i in xrange(q, -1, -1):
         if bids[i]:
             self.urls = bids[i]
             break
     if options & moonplayer.OPT_DOWNLOAD and bids[4]:
         if moonplayer.question('是否下载1080P版本?'):
             self.urls = bids[4]
     
     # Get video's key
     first_uid = self.urls[0].split('/')[-1].split('.')[0]
     self.suffix = str(self.urls[0].split('.')[-1])
     url = 'http://data.video.qiyi.com/' + first_uid + '.ts'
     moonplayer.get_url(url, self.parse_key, options)
Exemplo n.º 2
0
 def parse_vms(self, content, options):
     info = json.loads(content)
     if info['code'] != 'A000000':
         moonplayer.warn('Code Error')
         return
     if info["data"]['vp']["tkl"]=='':
         moonplayer.warn('Error: empty data.')
         return
     # Read urls of all qualities
     vs = info["data"]["vp"]["tkl"][0]["vs"]
     bids = [None] * 5
     for v in vs:
         bid = int(v[u'bid']) - 1
         if bid < 5 and bid >= 0:
             bids[bid] = v['fs']
             if not v["fs"][0]["l"].startswith("/"):
                 tmp = self.getVrsEncodeCode(v["fs"][0]["l"])
                 if tmp.endswith('mp4'):
                     bids[bid] = v["flvs"]
     # Select quality
     if options & moonplayer.OPT_QL_SUPER:
         q = 3
     elif options & moonplayer.OPT_QL_HIGH:
         q = 1
     else:
         q = 0
     for i in xrange(q, -1, -1):
         if bids[i]:
             self.video_links = bids[i]
             break
     if options & moonplayer.OPT_DOWNLOAD and bids[4]:
         if moonplayer.question('是否下载1080P版本?'):
             self.video_links = bids[4]
     
     # Get video's key
     self.urls = []
     self.vlinks = []
     self.key_roots = []
     self.info = info
     for i in self.video_links:
         vlink = i['l']
         if not vlink.startswith('/'):
             vlink = self.getVrsEncodeCode(vlink)
         self.vlinks.append(vlink)
         self.key_roots.append(vlink.split("/")[-1].split(".")[0])
     url = "http://data.video.qiyi.com/t?tn=" + str(random())
     moonplayer.get_url(url, self.parse_key, options)
Exemplo n.º 3
0
    def parse_vms(self, content, options):
        info = json.loads(content)
        if info['code'] != 'A000000':
            moonplayer.warn('Code Error')
            return
        if info["data"]['vp']["tkl"] == '':
            moonplayer.warn('Error: empty data.')
            return
        # Read urls of all qualities
        vs = info["data"]["vp"]["tkl"][0]["vs"]
        bids = [None] * 5
        for v in vs:
            bid = int(v[u'bid']) - 1
            if bid < 5 and bid >= 0:
                bids[bid] = v['fs']
                if not v["fs"][0]["l"].startswith("/"):
                    tmp = self.getVrsEncodeCode(v["fs"][0]["l"])
                    if tmp.endswith('mp4'):
                        bids[bid] = v["flvs"]
        # Select quality
        if options & moonplayer.OPT_QL_SUPER:
            q = 3
        elif options & moonplayer.OPT_QL_HIGH:
            q = 1
        else:
            q = 0
        for i in xrange(q, -1, -1):
            if bids[i]:
                self.video_links = bids[i]
                break
        if options & moonplayer.OPT_DOWNLOAD and bids[4]:
            if moonplayer.question('是否下载1080P版本?'):
                self.video_links = bids[4]

        # Get video's key
        self.urls = []
        self.vlinks = []
        self.key_roots = []
        self.info = info
        for i in self.video_links:
            vlink = i['l']
            if not vlink.startswith('/'):
                vlink = self.getVrsEncodeCode(vlink)
            self.vlinks.append(vlink)
            self.key_roots.append(vlink.split("/")[-1].split(".")[0])
        url = "http://data.video.qiyi.com/t?tn=" + str(random())
        moonplayer.get_url(url, self.parse_key, options)
Exemplo n.º 4
0
def parse_cb(page, data):
    options = data[0]
    url = data[1]
    match = cantonese_re.search(page)
    if match and not '_lang=1' in moonplayer.final_url:
        if moonplayer.question('是否解析为粤语版?'):
            url = match.group(1)
            if not url.startswith('http://'):
                url = 'http://www.flvcd.com/' + url
            url += '&go=1'
            moonplayer.get_url(url, parse_cb, data)
            return
    result = parse_flvcd_page(page, None)
    if len(result) == 0:
        moonplayer.warn('Cannot parse this video:\n' + url)
    elif options & moonplayer.OPT_DOWNLOAD:
        moonplayer.download(result, result[0])
    else:
        moonplayer.play(result)
Exemplo n.º 5
0
def parse_cb(page, data):
    options = data[0]
    url = data[1]
    match = cantonese_re.search(page)
    if match and not '_lang=1' in moonplayer.final_url:
        if moonplayer.question('是否解析为粤语版?'):
            url = match.group(1)
            if not url.startswith('http://'):
                url = 'http://www.flvcd.com/' + url
            url += '&go=1'
            moonplayer.get_url(url, parse_cb, data)
            return
    result = parse_flvcd_page(page, None)
    if len(result) == 0:
        moonplayer.warn('Cannot parse this video:\n' + url)
    elif options & moonplayer.OPT_DOWNLOAD:
        moonplayer.download(result, result[0])
    else:
        moonplayer.play(result)
Exemplo n.º 6
0
def parse_cb(page, options):
    # Check errors
    try:
        data = json.loads(page)['data']
    except:
        moonplayer.warn('Video not found!')
        return
    if 'error' in data:
        moonplayer.warn('Error: ' + data['error']['note'].encode('utf-8'))
        return
    
    # Get title, ep, ip, vid
    title = data['video']['title'].encode('utf-8')
    vid = data['video']['encodeid']
    ep = data['security']['encrypt_string']
    ip = data['security']['ip']
    
    # Sort streams' info
    streamlangs = {}
    for stream in data['stream']:
        lang = stream['audio_lang']
        if not lang in streamlangs:
            streamlangs[lang] = [None] * 4
        if stream['stream_type'] in ('flv', 'flvhd'):
            streamlangs[lang][QL_NORMAL] = stream
        elif stream['stream_type'] in ('mp4', 'mp4hd'):
            streamlangs[lang][QL_HIGH] = stream
        elif stream['stream_type'] in ('hd2', 'mp4hd2'):
            streamlangs[lang][QL_SUPER] = stream
        elif stream['stream_type'] in ('hd3', 'mp4hd3'):
            streamlangs[lang][QL_1080P] = stream
            
    # Select video's language
    try:
        for audiolang in data['dvd']['audiolang']:
            if audiolang['vid'] != vid:
                if moonplayer.question('是否切换至:' + audiolang['lang'].encode('utf-8')):
                    url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % audiolang['vid']
                    moonplayer.get_url(url, parse_cb, options, 'http://static.youku.com')
                    return
            else:
                lang = audiolang['langcode']
    except KeyError:
        lang = streamlangs.keys()[0]
    streams = streamlangs[lang]
        
    # Select video quality
    if options & moonplayer.OPT_QL_SUPER and streams[QL_SUPER]:
        stream = streams[QL_SUPER]
        st = 'flv'
    elif options & (moonplayer.OPT_QL_SUPER|moonplayer.OPT_QL_HIGH) and streams[QL_HIGH]:
        stream = streams[QL_HIGH]
        st = 'mp4'
    else:
        stream = streams[QL_NORMAL]
        st = 'flv'
    if options & moonplayer.OPT_DOWNLOAD and streams[QL_1080P]:
        if moonplayer.question('下载1080P版本吗?'):
            stream = streams[QL_1080P]
            st = 'flv'
            
    # Parse
    sid, token = trans_e('becaf9be', base64.b64decode(ep)).split('_')
    segs = stream['segs']
    result = []
    for i in xrange(len(segs)):
        name = '%s_%d.%s' % (title, i, st)
        hex_id = hex(i)[2:].upper().zfill(2)
        fileid = stream['stream_fileid'][0:8] + hex_id + stream['stream_fileid'][10:]
        url = 'http://k.youku.com/player/getFlvPath/sid/%s_%s/st/%s/fileid/%s?' % \
            (sid, hex_id, st, fileid)
        param = {
            'K': segs[i]['key'],
            'ctype': 12,
            'ev': 1,
            'oip': ip,
            'token': token,
            'ep': generate_ep(sid, fileid, token),
            'ymovie': 1,
            'xfsize': segs[i]['size']}
        url += urlencode(param)
        result.append(name)
        result.append(url)
        
    if options & moonplayer.OPT_DOWNLOAD:
        moonplayer.download(result, title + '.' + st)
    else:
        moonplayer.play(result)
Exemplo n.º 7
0
def parse_cb(page, data):
    options, fallback_sid, fallback_token = data
    # Check errors
    try:
        data = json.loads(page)['data']
    except:
        moonplayer.warn('Video not found!')
        return
    if 'error' in data:
        moonplayer.warn('Error: ' + data['error']['note'].encode('utf-8'))
        return
    
    # Get title, ep, ip, vid
    title = data['video']['title'].encode('utf-8')
    vid = data['video']['encodeid']
    ep = data['security']['encrypt_string']
    ip = data['security']['ip']
    
    # Sort streams' info
    streamlangs = {}
    for stream in data['stream']:
        lang = stream['audio_lang']
        if not lang in streamlangs:
            streamlangs[lang] = [None] * 4
        if stream['stream_type'] in ('flv', 'flvhd'):
            streamlangs[lang][QL_NORMAL] = stream
        elif stream['stream_type'] in ('mp4', 'mp4hd'):
            streamlangs[lang][QL_HIGH] = stream
        elif stream['stream_type'] in ('hd2', 'mp4hd2'):
            streamlangs[lang][QL_SUPER] = stream
        elif stream['stream_type'] in ('hd3', 'mp4hd3'):
            streamlangs[lang][QL_1080P] = stream
            
    # Select video's language
    try:
        for audiolang in data['dvd']['audiolang']:
            if audiolang['vid'] != vid:
                if moonplayer.question('是否切换至:' + audiolang['lang'].encode('utf-8')):
                    url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % audiolang['vid']
                    moonplayer.get_url(url, parse_cb, (options, None, None), 'http://static.youku.com')
                    return
            else:
                lang = audiolang['langcode']
    except KeyError:
        lang = streamlangs.keys()[0]
    streams = streamlangs[lang]
        
    # Select video quality
    if options & moonplayer.OPT_QL_1080P and streams[QL_1080P]:
        stream = streams[QL_1080P]
        st = 'flv'
    if options & moonplayer.OPT_QL_SUPER and streams[QL_SUPER]:
        stream = streams[QL_SUPER]
        st = 'flv'
    elif options & moonplayer.OPT_QL_HIGH and streams[QL_HIGH]:
        stream = streams[QL_HIGH]
        st = 'mp4'
    else:
        stream = streams[QL_NORMAL]
        st = 'flv'
            
    # Parse
    if fallback_sid:
        sid = fallback_sid
        token = fallback_token
    else:
        sid, token = trans_e('becaf9be', base64.b64decode(ep)).split('_')
    segs = stream['segs']
    result = []
    for i in xrange(len(segs)):
        name = '%s_%d.%s' % (title, i, st)
        hex_id = hex(i)[2:].upper().zfill(2)
        fileid = stream['stream_fileid'][0:8] + hex_id + stream['stream_fileid'][10:]
        url = 'http://k.youku.com/player/getFlvPath/sid/%s_%s/st/%s/fileid/%s?' % \
            (sid, hex_id, st, fileid)
        param = {
            'K': segs[i]['key'],
            'ctype': 12,
            'ev': 1,
            'oip': ip,
            'token': token,
            'ep': unquote(generate_ep(sid, fileid, token)),
            'ymovie': 1,
            'xfsize': segs[i]['size']}
        url += urlencode(param)
        result.append(name)
        result.append(url)
        
    # Check whether the parsed url is suit for your location.
    if fallback_sid == None:
        print 'Checking'
        try:
            url = result[1].replace('ymovie=', 'yxon=')
            req = urllib2.Request(url)
            req.add_header('User-Agnet', 'moonplayer')
            response = urllib2.urlopen(req, timeout=5)
        except urllib2.HTTPError, e:
            # Use fallback meta
            url = 'http://play.youku.com/play/get.json?vid=%s&ct=10' % vid
            moonplayer.get_url(url, parse_cb, (options, sid, token), 'http://static.youku.com')
            return