Beispiel #1
0
def parse_danmaku_cb(page, data):
    options, result, url = data
    # Cannot get the video name from flvcd.com page correctly
    match = name_re.search(page)
    if match:
        name = match.group(1) + ".flv"
    else:
        name = result[0]
        
    match = cid_re.search(page)
    if match:
        danmaku = 'http://danmu.aixifan.com/V2/' + match.group(1)
        if len(result) == 0:
            moonplayer.use_fallback_parser(url, options & moonplayer.OPT_DOWNLOAD, danmaku)
        elif options & moonplayer.OPT_DOWNLOAD:
            if len(result) == 2:
                result[0] = name
                moonplayer.download_with_danmaku(result, danmaku)
            else:
                moonplayer.download_with_danmaku(result, danmaku, name)
        else:
            moonplayer.play(result, danmaku)
    else:
        moonplayer.warn('无法获取弹幕!')
        if len(result) == 0:
            moonplayer.use_fallback_parser(url, options & moonplayer.OPT_DOWNLOAD)
        if options & moonplayer.OPT_DOWNLOAD:
            if len(result) == 2:
                result[0] = name
                moonplayer.download(result)
            else:
                moonplayer.download(result, name)
        else:
            moonplayer.play(result)
Beispiel #2
0
def parse_danmaku_cb(page, data):
    options, result, url = data
    match = cid_re.search(page)
    if match:
        danmaku = 'http://comment.bilibili.com/%s.xml' % match.group(1)
        if len(result) == 0:
            moonplayer.use_fallback_parser(url, options & moonplayer.OPT_DOWNLOAD, danmaku)
        elif options & moonplayer.OPT_DOWNLOAD:
            if len(result) == 2:
                moonplayer.download_with_danmaku(result, danmaku)
            else:
                moonplayer.download_with_danmaku(result, danmaku, result[0])
        else:
            moonplayer.play(result, danmaku)
    else:
        moonplayer.warn('无法获取弹幕!')
        if len(result) == 0:
            moonplayer.use_fallback_parser(url, options & moonplayer.OPT_DOWNLOAD)
        elif options & moonplayer.OPT_DOWNLOAD:
            if len(result) == 2:
                moonplayer.download(result)
            else:
                moonplayer.download(result, result[0])
        else:
            moonplayer.play(result)
Beispiel #3
0
def parse_danmaku_cb(page, data):
    options, result, url = data
    # Cannot get the video name from flvcd.com page correctly
    match = name_re.search(page)
    if match:
        name = match.group(1) + ".flv"
    else:
        name = result[0]
        
    match = cid_re.search(page)
    if match:
        danmaku = 'http://danmu.aixifan.com/V2/' + match.group(1)
        if len(result) == 0:
            moonplayer.use_fallback_parser(url, options & moonplayer.OPT_DOWNLOAD, danmaku)
        elif options & moonplayer.OPT_DOWNLOAD:
            if len(result) == 2:
                result[0] = name
                moonplayer.download_with_danmaku(result, danmaku)
            else:
                moonplayer.download_with_danmaku(result, danmaku, name)
        else:
            moonplayer.play(result, danmaku)
    else:
        moonplayer.warn('无法获取弹幕!')
        if len(result) == 0:
            moonplayer.use_fallback_parser(url, options & moonplayer.OPT_DOWNLOAD)
        if options & moonplayer.OPT_DOWNLOAD:
            if len(result) == 2:
                result[0] = name
                moonplayer.download(result)
            else:
                moonplayer.download(result, name)
        else:
            moonplayer.play(result)
Beispiel #4
0
def parse_cb(page, options):
    data = json.loads(page)
    if data[u'msg'] != u'ok':
        moonplayer.warn(data[u'msg'].encode('utf-8'))
        return
    info = data[u'info']
    name = info[u'Subject'].encode('utf-8')
    urls = [None] * 3
    for rfile in info[u'rfiles']:
        if rfile[u'type'] == u'super':
            urls[2] = rfile[u'url'].encode('utf-8')
        elif rfile[u'type'] == u'clear':
            urls[1] = rfile[u'url'].encode('utf-8')
        elif rfile[u'type'] == u'normal':
            urls[0] = rfile[u'url'].encode('utf-8')
    if options & moonplayer.OPT_QL_SUPER:
        q = 2
    elif options & moonplayer.OPT_QL_HIGH:
        q = 1
    else:
        q = 0
    for i in xrange(q, -1, -1):
        if urls[i]:
            if options & moonplayer.OPT_DOWNLOAD:
                moonplayer.download([name, urls[i]])
            else:
                moonplayer.play([name, urls[i]])
            return
