aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorifan-t <jacifan2000@gmail.com>2023-08-01 19:01:59 +0100
committerGitHub <noreply@github.com>2023-08-01 18:01:59 +0000
commitb9de629d78ce31699f2de886071dc257830f9676 (patch)
tree221147cb6c432def889a9ff89e607025aca12789
parenta854fbec56d5004f5147116a41d1dd050632a579 (diff)
downloadhypervideo-pre-b9de629d78ce31699f2de886071dc257830f9676.tar.lz
hypervideo-pre-b9de629d78ce31699f2de886071dc257830f9676.tar.xz
hypervideo-pre-b9de629d78ce31699f2de886071dc257830f9676.zip
[ie/S4C] Add extractor (#7730)
Authored by: ifan-t
-rw-r--r--yt_dlp/extractor/_extractors.py1
-rw-r--r--yt_dlp/extractor/s4c.py62
2 files changed, 63 insertions, 0 deletions
diff --git a/yt_dlp/extractor/_extractors.py b/yt_dlp/extractor/_extractors.py
index 2ad7e9800..63bb55ea7 100644
--- a/yt_dlp/extractor/_extractors.py
+++ b/yt_dlp/extractor/_extractors.py
@@ -1709,6 +1709,7 @@ from .ruv import (
RuvIE,
RuvSpilaIE
)
+from .s4c import S4CIE
from .safari import (
SafariIE,
SafariApiIE,
diff --git a/yt_dlp/extractor/s4c.py b/yt_dlp/extractor/s4c.py
new file mode 100644
index 000000000..38a905896
--- /dev/null
+++ b/yt_dlp/extractor/s4c.py
@@ -0,0 +1,62 @@
+from .common import InfoExtractor
+from ..utils import traverse_obj
+
+
+class S4CIE(InfoExtractor):
+ _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>\d+)'
+ _TESTS = [{
+ 'url': 'https://www.s4c.cymru/clic/programme/861362209',
+ 'info_dict': {
+ 'id': '861362209',
+ 'ext': 'mp4',
+ 'title': 'Y Swn',
+ 'description': 'md5:f7681a30e4955b250b3224aa9fe70cf0',
+ 'duration': 5340
+ },
+ }, {
+ 'url': 'https://www.s4c.cymru/clic/programme/856636948',
+ 'info_dict': {
+ 'id': '856636948',
+ 'ext': 'mp4',
+ 'title': 'Am Dro',
+ 'duration': 2880,
+ 'description': 'md5:100d8686fc9a632a0cb2db52a3433ffe',
+ },
+ }]
+
+ def _real_extract(self, url):
+ video_id = self._match_id(url)
+ details = self._download_json(
+ f'https://www.s4c.cymru/df/full_prog_details?lang=e&programme_id={video_id}',
+ video_id, fatal=False)
+
+ filename = self._download_json(
+ 'https://player-api.s4c-cdn.co.uk/player-configuration/prod', video_id, query={
+ 'programme_id': video_id,
+ 'signed': '0',
+ 'lang': 'en',
+ 'mode': 'od',
+ 'appId': 'clic',
+ 'streamName': '',
+ }, note='Downloading player config JSON')['filename']
+ m3u8_url = self._download_json(
+ 'https://player-api.s4c-cdn.co.uk/streaming-urls/prod', video_id, query={
+ 'mode': 'od',
+ 'application': 'clic',
+ 'region': 'WW',
+ 'extra': 'false',
+ 'thirdParty': 'false',
+ 'filename': filename,
+ }, note='Downloading streaming urls JSON')['hls']
+ formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id, 'mp4', m3u8_id='hls')
+
+ return {
+ 'id': video_id,
+ 'formats': formats,
+ 'subtitles': subtitles,
+ **traverse_obj(details, ('full_prog_details', 0, {
+ 'title': (('programme_title', 'series_title'), {str}),
+ 'description': ('full_billing', {str.strip}),
+ 'duration': ('duration', {lambda x: int(x) * 60}),
+ }), get_all=False),
+ }