]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/pinkbike.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / pinkbike.py
CommitLineData
7198063d
MH
1import re
2
3from .common import InfoExtractor
680f9744
MH
4from ..utils import (
5 int_or_none,
6 remove_end,
385c3e5e
S
7 remove_start,
8 str_to_int,
9 unified_strdate,
680f9744 10)
7198063d
MH
11
12
13class PinkbikeIE(InfoExtractor):
385c3e5e 14 _VALID_URL = r'https?://(?:(?:www\.)?pinkbike\.com/video/|es\.pinkbike\.org/i/kvid/kvid-y5\.swf\?id=)(?P<id>[0-9]+)'
7198063d
MH
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',
385c3e5e 22 'description': 'Official release: www.redbull.ca/rupertwalker',
ec85ded8 23 'thumbnail': r're:^https?://.*\.jpg$',
385c3e5e 24 'duration': 100,
7198063d 25 'upload_date': '20150406',
385c3e5e
S
26 'uploader': 'revelco',
27 'location': 'Victoria, British Columbia, Canada',
28 'view_count': int,
29 'comment_count': int,
add96eb9 30 },
7198063d 31 }, {
385c3e5e
S
32 'url': 'http://es.pinkbike.org/i/kvid/kvid-y5.swf?id=406629',
33 'only_matching': True,
7198063d
MH
34 }]
35
36 def _real_extract(self, url):
37 video_id = self._match_id(url)
7198063d 38
385c3e5e 39 webpage = self._download_webpage(
add96eb9 40 f'http://www.pinkbike.com/video/{video_id}', video_id)
7198063d 41
385c3e5e
S
42 formats = []
43 for _, format_id, src in re.findall(
6a745c2c 44 r'data-quality=((?:\\)?["\'])(.+?)\1[^>]+src=\1(.+?)\1', webpage):
385c3e5e
S
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 })
680f9744 52
385c3e5e
S
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)
680f9744
MH
59 duration = int_or_none(self._html_search_meta(
60 'video:duration', webpage, 'duration'))
7198063d 61
385c3e5e 62 uploader = self._search_regex(
3021cf83
S
63 r'<a[^>]+\brel=["\']author[^>]+>([^<]+)', webpage,
64 'uploader', fatal=False)
385c3e5e
S
65 upload_date = unified_strdate(self._search_regex(
66 r'class="fullTime"[^>]+title="([^"]+)"',
67 webpage, 'upload date', fatal=False))
7198063d
MH
68
69 location = self._html_search_regex(
385c3e5e
S
70 r'(?s)<dt>Location</dt>\s*<dd>(.+?)<',
71 webpage, 'location', fatal=False)
7198063d 72
385c3e5e
S
73 def extract_count(webpage, label):
74 return str_to_int(self._search_regex(
add96eb9 75 rf'<span[^>]+class="stat-num"[^>]*>([\d,.]+)</span>\s*<span[^>]+class="stat-label"[^>]*>{label}',
385c3e5e 76 webpage, label, fatal=False))
7198063d 77
385c3e5e
S
78 view_count = extract_count(webpage, 'Views')
79 comment_count = extract_count(webpage, 'Comments')
7198063d
MH
80
81 return {
82 'id': video_id,
83 'title': title,
84 'description': description,
385c3e5e 85 'thumbnail': thumbnail,
680f9744 86 'duration': duration,
7198063d 87 'upload_date': upload_date,
385c3e5e 88 'uploader': uploader,
7198063d 89 'location': location,
385c3e5e
S
90 'view_count': view_count,
91 'comment_count': comment_count,
add96eb9 92 'formats': formats,
7198063d 93 }