Beispiel #5
0
def parse_cb(page, options):
    data = json.loads(page)
    if data[u'msg'] != u'ok':
        moonplayer.warn(data[u'msg'].encode('utf-8'))
        return
    info = data[u'info']
    name = info[u'Subject'].encode('utf-8')
    urls = [None] * 3
    for rfile in info[u'rfiles']:
        if rfile[u'type'] == u'super':
            urls[2] = rfile[u'url'].encode('utf-8')
        elif rfile[u'type'] == u'clear':
            urls[1] = rfile[u'url'].encode('utf-8')
        elif rfile[u'type'] == u'normal':
            urls[0] = rfile[u'url'].encode('utf-8')
    if options & moonplayer.OPT_QL_SUPER:
        q = 2
    elif options & moonplayer.OPT_QL_HIGH:
        q = 1
    else:
        q = 0
    for i in xrange(q, -1, -1):
        if urls[i]:
            if options & moonplayer.OPT_DOWNLOAD:
                moonplayer.download([name, urls[i]])
            else:
                moonplayer.play([name, urls[i]])
            return
Beispiel #6
0
def parse_cb(page, options):
    result = parse_flvcd_page(page, None)
    if options & moonplayer.OPT_DOWNLOAD:
        moonplayer.warn(warning_msg)
        moonplayer.download(result, result[0])
    else:
        moonplayer.play(result)
Beispiel #7
0
def parse_danmaku_cb(page, result):
    match = cid_re.search(page)
    if match:
        danmaku = 'http://danmu.aixifan.com/V2/' + match.group(1)
        moonplayer.play(result, danmaku)
    else:
        moonplayer.warn('无法获取弹幕!')
        moonplayer.play(result)
Beispiel #8
0
def parse_m_cb(page, data):
    url = json.loads(page)[u'playlist'][0][u'urls'][0]
    name = data[1]
    options = data[0]
    if options & moonplayer.OPT_DOWNLOAD:
        moonplayer.download([name, str(url)])
    else:
        moonplayer.play([name, str(url)])
def parse_danmaku_cb(page, result):
    match = cid_re.search(page)
    if match:
        danmaku = 'http://comment.bilibili.com/%s.xml' % match.group(1)
        moonplayer.play(result, danmaku)
    else:
        moonplayer.warn('无法获取弹幕!')
        moonplayer.play(result)
Beispiel #10
0
def parse_cb2(content, name_options):
    root = ET.fromstring(content)
    name = name_options[0]
    options = name_options[1]
    url = root.text
    if options & moonplayer.OPT_DOWNLOAD:
        moonplayer.download([name + '.f4v', url])
    else:
        moonplayer.play([name + '.f4v', url])
Beispiel #11
0
def parse_cb2(content, name_options):
    root = ET.fromstring(content)
    name = name_options[0]
    options = name_options[1]
    url = root.text
    if options & moonplayer.OPT_DOWNLOAD:
        moonplayer.download([name + '.f4v', url])
    else:
        moonplayer.play([name + '.f4v', url])
Beispiel #12
0
def parse_cb(page, options):
    result = parse_flvcd_page(page, None)
    if options & moonplayer.OPT_DOWNLOAD:
        try:
            process_redirections(result)
            moonplayer.download(result, result[0])
        except:
            moonplayer.warn("Network error")
    else:
        moonplayer.play(result)
Beispiel #13
0
def parse_cb(page, options):
    result = parse_flvcd_page(page, None)
    if options & moonplayer.OPT_DOWNLOAD:
        try:
            process_redirections(result)
            moonplayer.download(result, result[0])
        except:
            moonplayer.warn('Network error')
    else:
        moonplayer.play(result)
Beispiel #14
0
 def parse_keys_cb(self, page, options):
     skey = json.loads(page.split("=")[1][:-1])["key"]
     vurl = "%s%s?vkey=%s" % (self.urlpre, self.fn, skey)
     name = "%s_%i.mp4" % (self.name, self.current)
     self.result.append(name)
     self.result.append(vurl)
     if self.current < self.count:
         self.parse_keys(options)
     elif options & moonplayer.OPT_DOWNLOAD:
         moonplayer.download(self.result, self.name + ".mp4")
     else:
         moonplayer.play(self.result)
