forked from ezioruan/youku-lixian
-
Notifications
You must be signed in to change notification settings - Fork 1
/
acfun.py
executable file
·77 lines (61 loc) · 2.13 KB
/
acfun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
__all__ = ['acfun_download']
import re
from common import *
#from iask import iask_download_by_id
from youku import youku_download_by_id
from tudou import tudou_download_by_iid
from qq import qq_download_by_id
import json
def get_srt_json(id):
url = 'http://comment.acfun.tv/%s.json' % id
return get_html(url)
def acfun_download_by_id(id, title, merge=True):
info = json.loads(get_html('http://www.acfun.tv/api/getVideoByID.aspx?vid=' + id))
t = info['vtype']
vid = info['vid']
if t == 'sina':
iask_download_by_id(vid, title, merge=merge)
elif t == 'youku':
youku_download_by_id(vid, title, merge=merge)
elif t == 'tudou':
tudou_download_by_iid(vid, title, merge=merge)
elif t == 'qq':
qq_download_by_id(vid, title, merge=merge)
else:
raise NotImplementedError(t)
srt = get_srt_json(vid)
with open(title + '.json', 'w') as x:
x.write(srt)
def acfun_download(url, merge=True):
assert re.match(r'http://www.acfun.tv/v/ac(\d+)', url)
html = get_html(url).decode('utf-8')
title = r1(r'<h1 id="title-article" class="title"[^<>]*>([^<>]+)</h1>', html)
assert title
title = unescape_html(title)
title = escape_file_path(title)
title = title.replace(' - AcFun.tv', '')
id = r1(r"\[[Vv]ideo\](\d+)\[/[Vv]ideo\]", html)
if id:
return acfun_download_by_id(id, title, merge=merge)
id = r1(r'<embed [^<>]* (?:src|flashvars)="[^"]+id=(\d+)[^"]+"', html)
assert id
iask_download_by_id(id, title, merge=merge)
def video_info(id):
url = 'http://platform.sina.com.cn/playurl/t_play?app_key=1917945218&vid=%s' % id
xml = get_decoded_html(url)
urls = re.findall(r'<url>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?</url>', xml)
name = r1(r'<vname>(?:<!\[CDATA\[)?(.+?)(?:\]\]>)?</vname>', xml)
vstr = r1(r'<vstr>(?:<!\[CDATA\[)?(.+?)(?:\]\]>)?</vstr>', xml)
return urls, name, vstr
def iask_download_by_id(id, title=None, merge=True):
urls, name, vstr = video_info(id)
title = title or name
assert title
download_urls(urls, title, 'flv', total_size=None, merge=merge)