]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/pinkbike.py
[spotify] Detect iframe embeds (#3430)
[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,
7198063d
MH
30 }
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
S
39 webpage = self._download_webpage(
40 'http://www.pinkbike.com/video/%s' % 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 })
52 self._sort_formats(formats)
680f9744 53
385c3e5e
S
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)
680f9744
MH
60 duration = int_or_none(self._html_search_meta(
61 'video:duration', webpage, 'duration'))
7198063d 62
385c3e5e 63 uploader = self._search_regex(
3021cf83
S
64 r'<a[^>]+\brel=["\']author[^>]+>([^<]+)', webpage,
65 'uploader', fatal=False)
385c3e5e
S
66 upload_date = unified_strdate(self._search_regex(
67 r'class="fullTime"[^>]+title="([^"]+)"',
68 webpage, 'upload date', fatal=False))
7198063d
MH
69
70 location = self._html_search_regex(
385c3e5e
S
71 r'(?s)<dt>Location</dt>\s*<dd>(.+?)<',
72 webpage, 'location', fatal=False)
7198063d 73
385c3e5e
S
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))
7198063d 78
385c3e5e
S
79 view_count = extract_count(webpage, 'Views')
80 comment_count = extract_count(webpage, 'Comments')
7198063d
MH
81
82 return {
83 'id': video_id,
84 'title': title,
85 'description': description,
385c3e5e 86 'thumbnail': thumbnail,
680f9744 87 'duration': duration,
7198063d 88 'upload_date': upload_date,
385c3e5e 89 'uploader': uploader,
7198063d 90 'location': location,
385c3e5e
S
91 'view_count': view_count,
92 'comment_count': comment_count,
7198063d
MH
93 'formats': formats
94 }