[qq] fix regression by 4c116c6; add guard for bad json

This commit is contained in:
MaxwellGoblin 2017-09-13 15:00:58 +08:00
parent 2a250cbcb4
commit 51a1a1e318

View File

@ -34,7 +34,10 @@ def qq_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False):
part_info = get_content(key_api)
key_json = json.loads(match1(part_info, r'QZOutputJson=(.*)')[:-1])
if key_json.get('key') is None:
log.w(key_json['msg'])
if part == 1:
log.wtf(key_json['msg'])
else:
log.w(key_json['msg'])
break
vkey = key_json['key']
url = '{}{}?vkey={}'.format(host, filename, vkey)
@ -135,7 +138,9 @@ def qq_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
else:
content = get_content(url)
vid = parse_qs(urlparse(url).query).get('vid') #for links specified vid like http://v.qq.com/cover/p/ps6mnfqyrfo7es3.html?vid=q0181hpdvo5
vid = vid[0] if vid else match1(content, r'v?id"*\s*:\s*"\s*([^"]+)"') #general fallback
vid = vid[0] if vid else match1(content, r'vid"*\s*:\s*"\s*([^"]+)"') #general fallback
if vid is None:
vid = match1(content, r'id"*\s*:\s*"(.+?)"')
title = match1(content,r'<a.*?id\s*=\s*"%s".*?title\s*=\s*"(.+?)".*?>'%vid)
title = match1(content, r'title">([^"]+)</p>') if not title else title
title = match1(content, r'"title":"([^"]+)"') if not title else title