you-get/src/you_get/extractors/qq.py

66 lines
2.5 KiB
Python
Raw Normal View History

2012-12-01 19:14:04 +04:00
#!/usr/bin/env python
__all__ = ['qq_download']
from ..common import *
2016-05-20 11:28:30 +03:00
from .qie import download as qieDownload
2016-05-28 12:32:07 +03:00
from urllib.parse import urlparse,parse_qs
2016-08-04 04:39:10 +03:00
2015-09-21 00:55:19 +03:00
def qq_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False):
2016-04-15 06:25:27 +03:00
api = "http://h5vv.video.qq.com/getinfo?otype=json&platform=10901&vid=%s" % vid
2015-09-21 00:55:19 +03:00
content = get_html(api)
output_json = json.loads(match1(content, r'QZOutputJson=(.*)')[:-1])
2016-02-24 10:41:47 +03:00
url = output_json['vl']['vi'][0]['ul']['ui'][0]['url']
fvkey = output_json['vl']['vi'][0]['fvkey']
mp4 = output_json['vl']['vi'][0]['cl'].get('ci', None)
if mp4:
mp4 = mp4[0]['keyid'].replace('.10', '.p') + '.mp4'
else:
mp4 = output_json['vl']['vi'][0]['fn']
url = '%s/%s?vkey=%s' % ( url, mp4, fvkey )
2015-09-21 00:55:19 +03:00
_, ext, size = url_info(url, faker=True)
print_info(site_info, title, ext, size)
2012-12-01 19:14:04 +04:00
if not info_only:
2015-09-21 00:55:19 +03:00
download_urls([url], title, ext, size, output_dir=output_dir, merge=merge)
2012-12-01 19:14:04 +04:00
2016-08-04 04:39:10 +03:00
def qq_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
2016-08-04 04:39:10 +03:00
""""""
2016-05-28 12:32:07 +03:00
if 'live.qq.com' in url:
qieDownload(url,output_dir=output_dir, merge=merge, info_only=info_only)
2016-08-21 19:54:58 +03:00
return
2016-05-28 12:32:07 +03:00
#do redirect
2016-04-19 12:38:27 +03:00
if 'v.qq.com/page' in url:
# for URLs like this:
# http://v.qq.com/page/k/9/7/k0194pwgw97.html
2016-05-28 12:32:07 +03:00
content = get_html(url)
url = match1(content,r'window\.location\.href="(.*?)"')
2016-08-21 19:54:58 +03:00
2016-08-04 04:39:10 +03:00
if 'kuaibao.qq.com' in url or re.match(r'http://daxue.qq.com/content/content/id/\d+', url):
2016-04-19 13:33:38 +03:00
content = get_html(url)
vid = match1(content, r'vid\s*=\s*"\s*([^"]+)"')
title = match1(content, r'title">([^"]+)</p>')
title = title.strip() if title else vid
2016-04-19 12:38:27 +03:00
elif 'iframe/player.html' in url:
vid = match1(url, r'\bvid=(\w+)')
# for embedded URLs; don't know what the title is
title = vid
else:
content = get_html(url)
2016-08-21 19:54:58 +03:00
vid = parse_qs(urlparse(url).query).get('vid') #for links specified vid like http://v.qq.com/cover/p/ps6mnfqyrfo7es3.html?vid=q0181hpdvo5
2016-05-28 12:32:07 +03:00
vid = vid[0] if vid else match1(content, r'vid\s*:\s*"\s*([^"]+)"') #general fallback
title = match1(content,r'<a.*?id\s*=\s*"%s".*?title\s*=\s*"(.+?)".*?>'%vid)
title = match1(content, r'title">([^"]+)</p>') if not title else title
2016-08-21 19:54:58 +03:00
title = match1(content, r'"title":"([^"]+)"') if not title else title
2016-05-28 12:32:07 +03:00
title = vid if not title else title #general fallback
2015-09-21 00:55:19 +03:00
2015-01-10 10:06:34 +03:00
qq_download_by_vid(vid, title, output_dir, merge, info_only)
2012-12-01 19:14:04 +04:00
2013-01-11 07:43:30 +04:00
site_info = "QQ.com"
2012-12-01 19:14:04 +04:00
download = qq_download
download_playlist = playlist_not_supported('qq')