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.

114 lines
4.4 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. 'uploader': 'CBCC-NEW',
  33. },
  34. 'params': {
  35. # rtmp download
  36. 'skip_download': True,
  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. 'info_dict': {
  43. 'id': '2680832926',
  44. 'ext': 'flv',
  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': '19700101',
  48. },
  49. }, {
  50. 'info_dict': {
  51. 'id': '2658915080',
  52. 'ext': 'flv',
  53. 'title': 'Fly like an eagle!',
  54. 'description': 'Eagle equipped with a mini camera flies from the world\'s tallest tower',
  55. 'upload_date': '19700101',
  56. },
  57. }],
  58. 'params': {
  59. # rtmp download
  60. 'skip_download': True,
  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': 'flv',
  91. 'title': 'Gerry Runs a Sweat Shop',
  92. 'description': 'md5:b457e1c01e8ff408d9d801c1c2cd29b0',
  93. 'timestamp': 1455067800,
  94. 'upload_date': '20160210',
  95. },
  96. 'params': {
  97. # rtmp download
  98. 'skip_download': True,
  99. },
  100. }
  101. def _real_extract(self, url):
  102. video_id = self._match_id(url)
  103. return self.url_result(
  104. 'http://feed.theplatform.com/f/ExhSPC/vms_5akSXx4Ng_Zn?byGuid=%s' % video_id,
  105. 'ThePlatformFeed', video_id)