]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/cbsnews.py
[dailymotion] Fix view count extraction
[yt-dlp.git] / youtube_dl / extractor / cbsnews.py
CommitLineData
85e787f5
S
1# encoding: utf-8
2from __future__ import unicode_literals
3
fd3a1f3d 4from .common import InfoExtractor
f125d911 5from .theplatform import ThePlatformIE
fd3a1f3d 6from ..utils import parse_duration
85e787f5
S
7
8
f125d911 9class CBSNewsIE(ThePlatformIE):
85e787f5 10 IE_DESC = 'CBS News'
fd3a1f3d 11 _VALID_URL = r'http://(?:www\.)?cbsnews\.com/(?:news|videos)/(?P<id>[\da-z_-]+)'
85e787f5
S
12
13 _TESTS = [
14 {
15 'url': 'http://www.cbsnews.com/news/tesla-and-spacex-elon-musks-industrial-empire/',
16 'info_dict': {
17 'id': 'tesla-and-spacex-elon-musks-industrial-empire',
18 'ext': 'flv',
19 'title': 'Tesla and SpaceX: Elon Musk\'s industrial empire',
20 'thumbnail': 'http://beta.img.cbsnews.com/i/2014/03/30/60147937-2f53-4565-ad64-1bdd6eb64679/60-0330-pelley-640x360.jpg',
21 'duration': 791,
22 },
23 'params': {
24 # rtmp download
25 'skip_download': True,
26 },
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': 'fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack',
f125d911 32 'ext': 'mp4',
85e787f5 33 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
e8cfacae 34 'thumbnail': 're:^https?://.*\.jpg$',
85e787f5 35 'duration': 205,
220ee33f
S
36 'subtitles': {
37 'en': [{
38 'ext': 'ttml',
39 }],
40 },
4118cc02
JA
41 },
42 'params': {
f125d911 43 # m3u8 download
4118cc02
JA
44 'skip_download': True,
45 },
46 },
85e787f5
S
47 ]
48
49 def _real_extract(self, url):
fd3a1f3d 50 video_id = self._match_id(url)
85e787f5
S
51
52 webpage = self._download_webpage(url, video_id)
53
fd3a1f3d 54 video_info = self._parse_json(self._html_search_regex(
85e787f5 55 r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
fd3a1f3d 56 webpage, 'video JSON info'), video_id)
85e787f5
S
57
58 item = video_info['item'] if 'item' in video_info else video_info
59 title = item.get('articleTitle') or item.get('hed')
60 duration = item.get('duration')
61 thumbnail = item.get('mediaImage') or item.get('thumbnail')
62
220ee33f 63 subtitles = {}
4118cc02 64 if 'mpxRefId' in video_info:
220ee33f
S
65 subtitles['en'] = [{
66 'ext': 'ttml',
67 'url': 'http://www.cbsnews.com/videos/captions/%s.adb_xml' % video_info['mpxRefId'],
68 }]
4118cc02 69
f125d911 70 formats = []
71 for format_id in ['RtmpMobileLow', 'RtmpMobileHigh', 'Hls', 'RtmpDesktop']:
72 pid = item.get('media' + format_id)
73 if not pid:
74 continue
75 release_url = 'http://link.theplatform.com/s/dJ5BDC/%s?format=SMIL&mbr=true' % pid
76 tp_formats, tp_subtitles = self._extract_theplatform_smil(release_url, video_id, 'Downloading %s SMIL data' % pid)
77 formats.extend(tp_formats)
78 subtitles = self._merge_subtitles(subtitles, tp_subtitles)
79 self._sort_formats(formats)
80
85e787f5
S
81 return {
82 'id': video_id,
83 'title': title,
84 'thumbnail': thumbnail,
85 'duration': duration,
86 'formats': formats,
4118cc02 87 'subtitles': subtitles,
5f6a1245 88 }
fd3a1f3d 89
90
91class CBSNewsLiveVideoIE(InfoExtractor):
92 IE_DESC = 'CBS News Live Videos'
93 _VALID_URL = r'http://(?:www\.)?cbsnews\.com/live/video/(?P<id>[\da-z_-]+)'
94
95 _TEST = {
96 'url': 'http://www.cbsnews.com/live/video/clinton-sanders-prepare-to-face-off-in-nh/',
97 'info_dict': {
98 'id': 'clinton-sanders-prepare-to-face-off-in-nh',
99 'ext': 'flv',
100 'title': 'Clinton, Sanders Prepare To Face Off In NH',
101 'duration': 334,
102 },
103 }
104
105 def _real_extract(self, url):
106 video_id = self._match_id(url)
107
108 webpage = self._download_webpage(url, video_id)
109
110 video_info = self._parse_json(self._html_search_regex(
111 r'data-story-obj=\'({.+?})\'', webpage, 'video JSON info'), video_id)['story']
112
113 hdcore_sign = 'hdcore=3.3.1'
114 f4m_formats = self._extract_f4m_formats(video_info['url'] + '&' + hdcore_sign, video_id)
115 if f4m_formats:
116 for entry in f4m_formats:
117 # URLs without the extra param induce an 404 error
118 entry.update({'extra_param_to_segment_url': hdcore_sign})
119
120 return {
121 'id': video_id,
122 'title': video_info['headline'],
123 'thumbnail': video_info.get('thumbnail_url_hd') or video_info.get('thumbnail_url_sd'),
124 'duration': parse_duration(video_info.get('segmentDur')),
125 'formats': f4m_formats,
126 }