]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/sbs.py
[extractor/youtube] Add `piped.video` (#5571)
[yt-dlp.git] / yt_dlp / extractor / sbs.py
1 from .common import InfoExtractor
2 from ..utils import (
3 smuggle_url,
4 ExtractorError,
5 )
6
7
8 class SBSIE(InfoExtractor):
9 IE_DESC = 'sbs.com.au'
10 _VALID_URL = r'''(?x)
11 https?://(?:www\.)?sbs\.com\.au/(?:
12 ondemand(?:
13 /video/(?:single/)?|
14 /movie/[^/]+/|
15 /(?:tv|news)-series/(?:[^/]+/){3}|
16 .*?\bplay=|/watch/
17 )|news/(?:embeds/)?video/
18 )(?P<id>[0-9]+)'''
19 _EMBED_REGEX = [r'''(?x)]
20 (?:
21 <meta\s+property="og:video"\s+content=|
22 <iframe[^>]+?src=
23 )
24 (["\'])(?P<url>https?://(?:www\.)?sbs\.com\.au/ondemand/video/.+?)\1''']
25
26 _TESTS = [{
27 # Original URL is handled by the generic IE which finds the iframe:
28 # http://www.sbs.com.au/thefeed/blog/2014/08/21/dingo-conservation
29 'url': 'http://www.sbs.com.au/ondemand/video/single/320403011771/?source=drupal&vertical=thefeed',
30 'md5': '3150cf278965eeabb5b4cea1c963fe0a',
31 'info_dict': {
32 'id': '_rFBPRPO4pMR',
33 'ext': 'mp4',
34 'title': 'Dingo Conservation (The Feed)',
35 'description': 'md5:f250a9856fca50d22dec0b5b8015f8a5',
36 'thumbnail': r're:http://.*\.jpg',
37 'duration': 308,
38 'timestamp': 1408613220,
39 'upload_date': '20140821',
40 'uploader': 'SBSC',
41 },
42 }, {
43 'url': 'http://www.sbs.com.au/ondemand/video/320403011771/Dingo-Conservation-The-Feed',
44 'only_matching': True,
45 }, {
46 'url': 'http://www.sbs.com.au/news/video/471395907773/The-Feed-July-9',
47 'only_matching': True,
48 }, {
49 'url': 'https://www.sbs.com.au/ondemand/?play=1836638787723',
50 'only_matching': True,
51 }, {
52 'url': 'https://www.sbs.com.au/ondemand/program/inside-windsor-castle?play=1283505731842',
53 'only_matching': True,
54 }, {
55 'url': 'https://www.sbs.com.au/news/embeds/video/1840778819866',
56 'only_matching': True,
57 }, {
58 'url': 'https://www.sbs.com.au/ondemand/watch/1698704451971',
59 'only_matching': True,
60 }, {
61 'url': 'https://www.sbs.com.au/ondemand/movie/coherence/1469404227931',
62 'only_matching': True,
63 }, {
64 'note': 'Live stream',
65 'url': 'https://www.sbs.com.au/ondemand/video/1726824003663/sbs-24x7-live-stream-nsw',
66 'only_matching': True,
67 }, {
68 'url': 'https://www.sbs.com.au/ondemand/news-series/dateline/dateline-2022/dateline-s2022-ep26/2072245827515',
69 'only_matching': True,
70 }, {
71 'url': 'https://www.sbs.com.au/ondemand/tv-series/the-handmaids-tale/season-5/the-handmaids-tale-s5-ep1/2065631811776',
72 'only_matching': True,
73 }]
74
75 def _real_extract(self, url):
76 video_id = self._match_id(url)
77 player_params = self._download_json(
78 'http://www.sbs.com.au/api/video_pdkvars/id/%s?form=json' % video_id, video_id)
79
80 error = player_params.get('error')
81 if error:
82 error_message = 'Sorry, The video you are looking for does not exist.'
83 video_data = error.get('results') or {}
84 error_code = error.get('errorCode')
85 if error_code == 'ComingSoon':
86 error_message = '%s is not yet available.' % video_data.get('title', '')
87 elif error_code in ('Forbidden', 'intranetAccessOnly'):
88 error_message = 'Sorry, This video cannot be accessed via this website'
89 elif error_code == 'Expired':
90 error_message = 'Sorry, %s is no longer available.' % video_data.get('title', '')
91 raise ExtractorError('%s said: %s' % (self.IE_NAME, error_message), expected=True)
92
93 urls = player_params['releaseUrls']
94 theplatform_url = (urls.get('progressive') or urls.get('html')
95 or urls.get('standard') or player_params['relatedItemsURL'])
96
97 return {
98 '_type': 'url_transparent',
99 'ie_key': 'ThePlatform',
100 'id': video_id,
101 'url': smuggle_url(self._proto_relative_url(theplatform_url), {'force_smil_url': True}),
102 'is_live': player_params.get('streamType') == 'live',
103 }