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.

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