support qq video soap opera album list download

This commit is contained in:
huangtiande 2016-01-12 17:29:52 +08:00
parent bc3e66a671
commit d0cdefae3a

View File

@ -4,7 +4,9 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import (
ExtractorError,
)
class QqVideoIE(InfoExtractor): class QqVideoIE(InfoExtractor):
""" qq viedo extractor """ """ qq viedo extractor """
@ -47,61 +49,77 @@ class QqVideoIE(InfoExtractor):
] ]
def _real_extract(self, url): def _soap_extract(self, url, video_id):
""" extract qq video url """ """ extract soap opera url of qq video,"""
mobj = re.match(self._VALID_URL, url) webpage = self._download_webpage(url, video_id, 'download web page: {0}'.format(url))
pid = mobj.group('pid') album_list = [album.group('vid') for album in re.finditer(r'(?is)<a[^>]+class="album_link"\s+id="(?P<vid>[\w\d\-_]+)"[^>]+>.*?</a>', webpage)]
video_id = mobj.group('id') or mobj.group('vid') or pid if len(album_list) == 0:
raise ExtractorError('invalid video id: {0}'.format(video_id))
elif video_id in album_list:
album_list.clear()
album_list.append(video_id)
info_doc = self._download_xml( entries = []
'http://vv.video.qq.com/getinfo?vid={0}&otype=xml&defaultfmt=shd'.format(video_id), for album_index in range(len(album_list)):
video_id, 'fetch video metadata') vid = album_list[album_index]
info_doc = self._download_xml(
title = info_doc.find('./vl/vi/ti').text 'http://vv.video.qq.com/getinfo?vid={0}&otype=xml&defaultfmt=shd'.format(vid),
vid, 'fetch video metadata: {0}'.format(vid))
if (pid is not None):
fclip = info_doc.find('./vl/vi/cl/fc').text fclip = info_doc.find('./vl/vi/cl/fc').text
fn = info_doc.find('./vl/vi/fn').text fn = info_doc.find('./vl/vi/fn').text
vtypes = {v.find('./name').text:v.find('./id').text for v in info_doc.findall('./fl/fi')} vtypes = {v.find('./name').text:v.find('./id').text for v in info_doc.findall('./fl/fi')}
url = info_doc.findall('./vl/vi/ul/ui/url')[-1].text base_url = info_doc.findall('./vl/vi/ul/ui/url')[-1].text
entries = [{ title = info_doc.find('./vl/vi/ti').text
'id': '{0}_part{1}'.format(video_id, i + 1),
'title': title,
'formats': [],
} for i in range(int(fclip))]
for i in range(int(fclip)): for i in range(int(fclip)):
newfn = '{0}.{1}.{2}'.format(fn[:-4], i + 1, 'mp4') newfn = '{0}.{1}.{2}'.format(fn[:-4], i + 1, 'mp4')
qid = vtypes['sd'] qid = vtypes['sd']
if 'fhd' in vtypes: if 'fhd' in vtypes:
qid = vtypes['fhd'] qid = vtypes['fhd']
elif 'shd' in vtypes: elif 'shd' in vtypes:
qid = vtypes['shd'] qid = vtypes['shd']
elif 'hd' in vtypes: elif 'hd' in vtypes:
qid = vtypes['hd'] qid = vtypes['hd']
key_doc = self._download_xml( key_doc = self._download_xml(
'http://vv.video.qq.com/getkey?format=10{0}&otype=xml&vid={1}&filename={2}'.format(int(qid) % 10000, video_id, newfn), 'http://vv.video.qq.com/getkey?format=10{0}&otype=xml&vid={1}&filename={2}'.format(int(qid) % 10000, vid, newfn),
video_id, 'get {0}{1} vkey'.format('clip', i + 1)) vid, 'get {0} {1}{2} vkey with vid: {3}'.format(title, 'clip', i + 1, vid))
vkey = key_doc.find('./key').text vkey = key_doc.find('./key').text
video_url = '{0}{1}?vkey={2}&type={3}'.format(url, newfn, vkey, 'mp4') video_url = '{0}{1}?vkey={2}&type={3}'.format(base_url, newfn, vkey, 'mp4')
entries[i]['formats'].append({ entries.append({
'url': video_url, 'id': '{0}_part{1}'.format(vid, i + 1),
'ext': 'mp4', 'title': title,
'formats': [{
'url': video_url,
'ext': 'mp4'
}],
}) })
return { return {
'_type': 'multi_video', '_type': 'multi_video',
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'entries': entries, 'entries': entries,
} }
else:
url_doc = self._download_xml( def _video_extract(self, url, video_id):
""" extract normal qq video url """
video_url = self._download_xml(
'http://vv.video.qq.com/geturl?vid={0}&otype=xml'.format(video_id), 'http://vv.video.qq.com/geturl?vid={0}&otype=xml'.format(video_id),
video_id, 'fetch video url') video_id, 'fetch video url').find('./vd/vi/url').text
url = url_doc.find('./vd/vi/url').text ext = self._search_regex('\.([\d\w]+)\?', video_url, '', '')
ext = self._search_regex('\.([\d\w]+)\?', url, '', '') title = self._download_xml(
return { 'http://vv.video.qq.com/getinfo?vid={0}&otype=xml&defaultfmt=shd'.format(video_id),
'id': video_id, video_id, 'fetch video metadata').find('./vl/vi/ti').text
'title': title, return {
'url': url, 'id': video_id,
'ext': ext, 'title': title,
} 'url': video_url,
'ext': ext,
}
def _real_extract(self, url):
""" extract qq video url """
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id') or mobj.group('vid') or mobj.group('pid')
if (mobj.group('pid') is not None):
return self._soap_extract(url, video_id)
else:
return self._video_extract(url, video_id)