mirror of
https://github.com/soimort/you-get.git
synced 2025-01-24 22:15:03 +03:00
Merge branch 'fix_acfun' of https://github.com/rosynirvana/you-get into rosynirvana-fix_acfun
This commit is contained in:
commit
da3d4cf344
@ -138,6 +138,29 @@ if sys.stdout.isatty():
|
|||||||
else:
|
else:
|
||||||
default_encoding = locale.getpreferredencoding().lower()
|
default_encoding = locale.getpreferredencoding().lower()
|
||||||
|
|
||||||
|
def rc4(key, data):
|
||||||
|
#all encryption algo should work on bytes
|
||||||
|
assert type(key)==type(data) and type(key) == type(b'')
|
||||||
|
state = list(range(256))
|
||||||
|
j = 0
|
||||||
|
for i in range(256):
|
||||||
|
j += state[i] + key[i % len(key)]
|
||||||
|
j &= 0xff
|
||||||
|
state[i], state[j] = state[j], state[i]
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
j = 0
|
||||||
|
out_list = []
|
||||||
|
for char in data:
|
||||||
|
i += 1
|
||||||
|
i &= 0xff
|
||||||
|
j += state[i]
|
||||||
|
j &= 0xff
|
||||||
|
state[i], state[j] = state[j], state[i]
|
||||||
|
prn = state[(state[i] + state[j]) & 0xff]
|
||||||
|
out_list.append(char ^ prn)
|
||||||
|
|
||||||
|
return bytes(out_list)
|
||||||
def maybe_print(*s):
|
def maybe_print(*s):
|
||||||
try: print(*s)
|
try: print(*s)
|
||||||
except: pass
|
except: pass
|
||||||
|
@ -10,11 +10,32 @@ from .sina import sina_download_by_vid
|
|||||||
from .tudou import tudou_download_by_iid
|
from .tudou import tudou_download_by_iid
|
||||||
from .youku import youku_download_by_vid, youku_open_download_by_vid
|
from .youku import youku_download_by_vid, youku_open_download_by_vid
|
||||||
|
|
||||||
import json, re
|
import json
|
||||||
|
import re
|
||||||
|
import base64
|
||||||
|
|
||||||
def get_srt_json(id):
|
def get_srt_json(id):
|
||||||
url = 'http://danmu.aixifan.com/V2/%s' % id
|
url = 'http://danmu.aixifan.com/V2/%s' % id
|
||||||
return get_html(url)
|
return get_content(url)
|
||||||
|
|
||||||
|
def youku_acfun_proxy(vid, sign):
|
||||||
|
url = 'http://aplay-vod.cn-beijing.aliyuncs.com/acfun/web?vid={}&ct=85&ev=3&sign={}'.format(vid, sign)
|
||||||
|
json_data = json.loads(get_content(url))['data']
|
||||||
|
enc_text = base64.b64decode(json_data)
|
||||||
|
dec_text = rc4(b'8bdc7e1a', enc_text).decode('utf8')
|
||||||
|
youku_json = json.loads(dec_text)
|
||||||
|
|
||||||
|
yk_streams = {}
|
||||||
|
for stream in youku_json['stream']:
|
||||||
|
tp = stream['stream_type']
|
||||||
|
yk_streams[tp] = [], stream['total_size']
|
||||||
|
if stream.get('segs'):
|
||||||
|
for seg in stream['segs']:
|
||||||
|
yk_streams[tp][0].append(seg['url'])
|
||||||
|
else:
|
||||||
|
yk_streams[tp] = stream['m3u8'], stream['total_size']
|
||||||
|
|
||||||
|
return yk_streams
|
||||||
|
|
||||||
def acfun_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False, **kwargs):
|
def acfun_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False, **kwargs):
|
||||||
"""str, str, str, bool, bool ->None
|
"""str, str, str, bool, bool ->None
|
||||||
@ -26,7 +47,7 @@ def acfun_download_by_vid(vid, title, output_dir='.', merge=True, info_only=Fals
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
#first call the main parasing API
|
#first call the main parasing API
|
||||||
info = json.loads(get_html('http://www.acfun.tv/video/getVideo.aspx?id=' + vid))
|
info = json.loads(get_content('http://www.acfun.tv/video/getVideo.aspx?id=' + vid))
|
||||||
|
|
||||||
sourceType = info['sourceType']
|
sourceType = info['sourceType']
|
||||||
|
|
||||||
@ -47,12 +68,23 @@ def acfun_download_by_vid(vid, title, output_dir='.', merge=True, info_only=Fals
|
|||||||
letvcloud_download_by_vu(sourceId, '2d8c027396', title, output_dir=output_dir, merge=merge, info_only=info_only)
|
letvcloud_download_by_vu(sourceId, '2d8c027396', title, output_dir=output_dir, merge=merge, info_only=info_only)
|
||||||
elif sourceType == 'zhuzhan':
|
elif sourceType == 'zhuzhan':
|
||||||
#As in Jul.28.2016, Acfun is using embsig to anti hotlink so we need to pass this
|
#As in Jul.28.2016, Acfun is using embsig to anti hotlink so we need to pass this
|
||||||
embsig = info['encode']
|
#In Mar. 2017 there is a dedicated ``acfun_proxy'' in youku cloud player
|
||||||
a = 'http://api.aixifan.com/plays/%s' % vid
|
#old code removed
|
||||||
s = json.loads(get_content(a, headers={'deviceType': '2'}))
|
yk_streams = youku_acfun_proxy(info['sourceId'], info['encode'])
|
||||||
if s['data']['source'] == "zhuzhan-youku":
|
seq = ['mp4hd3', 'mp4hd2', 'mp4hd', 'flvhd']
|
||||||
sourceId = s['data']['sourceId']
|
for t in seq:
|
||||||
youku_open_download_by_vid(client_id='908a519d032263f8', vid=sourceId, title=title, output_dir=output_dir,merge=merge, info_only=info_only, embsig = embsig, **kwargs)
|
if yk_streams.get(t):
|
||||||
|
preferred = yk_streams[t]
|
||||||
|
break
|
||||||
|
#total_size in the json could be incorrect(F.I. 0)
|
||||||
|
size = 0
|
||||||
|
for url in preferred[0]:
|
||||||
|
_, _, seg_size = url_info(url)
|
||||||
|
size += seg_size
|
||||||
|
#fallback to flvhd is not quite possible
|
||||||
|
print_info(site_info, title, 'mp4', size)
|
||||||
|
if not info_only:
|
||||||
|
download_urls(preferred[0], title, 'mp4', size, output_dir=output_dir, merge=merge)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(sourceType)
|
raise NotImplementedError(sourceType)
|
||||||
|
|
||||||
@ -71,7 +103,7 @@ def acfun_download_by_vid(vid, title, output_dir='.', merge=True, info_only=Fals
|
|||||||
|
|
||||||
def acfun_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
|
def acfun_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
|
||||||
assert re.match(r'http://[^\.]+.acfun.[^\.]+/\D/\D\D(\d+)', url)
|
assert re.match(r'http://[^\.]+.acfun.[^\.]+/\D/\D\D(\d+)', url)
|
||||||
html = get_html(url)
|
html = get_content(url)
|
||||||
|
|
||||||
title = r1(r'data-title="([^"]+)"', html)
|
title = r1(r'data-title="([^"]+)"', html)
|
||||||
title = unescape_html(title)
|
title = unescape_html(title)
|
||||||
|
Loading…
Reference in New Issue
Block a user