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.

124 lines
4.5 KiB

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