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+)'
8 'url': 'https://www.s4c.cymru/clic/programme/861362209',
13 'description': 'md5:f7681a30e4955b250b3224aa9fe70cf0',
15 'thumbnail': 'https://www.s4c.cymru/amg/1920x1080/Y_Swn_2023S4C_099_ii.jpg',
18 'url': 'https://www.s4c.cymru/clic/programme/856636948',
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
,
43 }, note
='Downloading player config JSON')
45 for sub
in traverse_obj(player_config
, ('subtitles', lambda _
, v
: url_or_none(v
['0']))):
46 subtitles
.setdefault(sub
.get('3', 'en'), []).append({
50 m3u8_url
= self
._download
_json
(
51 'https://player-api.s4c-cdn.co.uk/streaming-urls/prod', video_id
, query
={
53 'application': 'clic',
56 'thirdParty': 'false',
57 'filename': player_config
['filename'],
58 }, note
='Downloading streaming urls JSON')['hls']
62 'formats': self
._extract
_m
3u8_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}),
73 class S4CSeriesIE(InfoExtractor
):
74 _VALID_URL
= r
'https?://(?:www\.)?s4c\.cymru/clic/series/(?P<id>\d+)'
76 'url': 'https://www.s4c.cymru/clic/series/864982911',
77 'playlist_mincount': 6,
80 'title': 'Iaith ar Daith',
83 'url': 'https://www.s4c.cymru/clic/series/866852587',
84 'playlist_mincount': 8,
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
={
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}
)))