]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/cbsnews.py
[vk] Add support for pladform embeds (Closes #7780)
[youtube-dl] / youtube_dl / extractor / cbsnews.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import json
6
7 from .common import InfoExtractor
8
9
10 class CBSNewsIE(InfoExtractor):
11     IE_DESC = 'CBS News'
12     _VALID_URL = r'http://(?:www\.)?cbsnews\.com/(?:[^/]+/)+(?P<id>[\da-z_-]+)'
13
14     _TESTS = [
15         {
16             'url': 'http://www.cbsnews.com/news/tesla-and-spacex-elon-musks-industrial-empire/',
17             'info_dict': {
18                 'id': 'tesla-and-spacex-elon-musks-industrial-empire',
19                 'ext': 'flv',
20                 'title': 'Tesla and SpaceX: Elon Musk\'s industrial empire',
21                 'thumbnail': 'http://beta.img.cbsnews.com/i/2014/03/30/60147937-2f53-4565-ad64-1bdd6eb64679/60-0330-pelley-640x360.jpg',
22                 'duration': 791,
23             },
24             'params': {
25                 # rtmp download
26                 'skip_download': True,
27             },
28         },
29         {
30             'url': 'http://www.cbsnews.com/videos/fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack/',
31             'info_dict': {
32                 'id': 'fort-hood-shooting-army-downplays-mental-illness-as-cause-of-attack',
33                 'ext': 'flv',
34                 'title': 'Fort Hood shooting: Army downplays mental illness as cause of attack',
35                 'thumbnail': 're:^https?://.*\.jpg$',
36                 'duration': 205,
37             },
38             'params': {
39                 # rtmp download
40                 'skip_download': True,
41             },
42         },
43     ]
44
45     def _real_extract(self, url):
46         mobj = re.match(self._VALID_URL, url)
47         video_id = mobj.group('id')
48
49         webpage = self._download_webpage(url, video_id)
50
51         video_info = json.loads(self._html_search_regex(
52             r'(?:<ul class="media-list items" id="media-related-items"><li data-video-info|<div id="cbsNewsVideoPlayer" data-video-player-options)=\'({.+?})\'',
53             webpage, 'video JSON info'))
54
55         item = video_info['item'] if 'item' in video_info else video_info
56         title = item.get('articleTitle') or item.get('hed')
57         duration = item.get('duration')
58         thumbnail = item.get('mediaImage') or item.get('thumbnail')
59
60         formats = []
61         for format_id in ['RtmpMobileLow', 'RtmpMobileHigh', 'Hls', 'RtmpDesktop']:
62             uri = item.get('media' + format_id + 'URI')
63             if not uri:
64                 continue
65             fmt = {
66                 'url': uri,
67                 'format_id': format_id,
68             }
69             if uri.startswith('rtmp'):
70                 play_path = re.sub(
71                     r'{slistFilePath}', '',
72                     uri.split('<break>')[-1].split('{break}')[-1])
73                 fmt.update({
74                     'app': 'ondemand?auth=cbs',
75                     'play_path': 'mp4:' + play_path,
76                     'player_url': 'http://www.cbsnews.com/[[IMPORT]]/vidtech.cbsinteractive.com/player/3_3_0/CBSI_PLAYER_HD.swf',
77                     'page_url': 'http://www.cbsnews.com',
78                     'ext': 'flv',
79                 })
80             elif uri.endswith('.m3u8'):
81                 fmt['ext'] = 'mp4'
82             formats.append(fmt)
83
84         return {
85             'id': video_id,
86             'title': title,
87             'thumbnail': thumbnail,
88             'duration': duration,
89             'formats': formats,
90         }