corus.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. from .theplatform import ThePlatformFeedIE
  2. from ..utils import (
  3. ExtractorError,
  4. dict_get,
  5. float_or_none,
  6. int_or_none,
  7. )
  8. class CorusIE(ThePlatformFeedIE): # XXX: Do not subclass from concrete IE
  9. _VALID_URL = r'''(?x)
  10. https?://
  11. (?:www\.)?
  12. (?P<domain>
  13. (?:
  14. globaltv|
  15. etcanada|
  16. seriesplus|
  17. wnetwork|
  18. ytv
  19. )\.com|
  20. (?:
  21. hgtv|
  22. foodnetwork|
  23. slice|
  24. history|
  25. showcase|
  26. bigbrothercanada|
  27. abcspark|
  28. disney(?:channel|lachaine)
  29. )\.ca
  30. )
  31. /(?:[^/]+/)*
  32. (?:
  33. video\.html\?.*?\bv=|
  34. videos?/(?:[^/]+/)*(?:[a-z0-9-]+-)?
  35. )
  36. (?P<id>
  37. [\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}|
  38. (?:[A-Z]{4})?\d{12,20}
  39. )
  40. '''
  41. _TESTS = [{
  42. 'url': 'https://www.hgtv.ca/video/bryan-inc/movie-night-popcorn-with-bryan/870923331648/',
  43. 'info_dict': {
  44. 'id': '870923331648',
  45. 'ext': 'mp4',
  46. 'title': 'Movie Night Popcorn with Bryan',
  47. 'description': 'Bryan whips up homemade popcorn, the old fashion way for Jojo and Lincoln.',
  48. 'upload_date': '20170206',
  49. 'timestamp': 1486392197,
  50. },
  51. 'params': {
  52. 'skip_download': True,
  53. },
  54. 'expected_warnings': ['Failed to parse JSON'],
  55. # FIXME: yt-dlp wrongly raises for geo restriction
  56. }, {
  57. 'url': 'http://www.foodnetwork.ca/shows/chopped/video/episode/chocolate-obsession/video.html?v=872683587753',
  58. 'only_matching': True,
  59. }, {
  60. 'url': 'http://etcanada.com/video/873675331955/meet-the-survivor-game-changers-castaways-part-2/',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'http://www.history.ca/the-world-without-canada/video/full-episodes/natural-resources/video.html?v=955054659646#video',
  64. 'only_matching': True,
  65. }, {
  66. 'url': 'http://www.showcase.ca/eyewitness/video/eyewitness++106/video.html?v=955070531919&p=1&s=da#video',
  67. 'only_matching': True,
  68. }, {
  69. 'url': 'http://www.bigbrothercanada.ca/video/1457812035894/',
  70. 'only_matching': True,
  71. }, {
  72. 'url': 'https://www.bigbrothercanada.ca/video/big-brother-canada-704/1457812035894/',
  73. 'only_matching': True,
  74. }, {
  75. 'url': 'https://www.seriesplus.com/emissions/dre-mary-mort-sur-ordonnance/videos/deux-coeurs-battant/SERP0055626330000200/',
  76. 'only_matching': True,
  77. }, {
  78. 'url': 'https://www.disneychannel.ca/shows/gabby-duran-the-unsittables/video/crybaby-duran-clip/2f557eec-0588-11ea-ae2b-e2c6776b770e/',
  79. 'only_matching': True,
  80. }]
  81. _GEO_BYPASS = False
  82. _SITE_MAP = {
  83. 'globaltv': 'series',
  84. 'etcanada': 'series',
  85. 'foodnetwork': 'food',
  86. 'bigbrothercanada': 'series',
  87. 'disneychannel': 'disneyen',
  88. 'disneylachaine': 'disneyfr',
  89. }
  90. def _real_extract(self, url):
  91. domain, video_id = self._match_valid_url(url).groups()
  92. site = domain.split('.')[0]
  93. path = self._SITE_MAP.get(site, site)
  94. if path != 'series':
  95. path = 'migration/' + path
  96. video = self._download_json(
  97. f'https://globalcontent.corusappservices.com/templates/{path}/playlist/',
  98. video_id, query={'byId': video_id},
  99. headers={'Accept': 'application/json'})[0]
  100. title = video['title']
  101. formats = []
  102. for source in video.get('sources', []):
  103. smil_url = source.get('file')
  104. if not smil_url:
  105. continue
  106. source_type = source.get('type')
  107. note = 'Downloading{} smil file'.format(' ' + source_type if source_type else '')
  108. resp = self._download_webpage(
  109. smil_url, video_id, note, fatal=False,
  110. headers=self.geo_verification_headers())
  111. if not resp:
  112. continue
  113. error = self._parse_json(resp, video_id, fatal=False)
  114. if error:
  115. if error.get('exception') == 'GeoLocationBlocked':
  116. self.raise_geo_restricted(countries=['CA'])
  117. raise ExtractorError(error['description'])
  118. smil = self._parse_xml(resp, video_id, fatal=False)
  119. if smil is None:
  120. continue
  121. namespace = self._parse_smil_namespace(smil)
  122. formats.extend(self._parse_smil_formats(
  123. smil, smil_url, video_id, namespace))
  124. if not formats and video.get('drm'):
  125. self.report_drm(video_id)
  126. subtitles = {}
  127. for track in video.get('tracks', []):
  128. track_url = track.get('file')
  129. if not track_url:
  130. continue
  131. lang = 'fr' if site in ('disneylachaine', 'seriesplus') else 'en'
  132. subtitles.setdefault(lang, []).append({'url': track_url})
  133. metadata = video.get('metadata') or {}
  134. get_number = lambda x: int_or_none(video.get('pl1$' + x) or metadata.get(x + 'Number'))
  135. return {
  136. 'id': video_id,
  137. 'title': title,
  138. 'formats': formats,
  139. 'thumbnail': dict_get(video, ('defaultThumbnailUrl', 'thumbnail', 'image')),
  140. 'description': video.get('description'),
  141. 'timestamp': int_or_none(video.get('availableDate'), 1000),
  142. 'subtitles': subtitles,
  143. 'duration': float_or_none(metadata.get('duration')),
  144. 'series': dict_get(video, ('show', 'pl1$show')),
  145. 'season_number': get_number('season'),
  146. 'episode_number': get_number('episode'),
  147. }