From 51a02f2530c4ffb935ff995cd5b47e83826d3374 Mon Sep 17 00:00:00 2001 From: troywith77 Date: Tue, 9 May 2017 13:10:18 +0800 Subject: [PATCH 1/2] [pear] Add new extractor --- youtube_dl/extractor/extractors.py | 1 + youtube_dl/extractor/pear.py | 33 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 youtube_dl/extractor/pear.py diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 1d7495910..46b69c7f5 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -745,6 +745,7 @@ from .pandoratv import PandoraTVIE from .parliamentliveuk import ParliamentLiveUKIE from .patreon import PatreonIE from .pbs import PBSIE +from .pear import PearIE from .people import PeopleIE from .periscope import ( PeriscopeIE, diff --git a/youtube_dl/extractor/pear.py b/youtube_dl/extractor/pear.py new file mode 100644 index 000000000..52ed63d9a --- /dev/null +++ b/youtube_dl/extractor/pear.py @@ -0,0 +1,33 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor + +class PearIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?pearvideo\.com/video_(?P[0-9]+)' + _TEST = { + 'url': 'http://www.pearvideo.com/video_1076290', + 'info_dict': { + 'id': '1076290', + 'ext': 'mp4', + 'title': '小浣熊在主人家玻璃上滚石头:没砸', + 'description': '小浣熊找到一个小石头,仿佛发现了一个宝贝。它不停地用石头按在玻璃上,滚来滚去,吸引主人注意。', + 'url': 'http://video.pearvideo.com/mp4/short/20170508/cont-1076290-10438018-hd.mp4' + } + } + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + + title = self._html_search_regex(r']+class="video-tt">(.+)', webpage, 'title') + description = self._html_search_regex(r']+class="summary"[^>]*>([^<]+)<', webpage, 'description', fatal=False) + hdUrl = self._html_search_regex(r'hdUrl="(.*?)"', webpage, 'url') + + return { + 'id': video_id, + 'ext': 'mp4', + 'title': title, + 'description': description, + 'url': hdUrl + } \ No newline at end of file From 985417a8b3296698f96cba53e64e1fb8db18d2fe Mon Sep 17 00:00:00 2001 From: troywith77 Date: Tue, 9 May 2017 16:24:39 +0800 Subject: [PATCH 2/2] checked code with flake8 + added fatal=False to extractor fields --- youtube_dl/extractor/pear.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/pear.py b/youtube_dl/extractor/pear.py index 52ed63d9a..77fd46852 100644 --- a/youtube_dl/extractor/pear.py +++ b/youtube_dl/extractor/pear.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from .common import InfoExtractor + class PearIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?pearvideo\.com/video_(?P[0-9]+)' _TEST = { @@ -20,14 +21,14 @@ class PearIE(InfoExtractor): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) - title = self._html_search_regex(r']+class="video-tt">(.+)', webpage, 'title') + title = self._html_search_regex(r']+class="video-tt">(.+)', webpage, 'title', fatal=False) description = self._html_search_regex(r']+class="summary"[^>]*>([^<]+)<', webpage, 'description', fatal=False) - hdUrl = self._html_search_regex(r'hdUrl="(.*?)"', webpage, 'url') + url = self._html_search_regex(r'hdUrl="(.*?)"', webpage, 'url', fatal=False) return { 'id': video_id, 'ext': 'mp4', 'title': title, 'description': description, - 'url': hdUrl - } \ No newline at end of file + 'url': url + }