]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/sbs.py
[cleanup] Fix infodict returned fields (#8906)
[yt-dlp.git] / yt_dlp / extractor / sbs.py
CommitLineData
2ef6fcb5 1from .common import InfoExtractor
3d2623a8 2from ..networking import HEADRequest
a646a8cf 3from ..utils import (
6a765f13 4 float_or_none,
5 int_or_none,
6 parse_duration,
7 parse_iso8601,
8 traverse_obj,
9 update_url_query,
10 url_or_none,
a646a8cf 11)
2ef6fcb5
PH
12
13
14class SBSIE(InfoExtractor):
15 IE_DESC = 'sbs.com.au'
d52cd2f5 16 _VALID_URL = r'''(?x)
17 https?://(?:www\.)?sbs\.com\.au/(?:
18 ondemand(?:
19 /video/(?:single/)?|
6a765f13 20 /(?:movie|tv-program)/[^/]+/|
226c0f3a 21 /(?:tv|news)-series/(?:[^/]+/){3}|
d52cd2f5 22 .*?\bplay=|/watch/
23 )|news/(?:embeds/)?video/
24 )(?P<id>[0-9]+)'''
bfd973ec 25 _EMBED_REGEX = [r'''(?x)]
26 (?:
27 <meta\s+property="og:video"\s+content=|
28 <iframe[^>]+?src=
29 )
30 (["\'])(?P<url>https?://(?:www\.)?sbs\.com\.au/ondemand/video/.+?)\1''']
2ef6fcb5
PH
31
32 _TESTS = [{
33 # Original URL is handled by the generic IE which finds the iframe:
34 # http://www.sbs.com.au/thefeed/blog/2014/08/21/dingo-conservation
35 'url': 'http://www.sbs.com.au/ondemand/video/single/320403011771/?source=drupal&vertical=thefeed',
6a765f13 36 'md5': '31f84a7a19b53635db63c73f8ab0c4a7',
2ef6fcb5 37 'info_dict': {
6a765f13 38 'id': '320403011771', # '_rFBPRPO4pMR',
e35cb78c 39 'ext': 'mp4',
3c283a38
S
40 'title': 'Dingo Conservation (The Feed)',
41 'description': 'md5:f250a9856fca50d22dec0b5b8015f8a5',
6a765f13 42 'thumbnail': r're:https?://.*\.jpg',
3c283a38 43 'duration': 308,
79ba9140 44 'timestamp': 1408613220,
45 'upload_date': '20140821',
46 'uploader': 'SBSC',
2ef6fcb5 47 },
6a765f13 48 'expected_warnings': ['Unable to download JSON metadata'],
9e1a5b84 49 }, {
63cddb64
JMF
50 'url': 'http://www.sbs.com.au/ondemand/video/320403011771/Dingo-Conservation-The-Feed',
51 'only_matching': True,
3c283a38
S
52 }, {
53 'url': 'http://www.sbs.com.au/news/video/471395907773/The-Feed-July-9',
54 'only_matching': True,
00dd0cd5 55 }, {
56 'url': 'https://www.sbs.com.au/ondemand/?play=1836638787723',
57 'only_matching': True,
58 }, {
59 'url': 'https://www.sbs.com.au/ondemand/program/inside-windsor-castle?play=1283505731842',
60 'only_matching': True,
61 }, {
62 'url': 'https://www.sbs.com.au/news/embeds/video/1840778819866',
63 'only_matching': True,
cce889b9 64 }, {
65 'url': 'https://www.sbs.com.au/ondemand/watch/1698704451971',
66 'only_matching': True,
d52cd2f5 67 }, {
68 'url': 'https://www.sbs.com.au/ondemand/movie/coherence/1469404227931',
69 'only_matching': True,
70 }, {
71 'note': 'Live stream',
72 'url': 'https://www.sbs.com.au/ondemand/video/1726824003663/sbs-24x7-live-stream-nsw',
73 'only_matching': True,
226c0f3a 74 }, {
75 'url': 'https://www.sbs.com.au/ondemand/news-series/dateline/dateline-2022/dateline-s2022-ep26/2072245827515',
76 'only_matching': True,
77 }, {
78 'url': 'https://www.sbs.com.au/ondemand/tv-series/the-handmaids-tale/season-5/the-handmaids-tale-s5-ep1/2065631811776',
79 'only_matching': True,
6a765f13 80 }, {
81 'url': 'https://www.sbs.com.au/ondemand/tv-program/autun-romes-forgotten-sister/2116212803602',
82 'only_matching': True,
2ef6fcb5
PH
83 }]
84
6a765f13 85 _GEO_COUNTRIES = ['AU']
86 _AUS_TV_PARENTAL_GUIDELINES = {
87 'P': 0,
88 'C': 7,
89 'G': 0,
90 'PG': 0,
91 'M': 14,
92 'MA15+': 15,
93 'MAV15+': 15,
94 'R18+': 18,
95 }
96 _PLAYER_API = 'https://www.sbs.com.au/api/v3'
97
2ef6fcb5 98 def _real_extract(self, url):
ef2dcbe4 99 video_id = self._match_id(url)
6a765f13 100 formats, subtitles = self._extract_smil_formats_and_subtitles(
101 update_url_query(f'{self._PLAYER_API}/video_smil', {'id': video_id}), video_id)
a646a8cf 102
6a765f13 103 if not formats:
104 urlh = self._request_webpage(
105 HEADRequest('https://sbs-vod-prod-01.akamaized.net/'), video_id,
106 note='Checking geo-restriction', fatal=False, expected_status=403)
107 if urlh:
108 error_reasons = urlh.headers.get_all('x-error-reason') or []
109 if 'geo-blocked' in error_reasons:
110 self.raise_geo_restricted(countries=['AU'])
111 self.raise_no_formats('No formats are available', video_id=video_id)
2ef6fcb5 112
6a765f13 113 media = traverse_obj(self._download_json(
114 f'{self._PLAYER_API}/video_stream', video_id, fatal=False,
115 query={'id': video_id, 'context': 'tv'}), ('video_object', {dict})) or {}
116
117 media.update(self._download_json(
118 f'https://catalogue.pr.sbsod.com/mpx-media/{video_id}',
119 video_id, fatal=not media) or {})
120
121 # For named episodes, use the catalogue's title to set episode, rather than generic 'Episode N'.
122 if traverse_obj(media, ('partOfSeries', {dict})):
123 media['epName'] = traverse_obj(media, ('title', {str}))
2ef6fcb5
PH
124
125 return {
2ef6fcb5 126 'id': video_id,
6a765f13 127 **traverse_obj(media, {
128 'title': ('name', {str}),
129 'description': ('description', {str}),
130 'channel': ('taxonomy', 'channel', 'name', {str}),
131 'series': ((('partOfSeries', 'name'), 'seriesTitle'), {str}),
132 'series_id': ((('partOfSeries', 'uuid'), 'seriesID'), {str}),
133 'season_number': ('seasonNumber', {int_or_none}),
134 'episode': ('epName', {str}),
135 'episode_number': ('episodeNumber', {int_or_none}),
136 'timestamp': (('datePublished', ('publication', 'startDate')), {parse_iso8601}),
137 'release_year': ('releaseYear', {int_or_none}),
138 'duration': ('duration', ({float_or_none}, {parse_duration})),
139 'is_live': ('liveStream', {bool}),
f393bbe7 140 'age_limit': (('classificationID', 'contentRating'), {str.upper}, {
141 lambda x: self._AUS_TV_PARENTAL_GUIDELINES.get(x)}), # dict.get is unhashable in py3.7
6a765f13 142 }, get_all=False),
143 **traverse_obj(media, {
144 'categories': (('genres', ...), ('taxonomy', ('genre', 'subgenre'), 'name'), {str}),
145 'tags': (('consumerAdviceTexts', ('sbsSubCertification', 'consumerAdvice')), ..., {str}),
146 'thumbnails': ('thumbnails', lambda _, v: url_or_none(v['contentUrl']), {
147 'id': ('name', {str}),
148 'url': 'contentUrl',
149 'width': ('width', {int_or_none}),
150 'height': ('height', {int_or_none}),
151 }),
152 }),
153 'formats': formats,
154 'subtitles': subtitles,
155 'uploader': 'SBSC',
2ef6fcb5 156 }