[bilibili] add support for live.bilibili.com (close #986)

This commit is contained in:
Mort Yao 2016-03-15 05:11:34 +01:00
parent 2a80fb5d5b
commit 80ea797cb6

View File

@ -98,15 +98,25 @@ def bilibili_download_by_cid(cid, title, output_dir='.', merge=True, info_only=F
if not info_only:
download_urls(urls, title, type_, total_size=None, output_dir=output_dir, merge=merge)
def bilibili_live_download_by_cid(cid, title, output_dir='.', merge=True, info_only=False):
api_url = 'http://live.bilibili.com/api/playurl?cid=' + cid
urls = parse_cid_playurl(get_content(api_url))
for url in urls:
_, type_, _ = url_info(url)
size = 0
print_info(site_info, title, type_, size)
if not info_only:
download_urls([url], title, type_, total_size=None, output_dir=output_dir, merge=merge)
def bilibili_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
html = get_content(url)
title = r1_of([r'<meta name="title" content="([^<>]{1,999})" />',
r'<h1[^>]*>([^<>]+)</h1>'], html)
if not title:
log.wtf('[Failed] Video does not exist. Try to login with --cookies.')
title = unescape_html(title)
title = escape_file_path(title)
if title:
title = unescape_html(title)
title = escape_file_path(title)
flashvars = r1_of([r'(cid=\d+)', r'(cid: \d+)', r'flashvars="([^"]+)"', r'"https://[a-z]+\.bilibili\.com/secure,(cid=\d+)(?:&aid=\d+)?"'], html)
assert flashvars
@ -114,7 +124,10 @@ def bilibili_download(url, output_dir='.', merge=True, info_only=False, **kwargs
t, cid = flashvars.split('=', 1)
cid = cid.split('&')[0]
if t == 'cid':
if 'playlist' in kwargs and kwargs['playlist']:
if re.match(r'https?://live\.bilibili\.com/', url):
title = r1(r'<title>([^<>]+)</title>', html)
bilibili_live_download_by_cid(cid, title, output_dir=output_dir, merge=merge, info_only=info_only)
elif 'playlist' in kwargs and kwargs['playlist']:
# multi-P
cids = []
pages = re.findall('<option value=\'([^\']*)\'', html)