]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
85e787f5 S |
2 | from __future__ import unicode_literals |
3 | ||
fd3a1f3d | 4 | from .common import InfoExtractor |
dabe1570 | 5 | from .cbs import CBSIE |
8b809a07 | 6 | from ..utils import ( |
7 | parse_duration, | |
8b809a07 | 8 | ) |
85e787f5 S |
9 | |
10 | ||
dabe1570 | 11 | class CBSNewsIE(CBSIE): |
7fd57de6 | 12 | IE_NAME = 'cbsnews' |
85e787f5 | 13 | IE_DESC = 'CBS News' |
5886b38d | 14 | _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/(?:news|videos)/(?P<id>[\da-z_-]+)' |
85e787f5 S |
15 | |
16 | _TESTS = [ | |
17 | { | |
18 | 'url': 'http://www.cbsnews.com/news/tesla-and-spacex-elon-musks-industrial-empire/', | |
19 | 'info_dict': { | |
20 | 'id': 'tesla-and-spacex-elon-musks-industrial-empire', | |
21 | 'ext': 'flv', | |
22 | 'title': 'Tesla and SpaceX: Elon Musk\'s industrial empire', | |
23 | 'thumbnail': 'http://beta.img.cbsnews.com/i/2014/03/30/60147937-2f53-4565-ad64-1bdd6eb64679/60-0330-pelley-640x360.jpg', | |
24 | 'duration': 791, | |
25 | }, | |
26 | 'params': { | |
27 | # rtmp download | |
28 | 'skip_download': True, | |
29 | }, | |
ae7b8462 | 30 | 'skip': 'Subscribers only', |
85e787f5 S |
31 | }, |
32 | { | |
33 | 'url': 'http://www.cbsnews.com/videos/fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack/', | |
34 | 'info_dict': { | |
43518503 | 35 | 'id': 'SNJBOYzXiWBOvaLsdzwH8fmtP1SCd91Y', |
f125d911 | 36 | 'ext': 'mp4', |
85e787f5 | 37 | 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack', |
43518503 | 38 | 'description': 'md5:4a6983e480542d8b333a947bfc64ddc7', |
dabe1570 RA |
39 | 'upload_date': '20140404', |
40 | 'timestamp': 1396650660, | |
43518503 | 41 | 'uploader': 'CBSI-NEW', |
ec85ded8 | 42 | 'thumbnail': r're:^https?://.*\.jpg$', |
85e787f5 | 43 | 'duration': 205, |
220ee33f S |
44 | 'subtitles': { |
45 | 'en': [{ | |
46 | 'ext': 'ttml', | |
47 | }], | |
48 | }, | |
4118cc02 JA |
49 | }, |
50 | 'params': { | |
f125d911 | 51 | # m3u8 download |
4118cc02 JA |
52 | 'skip_download': True, |
53 | }, | |
54 | }, | |
85e787f5 S |
55 | ] |
56 | ||
57 | def _real_extract(self, url): | |
fd3a1f3d | 58 | video_id = self._match_id(url) |
85e787f5 S |
59 | |
60 | webpage = self._download_webpage(url, video_id) | |
61 | ||
fd3a1f3d | 62 | video_info = self._parse_json(self._html_search_regex( |
85e787f5 | 63 | r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'', |
7f4c3a74 | 64 | webpage, 'video JSON info', default='{}'), video_id, fatal=False) |
85e787f5 | 65 | |
7f4c3a74 S |
66 | if video_info: |
67 | item = video_info['item'] if 'item' in video_info else video_info | |
68 | else: | |
69 | state = self._parse_json(self._search_regex( | |
70 | r'data-cbsvideoui-options=(["\'])(?P<json>{.+?})\1', webpage, | |
71 | 'playlist JSON info', group='json'), video_id)['state'] | |
72 | item = state['playlist'][state['pid']] | |
73 | ||
74 | return self._extract_video_info(item['mpxRefId'], 'cbsnews') | |
fd3a1f3d | 75 | |
76 | ||
77 | class CBSNewsLiveVideoIE(InfoExtractor): | |
7fd57de6 | 78 | IE_NAME = 'cbsnews:livevideo' |
fd3a1f3d | 79 | IE_DESC = 'CBS News Live Videos' |
7fd57de6 | 80 | _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/live/video/(?P<id>[^/?#]+)' |
fd3a1f3d | 81 | |
69eb4d69 YCH |
82 | # Live videos get deleted soon. See http://www.cbsnews.com/live/ for the latest examples |
83 | _TEST = { | |
fd3a1f3d | 84 | 'url': 'http://www.cbsnews.com/live/video/clinton-sanders-prepare-to-face-off-in-nh/', |
85 | 'info_dict': { | |
86 | 'id': 'clinton-sanders-prepare-to-face-off-in-nh', | |
7fd57de6 | 87 | 'ext': 'mp4', |
fd3a1f3d | 88 | 'title': 'Clinton, Sanders Prepare To Face Off In NH', |
89 | 'duration': 334, | |
90 | }, | |
69eb4d69 YCH |
91 | 'skip': 'Video gone', |
92 | } | |
fd3a1f3d | 93 | |
94 | def _real_extract(self, url): | |
7fd57de6 | 95 | display_id = self._match_id(url) |
fd3a1f3d | 96 | |
7fd57de6 RA |
97 | video_info = self._download_json( |
98 | 'http://feeds.cbsn.cbsnews.com/rundown/story', display_id, query={ | |
99 | 'device': 'desktop', | |
100 | 'dvr_slug': display_id, | |
101 | }) | |
fd3a1f3d | 102 | |
7fd57de6 RA |
103 | formats = self._extract_akamai_formats(video_info['url'], display_id) |
104 | self._sort_formats(formats) | |
fd3a1f3d | 105 | |
106 | return { | |
7fd57de6 RA |
107 | 'id': display_id, |
108 | 'display_id': display_id, | |
fd3a1f3d | 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')), | |
7fd57de6 | 112 | 'formats': formats, |
fd3a1f3d | 113 | } |