From 38a2effb182576ba660b96de76b575a08ceba106 Mon Sep 17 00:00:00 2001 From: huangtiande Date: Fri, 8 Jan 2016 14:34:39 +0800 Subject: [PATCH 1/3] add extractor of v.ifeng.com --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/ifeng.py | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 youtube_dl/extractor/ifeng.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index a9d23b8f4..68c5044af 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -271,6 +271,7 @@ from .howstuffworks import HowStuffWorksIE from .huffpost import HuffPostIE from .hypem import HypemIE from .iconosquare import IconosquareIE +from .ifeng import IfengIE from .ign import ( IGNIE, OneUPIE, diff --git a/youtube_dl/extractor/ifeng.py b/youtube_dl/extractor/ifeng.py new file mode 100644 index 000000000..a74922fe5 --- /dev/null +++ b/youtube_dl/extractor/ifeng.py @@ -0,0 +1,64 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor + + +class IfengIE(InfoExtractor): + IE_NAME = 'ifeng' + IE_DESC = '凤凰网' + # http://v.ifeng.com/mil/mainland/201601/01d92436-8afe-4af0-82a4-cef889018295.shtml + # http://v.ifeng.com/ent/mingxing/201601/01e29bc2-1e89-41ee-9a91-25d56e2b0740.shtml + _VALID_URL = r'http://v\.ifeng\.com/.+?/(?P[\w\-\d]+)\.shtml' + _TESTS = [{ + 'url': 'http://v.ifeng.com/mil/mainland/201601/01d92436-8afe-4af0-82a4-cef889018295.shtml', + 'info_dict': { + 'id': '01d92436-8afe-4af0-82a4-cef889018295', + 'ext': 'mp4', + 'title': '中国火箭军正式亮相 多支导弹旅携罕见导弹出镜', + } + }, + { + 'url': 'http://v.ifeng.com/ent/mingxing/201601/01e29bc2-1e89-41ee-9a91-25d56e2b0740.shtml', + 'info_dict': { + 'id': '01e29bc2-1e89-41ee-9a91-25d56e2b0740', + 'ext': 'mp4', + 'title': '陈羽凡锁骨骨折 盼早日康复', + }, + }, + { + 'url': 'http://v.ifeng.com/mil/mainland/201601/01168f8e-bcd5-459b-91b4-f85893b3e40a.shtml', + 'info_dict': { + 'id': '01168f8e-bcd5-459b-91b4-f85893b3e40a', + 'ext': 'mp4', + 'title': '2015年中美两国组织多次演练', + }, + } + ] + + def _real_extract(self, url): + video_id = self._match_id(url); + + d = video_id[-2] + dd = video_id[-2:] + + info_doc = self._download_xml( + 'http://v.ifeng.com/video_info_new/%s/%s/%s.xml' % (d, dd, video_id), + video_id, 'fetch video metadata') + + title = info_doc.find('./item').get('Name') + + for element in info_doc.findall('./videos/video'): + if element.get('mediaType') != 'mp4': + continue + + url = element.get('VideoPlayUrl') + if element.get('type') == '500k': + break + + return { + 'id': video_id, + 'title': title, + 'url': url, + 'ext': 'mp4', + } From cd4f624a8a28ad64ce358e3ee122afb432f0305c Mon Sep 17 00:00:00 2001 From: huangtiande Date: Mon, 11 Jan 2016 17:27:08 +0800 Subject: [PATCH 2/3] add comment and correct string interpolation operator --- youtube_dl/extractor/ifeng.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/ifeng.py b/youtube_dl/extractor/ifeng.py index a74922fe5..aba8203f0 100644 --- a/youtube_dl/extractor/ifeng.py +++ b/youtube_dl/extractor/ifeng.py @@ -5,6 +5,7 @@ from .common import InfoExtractor class IfengIE(InfoExtractor): + ''' ifeng extractor ''' IE_NAME = 'ifeng' IE_DESC = '凤凰网' # http://v.ifeng.com/mil/mainland/201601/01d92436-8afe-4af0-82a4-cef889018295.shtml @@ -37,13 +38,14 @@ class IfengIE(InfoExtractor): ] def _real_extract(self, url): + ''' extract ifeng url ''' video_id = self._match_id(url); d = video_id[-2] dd = video_id[-2:] info_doc = self._download_xml( - 'http://v.ifeng.com/video_info_new/%s/%s/%s.xml' % (d, dd, video_id), + 'http://v.ifeng.com/video_info_new/{0}/{1}/{2}.xml'.format(d, dd, video_id), video_id, 'fetch video metadata') title = info_doc.find('./item').get('Name') From 86c7cdc37f83637a9b0657813b2f4f1f1a986612 Mon Sep 17 00:00:00 2001 From: huangtiande Date: Mon, 18 Jan 2016 11:33:20 +0800 Subject: [PATCH 3/3] add multi video --- youtube_dl/extractor/ifeng.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/ifeng.py b/youtube_dl/extractor/ifeng.py index aba8203f0..fd576a8c5 100644 --- a/youtube_dl/extractor/ifeng.py +++ b/youtube_dl/extractor/ifeng.py @@ -50,17 +50,29 @@ class IfengIE(InfoExtractor): title = info_doc.find('./item').get('Name') + entry = { + 'id': '{0}'.format(video_id), + 'title': title, + 'formats': [] + } + for element in info_doc.findall('./videos/video'): if element.get('mediaType') != 'mp4': continue - url = element.get('VideoPlayUrl') + quality = -1 if element.get('type') == '500k': - break + quality = 0 + + entry['formats'].append({ + 'url': element.get('VideoPlayUrl'), + 'ext': 'mp4', + 'quality' : quality + }) return { 'id': video_id, 'title': title, - 'url': url, - 'ext': 'mp4', + '_type': 'multi_video', + 'entries': [entry], }