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.

129 lines
4.9 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 _parse_smil_subtitles(self, smil, namespace=None, subtitles_lang='en'):
  45. closed_caption_e = smil.find(self._xpath_ns('.//param[@name=\'ClosedCaptionURL\']', namespace))
  46. return {
  47. 'en': [{
  48. 'ext': 'ttml',
  49. 'url': closed_caption_e.attrib['value'],
  50. }]
  51. } if closed_caption_e is not None and closed_caption_e.attrib.get('value') else []
  52. def _real_extract(self, url):
  53. video_id = self._match_id(url)
  54. webpage = self._download_webpage(url, video_id)
  55. video_info = self._parse_json(self._html_search_regex(
  56. r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
  57. webpage, 'video JSON info'), video_id)
  58. item = video_info['item'] if 'item' in video_info else video_info
  59. title = item.get('articleTitle') or item.get('hed')
  60. duration = item.get('duration')
  61. thumbnail = item.get('mediaImage') or item.get('thumbnail')
  62. subtitles = {}
  63. formats = []
  64. for format_id in ['RtmpMobileLow', 'RtmpMobileHigh', 'Hls', 'RtmpDesktop']:
  65. pid = item.get('media' + format_id)
  66. if not pid:
  67. continue
  68. release_url = 'http://link.theplatform.com/s/dJ5BDC/%s?format=SMIL&mbr=true' % pid
  69. tp_formats, tp_subtitles = self._extract_theplatform_smil(release_url, video_id, 'Downloading %s SMIL data' % pid)
  70. formats.extend(tp_formats)
  71. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  72. self._sort_formats(formats)
  73. return {
  74. 'id': video_id,
  75. 'title': title,
  76. 'thumbnail': thumbnail,
  77. 'duration': duration,
  78. 'formats': formats,
  79. 'subtitles': subtitles,
  80. }
  81. class CBSNewsLiveVideoIE(InfoExtractor):
  82. IE_DESC = 'CBS News Live Videos'
  83. _VALID_URL = r'http://(?:www\.)?cbsnews\.com/live/video/(?P<id>[\da-z_-]+)'
  84. _TEST = {
  85. 'url': 'http://www.cbsnews.com/live/video/clinton-sanders-prepare-to-face-off-in-nh/',
  86. 'info_dict': {
  87. 'id': 'clinton-sanders-prepare-to-face-off-in-nh',
  88. 'ext': 'flv',
  89. 'title': 'Clinton, Sanders Prepare To Face Off In NH',
  90. 'duration': 334,
  91. },
  92. }
  93. def _real_extract(self, url):
  94. video_id = self._match_id(url)
  95. webpage = self._download_webpage(url, video_id)
  96. video_info = self._parse_json(self._html_search_regex(
  97. r'data-story-obj=\'({.+?})\'', webpage, 'video JSON info'), video_id)['story']
  98. hdcore_sign = 'hdcore=3.3.1'
  99. f4m_formats = self._extract_f4m_formats(video_info['url'] + '&' + hdcore_sign, video_id)
  100. if f4m_formats:
  101. for entry in f4m_formats:
  102. # URLs without the extra param induce an 404 error
  103. entry.update({'extra_param_to_segment_url': hdcore_sign})
  104. return {
  105. 'id': video_id,
  106. 'title': video_info['headline'],
  107. 'thumbnail': video_info.get('thumbnail_url_hd') or video_info.get('thumbnail_url_sd'),
  108. 'duration': parse_duration(video_info.get('segmentDur')),
  109. 'formats': f4m_formats,
  110. }