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