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.

133 lines
4.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .cbs import CBSIE
  5. from ..utils import (
  6. parse_duration,
  7. )
  8. class CBSNewsIE(CBSIE):
  9. IE_NAME = 'cbsnews'
  10. IE_DESC = 'CBS News'
  11. _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/(?:news|videos)/(?P<id>[\da-z_-]+)'
  12. _TESTS = [
  13. {
  14. # 60 minutes
  15. 'url': 'http://www.cbsnews.com/news/artificial-intelligence-positioned-to-be-a-game-changer/',
  16. 'info_dict': {
  17. 'id': '_B6Ga3VJrI4iQNKsir_cdFo9Re_YJHE_',
  18. 'ext': 'mp4',
  19. 'title': 'Artificial Intelligence',
  20. 'description': 'md5:8818145f9974431e0fb58a1b8d69613c',
  21. 'thumbnail': r're:^https?://.*\.jpg$',
  22. 'duration': 1606,
  23. 'uploader': 'CBSI-NEW',
  24. 'timestamp': 1498431900,
  25. 'upload_date': '20170625',
  26. },
  27. 'params': {
  28. # m3u8 download
  29. 'skip_download': True,
  30. },
  31. },
  32. {
  33. 'url': 'http://www.cbsnews.com/videos/fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack/',
  34. 'info_dict': {
  35. 'id': 'SNJBOYzXiWBOvaLsdzwH8fmtP1SCd91Y',
  36. 'ext': 'mp4',
  37. 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
  38. 'description': 'md5:4a6983e480542d8b333a947bfc64ddc7',
  39. 'upload_date': '20140404',
  40. 'timestamp': 1396650660,
  41. 'uploader': 'CBSI-NEW',
  42. 'thumbnail': r're:^https?://.*\.jpg$',
  43. 'duration': 205,
  44. 'subtitles': {
  45. 'en': [{
  46. 'ext': 'ttml',
  47. }],
  48. },
  49. },
  50. 'params': {
  51. # m3u8 download
  52. 'skip_download': True,
  53. },
  54. },
  55. {
  56. # 48 hours
  57. 'url': 'http://www.cbsnews.com/news/maria-ridulph-murder-will-the-nations-oldest-cold-case-to-go-to-trial-ever-get-solved/',
  58. 'info_dict': {
  59. 'id': 'QpM5BJjBVEAUFi7ydR9LusS69DPLqPJ1',
  60. 'ext': 'mp4',
  61. 'title': 'Cold as Ice',
  62. 'description': 'Can a childhood memory of a friend\'s murder solve a 1957 cold case? "48 Hours" correspondent Erin Moriarty has the latest.',
  63. 'upload_date': '20170604',
  64. 'timestamp': 1496538000,
  65. 'uploader': 'CBSI-NEW',
  66. },
  67. 'params': {
  68. 'skip_download': True,
  69. },
  70. },
  71. ]
  72. def _real_extract(self, url):
  73. video_id = self._match_id(url)
  74. webpage = self._download_webpage(url, video_id)
  75. video_info = self._parse_json(self._html_search_regex(
  76. r'(?:<ul class="media-list items" id="media-related-items"[^>]*><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
  77. webpage, 'video JSON info', default='{}'), video_id, fatal=False)
  78. if video_info:
  79. item = video_info['item'] if 'item' in video_info else video_info
  80. else:
  81. state = self._parse_json(self._search_regex(
  82. r'data-cbsvideoui-options=(["\'])(?P<json>{.+?})\1', webpage,
  83. 'playlist JSON info', group='json'), video_id)['state']
  84. item = state['playlist'][state['pid']]
  85. return self._extract_video_info(item['mpxRefId'], 'cbsnews')
  86. class CBSNewsLiveVideoIE(InfoExtractor):
  87. IE_NAME = 'cbsnews:livevideo'
  88. IE_DESC = 'CBS News Live Videos'
  89. _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/live/video/(?P<id>[^/?#]+)'
  90. # Live videos get deleted soon. See http://www.cbsnews.com/live/ for the latest examples
  91. _TEST = {
  92. 'url': 'http://www.cbsnews.com/live/video/clinton-sanders-prepare-to-face-off-in-nh/',
  93. 'info_dict': {
  94. 'id': 'clinton-sanders-prepare-to-face-off-in-nh',
  95. 'ext': 'mp4',
  96. 'title': 'Clinton, Sanders Prepare To Face Off In NH',
  97. 'duration': 334,
  98. },
  99. 'skip': 'Video gone',
  100. }
  101. def _real_extract(self, url):
  102. display_id = self._match_id(url)
  103. video_info = self._download_json(
  104. 'http://feeds.cbsn.cbsnews.com/rundown/story', display_id, query={
  105. 'device': 'desktop',
  106. 'dvr_slug': display_id,
  107. })
  108. formats = self._extract_akamai_formats(video_info['url'], display_id)
  109. self._sort_formats(formats)
  110. return {
  111. 'id': display_id,
  112. 'display_id': display_id,
  113. 'title': video_info['headline'],
  114. 'thumbnail': video_info.get('thumbnail_url_hd') or video_info.get('thumbnail_url_sd'),
  115. 'duration': parse_duration(video_info.get('segmentDur')),
  116. 'formats': formats,
  117. }