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.

113 lines
4.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import js_to_json
  6. class CBCIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?cbc\.ca/(?:[^/]+/)+(?P<id>[^/?#]+)'
  8. _TESTS = [{
  9. # with mediaId
  10. 'url': 'http://www.cbc.ca/22minutes/videos/clips-season-23/don-cherry-play-offs',
  11. 'info_dict': {
  12. 'id': '2682904050',
  13. 'ext': 'flv',
  14. 'title': 'Don Cherry – All-Stars',
  15. 'description': 'Don Cherry has a bee in his bonnet about AHL player John Scott because that guy’s got heart.',
  16. 'timestamp': 1454475540,
  17. 'upload_date': '20160203',
  18. },
  19. 'params': {
  20. # rtmp download
  21. 'skip_download': True,
  22. },
  23. }, {
  24. # with clipId
  25. 'url': 'http://www.cbc.ca/archives/entry/1978-robin-williams-freestyles-on-90-minutes-live',
  26. 'info_dict': {
  27. 'id': '2487345465',
  28. 'ext': 'flv',
  29. 'title': 'Robin Williams freestyles on 90 Minutes Live',
  30. 'description': 'Wacky American comedian Robin Williams shows off his infamous "freestyle" comedic talents while being interviewed on CBC\'s 90 Minutes Live.',
  31. 'upload_date': '19700101',
  32. },
  33. 'params': {
  34. # rtmp download
  35. 'skip_download': True,
  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. 'info_dict': {
  42. 'id': '2680832926',
  43. 'ext': 'flv',
  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': '19700101',
  47. },
  48. }, {
  49. 'info_dict': {
  50. 'id': '2658915080',
  51. 'ext': 'flv',
  52. 'title': 'Fly like an eagle!',
  53. 'description': 'Eagle equipped with a mini camera flies from the world\'s tallest tower',
  54. 'upload_date': '19700101',
  55. },
  56. }],
  57. 'params': {
  58. # rtmp download
  59. 'skip_download': True,
  60. },
  61. }]
  62. @classmethod
  63. def suitable(cls, url):
  64. return False if CBCPlayerIE.suitable(url) else super(CBCIE, cls).suitable(url)
  65. def _real_extract(self, url):
  66. display_id = self._match_id(url)
  67. webpage = self._download_webpage(url, display_id)
  68. player_init = self._search_regex(
  69. r'CBC\.APP\.Caffeine\.initInstance\(({.+?})\);', webpage, 'player init',
  70. default=None)
  71. if player_init:
  72. player_info = self._parse_json(player_init, display_id, js_to_json)
  73. media_id = player_info.get('mediaId')
  74. if not media_id:
  75. clip_id = player_info['clipId']
  76. media_id = self._download_json(
  77. 'http://feed.theplatform.com/f/h9dtGB/punlNGjMlc1F?fields=id&byContent=byReleases%3DbyId%253D' + clip_id,
  78. clip_id)['entries'][0]['id'].split('/')[-1]
  79. return self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id)
  80. else:
  81. entries = [self.url_result('cbcplayer:%s' % media_id, 'CBCPlayer', media_id) for media_id in re.findall(r'<iframe[^>]+src="[^"]+?mediaId=(\d+)"', webpage)]
  82. return self.playlist_result(entries)
  83. class CBCPlayerIE(InfoExtractor):
  84. _VALID_URL = r'(?:cbcplayer:|https?://(?:www\.)?cbc\.ca/(?:player/play/|i/caffeine/syndicate/\?mediaId=))(?P<id>\d+)'
  85. _TEST = {
  86. 'url': 'http://www.cbc.ca/player/play/2683190193',
  87. 'info_dict': {
  88. 'id': '2683190193',
  89. 'ext': 'flv',
  90. 'title': 'Gerry Runs a Sweat Shop',
  91. 'description': 'md5:b457e1c01e8ff408d9d801c1c2cd29b0',
  92. 'timestamp': 1455067800,
  93. 'upload_date': '20160210',
  94. },
  95. 'params': {
  96. # rtmp download
  97. 'skip_download': True,
  98. },
  99. }
  100. def _real_extract(self, url):
  101. video_id = self._match_id(url)
  102. return self.url_result(
  103. 'http://feed.theplatform.com/f/ExhSPC/vms_5akSXx4Ng_Zn?byGuid=%s' % video_id,
  104. 'ThePlatformFeed', video_id)