Beispiel #15
0
 def parse_keys_cb(self, page, options):
     skey = json.loads(page.split('=')[1][:-1])['key']
     vurl = '%s%s?vkey=%s' % (self.urlpre, self.fn, skey)
     name = '%s_%i.mp4' % (self.name, self.current)
     self.result.append(name)
     self.result.append(vurl)
     if self.current < self.count:
         self.parse_keys(options)
     elif options & moonplayer.OPT_DOWNLOAD:
         moonplayer.download(self.result, self.name + '.mp4')
     else:
         moonplayer.play(self.result)
Beispiel #16
0
def parse_cdnlist(page, data):
    result = data['result']
    cdnlist = data['cdnlist']
    url = str(json.loads(page)[u'url'])
    i = len(result) / 2
    result.append(data['name'] + '_' + str(i) + '.mp4')
    result.append(url)
    if i < len(cdnlist):
        moonplayer.get_url(cdnlist[i], parse_cdnlist, data)
    elif data['options'] & moonplayer.OPT_DOWNLOAD:
        moonplayer.download(result, data['name'] + '.mp4')
    else:
        moonplayer.play(result)
Beispiel #17
0
 def parse_keys(self, content, options):
     root = ET.fromstring(content)
     i = len(self.result) / 2
     self.result.append('%s_%i.f4v' % (self.name, i))
     self.result.append(root.text)
     i += 1
     if i < len(self.keys):
         url = 'http://v2.tudou.com/f?id=' + self.keys[i]
         moonplayer.get_url(url, self.parse_keys, options)
     elif options & moonplayer.OPT_DOWNLOAD:
         moonplayer.download(self.result, self.name + '.f4v')
     else:
         moonplayer.play(self.result)
Beispiel #18
0
 def parse_final_url(self, content, options):
     i = len(self.result) / 2
     self.result.append('%s_%i.mp4' % (self.name, i))
     self.result.append(str(json.loads(content)['l']))
     i += 1
     if i < len(self.urls):  # Parse next final url
         moonplayer.get_url(self.urls[i], self.parse_final_url, options)
     elif options & moonplayer.OPT_DOWNLOAD:
         moonplayer.download(self.result, self.name + '.mp4')
     else:
         if len(self.urls) > 2:
             moonplayer.warn('本视频较长,爱奇艺视频地址10分钟变化一次,建议下载后播放,避免播放到一半时下载地址失效!')
         moonplayer.play(self.result)
Beispiel #19
0
def parse_cdnlist(page, data):
    result = data['result']
    cdnlist = data['cdnlist']
    url = str(json.loads(page)[u'url'])
    i = len(result) / 2
    result.append(data['name'] + '_' + str(i) + '.mp4') 
    result.append(url)
    if i < len(cdnlist):
        moonplayer.get_url(cdnlist[i], parse_cdnlist, data)
    elif data['options'] & moonplayer.OPT_DOWNLOAD:
        moonplayer.download(result, data['name'] + '.mp4')
    else:
        moonplayer.play(result)
Beispiel #20
0
 def parse_keys(self, content, options):
     root = ET.fromstring(content)
     i = len(self.result) / 2
     self.result.append('%s_%i.f4v' % (self.name, i))
     self.result.append(root.text)
     i += 1
     if i < len(self.keys):
         url = 'http://v2.tudou.com/f?id=' + self.keys[i]
         moonplayer.get_url(url, self.parse_keys, options)
     elif options & moonplayer.OPT_DOWNLOAD:
         moonplayer.download(self.result, self.name + '.f4v')
     else:
         moonplayer.play(self.result)
Beispiel #21
0
 def parse_key(self, content, options):
     result = []
     key = moonplayer.final_url.split('key=')[1]
     for i in xrange(len(self.urls)):
         name = '%s_%d.%s' % (self.name, i, self.suffix)
         result.append(name) #name
         result.append(self.urls[i] + '?key=' + key) #url
         
     if options & moonplayer.OPT_DOWNLOAD:
         moonplayer.download(result, result[0])
     else:
         if len(self.urls) > 2:
             moonplayer.warn('本视频较长,爱奇艺视频地址10分钟变化一次,建议下载后播放,避免播放到一半时下载地址失效!')
         moonplayer.play(result)
