]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/pinkbike.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / pinkbike.py
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
53 title = remove_end(self._og_search_title(webpage), ' Video - Pinkbike')
54 description = self._html_search_regex(
55 r'(?s)id="media-description"[^>]*>(.+?)<',
56 webpage, 'description', default=None) or remove_start(
57 self._og_search_description(webpage), title + '. ')
58 thumbnail = self._og_search_thumbnail(webpage)
59 duration = int_or_none(self._html_search_meta(
60 'video:duration', webpage, 'duration'))
61
62 uploader = self._search_regex(
63 r'<a[^>]+\brel=["\']author[^>]+>([^<]+)', webpage,
64 'uploader', fatal=False)
65 upload_date = unified_strdate(self._search_regex(
66 r'class="fullTime"[^>]+title="([^"]+)"',
67 webpage, 'upload date', fatal=False))
68
69 location = self._html_search_regex(
70 r'(?s)<dt>Location</dt>\s*<dd>(.+?)<',
71 webpage, 'location', fatal=False)
72
73 def extract_count(webpage, label):
74 return str_to_int(self._search_regex(
75 r'<span[^>]+class="stat-num"[^>]*>([\d,.]+)</span>\s*<span[^>]+class="stat-label"[^>]*>%s' % label,
76 webpage, label, fatal=False))
77
78 view_count = extract_count(webpage, 'Views')
79 comment_count = extract_count(webpage, 'Comments')
80
81 return {
82 'id': video_id,
83 'title': title,
84 'description': description,
85 'thumbnail': thumbnail,
86 'duration': duration,
87 'upload_date': upload_date,
88 'uploader': uploader,
89 'location': location,
90 'view_count': view_count,
91 'comment_count': comment_count,
92 'formats': formats
93 }