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

71 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 *
2014-05-29 03:54:58 +04:00
def qq_download_by_id(id, title=None, output_dir='.', merge=True, info_only=False):
xml = get_html('http://www.acfun.com/getinfo?vids=%s' % id)
from xml.dom.minidom import parseString
doc = parseString(xml)
doc_root = doc.getElementsByTagName('root')[0]
doc_vl = doc_root.getElementsByTagName('vl')[0]
doc_vi = doc_vl.getElementsByTagName('vi')[0]
fn = doc_vi.getElementsByTagName('fn')[0].firstChild.data
fclip = doc_vi.getElementsByTagName('fclip')[0].firstChild.data
if int(fclip) > 0:
fn = fn[:-4] + "." + fclip + fn[-4:]
fvkey = doc_vi.getElementsByTagName('fvkey')[0].firstChild.data
doc_ul = doc_vi.getElementsByTagName('ul')
url = doc_ul[0].getElementsByTagName('url')[0].firstChild.data
url = url + fn + '?vkey=' + fvkey
_, ext, size = url_info(url)
print_info(site_info, title, ext, size)
2012-12-01 19:14:04 +04:00
if not info_only:
2014-05-29 03:54:58 +04:00
download_urls([url], title, ext, size, output_dir=output_dir, merge=merge)
2012-12-01 19:14:04 +04:00
def qq_download(url, output_dir = '.', merge = True, info_only = False):
if re.match(r'http://v.qq.com/([^\?]+)\?vid', url):
aid = r1(r'(.*)\.html', url)
vid = r1(r'http://v.qq.com/[^\?]+\?vid=(\w+)', url)
2013-12-31 17:49:20 +04:00
url = 'http://sns.video.qq.com/tvideo/fcgi-bin/video?vid=%s' % vid
2013-03-08 01:56:28 +04:00
if re.match(r'http://y.qq.com/([^\?]+)\?vid', url):
vid = r1(r'http://y.qq.com/[^\?]+\?vid=(\w+)', url)
2013-12-31 17:49:20 +04:00
2013-03-09 02:26:39 +04:00
url = "http://v.qq.com/page/%s.html" % vid
2013-12-31 17:49:20 +04:00
2013-03-09 02:26:39 +04:00
r_url = r1(r'<meta http-equiv="refresh" content="0;url=([^"]*)', get_html(url))
if r_url:
aid = r1(r'(.*)\.html', r_url)
url = "%s/%s.html" % (aid, vid)
2013-12-31 17:49:20 +04:00
2013-04-23 15:05:11 +04:00
if re.match(r'http://static.video.qq.com/.*vid=', url):
vid = r1(r'http://static.video.qq.com/.*vid=(\w+)', url)
url = "http://v.qq.com/page/%s.html" % vid
2013-12-31 17:49:20 +04:00
if re.match(r'http://v.qq.com/cover/.*\.html', url):
html = get_html(url)
vid = r1(r'vid:"([^"]+)"', html)
url = 'http://sns.video.qq.com/tvideo/fcgi-bin/video?vid=%s' % vid
2012-12-01 19:14:04 +04:00
html = get_html(url)
2013-12-31 17:49:20 +04:00
title = match1(html, r'<title>(.+?)</title>', r'title:"([^"]+)"')[0].strip()
2012-12-01 19:14:04 +04:00
assert title
title = unescape_html(title)
title = escape_file_path(title)
2013-12-31 17:49:20 +04:00
try:
id = vid
except:
id = r1(r'vid:"([^"]+)"', html)
2013-12-31 17:49:20 +04:00
2012-12-01 19:14:04 +04:00
qq_download_by_id(id, title, output_dir = output_dir, merge = merge, info_only = info_only)
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')