cbc.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/(?:[^/]+/)+(?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. 'info_dict': {
  28. 'id': '2487345465',
  29. 'ext': 'mp4',
  30. 'title': 'Robin Williams freestyles on 90 Minutes Live',
  31. 'description': 'Wacky American comedian Robin Williams shows off his infamous "freestyle" comedic talents while being interviewed on CBC\'s 90 Minutes Live.',
  32. 'upload_date': '19780210',
  33. 'uploader': 'CBCC-NEW',
  34. 'timestamp': 255977160,
  35. },
  36. }, {
  37. # multiple iframes
  38. 'url': 'http://www.cbc.ca/natureofthings/blog/birds-eye-view-from-vancouvers-burrard-street-bridge-how-we-got-the-shot',
  39. 'playlist': [{
  40. 'md5': '377572d0b49c4ce0c9ad77470e0b96b4',
  41. 'info_dict': {
  42. 'id': '2680832926',
  43. 'ext': 'mp4',
  44. 'title': 'An Eagle\'s-Eye View Off Burrard Bridge',
  45. 'description': 'Hercules the eagle flies from Vancouver\'s Burrard Bridge down to a nearby park with a mini-camera strapped to his back.',
  46. 'upload_date': '20160201',
  47. 'timestamp': 1454342820,
  48. 'uploader': 'CBCC-NEW',
  49. },
  50. }, {
  51. 'md5': '415a0e3f586113894174dfb31aa5bb1a',
  52. 'info_dict': {
  53. 'id': '2658915080',
  54. 'ext': 'mp4',
  55. 'title': 'Fly like an eagle!',
  56. 'description': 'Eagle equipped with a mini camera flies from the world\'s tallest tower',
  57. 'upload_date': '20150315',
  58. 'timestamp': 1426443984,
  59. 'uploader': 'CBCC-NEW',
  60. },
  61. }],
  62. }]
  63. @classmethod
  64. def suitable(cls, url):
  65. return False if CBCPlayerIE.suitable(url) else super(CBCIE, cls).suitable(url)
  66. def _real_extract(self, url):
  67. display_id = self._match_id(url)
  68. webpage = self._download_webpage(url, display_id)
  69. player_init = self._search_regex(
  70. r'CBC\.APP\.Caffeine\.initInstance\(({.+?})\);', webpage, 'player init',
  71. default=None)
  72. if player_init:
  73. player_info = self._parse_json(player_init, display_id, js_to_json)
  74. media_id = player_info.get('mediaId')
  75. if not media_id:
  76. clip_id = player_info['clipId']
  77. media_id = self._download_json(
  78. 'http://feed.theplatform.com/f/h9dtGB/punlNGjMlc1F?fields=id&byContent=byReleases%3DbyId%253D' + clip_id,
  79. clip_id)['entries'][0]['id'].split('/')[-1]
  80. return self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id)
  81. else:
  82. entries = [self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id) for media_id in re.findall(r'<iframe[^>]+src="[^"]+?mediaId=(\d+)"', webpage)]
  83. return self.playlist_result(entries)
  84. class CBCPlayerIE(InfoExtractor):
  85. _VALID_URL = r'(?:cbcplayer:|https?://(?:www\.)?cbc\.ca/(?:player/play/|i/caffeine/syndicate/\?mediaId=))(?P<id>\d+)'
  86. _TEST = {
  87. 'url': 'http://www.cbc.ca/player/play/2683190193',
  88. 'info_dict': {
  89. 'id': '2683190193',
  90. 'ext': 'mp4',
  91. 'title': 'Gerry Runs a Sweat Shop',
  92. 'description': 'md5:b457e1c01e8ff408d9d801c1c2cd29b0',
  93. 'timestamp': 1455071400,
  94. 'upload_date': '20160210',
  95. 'uploader': 'CBCC-NEW',
  96. },
  97. }
  98. def _real_extract(self, url):
  99. video_id = self._match_id(url)
  100. return {
  101. '_type': 'url_transparent',
  102. 'ie_key': 'ThePlatform',
  103. 'url': smuggle_url(
  104. 'http://link.theplatform.com/s/ExhSPC/media/guid/2655402169/%s?mbr=true' % video_id, {
  105. 'force_smil_url': True
  106. }),
  107. 'id': video_id,
  108. }