]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cbs.py
debian/control: Update list of extractors in long description.
[youtubedl] / youtube_dl / extractor / cbs.py
1 from __future__ import unicode_literals
2
3 from .theplatform import ThePlatformFeedIE
4 from ..utils import (
5 ExtractorError,
6 int_or_none,
7 find_xpath_attr,
8 xpath_element,
9 xpath_text,
10 update_url_query,
11 )
12
13
14 class CBSBaseIE(ThePlatformFeedIE):
15 def _parse_smil_subtitles(self, smil, namespace=None, subtitles_lang='en'):
16 closed_caption_e = find_xpath_attr(smil, self._xpath_ns('.//param', namespace), 'name', 'ClosedCaptionURL')
17 return {
18 'en': [{
19 'ext': 'ttml',
20 'url': closed_caption_e.attrib['value'],
21 }]
22 } if closed_caption_e is not None and closed_caption_e.attrib.get('value') else []
23
24
25 class CBSIE(CBSBaseIE):
26 _VALID_URL = r'(?:cbs:|https?://(?:www\.)?(?:cbs\.com/shows/[^/]+/video|colbertlateshow\.com/(?:video|podcasts))/)(?P<id>[\w-]+)'
27
28 _TESTS = [{
29 'url': 'http://www.cbs.com/shows/garth-brooks/video/_u7W953k6la293J7EPTd9oHkSPs6Xn6_/connect-chat-feat-garth-brooks/',
30 'info_dict': {
31 'id': '_u7W953k6la293J7EPTd9oHkSPs6Xn6_',
32 'ext': 'mp4',
33 'title': 'Connect Chat feat. Garth Brooks',
34 'description': 'Connect with country music singer Garth Brooks, as he chats with fans on Wednesday November 27, 2013. Be sure to tune in to Garth Brooks: Live from Las Vegas, Friday November 29, at 9/8c on CBS!',
35 'duration': 1495,
36 'timestamp': 1385585425,
37 'upload_date': '20131127',
38 'uploader': 'CBSI-NEW',
39 },
40 'params': {
41 # m3u8 download
42 'skip_download': True,
43 },
44 '_skip': 'Blocked outside the US',
45 }, {
46 'url': 'http://colbertlateshow.com/video/8GmB0oY0McANFvp2aEffk9jZZZ2YyXxy/the-colbeard/',
47 'only_matching': True,
48 }, {
49 'url': 'http://www.colbertlateshow.com/podcasts/dYSwjqPs_X1tvbV_P2FcPWRa_qT6akTC/in-the-bad-room-with-stephen/',
50 'only_matching': True,
51 }]
52
53 def _extract_video_info(self, content_id, site='cbs', mpx_acc=2198311517):
54 items_data = self._download_xml(
55 'http://can.cbs.com/thunder/player/videoPlayerService.php',
56 content_id, query={'partner': site, 'contentId': content_id})
57 video_data = xpath_element(items_data, './/item')
58 title = xpath_text(video_data, 'videoTitle', 'title', True)
59 tp_path = 'dJ5BDC/media/guid/%d/%s' % (mpx_acc, content_id)
60 tp_release_url = 'http://link.theplatform.com/s/' + tp_path
61
62 asset_types = []
63 subtitles = {}
64 formats = []
65 last_e = None
66 for item in items_data.findall('.//item'):
67 asset_type = xpath_text(item, 'assetType')
68 if not asset_type or asset_type in asset_types or asset_type in ('HLS_FPS', 'DASH_CENC'):
69 continue
70 asset_types.append(asset_type)
71 query = {
72 'mbr': 'true',
73 'assetTypes': asset_type,
74 }
75 if asset_type.startswith('HLS') or asset_type in ('OnceURL', 'StreamPack'):
76 query['formats'] = 'MPEG4,M3U'
77 elif asset_type in ('RTMP', 'WIFI', '3G'):
78 query['formats'] = 'MPEG4,FLV'
79 try:
80 tp_formats, tp_subtitles = self._extract_theplatform_smil(
81 update_url_query(tp_release_url, query), content_id,
82 'Downloading %s SMIL data' % asset_type)
83 except ExtractorError as e:
84 last_e = e
85 continue
86 formats.extend(tp_formats)
87 subtitles = self._merge_subtitles(subtitles, tp_subtitles)
88 if last_e and not formats:
89 raise last_e
90 self._sort_formats(formats)
91
92 info = self._extract_theplatform_metadata(tp_path, content_id)
93 info.update({
94 'id': content_id,
95 'title': title,
96 'series': xpath_text(video_data, 'seriesTitle'),
97 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')),
98 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')),
99 'duration': int_or_none(xpath_text(video_data, 'videoLength'), 1000),
100 'thumbnail': xpath_text(video_data, 'previewImageURL'),
101 'formats': formats,
102 'subtitles': subtitles,
103 })
104 return info
105
106 def _real_extract(self, url):
107 content_id = self._match_id(url)
108 return self._extract_video_info(content_id)