From d299888259bdc16fa520ac41da7eaf5a5a078cdd Mon Sep 17 00:00:00 2001 From: edward32tnt Date: Thu, 26 Nov 2015 17:26:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=85=BE=E8=AE=AFextractor=20=E4=B9=9F?= =?UTF-8?q?=E4=BD=BF=E7=94=A8VideoExtractor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/you_get/extractors/qq.py | 88 +++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 16 deletions(-) diff --git a/src/you_get/extractors/qq.py b/src/you_get/extractors/qq.py index b1d8eb0f..15d6618b 100644 --- a/src/you_get/extractors/qq.py +++ b/src/you_get/extractors/qq.py @@ -1,27 +1,83 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- -__all__ = ['qq_download'] from ..common import * +from ..extractor import VideoExtractor -def qq_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False): - api = "http://vv.video.qq.com/geturl?otype=json&vid=%s" % vid - content = get_html(api) - output_json = json.loads(match1(content, r'QZOutputJson=(.*)')[:-1]) - url = output_json['vd']['vi'][0]['url'] - _, ext, size = url_info(url, faker=True) - print_info(site_info, title, ext, size) - if not info_only: - download_urls([url], title, ext, size, output_dir=output_dir, merge=merge) +class QQ(VideoExtractor): + name = "腾讯 (QQ)" -def qq_download(url, output_dir='.', merge=True, info_only=False, **kwargs): - content = get_html(url) - vid = match1(content, r'vid\s*:\s*"\s*([^"]+)"') - title = match1(content, r'title\s*:\s*"\s*([^"]+)"') + stream_types = [ + {'id': 'mp4', 'container': 'mp4', 'video_profile': '标清'}, + ] - qq_download_by_vid(vid, title, output_dir, merge, info_only) + def get_prepare_data(url): + content = get_html(url) + vid = match1(content, r'vid\s*:\s*"\s*([^"]+)"') + title = match1(content, r'title\s*:\s*"\s*([^"]+)"') + + return {'vid': vid, 'title': title} + + + def prepare(self, **kwargs): + assert self.url or self.vid + + if not self.vid: + prepare_data = self.__class__.get_prepare_data(self.url) + self.vid = prepare_data['vid'] + self.title = prepare_data['title'] + + self.site = self.name + + api = "http://vv.video.qq.com/geturl?otype=json&vid=%s" % self.vid + content = get_html(api) + + output_json = json.loads(match1(content, r'QZOutputJson=(.*)')[:-1]) + url = output_json['vd']['vi'][0]['url'] + _, ext, size = url_info(url, faker=True) + + stream_types = dict([(i['id'], i) for i in self.stream_types]) + stream_id = ext + if stream_id in stream_types: + self.streams[stream_id] = { + 'container': stream_types[stream_id]['container'], + 'video_profile': stream_types[stream_id]['video_profile'], + 'size': size, + 'src': [url], + } + + def extract(self, **kwargs): + pass + + +def qq_download_by_url(*args, **kwargs): + site.download_by_url(*args, **kwargs) + +def qq_download_by_vid(*args, **kwargs): + site.title = args[1] + site.download_by_vid(*args, **kwargs) + +# def qq_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False): +# api = "http://vv.video.qq.com/geturl?otype=json&vid=%s" % vid +# content = get_html(api) +# output_json = json.loads(match1(content, r'QZOutputJson=(.*)')[:-1]) +# url = output_json['vd']['vi'][0]['url'] +# _, ext, size = url_info(url, faker=True) +# +# print_info(site_info, title, ext, size) +# if not info_only: +# download_urls([url], title, ext, size, output_dir=output_dir, merge=merge) +# +# def qq_download(url, output_dir='.', merge=True, info_only=False, **kwargs): +# content = get_html(url) +# vid = match1(content, r'vid\s*:\s*"\s*([^"]+)"') +# title = match1(content, r'title\s*:\s*"\s*([^"]+)"') +# +# qq_download_by_vid(vid, title, output_dir, merge, info_only) site_info = "QQ.com" -download = qq_download +site = QQ() +download = qq_download_by_url download_playlist = playlist_not_supported('qq')