]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/sbs.py
[extractor/sbs] Python 3.7 compat
[yt-dlp.git] / yt_dlp / extractor / sbs.py
CommitLineData
2ef6fcb5 1from .common import InfoExtractor
a646a8cf 2from ..utils import (
6a765f13 3 HEADRequest,
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',
6a765f13 47 'tags': None,
48 'categories': None,
2ef6fcb5 49 },
6a765f13 50 'expected_warnings': ['Unable to download JSON metadata'],
9e1a5b84 51 }, {
63cddb64
JMF
52 'url': 'http://www.sbs.com.au/ondemand/video/320403011771/Dingo-Conservation-The-Feed',
53 'only_matching': True,
3c283a38
S
54 }, {
55 'url': 'http://www.sbs.com.au/news/video/471395907773/The-Feed-July-9',
56 'only_matching': True,
00dd0cd5 57 }, {
58 'url': 'https://www.sbs.com.au/ondemand/?play=1836638787723',
59 'only_matching': True,
60 }, {
61 'url': 'https://www.sbs.com.au/ondemand/program/inside-windsor-castle?play=1283505731842',
62 'only_matching': True,
63 }, {
64 'url': 'https://www.sbs.com.au/news/embeds/video/1840778819866',
65 'only_matching': True,
cce889b9 66 }, {
67 'url': 'https://www.sbs.com.au/ondemand/watch/1698704451971',
68 'only_matching': True,
d52cd2f5 69 }, {
70 'url': 'https://www.sbs.com.au/ondemand/movie/coherence/1469404227931',
71 'only_matching': True,
72 }, {
73 'note': 'Live stream',
74 'url': 'https://www.sbs.com.au/ondemand/video/1726824003663/sbs-24x7-live-stream-nsw',
75 'only_matching': True,
226c0f3a 76 }, {
77 'url': 'https://www.sbs.com.au/ondemand/news-series/dateline/dateline-2022/dateline-s2022-ep26/2072245827515',
78 'only_matching': True,
79 }, {
80 'url': 'https://www.sbs.com.au/ondemand/tv-series/the-handmaids-tale/season-5/the-handmaids-tale-s5-ep1/2065631811776',
81 'only_matching': True,
6a765f13 82 }, {
83 'url': 'https://www.sbs.com.au/ondemand/tv-program/autun-romes-forgotten-sister/2116212803602',
84 'only_matching': True,
2ef6fcb5
PH
85 }]
86
6a765f13 87 _GEO_COUNTRIES = ['AU']
88 _AUS_TV_PARENTAL_GUIDELINES = {
89 'P': 0,
90 'C': 7,
91 'G': 0,
92 'PG': 0,
93 'M': 14,
94 'MA15+': 15,
95 'MAV15+': 15,
96 'R18+': 18,
97 }
98 _PLAYER_API = 'https://www.sbs.com.au/api/v3'
99
2ef6fcb5 100 def _real_extract(self, url):
ef2dcbe4 101 video_id = self._match_id(url)
6a765f13 102 formats, subtitles = self._extract_smil_formats_and_subtitles(
103 update_url_query(f'{self._PLAYER_API}/video_smil', {'id': video_id}), video_id)
a646a8cf 104
6a765f13 105 if not formats:
106 urlh = self._request_webpage(
107 HEADRequest('https://sbs-vod-prod-01.akamaized.net/'), video_id,
108 note='Checking geo-restriction', fatal=False, expected_status=403)
109 if urlh:
110 error_reasons = urlh.headers.get_all('x-error-reason') or []
111 if 'geo-blocked' in error_reasons:
112 self.raise_geo_restricted(countries=['AU'])
113 self.raise_no_formats('No formats are available', video_id=video_id)
2ef6fcb5 114
6a765f13 115 media = traverse_obj(self._download_json(
116 f'{self._PLAYER_API}/video_stream', video_id, fatal=False,
117 query={'id': video_id, 'context': 'tv'}), ('video_object', {dict})) or {}
118
119 media.update(self._download_json(
120 f'https://catalogue.pr.sbsod.com/mpx-media/{video_id}',
121 video_id, fatal=not media) or {})
122
123 # For named episodes, use the catalogue's title to set episode, rather than generic 'Episode N'.
124 if traverse_obj(media, ('partOfSeries', {dict})):
125 media['epName'] = traverse_obj(media, ('title', {str}))
2ef6fcb5
PH
126
127 return {
2ef6fcb5 128 'id': video_id,
6a765f13 129 **traverse_obj(media, {
130 'title': ('name', {str}),
131 'description': ('description', {str}),
132 'channel': ('taxonomy', 'channel', 'name', {str}),
133 'series': ((('partOfSeries', 'name'), 'seriesTitle'), {str}),
134 'series_id': ((('partOfSeries', 'uuid'), 'seriesID'), {str}),
135 'season_number': ('seasonNumber', {int_or_none}),
136 'episode': ('epName', {str}),
137 'episode_number': ('episodeNumber', {int_or_none}),
138 'timestamp': (('datePublished', ('publication', 'startDate')), {parse_iso8601}),
139 'release_year': ('releaseYear', {int_or_none}),
140 'duration': ('duration', ({float_or_none}, {parse_duration})),
141 'is_live': ('liveStream', {bool}),
f393bbe7 142 'age_limit': (('classificationID', 'contentRating'), {str.upper}, {
143 lambda x: self._AUS_TV_PARENTAL_GUIDELINES.get(x)}), # dict.get is unhashable in py3.7
6a765f13 144 }, get_all=False),
145 **traverse_obj(media, {
146 'categories': (('genres', ...), ('taxonomy', ('genre', 'subgenre'), 'name'), {str}),
147 'tags': (('consumerAdviceTexts', ('sbsSubCertification', 'consumerAdvice')), ..., {str}),
148 'thumbnails': ('thumbnails', lambda _, v: url_or_none(v['contentUrl']), {
149 'id': ('name', {str}),
150 'url': 'contentUrl',
151 'width': ('width', {int_or_none}),
152 'height': ('height', {int_or_none}),
153 }),
154 }),
155 'formats': formats,
156 'subtitles': subtitles,
157 'uploader': 'SBSC',
2ef6fcb5 158 }