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.

126 lines
4.7 KiB

10 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .theplatform import ThePlatformIE
  5. from ..utils import parse_duration
  6. class CBSNewsIE(ThePlatformIE):
  7. IE_DESC = 'CBS News'
  8. _VALID_URL = r'http://(?:www\.)?cbsnews\.com/(?:news|videos)/(?P<id>[\da-z_-]+)'
  9. _TESTS = [
  10. {
  11. 'url': 'http://www.cbsnews.com/news/tesla-and-spacex-elon-musks-industrial-empire/',
  12. 'info_dict': {
  13. 'id': 'tesla-and-spacex-elon-musks-industrial-empire',
  14. 'ext': 'flv',
  15. 'title': 'Tesla and SpaceX: Elon Musk\'s industrial empire',
  16. 'thumbnail': 'http://beta.img.cbsnews.com/i/2014/03/30/60147937-2f53-4565-ad64-1bdd6eb64679/60-0330-pelley-640x360.jpg',
  17. 'duration': 791,
  18. },
  19. 'params': {
  20. # rtmp download
  21. 'skip_download': True,
  22. },
  23. },
  24. {
  25. 'url': 'http://www.cbsnews.com/videos/fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack/',
  26. 'info_dict': {
  27. 'id': 'fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack',
  28. 'ext': 'mp4',
  29. 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
  30. 'thumbnail': 're:^https?://.*\.jpg$',
  31. 'duration': 205,
  32. 'subtitles': {
  33. 'en': [{
  34. 'ext': 'ttml',
  35. }],
  36. },
  37. },
  38. 'params': {
  39. # m3u8 download
  40. 'skip_download': True,
  41. },
  42. },
  43. ]
  44. def _real_extract(self, url):
  45. video_id = self._match_id(url)
  46. webpage = self._download_webpage(url, video_id)
  47. video_info = self._parse_json(self._html_search_regex(
  48. r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
  49. webpage, 'video JSON info'), video_id)
  50. item = video_info['item'] if 'item' in video_info else video_info
  51. title = item.get('articleTitle') or item.get('hed')
  52. duration = item.get('duration')
  53. thumbnail = item.get('mediaImage') or item.get('thumbnail')
  54. subtitles = {}
  55. if 'mpxRefId' in video_info:
  56. subtitles['en'] = [{
  57. 'ext': 'ttml',
  58. 'url': 'http://www.cbsnews.com/videos/captions/%s.adb_xml' % video_info['mpxRefId'],
  59. }]
  60. formats = []
  61. for format_id in ['RtmpMobileLow', 'RtmpMobileHigh', 'Hls', 'RtmpDesktop']:
  62. pid = item.get('media' + format_id)
  63. if not pid:
  64. continue
  65. release_url = 'http://link.theplatform.com/s/dJ5BDC/%s?format=SMIL&mbr=true' % pid
  66. tp_formats, tp_subtitles = self._extract_theplatform_smil(release_url, video_id, 'Downloading %s SMIL data' % pid)
  67. formats.extend(tp_formats)
  68. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  69. self._sort_formats(formats)
  70. return {
  71. 'id': video_id,
  72. 'title': title,
  73. 'thumbnail': thumbnail,
  74. 'duration': duration,
  75. 'formats': formats,
  76. 'subtitles': subtitles,
  77. }
  78. class CBSNewsLiveVideoIE(InfoExtractor):
  79. IE_DESC = 'CBS News Live Videos'
  80. _VALID_URL = r'http://(?:www\.)?cbsnews\.com/live/video/(?P<id>[\da-z_-]+)'
  81. _TEST = {
  82. 'url': 'http://www.cbsnews.com/live/video/clinton-sanders-prepare-to-face-off-in-nh/',
  83. 'info_dict': {
  84. 'id': 'clinton-sanders-prepare-to-face-off-in-nh',
  85. 'ext': 'flv',
  86. 'title': 'Clinton, Sanders Prepare To Face Off In NH',
  87. 'duration': 334,
  88. },
  89. }
  90. def _real_extract(self, url):
  91. video_id = self._match_id(url)
  92. webpage = self._download_webpage(url, video_id)
  93. video_info = self._parse_json(self._html_search_regex(
  94. r'data-story-obj=\'({.+?})\'', webpage, 'video JSON info'), video_id)['story']
  95. hdcore_sign = 'hdcore=3.3.1'
  96. f4m_formats = self._extract_f4m_formats(video_info['url'] + '&' + hdcore_sign, video_id)
  97. if f4m_formats:
  98. for entry in f4m_formats:
  99. # URLs without the extra param induce an 404 error
  100. entry.update({'extra_param_to_segment_url': hdcore_sign})
  101. return {
  102. 'id': video_id,
  103. 'title': video_info['headline'],
  104. 'thumbnail': video_info.get('thumbnail_url_hd') or video_info.get('thumbnail_url_sd'),
  105. 'duration': parse_duration(video_info.get('segmentDur')),
  106. 'formats': f4m_formats,
  107. }