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.

113 lines
4.2 KiB

  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. 'skip': 'Subscribers only',
  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': 'SNJBOYzXiWBOvaLsdzwH8fmtP1SCd91Y',
  31. 'ext': 'mp4',
  32. 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
  33. 'description': 'md5:4a6983e480542d8b333a947bfc64ddc7',
  34. 'upload_date': '19700101',
  35. 'uploader': 'CBSI-NEW',
  36. 'thumbnail': 're:^https?://.*\.jpg$',
  37. 'duration': 205,
  38. 'subtitles': {
  39. 'en': [{
  40. 'ext': 'ttml',
  41. }],
  42. },
  43. },
  44. 'params': {
  45. # m3u8 download
  46. 'skip_download': True,
  47. },
  48. },
  49. ]
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. webpage = self._download_webpage(url, video_id)
  53. video_info = self._parse_json(self._html_search_regex(
  54. r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
  55. webpage, 'video JSON info'), video_id)
  56. item = video_info['item'] if 'item' in video_info else video_info
  57. guid = item['mpxRefId']
  58. return self._extract_video_info('byGuid=%s' % guid, guid)
  59. class CBSNewsLiveVideoIE(InfoExtractor):
  60. IE_DESC = 'CBS News Live Videos'
  61. _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/live/video/(?P<id>[\da-z_-]+)'
  62. _TESTS = [{
  63. 'url': 'http://www.cbsnews.com/live/video/clinton-sanders-prepare-to-face-off-in-nh/',
  64. 'info_dict': {
  65. 'id': 'clinton-sanders-prepare-to-face-off-in-nh',
  66. 'ext': 'flv',
  67. 'title': 'Clinton, Sanders Prepare To Face Off In NH',
  68. 'duration': 334,
  69. },
  70. 'skip': 'Video gone, redirected to http://www.cbsnews.com/live/',
  71. }, {
  72. 'url': 'http://www.cbsnews.com/live/video/video-shows-intense-paragliding-accident/',
  73. 'info_dict': {
  74. 'id': 'video-shows-intense-paragliding-accident',
  75. 'ext': 'flv',
  76. 'title': 'Video Shows Intense Paragliding Accident',
  77. },
  78. }]
  79. def _real_extract(self, url):
  80. video_id = self._match_id(url)
  81. webpage = self._download_webpage(url, video_id)
  82. video_info = self._parse_json(self._html_search_regex(
  83. r'data-story-obj=\'({.+?})\'', webpage, 'video JSON info'), video_id)['story']
  84. hdcore_sign = 'hdcore=3.3.1'
  85. f4m_formats = self._extract_f4m_formats(video_info['url'] + '&' + hdcore_sign, video_id)
  86. if f4m_formats:
  87. for entry in f4m_formats:
  88. # URLs without the extra param induce an 404 error
  89. entry.update({'extra_param_to_segment_url': hdcore_sign})
  90. self._sort_formats(f4m_formats)
  91. return {
  92. 'id': video_id,
  93. 'title': video_info['headline'],
  94. 'thumbnail': video_info.get('thumbnail_url_hd') or video_info.get('thumbnail_url_sd'),
  95. 'duration': parse_duration(video_info.get('segmentDur')),
  96. 'formats': f4m_formats,
  97. }