1 from __future__ import unicode_literals
5 from .theplatform import ThePlatformIE
14 class CBSBaseIE(ThePlatformIE):
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')
20 'url': closed_caption_e.attrib['value'],
22 } if closed_caption_e is not None and closed_caption_e.attrib.get('value') else []
25 class CBSIE(CBSBaseIE):
26 _VALID_URL = r'(?:cbs:(?P<content_id>\w+)|https?://(?:www\.)?(?:cbs\.com/shows/[^/]+/(?:video|artist)|colbertlateshow\.com/(?:video|podcasts))/[^/]+/(?P<display_id>[^/]+))'
29 'url': 'http://www.cbs.com/shows/garth-brooks/video/_u7W953k6la293J7EPTd9oHkSPs6Xn6_/connect-chat-feat-garth-brooks/',
31 'id': '_u7W953k6la293J7EPTd9oHkSPs6Xn6_',
32 'display_id': 'connect-chat-feat-garth-brooks',
34 'title': 'Connect Chat feat. Garth Brooks',
35 '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!',
37 'timestamp': 1385585425,
38 'upload_date': '20131127',
39 'uploader': 'CBSI-NEW',
43 'skip_download': True,
45 '_skip': 'Blocked outside the US',
47 'url': 'http://www.cbs.com/shows/liveonletterman/artist/221752/st-vincent/',
50 'display_id': 'st-vincent',
52 'title': 'Live on Letterman - St. Vincent',
53 'description': 'Live On Letterman: St. Vincent in concert from New York\'s Ed Sullivan Theater on Tuesday, July 16, 2014.',
58 'skip_download': True,
60 '_skip': 'Blocked outside the US',
62 'url': 'http://colbertlateshow.com/video/8GmB0oY0McANFvp2aEffk9jZZZ2YyXxy/the-colbeard/',
63 'only_matching': True,
65 'url': 'http://www.colbertlateshow.com/podcasts/dYSwjqPs_X1tvbV_P2FcPWRa_qT6akTC/in-the-bad-room-with-stephen/',
66 'only_matching': True,
68 TP_RELEASE_URL_TEMPLATE = 'http://link.theplatform.com/s/dJ5BDC/%s?mbr=true'
70 def _real_extract(self, url):
71 content_id, display_id = re.match(self._VALID_URL, url).groups()
73 webpage = self._download_webpage(url, display_id)
74 content_id = self._search_regex(
75 [r"video\.settings\.content_id\s*=\s*'([^']+)';", r"cbsplayer\.contentId\s*=\s*'([^']+)';"],
76 webpage, 'content id')
77 items_data = self._download_xml(
78 'http://can.cbs.com/thunder/player/videoPlayerService.php',
79 content_id, query={'partner': 'cbs', 'contentId': content_id})
80 video_data = xpath_element(items_data, './/item')
81 title = xpath_text(video_data, 'videoTitle', 'title', True)
85 for item in items_data.findall('.//item'):
86 pid = xpath_text(item, 'pid')
89 tp_release_url = self.TP_RELEASE_URL_TEMPLATE % pid
90 if '.m3u8' in xpath_text(item, 'contentUrl', default=''):
91 tp_release_url += '&manifest=m3u'
92 tp_formats, tp_subtitles = self._extract_theplatform_smil(
93 tp_release_url, content_id, 'Downloading %s SMIL data' % pid)
94 formats.extend(tp_formats)
95 subtitles = self._merge_subtitles(subtitles, tp_subtitles)
96 self._sort_formats(formats)
98 info = self.get_metadata('dJ5BDC/media/guid/2198311517/%s' % content_id, content_id)
101 'display_id': display_id,
103 'series': xpath_text(video_data, 'seriesTitle'),
104 'season_number': int_or_none(xpath_text(video_data, 'seasonNumber')),
105 'episode_number': int_or_none(xpath_text(video_data, 'episodeNumber')),
106 'duration': int_or_none(xpath_text(video_data, 'videoLength'), 1000),
107 'thumbnail': xpath_text(video_data, 'previewImageURL'),
109 'subtitles': subtitles,