cbsnews.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..utils import remove_start
  7. class CBSNewsIE(InfoExtractor):
  8. IE_DESC = 'CBS News'
  9. _VALID_URL = r'http://(?:www\.)?cbsnews\.com/(?:[^/]+/)+(?P<id>[\da-z_-]+)'
  10. _TESTS = [
  11. {
  12. 'url': 'http://www.cbsnews.com/news/tesla-and-spacex-elon-musks-industrial-empire/',
  13. 'info_dict': {
  14. 'id': 'tesla-and-spacex-elon-musks-industrial-empire',
  15. 'ext': 'flv',
  16. 'title': 'Tesla and SpaceX: Elon Musk\'s industrial empire',
  17. 'thumbnail': 'http://beta.img.cbsnews.com/i/2014/03/30/60147937-2f53-4565-ad64-1bdd6eb64679/60-0330-pelley-640x360.jpg',
  18. 'duration': 791,
  19. },
  20. 'params': {
  21. # rtmp download
  22. 'skip_download': True,
  23. },
  24. },
  25. {
  26. 'url': 'http://www.cbsnews.com/videos/fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack/',
  27. 'info_dict': {
  28. 'id': 'fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack',
  29. 'ext': 'flv',
  30. 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
  31. 'thumbnail': 're:^https?://.*\.jpg$',
  32. 'duration': 205,
  33. 'subtitles': {
  34. 'en': [{
  35. 'ext': 'ttml',
  36. }],
  37. },
  38. },
  39. 'params': {
  40. # rtmp download
  41. 'skip_download': True,
  42. },
  43. },
  44. ]
  45. def _real_extract(self, url):
  46. mobj = re.match(self._VALID_URL, url)
  47. video_id = mobj.group('id')
  48. webpage = self._download_webpage(url, video_id)
  49. video_info = json.loads(self._html_search_regex(
  50. r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
  51. webpage, 'video JSON info'))
  52. item = video_info['item'] if 'item' in video_info else video_info
  53. title = item.get('articleTitle') or item.get('hed')
  54. duration = item.get('duration')
  55. thumbnail = item.get('mediaImage') or item.get('thumbnail')
  56. formats = []
  57. for format_id in ['RtmpMobileLow', 'RtmpMobileHigh', 'Hls', 'RtmpDesktop']:
  58. uri = item.get('media' + format_id + 'URI')
  59. if not uri:
  60. continue
  61. uri = remove_start(uri, '{manifest:none}')
  62. fmt = {
  63. 'url': uri,
  64. 'format_id': format_id,
  65. }
  66. if uri.startswith('rtmp'):
  67. play_path = re.sub(
  68. r'{slistFilePath}', '',
  69. uri.split('<break>')[-1].split('{break}')[-1])
  70. play_path = re.sub(
  71. r'{manifest:.+}.*$', '', play_path)
  72. fmt.update({
  73. 'app': 'ondemand?auth=cbs',
  74. 'play_path': 'mp4:' + play_path,
  75. 'player_url': 'http://www.cbsnews.com/[[IMPORT]]/vidtech.cbsinteractive.com/player/3_3_0/CBSI_PLAYER_HD.swf',
  76. 'page_url': 'http://www.cbsnews.com',
  77. 'ext': 'flv',
  78. })
  79. elif uri.endswith('.m3u8'):
  80. fmt['ext'] = 'mp4'
  81. formats.append(fmt)
  82. subtitles = {}
  83. if 'mpxRefId' in video_info:
  84. subtitles['en'] = [{
  85. 'ext': 'ttml',
  86. 'url': 'http://www.cbsnews.com/videos/captions/%s.adb_xml' % video_info['mpxRefId'],
  87. }]
  88. return {
  89. 'id': video_id,
  90. 'title': title,
  91. 'thumbnail': thumbnail,
  92. 'duration': duration,
  93. 'formats': formats,
  94. 'subtitles': subtitles,
  95. }