mirror of
https://github.com/soimort/you-get.git
synced 2025-03-13 03:17:44 +03:00
add support for bilibili
This commit is contained in:
parent
0fad3d9673
commit
7789496949
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from .acfun import *
|
||||
from .bilibili import *
|
||||
from .cntv import *
|
||||
from .iqiyi import *
|
||||
from .ku6 import *
|
||||
|
76
you_get/downloader/bilibili.py
Normal file
76
you_get/downloader/bilibili.py
Normal file
@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
__all__ = ['bilibili_download']
|
||||
|
||||
from ..common import *
|
||||
|
||||
from .sina import sina_download_by_id
|
||||
from .tudou import tudou_download_by_id
|
||||
from .youku import youku_download_by_id
|
||||
|
||||
import re
|
||||
|
||||
def get_srt_xml(id):
|
||||
url = 'http://comment.bilibili.tv/dm,%s' % id
|
||||
return get_html(url)
|
||||
|
||||
def parse_srt_p(p):
|
||||
fields = p.split(',')
|
||||
assert len(fields) == 8, fields
|
||||
time, mode, font_size, font_color, pub_time, pool, user_id, history = fields
|
||||
time = float(time)
|
||||
|
||||
mode = int(mode)
|
||||
assert 1 <= mode <= 8
|
||||
# mode 1~3: scrolling
|
||||
# mode 4: bottom
|
||||
# mode 5: top
|
||||
# mode 6: reverse?
|
||||
# mode 7: position
|
||||
# mode 8: advanced
|
||||
|
||||
pool = int(pool)
|
||||
assert 0 <= pool <= 2
|
||||
# pool 0: normal
|
||||
# pool 1: srt
|
||||
# pool 2: special?
|
||||
|
||||
font_size = int(font_size)
|
||||
|
||||
font_color = '#%06x' % int(font_color)
|
||||
|
||||
return pool, mode, font_size, font_color
|
||||
|
||||
def parse_srt_xml(xml):
|
||||
d = re.findall(r'<d p="([^"]+)">(.*)</d>', xml)
|
||||
for x, y in d:
|
||||
p = parse_srt_p(x)
|
||||
raise NotImplementedError()
|
||||
|
||||
def bilibili_download(url, output_dir = '.', merge = True, info_only = False):
|
||||
assert re.match(r'http://(www.bilibili.tv|bilibili.kankanews.com)/video/av(\d+)', url)
|
||||
html = get_html(url)
|
||||
|
||||
title = r1(r'<h2>([^<>]+)</h2>', html)
|
||||
title = unescape_html(title)
|
||||
title = escape_file_path(title)
|
||||
|
||||
flashvars = r1(r'flashvars="([^"]+)"', html)
|
||||
assert flashvars
|
||||
t, id = flashvars.split('=', 1)
|
||||
if t == 'vid':
|
||||
sina_download_by_id(id, title, output_dir = output_dir, merge = merge, info_only = info_only)
|
||||
elif t == 'ykid':
|
||||
youku_download_by_id(id, title, output_dir = output_dir, merge = merge, info_only = info_only)
|
||||
elif t == 'uid':
|
||||
tudou_download_by_id(id, title, output_dir = output_dir, merge = merge, info_only = info_only)
|
||||
else:
|
||||
raise NotImplementedError(flashvars)
|
||||
|
||||
#xml = get_srt_xml(id)
|
||||
#with open(title + '.xml', 'w') as x:
|
||||
# x.write(xml.encode('utf-8'))
|
||||
|
||||
site_info = "bilibili.tv"
|
||||
download = bilibili_download
|
||||
download_playlist = playlist_not_supported('bilibili')
|
@ -18,9 +18,11 @@ def url_to_module(url):
|
||||
downloads = {
|
||||
'56': w56,
|
||||
'acfun': acfun,
|
||||
'bilibili': bilibili,
|
||||
'cntv': cntv,
|
||||
'iask': sina,
|
||||
'iqiyi': iqiyi,
|
||||
'kankanews': bilibili,
|
||||
'ku6': ku6,
|
||||
'pptv': pptv,
|
||||
'sina': sina,
|
||||
@ -29,9 +31,7 @@ def url_to_module(url):
|
||||
'yinyuetai': yinyuetai,
|
||||
'youku': youku,
|
||||
'youtube': youtube,
|
||||
#TODO:
|
||||
# 'bilibili': bilibili,
|
||||
# 'kankanews': bilibili,
|
||||
#TODO
|
||||
}
|
||||
if k in downloads:
|
||||
return downloads[k]
|
||||
|
Loading…
x
Reference in New Issue
Block a user