cbc.py 6.2 KB

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