]>
Commit | Line | Data |
---|---|---|
a4a02832 PH |
1 | from __future__ import unicode_literals |
2 | ||
ea63e499 | 3 | import re |
ea63e499 | 4 | |
84db8181 | 5 | from .mtv import MTVServicesInfoExtractor |
1cc79574 | 6 | from ..compat import ( |
ea63e499 | 7 | compat_str, |
15707c7e | 8 | compat_urllib_parse_urlencode, |
1cc79574 PH |
9 | ) |
10 | from ..utils import ( | |
ea63e499 | 11 | ExtractorError, |
43f775e4 | 12 | float_or_none, |
ea63e499 PH |
13 | unified_strdate, |
14 | ) | |
15 | ||
16 | ||
84db8181 | 17 | class ComedyCentralIE(MTVServicesInfoExtractor): |
b4c538b0 | 18 | _VALID_URL = r'''(?x)https?://(?:www\.)?cc\.com/ |
70232512 | 19 | (video-clips|episodes|cc-studios|video-collections|full-episodes|shows) |
efa1739b | 20 | /(?P<title>.*)''' |
a4a02832 | 21 | _FEED_URL = 'http://comedycentral.com/feeds/mrss/' |
66cfab42 | 22 | |
70232512 | 23 | _TESTS = [{ |
b4c538b0 | 24 | 'url': 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother', |
3ab34c60 | 25 | 'md5': 'c4f48e9eda1b16dd10add0744344b6d8', |
a4a02832 PH |
26 | 'info_dict': { |
27 | 'id': 'cef0cbb3-e776-4bc9-b62e-8016deccb354', | |
28 | 'ext': 'mp4', | |
29 | 'title': 'CC:Stand-Up|Greg Fitzsimmons: Life on Stage|Uncensored - Too Good of a Mother', | |
30 | 'description': 'After a certain point, breastfeeding becomes c**kblocking.', | |
66cfab42 | 31 | }, |
70232512 JMF |
32 | }, { |
33 | 'url': 'http://www.cc.com/shows/the-daily-show-with-trevor-noah/interviews/6yx39d/exclusive-rand-paul-extended-interview', | |
34 | 'only_matching': True, | |
35 | }] | |
66cfab42 | 36 | |
66cfab42 | 37 | |
5fee0eea | 38 | class ComedyCentralShowsIE(MTVServicesInfoExtractor): |
99b380c3 | 39 | IE_DESC = 'The Daily Show / The Colbert Report' |
650ab5be | 40 | # urls can be abbreviations like :thedailyshow |
ea63e499 PH |
41 | # urls for episodes like: |
42 | # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day | |
43 | # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news | |
44 | # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524 | |
650ab5be | 45 | _VALID_URL = r'''(?x)^(:(?P<shortname>tds|thedailyshow) |
99b380c3 | 46 | |https?://(:www\.)? |
c8831015 | 47 | (?P<showname>thedailyshow|thecolbertreport|tosh)\.(?:cc\.)?com/ |
29e3e682 | 48 | ((?:full-)?episodes/(?:[0-9a-z]{6}/)?(?P<episode>.*)| |
ea63e499 | 49 | (?P<clip> |
0150a00f | 50 | (?:(?:guests/[^/]+|videos|video-(?:clips|playlists)|special-editions|news-team/[^/]+)/[^/]+/(?P<videotitle>[^/?#]+)) |
16f4eb72 | 51 | |(the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?)) |
65148662 PH |
52 | |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*)) |
53 | )| | |
ddbfd0f0 | 54 | (?P<interview> |
91755ee3 PH |
55 | extended-interviews/(?P<interID>[0-9a-z]+)/ |
56 | (?:playlist_tds_extended_)?(?P<interview_title>[^/?#]*?) | |
57 | (?:/[^/?#]?|[?#]|$)))) | |
27d67ea2 | 58 | ''' |
7260ea07 | 59 | _TESTS = [{ |
99b380c3 | 60 | 'url': 'http://thedailyshow.cc.com/watch/thu-december-13-2012/kristen-stewart', |
a4a02832 PH |
61 | 'md5': '4e2f5cb088a83cd8cdb7756132f9739d', |
62 | 'info_dict': { | |
99b380c3 PH |
63 | 'id': 'ab9ab3e7-5a98-4dbe-8b21-551dc0523d55', |
64 | 'ext': 'mp4', | |
65 | 'upload_date': '20121213', | |
66 | 'description': 'Kristen Stewart learns to let loose in "On the Road."', | |
67 | 'uploader': 'thedailyshow', | |
97b55738 | 68 | 'title': 'thedailyshow kristen-stewart part 1', |
6f5ac90c | 69 | } |
91755ee3 PH |
70 | }, { |
71 | 'url': 'http://thedailyshow.cc.com/extended-interviews/b6364d/sarah-chayes-extended-interview', | |
72 | 'info_dict': { | |
73 | 'id': 'sarah-chayes-extended-interview', | |
74 | 'description': 'Carnegie Endowment Senior Associate Sarah Chayes discusses how corrupt institutions function throughout the world in her book "Thieves of State: Why Corruption Threatens Global Security."', | |
75 | 'title': 'thedailyshow Sarah Chayes Extended Interview', | |
76 | }, | |
e41b1f73 JMF |
77 | 'playlist': [ |
78 | { | |
79 | 'info_dict': { | |
80 | 'id': '0baad492-cbec-4ec1-9e50-ad91c291127f', | |
81 | 'ext': 'mp4', | |
82 | 'upload_date': '20150129', | |
83 | 'description': 'Carnegie Endowment Senior Associate Sarah Chayes discusses how corrupt institutions function throughout the world in her book "Thieves of State: Why Corruption Threatens Global Security."', | |
84 | 'uploader': 'thedailyshow', | |
85 | 'title': 'thedailyshow sarah-chayes-extended-interview part 1', | |
86 | }, | |
87 | }, | |
88 | { | |
89 | 'info_dict': { | |
90 | 'id': '1e4fb91b-8ce7-4277-bd7c-98c9f1bbd283', | |
91 | 'ext': 'mp4', | |
92 | 'upload_date': '20150129', | |
93 | 'description': 'Carnegie Endowment Senior Associate Sarah Chayes discusses how corrupt institutions function throughout the world in her book "Thieves of State: Why Corruption Threatens Global Security."', | |
94 | 'uploader': 'thedailyshow', | |
95 | 'title': 'thedailyshow sarah-chayes-extended-interview part 2', | |
96 | }, | |
97 | }, | |
98 | ], | |
91755ee3 PH |
99 | 'params': { |
100 | 'skip_download': True, | |
101 | }, | |
7260ea07 PH |
102 | }, { |
103 | 'url': 'http://thedailyshow.cc.com/extended-interviews/xm3fnq/andrew-napolitano-extended-interview', | |
104 | 'only_matching': True, | |
105 | }, { | |
106 | 'url': 'http://thecolbertreport.cc.com/videos/29w6fx/-realhumanpraise-for-fox-news', | |
107 | 'only_matching': True, | |
108 | }, { | |
109 | 'url': 'http://thecolbertreport.cc.com/videos/gh6urb/neil-degrasse-tyson-pt--1?xrs=eml_col_031114', | |
110 | 'only_matching': True, | |
111 | }, { | |
112 | 'url': 'http://thedailyshow.cc.com/guests/michael-lewis/3efna8/exclusive---michael-lewis-extended-interview-pt--3', | |
113 | 'only_matching': True, | |
114 | }, { | |
115 | 'url': 'http://thedailyshow.cc.com/episodes/sy7yv0/april-8--2014---denis-leary', | |
116 | 'only_matching': True, | |
117 | }, { | |
118 | 'url': 'http://thecolbertreport.cc.com/episodes/8ase07/april-8--2014---jane-goodall', | |
119 | 'only_matching': True, | |
120 | }, { | |
121 | 'url': 'http://thedailyshow.cc.com/video-playlists/npde3s/the-daily-show-19088-highlights', | |
122 | 'only_matching': True, | |
27d67ea2 PH |
123 | }, { |
124 | 'url': 'http://thedailyshow.cc.com/video-playlists/t6d9sg/the-daily-show-20038-highlights/be3cwo', | |
125 | 'only_matching': True, | |
7260ea07 PH |
126 | }, { |
127 | 'url': 'http://thedailyshow.cc.com/special-editions/2l8fdb/special-edition---a-look-back-at-food', | |
128 | 'only_matching': True, | |
4c59dc4c PH |
129 | }, { |
130 | 'url': 'http://thedailyshow.cc.com/news-team/michael-che/7wnfel/we-need-to-talk-about-israel', | |
131 | 'only_matching': True, | |
0150a00f S |
132 | }, { |
133 | 'url': 'http://tosh.cc.com/video-clips/68g93d/twitter-users-share-summer-plans', | |
134 | 'only_matching': True, | |
7260ea07 | 135 | }] |
ea63e499 PH |
136 | |
137 | _available_formats = ['3500', '2200', '1700', '1200', '750', '400'] | |
138 | ||
139 | _video_extensions = { | |
140 | '3500': 'mp4', | |
141 | '2200': 'mp4', | |
142 | '1700': 'mp4', | |
143 | '1200': 'mp4', | |
144 | '750': 'mp4', | |
145 | '400': 'mp4', | |
146 | } | |
147 | _video_dimensions = { | |
d93bdee9 PH |
148 | '3500': (1280, 720), |
149 | '2200': (960, 540), | |
150 | '1700': (768, 432), | |
151 | '1200': (640, 360), | |
152 | '750': (512, 288), | |
153 | '400': (384, 216), | |
ea63e499 PH |
154 | } |
155 | ||
ea63e499 | 156 | def _real_extract(self, url): |
6adeffa7 | 157 | mobj = re.match(self._VALID_URL, url) |
ea63e499 PH |
158 | |
159 | if mobj.group('shortname'): | |
c596ce91 | 160 | return self.url_result('http://www.cc.com/shows/the-daily-show-with-trevor-noah/full-episodes') |
ea63e499 PH |
161 | |
162 | if mobj.group('clip'): | |
16f4eb72 PH |
163 | if mobj.group('videotitle'): |
164 | epTitle = mobj.group('videotitle') | |
165 | elif mobj.group('showname') == 'thedailyshow': | |
ea63e499 PH |
166 | epTitle = mobj.group('tdstitle') |
167 | else: | |
168 | epTitle = mobj.group('cntitle') | |
169 | dlNewest = False | |
ddbfd0f0 JMF |
170 | elif mobj.group('interview'): |
171 | epTitle = mobj.group('interview_title') | |
172 | dlNewest = False | |
ea63e499 PH |
173 | else: |
174 | dlNewest = not mobj.group('episode') | |
175 | if dlNewest: | |
176 | epTitle = mobj.group('showname') | |
177 | else: | |
178 | epTitle = mobj.group('episode') | |
99b380c3 | 179 | show_name = mobj.group('showname') |
ea63e499 | 180 | |
99b380c3 | 181 | webpage, htmlHandle = self._download_webpage_handle(url, epTitle) |
ea63e499 PH |
182 | if dlNewest: |
183 | url = htmlHandle.geturl() | |
184 | mobj = re.match(self._VALID_URL, url, re.VERBOSE) | |
185 | if mobj is None: | |
a4a02832 | 186 | raise ExtractorError('Invalid redirected URL: ' + url) |
ea63e499 | 187 | if mobj.group('episode') == '': |
a4a02832 | 188 | raise ExtractorError('Redirected URL is still not specific: ' + url) |
60b2dd12 | 189 | epTitle = (mobj.group('episode') or mobj.group('videotitle')).rpartition('/')[-1] |
ea63e499 PH |
190 | |
191 | mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage) | |
ea63e499 PH |
192 | if len(mMovieParams) == 0: |
193 | # The Colbert Report embeds the information in a without | |
194 | # a URL prefix; so extract the alternate reference | |
195 | # and then add the URL prefix manually. | |
196 | ||
24a2aac4 | 197 | altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage) |
ea63e499 | 198 | if len(altMovieParams) == 0: |
a4a02832 | 199 | raise ExtractorError('unable to find Flash URL in webpage ' + url) |
ea63e499 | 200 | else: |
611c1dd9 | 201 | mMovieParams = [('http://media.mtvnservices.com/' + altMovieParams[0], altMovieParams[0])] |
ea63e499 PH |
202 | |
203 | uri = mMovieParams[0][1] | |
865cbf4f | 204 | # Correct cc.com in uri |
7691a7a3 | 205 | uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.com', uri) |
865cbf4f | 206 | |
15707c7e | 207 | index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse_urlencode({'uri': uri})) |
99b380c3 PH |
208 | idoc = self._download_xml( |
209 | index_url, epTitle, | |
210 | 'Downloading show index', 'Unable to download episode index') | |
211 | ||
212 | title = idoc.find('./channel/title').text | |
213 | description = idoc.find('./channel/description').text | |
214 | ||
215 | entries = [] | |
216 | item_els = idoc.findall('.//item') | |
217 | for part_num, itemEl in enumerate(item_els): | |
218 | upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text) | |
219 | thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url') | |
220 | ||
221 | content = itemEl.find('.//{http://search.yahoo.com/mrss/}content') | |
43f775e4 | 222 | duration = float_or_none(content.attrib.get('duration')) |
99b380c3 | 223 | mediagen_url = content.attrib['url'] |
9ddaf4ef | 224 | guid = itemEl.find('./guid').text.rpartition(':')[-1] |
99b380c3 PH |
225 | |
226 | cdoc = self._download_xml( | |
227 | mediagen_url, epTitle, | |
228 | 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els))) | |
ea63e499 | 229 | |
ea63e499 PH |
230 | turls = [] |
231 | for rendition in cdoc.findall('.//rendition'): | |
232 | finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text) | |
233 | turls.append(finfo) | |
234 | ||
d93bdee9 PH |
235 | formats = [] |
236 | for format, rtmp_video_url in turls: | |
237 | w, h = self._video_dimensions.get(format, (None, None)) | |
238 | formats.append({ | |
99b380c3 | 239 | 'format_id': 'vhttp-%s' % format, |
d93bdee9 PH |
240 | 'url': self._transform_rtmp_url(rtmp_video_url), |
241 | 'ext': self._video_extensions.get(format, 'mp4'), | |
d93bdee9 PH |
242 | 'height': h, |
243 | 'width': w, | |
244 | }) | |
99b380c3 PH |
245 | formats.append({ |
246 | 'format_id': 'rtmp-%s' % format, | |
6db80ad2 | 247 | 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'), |
99b380c3 PH |
248 | 'ext': self._video_extensions.get(format, 'mp4'), |
249 | 'height': h, | |
250 | 'width': w, | |
251 | }) | |
252 | self._sort_formats(formats) | |
ea63e499 | 253 | |
2e241242 PM |
254 | subtitles = self._extract_subtitles(cdoc, guid) |
255 | ||
34cbc7ee | 256 | virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1) |
99b380c3 PH |
257 | entries.append({ |
258 | 'id': guid, | |
259 | 'title': virtual_id, | |
d93bdee9 | 260 | 'formats': formats, |
99b380c3 PH |
261 | 'uploader': show_name, |
262 | 'upload_date': upload_date, | |
263 | 'duration': duration, | |
264 | 'thumbnail': thumbnail, | |
265 | 'description': description, | |
2e241242 | 266 | 'subtitles': subtitles, |
fb7abb31 | 267 | }) |
ea63e499 | 268 | |
99b380c3 PH |
269 | return { |
270 | '_type': 'playlist', | |
91755ee3 | 271 | 'id': epTitle, |
99b380c3 | 272 | 'entries': entries, |
34cbc7ee | 273 | 'title': show_name + ' ' + title, |
99b380c3 PH |
274 | 'description': description, |
275 | } |