Beispiel #22
0
 def parse_final_url(self, content, options):
     i = len(self.result) / 2
     self.result.append('%s_%i.mp4' % (self.name, i))
     self.result.append(str(json.loads(content)['l']))
     i += 1
     if i < len(self.urls):  # Parse next final url
         moonplayer.get_url(self.urls[i], self.parse_final_url, options)
     elif options & moonplayer.OPT_DOWNLOAD:
         moonplayer.download(self.result, self.name + '.mp4')
     else:
         if len(self.urls) > 2:
             moonplayer.warn(
                 '本视频较长,爱奇艺视频地址10分钟变化一次,建议下载后播放,避免播放到一半时下载地址失效!')
         moonplayer.play(self.result)
Beispiel #23
0
def parse_danmaku_cb(page, data):
    (options, result) = data
    match = cid_re.search(page)
    if match:
        danmaku = 'http://comment.bilibili.com/%s.xml' % match.group(1)
        if options & moonplayer.OPT_DOWNLOAD:
            moonplayer.download_with_danmaku(result, danmaku)
        else:
            moonplayer.play(result, danmaku)
    else:
        moonplayer.warn('无法获取弹幕!')
        if options & moonplayer.OPT_DOWNLOAD:
            moonplayer.download(result)
        else:
            moonplayer.play(result)
Beispiel #24
0
def parse_m3u8_cb(page, data):
    options, title = data
    i = 0
    prev_url = ''
    result = []
    for line in page.split('\n'):
        if line.startswith('http://'):
            url = line.split('.ts?')[0]
            if url != prev_url:
                suffix = url.split('.')[-1]
                result.append('%s_%i.%s' % (title, i, suffix))
                result.append(url)
                prev_url = url
                i += 1
    if options & moonplayer.OPT_DOWNLOAD:
        moonplayer.download(result, title)
    else:
        moonplayer.play(result)
Beispiel #25
0
def parse_danmaku_cb(page, data):
    (options, result) = data
    match = name_re.search(page)
    if match:
        result[0] = match.group(1) + ".flv"
        
    match = cid_re.search(page)
    if match:
        danmaku = 'http://danmu.aixifan.com/V2/' + match.group(1)
        if options & moonplayer.OPT_DOWNLOAD:
            moonplayer.download_with_danmaku(result, danmaku)
        else:
            moonplayer.play(result, danmaku)
    else:
        moonplayer.warn('无法获取弹幕!')
        if options & moonplayer.OPT_DOWNLOAD:
            moonplayer.download(result)
        else:
            moonplayer.play(result)
Beispiel #26
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)
Beispiel #27
0
def parse_danmaku_cb(page, data):
    (options, result) = data
    match = name_re.search(page)
    if match:
        result[0] = match.group(1) + ".flv"

    match = cid_re.search(page)
    if match:
        danmaku = 'http://danmu.aixifan.com/V2/' + match.group(1)
        if options & moonplayer.OPT_DOWNLOAD:
            moonplayer.download_with_danmaku(result, danmaku)
        else:
            moonplayer.play(result, danmaku)
    else:
        moonplayer.warn('无法获取弹幕!')
        if options & moonplayer.OPT_DOWNLOAD:
            moonplayer.download(result)
        else:
            moonplayer.play(result)
Beispiel #28
0
def parse_cb(content, options):
    name_match = name_re.search(content)
    url_match = url_re.search(content)
    if not name_match and not url_match:
        moonplayer.warn('Fail')
        return
    name = name_match.group(1)
    result = []
    i = 0
    while url_match:
        url = url_match.group(1)
        result.append('%s_%i.hlv' % (name, i))
        result.append(url)
        i += 1
        url_match = url_re.search(content, url_match.end(0))
    if options & moonplayer.OPT_DOWNLOAD:
        moonplayer.download(result, name)
    else:
        moonplayer.play(result)
Beispiel #29
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)
Beispiel #30
0
            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
    
    if options & moonplayer.OPT_DOWNLOAD:
        if len(result) == 2:
            moonplayer.download(result)
        else:
            moonplayer.download(result, title + '.' + st)
    else:
        moonplayer.play(result)
    

def compat_ord(c):
    if type(c) is int:
        return c
    else:
        return ord(c)

def trans_e(s1, s2):
    ls = list(range(256))
    t = 0
    for i in xrange(256):
        t = (t + ls[i] + compat_ord(s1[i % len(s1)])) % 256
        ls[i], ls[t] = ls[t], ls[i]
    s = bytearray()
Beispiel #31
0
def parse_cb(page, options):
    result = parse_flvcd_page(page, None)
    if options & moonplayer.OPT_DOWNLOAD:
        moonplayer.download(result, result[0])
    else:
        moonplayer.play(result)
Beispiel #32
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)