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.

145 lines
6.0 KiB

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