corus.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. from .theplatform import ThePlatformFeedIE
  2. from ..utils import (
  3. dict_get,
  4. ExtractorError,
  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': 'http://www.hgtv.ca/shows/bryan-inc/videos/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. }, {
  56. 'url': 'http://www.foodnetwork.ca/shows/chopped/video/episode/chocolate-obsession/video.html?v=872683587753',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'http://etcanada.com/video/873675331955/meet-the-survivor-game-changers-castaways-part-2/',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'http://www.history.ca/the-world-without-canada/video/full-episodes/natural-resources/video.html?v=955054659646#video',
  63. 'only_matching': True,
  64. }, {
  65. 'url': 'http://www.showcase.ca/eyewitness/video/eyewitness++106/video.html?v=955070531919&p=1&s=da#video',
  66. 'only_matching': True,
  67. }, {
  68. 'url': 'http://www.bigbrothercanada.ca/video/1457812035894/',
  69. 'only_matching': True
  70. }, {
  71. 'url': 'https://www.bigbrothercanada.ca/video/big-brother-canada-704/1457812035894/',
  72. 'only_matching': True
  73. }, {
  74. 'url': 'https://www.seriesplus.com/emissions/dre-mary-mort-sur-ordonnance/videos/deux-coeurs-battant/SERP0055626330000200/',
  75. 'only_matching': True
  76. }, {
  77. 'url': 'https://www.disneychannel.ca/shows/gabby-duran-the-unsittables/video/crybaby-duran-clip/2f557eec-0588-11ea-ae2b-e2c6776b770e/',
  78. 'only_matching': True
  79. }]
  80. _GEO_BYPASS = False
  81. _SITE_MAP = {
  82. 'globaltv': 'series',
  83. 'etcanada': 'series',
  84. 'foodnetwork': 'food',
  85. 'bigbrothercanada': 'series',
  86. 'disneychannel': 'disneyen',
  87. 'disneylachaine': 'disneyfr',
  88. }
  89. def _real_extract(self, url):
  90. domain, video_id = self._match_valid_url(url).groups()
  91. site = domain.split('.')[0]
  92. path = self._SITE_MAP.get(site, site)
  93. if path != 'series':
  94. path = 'migration/' + path
  95. video = self._download_json(
  96. 'https://globalcontent.corusappservices.com/templates/%s/playlist/' % path,
  97. video_id, query={'byId': video_id},
  98. headers={'Accept': 'application/json'})[0]
  99. title = video['title']
  100. formats = []
  101. for source in video.get('sources', []):
  102. smil_url = source.get('file')
  103. if not smil_url:
  104. continue
  105. source_type = source.get('type')
  106. note = 'Downloading%s smil file' % (' ' + source_type if source_type else '')
  107. resp = self._download_webpage(
  108. smil_url, video_id, note, fatal=False,
  109. headers=self.geo_verification_headers())
  110. if not resp:
  111. continue
  112. error = self._parse_json(resp, video_id, fatal=False)
  113. if error:
  114. if error.get('exception') == 'GeoLocationBlocked':
  115. self.raise_geo_restricted(countries=['CA'])
  116. raise ExtractorError(error['description'])
  117. smil = self._parse_xml(resp, video_id, fatal=False)
  118. if smil is None:
  119. continue
  120. namespace = self._parse_smil_namespace(smil)
  121. formats.extend(self._parse_smil_formats(
  122. smil, smil_url, video_id, namespace))
  123. if not formats and video.get('drm'):
  124. self.report_drm(video_id)
  125. subtitles = {}
  126. for track in video.get('tracks', []):
  127. track_url = track.get('file')
  128. if not track_url:
  129. continue
  130. lang = 'fr' if site in ('disneylachaine', 'seriesplus') else 'en'
  131. subtitles.setdefault(lang, []).append({'url': track_url})
  132. metadata = video.get('metadata') or {}
  133. get_number = lambda x: int_or_none(video.get('pl1$' + x) or metadata.get(x + 'Number'))
  134. return {
  135. 'id': video_id,
  136. 'title': title,
  137. 'formats': formats,
  138. 'thumbnail': dict_get(video, ('defaultThumbnailUrl', 'thumbnail', 'image')),
  139. 'description': video.get('description'),
  140. 'timestamp': int_or_none(video.get('availableDate'), 1000),
  141. 'subtitles': subtitles,
  142. 'duration': float_or_none(metadata.get('duration')),
  143. 'series': dict_get(video, ('show', 'pl1$show')),
  144. 'season_number': get_number('season'),
  145. 'episode_number': get_number('episode'),
  146. }