]>
Commit | Line | Data |
---|---|---|
1 | import re | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | int_or_none, | |
6 | remove_end, | |
7 | remove_start, | |
8 | str_to_int, | |
9 | unified_strdate, | |
10 | ) | |
11 | ||
12 | ||
13 | class PinkbikeIE(InfoExtractor): | |
14 | _VALID_URL = r'https?://(?:(?:www\.)?pinkbike\.com/video/|es\.pinkbike\.org/i/kvid/kvid-y5\.swf\?id=)(?P<id>[0-9]+)' | |
15 | _TESTS = [{ | |
16 | 'url': 'http://www.pinkbike.com/video/402811/', | |
17 | 'md5': '4814b8ca7651034cd87e3361d5c2155a', | |
18 | 'info_dict': { | |
19 | 'id': '402811', | |
20 | 'ext': 'mp4', | |
21 | 'title': 'Brandon Semenuk - RAW 100', | |
22 | 'description': 'Official release: www.redbull.ca/rupertwalker', | |
23 | 'thumbnail': r're:^https?://.*\.jpg$', | |
24 | 'duration': 100, | |
25 | 'upload_date': '20150406', | |
26 | 'uploader': 'revelco', | |
27 | 'location': 'Victoria, British Columbia, Canada', | |
28 | 'view_count': int, | |
29 | 'comment_count': int, | |
30 | } | |
31 | }, { | |
32 | 'url': 'http://es.pinkbike.org/i/kvid/kvid-y5.swf?id=406629', | |
33 | 'only_matching': True, | |
34 | }] | |
35 | ||
36 | def _real_extract(self, url): | |
37 | video_id = self._match_id(url) | |
38 | ||
39 | webpage = self._download_webpage( | |
40 | 'http://www.pinkbike.com/video/%s' % video_id, video_id) | |
41 | ||
42 | formats = [] | |
43 | for _, format_id, src in re.findall( | |
44 | r'data-quality=((?:\\)?["\'])(.+?)\1[^>]+src=\1(.+?)\1', webpage): | |
45 | height = int_or_none(self._search_regex( | |
46 | r'^(\d+)[pP]$', format_id, 'height', default=None)) | |
47 | formats.append({ | |
48 | 'url': src, | |
49 | 'format_id': format_id, | |
50 | 'height': height, | |
51 | }) | |
52 | self._sort_formats(formats) | |
53 | ||
54 | title = remove_end(self._og_search_title(webpage), ' Video - Pinkbike') | |
55 | description = self._html_search_regex( | |
56 | r'(?s)id="media-description"[^>]*>(.+?)<', | |
57 | webpage, 'description', default=None) or remove_start( | |
58 | self._og_search_description(webpage), title + '. ') | |
59 | thumbnail = self._og_search_thumbnail(webpage) | |
60 | duration = int_or_none(self._html_search_meta( | |
61 | 'video:duration', webpage, 'duration')) | |
62 | ||
63 | uploader = self._search_regex( | |
64 | r'<a[^>]+\brel=["\']author[^>]+>([^<]+)', webpage, | |
65 | 'uploader', fatal=False) | |
66 | upload_date = unified_strdate(self._search_regex( | |
67 | r'class="fullTime"[^>]+title="([^"]+)"', | |
68 | webpage, 'upload date', fatal=False)) | |
69 | ||
70 | location = self._html_search_regex( | |
71 | r'(?s)<dt>Location</dt>\s*<dd>(.+?)<', | |
72 | webpage, 'location', fatal=False) | |
73 | ||
74 | def extract_count(webpage, label): | |
75 | return str_to_int(self._search_regex( | |
76 | r'<span[^>]+class="stat-num"[^>]*>([\d,.]+)</span>\s*<span[^>]+class="stat-label"[^>]*>%s' % label, | |
77 | webpage, label, fatal=False)) | |
78 | ||
79 | view_count = extract_count(webpage, 'Views') | |
80 | comment_count = extract_count(webpage, 'Comments') | |
81 | ||
82 | return { | |
83 | 'id': video_id, | |
84 | 'title': title, | |
85 | 'description': description, | |
86 | 'thumbnail': thumbnail, | |
87 | 'duration': duration, | |
88 | 'upload_date': upload_date, | |
89 | 'uploader': uploader, | |
90 | 'location': location, | |
91 | 'view_count': view_count, | |
92 | 'comment_count': comment_count, | |
93 | 'formats': formats | |
94 | } |