[cbsnews] Update _TESTS of CBSNewsLiveVideoIE
[youtube-dl] / youtube_dl / extractor / cbsnews.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .cbs import CBSBaseIE
6 from ..utils import (
7     parse_duration,
8 )
9
10
11 class CBSNewsIE(CBSBaseIE):
12     IE_DESC = 'CBS News'
13     _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/(?:news|videos)/(?P<id>[\da-z_-]+)'
14
15     _TESTS = [
16         {
17             'url': 'http://www.cbsnews.com/news/tesla-and-spacex-elon-musks-industrial-empire/',
18             'info_dict': {
19                 'id': 'tesla-and-spacex-elon-musks-industrial-empire',
20                 'ext': 'flv',
21                 'title': 'Tesla and SpaceX: Elon Musk\'s industrial empire',
22                 'thumbnail': 'http://beta.img.cbsnews.com/i/2014/03/30/60147937-2f53-4565-ad64-1bdd6eb64679/60-0330-pelley-640x360.jpg',
23                 'duration': 791,
24             },
25             'params': {
26                 # rtmp download
27                 'skip_download': True,
28             },
29             'skip': 'Subscribers only',
30         },
31         {
32             'url': 'http://www.cbsnews.com/videos/fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack/',
33             'info_dict': {
34                 'id': 'SNJBOYzXiWBOvaLsdzwH8fmtP1SCd91Y',
35                 'ext': 'mp4',
36                 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
37                 'description': 'md5:4a6983e480542d8b333a947bfc64ddc7',
38                 'upload_date': '19700101',
39                 'uploader': 'CBSI-NEW',
40                 'thumbnail': 're:^https?://.*\.jpg$',
41                 'duration': 205,
42                 'subtitles': {
43                     'en': [{
44                         'ext': 'ttml',
45                     }],
46                 },
47             },
48             'params': {
49                 # m3u8 download
50                 'skip_download': True,
51             },
52         },
53     ]
54
55     def _real_extract(self, url):
56         video_id = self._match_id(url)
57
58         webpage = self._download_webpage(url, video_id)
59
60         video_info = self._parse_json(self._html_search_regex(
61             r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
62             webpage, 'video JSON info'), video_id)
63
64         item = video_info['item'] if 'item' in video_info else video_info
65         guid = item['mpxRefId']
66         return self._extract_video_info('byGuid=%s' % guid, guid)
67
68
69 class CBSNewsLiveVideoIE(InfoExtractor):
70     IE_DESC = 'CBS News Live Videos'
71     _VALID_URL = r'https?://(?:www\.)?cbsnews\.com/live/video/(?P<id>[\da-z_-]+)'
72
73     _TESTS = [{
74         'url': 'http://www.cbsnews.com/live/video/clinton-sanders-prepare-to-face-off-in-nh/',
75         'info_dict': {
76             'id': 'clinton-sanders-prepare-to-face-off-in-nh',
77             'ext': 'flv',
78             'title': 'Clinton, Sanders Prepare To Face Off In NH',
79             'duration': 334,
80         },
81         'skip': 'Video gone, redirected to http://www.cbsnews.com/live/',
82     }, {
83         'url': 'http://www.cbsnews.com/live/video/video-shows-intense-paragliding-accident/',
84         'info_dict': {
85             'id': 'video-shows-intense-paragliding-accident',
86             'ext': 'flv',
87             'title': 'Video Shows Intense Paragliding Accident',
88         },
89     }]
90
91     def _real_extract(self, url):
92         video_id = self._match_id(url)
93
94         webpage = self._download_webpage(url, video_id)
95
96         video_info = self._parse_json(self._html_search_regex(
97             r'data-story-obj=\'({.+?})\'', webpage, 'video JSON info'), video_id)['story']
98
99         hdcore_sign = 'hdcore=3.3.1'
100         f4m_formats = self._extract_f4m_formats(video_info['url'] + '&' + hdcore_sign, video_id)
101         if f4m_formats:
102             for entry in f4m_formats:
103                 # URLs without the extra param induce an 404 error
104                 entry.update({'extra_param_to_segment_url': hdcore_sign})
105         self._sort_formats(f4m_formats)
106
107         return {
108             'id': video_id,
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')),
112             'formats': f4m_formats,
113         }