[pearvideo] Add extractor
[youtube-dl] / youtube_dl / extractor / pear.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class PearIE(InfoExtractor):
8     _VALID_URL = r'https?://(?:www\.)?pearvideo\.com/video_(?P<id>[0-9]+)'
9     _TEST = {
10         'url': 'http://www.pearvideo.com/video_1076290',
11         'info_dict': {
12             'id': '1076290',
13             'ext': 'mp4',
14             'title': '小浣熊在主人家玻璃上滚石头:没砸',
15             'description': '小浣熊找到一个小石头,仿佛发现了一个宝贝。它不停地用石头按在玻璃上,滚来滚去,吸引主人注意。',
16             'url': 'http://video.pearvideo.com/mp4/short/20170508/cont-1076290-10438018-hd.mp4'
17         }
18     }
19
20     def _real_extract(self, url):
21         video_id = self._match_id(url)
22         webpage = self._download_webpage(url, video_id)
23
24         title = self._html_search_regex(r'<h1[^>]+class="video-tt">(.+)</h1>', webpage, 'title', fatal=False)
25         description = self._html_search_regex(r'<div[^>]+class="summary"[^>]*>([^<]+)<', webpage, 'description', fatal=False)
26         url = self._html_search_regex(r'hdUrl="(.*?)"', webpage, 'url', fatal=False)
27
28         return {
29             'id': video_id,
30             'ext': 'mp4',
31             'title': title,
32             'description': description,
33             'url': url
34         }