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.

107 lines
3.8 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. '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. 'skip': 'Subscribers only',
  27. },
  28. {
  29. 'url': 'http://www.cbsnews.com/videos/fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack/',
  30. 'info_dict': {
  31. 'id': 'SNJBOYzXiWBOvaLsdzwH8fmtP1SCd91Y',
  32. 'ext': 'mp4',
  33. 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
  34. 'description': 'md5:4a6983e480542d8b333a947bfc64ddc7',
  35. 'upload_date': '20140404',
  36. 'timestamp': 1396650660,
  37. 'uploader': 'CBSI-NEW',
  38. 'thumbnail': r're:^https?://.*\.jpg$',
  39. 'duration': 205,
  40. 'subtitles': {
  41. 'en': [{
  42. 'ext': 'ttml',
  43. }],
  44. },
  45. },
  46. 'params': {
  47. # m3u8 download
  48. 'skip_download': True,
  49. },
  50. },
  51. ]
  52. def _real_extract(self, url):
  53. video_id = self._match_id(url)
  54. webpage = self._download_webpage(url, video_id)
  55. video_info = self._parse_json(self._html_search_regex(
  56. r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
  57. webpage, 'video JSON info'), video_id)
  58. item = video_info['item'] if 'item' in video_info else video_info
  59. guid = item['mpxRefId']
  60. return self._extract_video_info(guid)
  61. class CBSNewsLiveVideoIE(InfoExtractor):
  62. IE_NAME = 'cbsnews:livevideo'
  63. IE_DESC = 'CBS News Live Videos'
  64. _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/live/video/(?P<id>[^/?#]+)'
  65. # Live videos get deleted soon. See http://www.cbsnews.com/live/ for the latest examples
  66. _TEST = {
  67. 'url': 'http://www.cbsnews.com/live/video/clinton-sanders-prepare-to-face-off-in-nh/',
  68. 'info_dict': {
  69. 'id': 'clinton-sanders-prepare-to-face-off-in-nh',
  70. 'ext': 'mp4',
  71. 'title': 'Clinton, Sanders Prepare To Face Off In NH',
  72. 'duration': 334,
  73. },
  74. 'skip': 'Video gone',
  75. }
  76. def _real_extract(self, url):
  77. display_id = self._match_id(url)
  78. video_info = self._download_json(
  79. 'http://feeds.cbsn.cbsnews.com/rundown/story', display_id, query={
  80. 'device': 'desktop',
  81. 'dvr_slug': display_id,
  82. })
  83. formats = self._extract_akamai_formats(video_info['url'], display_id)
  84. self._sort_formats(formats)
  85. return {
  86. 'id': display_id,
  87. 'display_id': display_id,
  88. 'title': video_info['headline'],
  89. 'thumbnail': video_info.get('thumbnail_url_hd') or video_info.get('thumbnail_url_sd'),
  90. 'duration': parse_duration(video_info.get('segmentDur')),
  91. 'formats': formats,
  92. }