sbs.py 6.4 KB

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