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