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.

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