]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pearvideo.py
Start new release.
[youtubedl] / youtube_dl / extractor / pearvideo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 qualities,
9 unified_timestamp,
10 )
11
12
13 class PearVideoIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?pearvideo\.com/video_(?P<id>\d+)'
15 _TEST = {
16 'url': 'http://www.pearvideo.com/video_1076290',
17 'info_dict': {
18 'id': '1076290',
19 'ext': 'mp4',
20 'title': '小浣熊在主人家玻璃上滚石头:没砸',
21 'description': 'md5:01d576b747de71be0ee85eb7cac25f9d',
22 'timestamp': 1494275280,
23 'upload_date': '20170508',
24 }
25 }
26
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
29
30 webpage = self._download_webpage(url, video_id)
31
32 quality = qualities(
33 ('ldflv', 'ld', 'sdflv', 'sd', 'hdflv', 'hd', 'src'))
34
35 formats = [{
36 'url': mobj.group('url'),
37 'format_id': mobj.group('id'),
38 'quality': quality(mobj.group('id')),
39 } for mobj in re.finditer(
40 r'(?P<id>[a-zA-Z]+)Url\s*=\s*(["\'])(?P<url>(?:https?:)?//.+?)\2',
41 webpage)]
42 self._sort_formats(formats)
43
44 title = self._search_regex(
45 (r'<h1[^>]+\bclass=(["\'])video-tt\1[^>]*>(?P<value>[^<]+)',
46 r'<[^>]+\bdata-title=(["\'])(?P<value>(?:(?!\1).)+)\1'),
47 webpage, 'title', group='value')
48 description = self._search_regex(
49 (r'<div[^>]+\bclass=(["\'])summary\1[^>]*>(?P<value>[^<]+)',
50 r'<[^>]+\bdata-summary=(["\'])(?P<value>(?:(?!\1).)+)\1'),
51 webpage, 'description', default=None,
52 group='value') or self._html_search_meta('Description', webpage)
53 timestamp = unified_timestamp(self._search_regex(
54 r'<div[^>]+\bclass=["\']date["\'][^>]*>([^<]+)',
55 webpage, 'timestamp', fatal=False))
56
57 return {
58 'id': video_id,
59 'title': title,
60 'description': description,
61 'timestamp': timestamp,
62 'formats': formats,
63 }