]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/cbs.py
[extractor/common] Improve thumbnail extraction for HTML5 entries
[yt-dlp.git] / youtube_dl / extractor / cbs.py
CommitLineData
e42a692f
PH
1from __future__ import unicode_literals
2
43518503 3from .theplatform import ThePlatformFeedIE
5c2266df 4from ..utils import (
63c55e9f 5 int_or_none,
63c55e9f 6 find_xpath_attr,
45cae3b0
RA
7 xpath_element,
8 xpath_text,
9 update_url_query,
5c2266df 10)
fa3ae234
PH
11
12
43518503 13class CBSBaseIE(ThePlatformFeedIE):
3e0c3d14 14 def _parse_smil_subtitles(self, smil, namespace=None, subtitles_lang='en'):
15 closed_caption_e = find_xpath_attr(smil, self._xpath_ns('.//param', namespace), 'name', 'ClosedCaptionURL')
16 return {
17 'en': [{
18 'ext': 'ttml',
19 'url': closed_caption_e.attrib['value'],
20 }]
21 } if closed_caption_e is not None and closed_caption_e.attrib.get('value') else []
22
23
24class CBSIE(CBSBaseIE):
81970792 25 _VALID_URL = r'(?:cbs:|https?://(?:www\.)?(?:cbs\.com/shows/[^/]+/video|colbertlateshow\.com/(?:video|podcasts))/)(?P<id>[\w-]+)'
fa3ae234 26
2871d489 27 _TESTS = [{
e42a692f
PH
28 'url': 'http://www.cbs.com/shows/garth-brooks/video/_u7W953k6la293J7EPTd9oHkSPs6Xn6_/connect-chat-feat-garth-brooks/',
29 'info_dict': {
63c55e9f 30 'id': '_u7W953k6la293J7EPTd9oHkSPs6Xn6_',
63c55e9f 31 'ext': 'mp4',
e42a692f
PH
32 'title': 'Connect Chat feat. Garth Brooks',
33 '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!',
34 'duration': 1495,
79ba9140 35 'timestamp': 1385585425,
36 'upload_date': '20131127',
37 'uploader': 'CBSI-NEW',
fa3ae234 38 },
dabe1570
RA
39 'params': {
40 # m3u8 download
41 'skip_download': True,
42 },
e42a692f 43 '_skip': 'Blocked outside the US',
9bf99891
S
44 }, {
45 'url': 'http://colbertlateshow.com/video/8GmB0oY0McANFvp2aEffk9jZZZ2YyXxy/the-colbeard/',
46 'only_matching': True,
47 }, {
9d581f3d 48 'url': 'http://www.colbertlateshow.com/podcasts/dYSwjqPs_X1tvbV_P2FcPWRa_qT6akTC/in-the-bad-room-with-stephen/',
9bf99891 49 'only_matching': True,
2871d489 50 }]
dabe1570 51
96820c1c 52 def _extract_video_info(self, content_id, site='cbs', mpx_acc=2198311517):
45cae3b0
RA
53 items_data = self._download_xml(
54 'http://can.cbs.com/thunder/player/videoPlayerService.php',
96820c1c 55 content_id, query={'partner': site, 'contentId': content_id})
45cae3b0
RA
56 video_data = xpath_element(items_data, './/item')
57 title = xpath_text(video_data, 'videoTitle', 'title', True)
96820c1c 58 tp_path = 'dJ5BDC/media/guid/%d/%s' % (mpx_acc, content_id)
45cae3b0
RA
59 tp_release_url = 'http://link.theplatform.com/s/' + tp_path
60
61 asset_types = []
62 subtitles = {}
63 formats = []
64 for item in items_data.findall('.//item'):
65 asset_type = xpath_text(item, 'assetType')
66 if not asset_type or asset_type in asset_types:
dabe1570 67 continue
45cae3b0
RA
68 asset_types.append(asset_type)
69 query = {
70 'mbr': 'true',
71 'assetTypes': asset_type,
72 }
73 if asset_type.startswith('HLS') or asset_type in ('OnceURL', 'StreamPack'):
74 query['formats'] = 'MPEG4,M3U'
75 elif asset_type in ('RTMP', 'WIFI', '3G'):
76 query['formats'] = 'MPEG4,FLV'
77 tp_formats, tp_subtitles = self._extract_theplatform_smil(
78 update_url_query(tp_release_url, query), content_id,
79 'Downloading %s SMIL data' % asset_type)
80 formats.extend(tp_formats)
81 subtitles = self._merge_subtitles(subtitles, tp_subtitles)
dabe1570 82 self._sort_formats(formats)
45cae3b0
RA
83
84 info = self._extract_theplatform_metadata(tp_path, content_id)
dabe1570 85 info.update({
45cae3b0
RA
86 'id': content_id,
87 'title': title,
88 'series': xpath_text(video_data, 'seriesTitle'),
89 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')),
90 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')),
91 'duration': int_or_none(xpath_text(video_data, 'videoLength'), 1000),
92 'thumbnail': xpath_text(video_data, 'previewImageURL'),
dabe1570
RA
93 'formats': formats,
94 'subtitles': subtitles,
dabe1570
RA
95 })
96 return info
63c55e9f 97
fa3ae234 98 def _real_extract(self, url):
43518503 99 content_id = self._match_id(url)
dabe1570 100 return self._extract_video_info(content_id)