]>
Commit | Line | Data |
---|---|---|
b9de629d | 1 | from .common import InfoExtractor |
fe371dcf | 2 | from ..utils import traverse_obj, url_or_none |
b9de629d | 3 | |
4 | ||
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', | |
fe371dcf | 14 | 'duration': 5340, |
15 | 'thumbnail': 'https://www.s4c.cymru/amg/1920x1080/Y_Swn_2023S4C_099_ii.jpg' | |
b9de629d | 16 | }, |
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', | |
fe371dcf | 25 | 'thumbnail': 'https://www.s4c.cymru/amg/1920x1080/Am_Dro_2022-23S4C_P6_4005.jpg' |
b9de629d | 26 | }, |
27 | }] | |
28 | ||
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) | |
34 | ||
fe371dcf | 35 | player_config = self._download_json( |
b9de629d | 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': '', | |
fe371dcf | 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'), | |
49 | }) | |
b9de629d | 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', | |
fe371dcf | 57 | 'filename': player_config['filename'], |
b9de629d | 58 | }, note='Downloading streaming urls JSON')['hls'] |
b9de629d | 59 | |
60 | return { | |
61 | 'id': video_id, | |
fe371dcf | 62 | 'formats': self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', m3u8_id='hls'), |
b9de629d | 63 | 'subtitles': subtitles, |
fe371dcf | 64 | 'thumbnail': url_or_none(player_config.get('poster')), |
b9de629d | 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), | |
70 | } | |
fe371dcf | 71 | |
72 | ||
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', | |
81 | 'description': 'md5:e878ebf660dce89bd2ef521d7ce06397' | |
82 | }, | |
83 | }, { | |
84 | 'url': 'https://www.s4c.cymru/clic/series/866852587', | |
85 | 'playlist_mincount': 8, | |
86 | 'info_dict': { | |
87 | 'id': '866852587', | |
88 | 'title': 'FFIT Cymru', | |
89 | 'description': 'md5:abcb3c129cb68dbb6cd304fd33b07e96' | |
90 | }, | |
91 | }] | |
92 | ||
93 | def _real_extract(self, url): | |
94 | series_id = self._match_id(url) | |
95 | series_details = self._download_json( | |
96 | 'https://www.s4c.cymru/df/series_details', series_id, query={ | |
97 | 'lang': 'e', | |
98 | 'series_id': series_id, | |
99 | 'show_prog_in_series': 'Y' | |
100 | }, note='Downloading series details JSON') | |
101 | ||
102 | return self.playlist_result( | |
103 | [self.url_result(f'https://www.s4c.cymru/clic/programme/{episode_id}', S4CIE, episode_id) | |
104 | for episode_id in traverse_obj(series_details, ('other_progs_in_series', ..., 'id'))], | |
105 | series_id, traverse_obj(series_details, ('full_prog_details', 0, 'series_title', {str}))) |