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.

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