[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / gopro.py
blob9142566c35d00c78500a8acc2277f89aeb7e4f70
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 remove_end,
5 str_or_none,
6 try_get,
7 unified_timestamp,
8 url_or_none,
12 class GoProIE(InfoExtractor):
13 _VALID_URL = r'https?://(www\.)?gopro\.com/v/(?P<id>[A-Za-z0-9]+)'
15 _TESTS = [{
16 'url': 'https://gopro.com/v/ZNVvED8QDzR5V',
17 'info_dict': {
18 'id': 'ZNVvED8QDzR5V',
19 'title': 'My GoPro Adventure - 9/19/21',
20 'thumbnail': r're:https?://.+',
21 'ext': 'mp4',
22 'timestamp': 1632072947,
23 'upload_date': '20210919',
24 'uploader_id': 'fireydive30018',
25 'duration': 396062,
27 }, {
28 'url': 'https://gopro.com/v/KRm6Vgp2peg4e',
29 'info_dict': {
30 'id': 'KRm6Vgp2peg4e',
31 'title': 'じゃがいも カリカリ オーブン焼き',
32 'thumbnail': r're:https?://.+',
33 'ext': 'mp4',
34 'timestamp': 1607231125,
35 'upload_date': '20201206',
36 'uploader_id': 'dc9bcb8b-47d2-47c6-afbc-4c48f9a3769e',
37 'duration': 45187,
38 'track': 'The Sky Machine',
40 }, {
41 'url': 'https://gopro.com/v/kVrK9wlJvBMwn',
42 'info_dict': {
43 'id': 'kVrK9wlJvBMwn',
44 'title': 'DARKNESS',
45 'thumbnail': r're:https?://.+',
46 'ext': 'mp4',
47 'timestamp': 1594183735,
48 'upload_date': '20200708',
49 'uploader_id': '闇夜乃皇帝',
50 'duration': 313075,
51 'track': 'Battery (Live)',
52 'artist': 'Metallica',
56 def _real_extract(self, url):
57 video_id = self._match_id(url)
58 webpage = self._download_webpage(url, video_id)
60 metadata = self._search_json(
61 r'window\.__reflectData\s*=', webpage, 'metadata', video_id)
63 video_info = metadata['collectionMedia'][0]
64 media_data = self._download_json(
65 'https://api.gopro.com/media/{}/download'.format(video_info['id']), video_id)
67 formats = []
68 for fmt in try_get(media_data, lambda x: x['_embedded']['variations']) or []:
69 format_url = url_or_none(fmt.get('url'))
70 if not format_url:
71 continue
72 formats.append({
73 'url': format_url,
74 'format_id': str_or_none(fmt.get('quality')),
75 'format_note': str_or_none(fmt.get('label')),
76 'ext': str_or_none(fmt.get('type')),
77 'width': int_or_none(fmt.get('width')),
78 'height': int_or_none(fmt.get('height')),
81 title = str_or_none(
82 try_get(metadata, lambda x: x['collection']['title'])
83 or self._html_search_meta(['og:title', 'twitter:title'], webpage)
84 or remove_end(self._html_search_regex(
85 r'<title[^>]*>([^<]+)</title>', webpage, 'title', fatal=False), ' | GoPro'))
86 if title:
87 title = title.replace('\n', ' ')
89 return {
90 'id': video_id,
91 'title': title,
92 'formats': formats,
93 'thumbnail': url_or_none(
94 self._html_search_meta(['og:image', 'twitter:image'], webpage)),
95 'timestamp': unified_timestamp(
96 try_get(metadata, lambda x: x['collection']['created_at'])),
97 'uploader_id': str_or_none(
98 try_get(metadata, lambda x: x['account']['nickname'])),
99 'duration': int_or_none(
100 video_info.get('source_duration')),
101 'artist': str_or_none(
102 video_info.get('music_track_artist')) or None,
103 'track': str_or_none(
104 video_info.get('music_track_name')) or None,