logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

corus.py (6404B)


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