[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / s4c.py
blob6eb8b2b2c62918a662e73fbfef0b264ff9ae0b37
1 from .common import InfoExtractor
2 from ..utils import traverse_obj, url_or_none
5 class S4CIE(InfoExtractor):
6 _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>\d+)'
7 _TESTS = [{
8 'url': 'https://www.s4c.cymru/clic/programme/861362209',
9 'info_dict': {
10 'id': '861362209',
11 'ext': 'mp4',
12 'title': 'Y Swn',
13 'description': 'md5:f7681a30e4955b250b3224aa9fe70cf0',
14 'duration': 5340,
15 'thumbnail': 'https://www.s4c.cymru/amg/1920x1080/Y_Swn_2023S4C_099_ii.jpg',
17 }, {
18 'url': 'https://www.s4c.cymru/clic/programme/856636948',
19 'info_dict': {
20 'id': '856636948',
21 'ext': 'mp4',
22 'title': 'Am Dro',
23 'duration': 2880,
24 'description': 'md5:100d8686fc9a632a0cb2db52a3433ffe',
25 'thumbnail': 'https://www.s4c.cymru/amg/1920x1080/Am_Dro_2022-23S4C_P6_4005.jpg',
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
31 details = self._download_json(
32 f'https://www.s4c.cymru/df/full_prog_details?lang=e&programme_id={video_id}',
33 video_id, fatal=False)
35 player_config = self._download_json(
36 'https://player-api.s4c-cdn.co.uk/player-configuration/prod', video_id, query={
37 'programme_id': video_id,
38 'signed': '0',
39 'lang': 'en',
40 'mode': 'od',
41 'appId': 'clic',
42 'streamName': '',
43 }, note='Downloading player config JSON')
44 subtitles = {}
45 for sub in traverse_obj(player_config, ('subtitles', lambda _, v: url_or_none(v['0']))):
46 subtitles.setdefault(sub.get('3', 'en'), []).append({
47 'url': sub['0'],
48 'name': sub.get('1'),
50 m3u8_url = self._download_json(
51 'https://player-api.s4c-cdn.co.uk/streaming-urls/prod', video_id, query={
52 'mode': 'od',
53 'application': 'clic',
54 'region': 'WW',
55 'extra': 'false',
56 'thirdParty': 'false',
57 'filename': player_config['filename'],
58 }, note='Downloading streaming urls JSON')['hls']
60 return {
61 'id': video_id,
62 'formats': self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', m3u8_id='hls'),
63 'subtitles': subtitles,
64 'thumbnail': url_or_none(player_config.get('poster')),
65 **traverse_obj(details, ('full_prog_details', 0, {
66 'title': (('programme_title', 'series_title'), {str}),
67 'description': ('full_billing', {str.strip}),
68 'duration': ('duration', {lambda x: int(x) * 60}),
69 }), get_all=False),
73 class S4CSeriesIE(InfoExtractor):
74 _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/series/(?P<id>\d+)'
75 _TESTS = [{
76 'url': 'https://www.s4c.cymru/clic/series/864982911',
77 'playlist_mincount': 6,
78 'info_dict': {
79 'id': '864982911',
80 'title': 'Iaith ar Daith',
82 }, {
83 'url': 'https://www.s4c.cymru/clic/series/866852587',
84 'playlist_mincount': 8,
85 'info_dict': {
86 'id': '866852587',
87 'title': 'FFIT Cymru',
91 def _real_extract(self, url):
92 series_id = self._match_id(url)
93 series_details = self._download_json(
94 'https://www.s4c.cymru/df/series_details', series_id, query={
95 'lang': 'e',
96 'series_id': series_id,
97 'show_prog_in_series': 'Y',
98 }, note='Downloading series details JSON')
100 return self.playlist_result(
101 [self.url_result(f'https://www.s4c.cymru/clic/programme/{episode_id}', S4CIE, episode_id)
102 for episode_id in traverse_obj(series_details, ('other_progs_in_series', ..., 'id'))],
103 series_id, traverse_obj(series_details, ('full_prog_details', 0, 'series_title', {str})))