You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
7.2 KiB

9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. js_to_json,
  8. smuggle_url,
  9. try_get,
  10. )
  11. class CBCIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?cbc\.ca/(?!player/)(?:[^/]+/)+(?P<id>[^/?#]+)'
  13. _TESTS = [{
  14. # with mediaId
  15. 'url': 'http://www.cbc.ca/22minutes/videos/clips-season-23/don-cherry-play-offs',
  16. 'md5': '97e24d09672fc4cf56256d6faa6c25bc',
  17. 'info_dict': {
  18. 'id': '2682904050',
  19. 'ext': 'mp4',
  20. 'title': 'Don Cherry – All-Stars',
  21. 'description': 'Don Cherry has a bee in his bonnet about AHL player John Scott because that guy’s got heart.',
  22. 'timestamp': 1454463000,
  23. 'upload_date': '20160203',
  24. 'uploader': 'CBCC-NEW',
  25. },
  26. 'skip': 'Geo-restricted to Canada',
  27. }, {
  28. # with clipId, feed available via tpfeed.cbc.ca and feed.theplatform.com
  29. 'url': 'http://www.cbc.ca/22minutes/videos/22-minutes-update/22-minutes-update-episode-4',
  30. 'md5': '162adfa070274b144f4fdc3c3b8207db',
  31. 'info_dict': {
  32. 'id': '2414435309',
  33. 'ext': 'mp4',
  34. 'title': '22 Minutes Update: What Not To Wear Quebec',
  35. 'description': "This week's latest Canadian top political story is What Not To Wear Quebec.",
  36. 'upload_date': '20131025',
  37. 'uploader': 'CBCC-NEW',
  38. 'timestamp': 1382717907,
  39. },
  40. }, {
  41. # with clipId, feed only available via tpfeed.cbc.ca
  42. 'url': 'http://www.cbc.ca/archives/entry/1978-robin-williams-freestyles-on-90-minutes-live',
  43. 'md5': '0274a90b51a9b4971fe005c63f592f12',
  44. 'info_dict': {
  45. 'id': '2487345465',
  46. 'ext': 'mp4',
  47. 'title': 'Robin Williams freestyles on 90 Minutes Live',
  48. 'description': 'Wacky American comedian Robin Williams shows off his infamous "freestyle" comedic talents while being interviewed on CBC\'s 90 Minutes Live.',
  49. 'upload_date': '19780210',
  50. 'uploader': 'CBCC-NEW',
  51. 'timestamp': 255977160,
  52. },
  53. }, {
  54. # multiple iframes
  55. 'url': 'http://www.cbc.ca/natureofthings/blog/birds-eye-view-from-vancouvers-burrard-street-bridge-how-we-got-the-shot',
  56. 'playlist': [{
  57. 'md5': '377572d0b49c4ce0c9ad77470e0b96b4',
  58. 'info_dict': {
  59. 'id': '2680832926',
  60. 'ext': 'mp4',
  61. 'title': 'An Eagle\'s-Eye View Off Burrard Bridge',
  62. 'description': 'Hercules the eagle flies from Vancouver\'s Burrard Bridge down to a nearby park with a mini-camera strapped to his back.',
  63. 'upload_date': '20160201',
  64. 'timestamp': 1454342820,
  65. 'uploader': 'CBCC-NEW',
  66. },
  67. }, {
  68. 'md5': '415a0e3f586113894174dfb31aa5bb1a',
  69. 'info_dict': {
  70. 'id': '2658915080',
  71. 'ext': 'mp4',
  72. 'title': 'Fly like an eagle!',
  73. 'description': 'Eagle equipped with a mini camera flies from the world\'s tallest tower',
  74. 'upload_date': '20150315',
  75. 'timestamp': 1426443984,
  76. 'uploader': 'CBCC-NEW',
  77. },
  78. }],
  79. 'skip': 'Geo-restricted to Canada',
  80. }]
  81. @classmethod
  82. def suitable(cls, url):
  83. return False if CBCPlayerIE.suitable(url) else super(CBCIE, cls).suitable(url)
  84. def _real_extract(self, url):
  85. display_id = self._match_id(url)
  86. webpage = self._download_webpage(url, display_id)
  87. player_init = self._search_regex(
  88. r'CBC\.APP\.Caffeine\.initInstance\(({.+?})\);', webpage, 'player init',
  89. default=None)
  90. if player_init:
  91. player_info = self._parse_json(player_init, display_id, js_to_json)
  92. media_id = player_info.get('mediaId')
  93. if not media_id:
  94. clip_id = player_info['clipId']
  95. feed = self._download_json(
  96. 'http://tpfeed.cbc.ca/f/ExhSPC/vms_5akSXx4Ng_Zn?byCustomValue={:mpsReleases}{%s}' % clip_id,
  97. clip_id, fatal=False)
  98. if feed:
  99. media_id = try_get(feed, lambda x: x['entries'][0]['guid'], compat_str)
  100. if not media_id:
  101. media_id = self._download_json(
  102. 'http://feed.theplatform.com/f/h9dtGB/punlNGjMlc1F?fields=id&byContent=byReleases%3DbyId%253D' + clip_id,
  103. clip_id)['entries'][0]['id'].split('/')[-1]
  104. return self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id)
  105. else:
  106. entries = [self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id) for media_id in re.findall(r'<iframe[^>]+src="[^"]+?mediaId=(\d+)"', webpage)]
  107. return self.playlist_result(entries)
  108. class CBCPlayerIE(InfoExtractor):
  109. _VALID_URL = r'(?:cbcplayer:|https?://(?:www\.)?cbc\.ca/(?:player/play/|i/caffeine/syndicate/\?mediaId=))(?P<id>\d+)'
  110. _TESTS = [{
  111. 'url': 'http://www.cbc.ca/player/play/2683190193',
  112. 'md5': '64d25f841ddf4ddb28a235338af32e2c',
  113. 'info_dict': {
  114. 'id': '2683190193',
  115. 'ext': 'mp4',
  116. 'title': 'Gerry Runs a Sweat Shop',
  117. 'description': 'md5:b457e1c01e8ff408d9d801c1c2cd29b0',
  118. 'timestamp': 1455071400,
  119. 'upload_date': '20160210',
  120. 'uploader': 'CBCC-NEW',
  121. },
  122. 'skip': 'Geo-restricted to Canada',
  123. }, {
  124. # Redirected from http://www.cbc.ca/player/AudioMobile/All%20in%20a%20Weekend%20Montreal/ID/2657632011/
  125. 'url': 'http://www.cbc.ca/player/play/2657631896',
  126. 'md5': 'e5e708c34ae6fca156aafe17c43e8b75',
  127. 'info_dict': {
  128. 'id': '2657631896',
  129. 'ext': 'mp3',
  130. 'title': 'CBC Montreal is organizing its first ever community hackathon!',
  131. 'description': 'The modern technology we tend to depend on so heavily, is never without it\'s share of hiccups and headaches. Next weekend - CBC Montreal will be getting members of the public for its first Hackathon.',
  132. 'timestamp': 1425704400,
  133. 'upload_date': '20150307',
  134. 'uploader': 'CBCC-NEW',
  135. },
  136. }, {
  137. # available only when we add `formats=MPEG4,FLV,MP3` to theplatform url
  138. 'url': 'http://www.cbc.ca/player/play/2164402062',
  139. 'md5': '17a61eb813539abea40618d6323a7f82',
  140. 'info_dict': {
  141. 'id': '2164402062',
  142. 'ext': 'flv',
  143. 'title': 'Cancer survivor four times over',
  144. 'description': 'Tim Mayer has beaten three different forms of cancer four times in five years.',
  145. 'timestamp': 1320410746,
  146. 'upload_date': '20111104',
  147. 'uploader': 'CBCC-NEW',
  148. },
  149. }]
  150. def _real_extract(self, url):
  151. video_id = self._match_id(url)
  152. return {
  153. '_type': 'url_transparent',
  154. 'ie_key': 'ThePlatform',
  155. 'url': smuggle_url(
  156. 'http://link.theplatform.com/s/ExhSPC/media/guid/2655402169/%s?mbr=true&formats=MPEG4,FLV,MP3' % video_id, {
  157. 'force_smil_url': True
  158. }),
  159. 'id': video_id,
  160. }