]>
Commit | Line | Data |
---|---|---|
a4a02832 PH |
1 | from __future__ import unicode_literals |
2 | ||
ea63e499 | 3 | import re |
ea63e499 PH |
4 | |
5 | from .common import InfoExtractor | |
84db8181 | 6 | from .mtv import MTVServicesInfoExtractor |
ea63e499 PH |
7 | from ..utils import ( |
8 | compat_str, | |
9 | compat_urllib_parse, | |
ea63e499 | 10 | ExtractorError, |
43f775e4 | 11 | float_or_none, |
ea63e499 PH |
12 | unified_strdate, |
13 | ) | |
14 | ||
15 | ||
84db8181 | 16 | class ComedyCentralIE(MTVServicesInfoExtractor): |
b4c538b0 | 17 | _VALID_URL = r'''(?x)https?://(?:www\.)?cc\.com/ |
13059bce | 18 | (video-clips|episodes|cc-studios|video-collections|full-episodes) |
efa1739b | 19 | /(?P<title>.*)''' |
a4a02832 | 20 | _FEED_URL = 'http://comedycentral.com/feeds/mrss/' |
66cfab42 JMF |
21 | |
22 | _TEST = { | |
b4c538b0 | 23 | 'url': 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother', |
3ab34c60 | 24 | 'md5': 'c4f48e9eda1b16dd10add0744344b6d8', |
a4a02832 PH |
25 | 'info_dict': { |
26 | 'id': 'cef0cbb3-e776-4bc9-b62e-8016deccb354', | |
27 | 'ext': 'mp4', | |
28 | 'title': 'CC:Stand-Up|Greg Fitzsimmons: Life on Stage|Uncensored - Too Good of a Mother', | |
29 | 'description': 'After a certain point, breastfeeding becomes c**kblocking.', | |
66cfab42 JMF |
30 | }, |
31 | } | |
66cfab42 | 32 | |
66cfab42 JMF |
33 | |
34 | class ComedyCentralShowsIE(InfoExtractor): | |
99b380c3 | 35 | IE_DESC = 'The Daily Show / The Colbert Report' |
ea63e499 PH |
36 | # urls can be abbreviations like :thedailyshow or :colbert |
37 | # urls for episodes like: | |
38 | # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day | |
39 | # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news | |
40 | # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524 | |
99b380c3 PH |
41 | _VALID_URL = r'''(?x)^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport) |
42 | |https?://(:www\.)? | |
43 | (?P<showname>thedailyshow|thecolbertreport)\.(?:cc\.)?com/ | |
29e3e682 | 44 | ((?:full-)?episodes/(?:[0-9a-z]{6}/)?(?P<episode>.*)| |
ea63e499 | 45 | (?P<clip> |
7753cadb | 46 | (?:(?:guests/[^/]+|videos|video-playlists|special-editions)/[^/]+/(?P<videotitle>[^/?#]+)) |
16f4eb72 | 47 | |(the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?)) |
65148662 PH |
48 | |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*)) |
49 | )| | |
ddbfd0f0 | 50 | (?P<interview> |
24a2aac4 | 51 | extended-interviews/(?P<interID>[0-9a-z]+)/(?:playlist_tds_extended_)?(?P<interview_title>.*?)(/.*?)?))) |
65148662 | 52 | (?:[?#].*|$)''' |
7260ea07 | 53 | _TESTS = [{ |
99b380c3 | 54 | 'url': 'http://thedailyshow.cc.com/watch/thu-december-13-2012/kristen-stewart', |
a4a02832 PH |
55 | 'md5': '4e2f5cb088a83cd8cdb7756132f9739d', |
56 | 'info_dict': { | |
99b380c3 PH |
57 | 'id': 'ab9ab3e7-5a98-4dbe-8b21-551dc0523d55', |
58 | 'ext': 'mp4', | |
59 | 'upload_date': '20121213', | |
60 | 'description': 'Kristen Stewart learns to let loose in "On the Road."', | |
61 | 'uploader': 'thedailyshow', | |
97b55738 | 62 | 'title': 'thedailyshow kristen-stewart part 1', |
6f5ac90c | 63 | } |
7260ea07 PH |
64 | }, { |
65 | 'url': 'http://thedailyshow.cc.com/extended-interviews/xm3fnq/andrew-napolitano-extended-interview', | |
66 | 'only_matching': True, | |
67 | }, { | |
68 | 'url': 'http://thecolbertreport.cc.com/videos/29w6fx/-realhumanpraise-for-fox-news', | |
69 | 'only_matching': True, | |
70 | }, { | |
71 | 'url': 'http://thecolbertreport.cc.com/videos/gh6urb/neil-degrasse-tyson-pt--1?xrs=eml_col_031114', | |
72 | 'only_matching': True, | |
73 | }, { | |
74 | 'url': 'http://thedailyshow.cc.com/guests/michael-lewis/3efna8/exclusive---michael-lewis-extended-interview-pt--3', | |
75 | 'only_matching': True, | |
76 | }, { | |
77 | 'url': 'http://thedailyshow.cc.com/episodes/sy7yv0/april-8--2014---denis-leary', | |
78 | 'only_matching': True, | |
79 | }, { | |
80 | 'url': 'http://thecolbertreport.cc.com/episodes/8ase07/april-8--2014---jane-goodall', | |
81 | 'only_matching': True, | |
82 | }, { | |
83 | 'url': 'http://thedailyshow.cc.com/video-playlists/npde3s/the-daily-show-19088-highlights', | |
84 | 'only_matching': True, | |
85 | }, { | |
86 | 'url': 'http://thedailyshow.cc.com/special-editions/2l8fdb/special-edition---a-look-back-at-food', | |
87 | 'only_matching': True, | |
88 | }] | |
ea63e499 PH |
89 | |
90 | _available_formats = ['3500', '2200', '1700', '1200', '750', '400'] | |
91 | ||
92 | _video_extensions = { | |
93 | '3500': 'mp4', | |
94 | '2200': 'mp4', | |
95 | '1700': 'mp4', | |
96 | '1200': 'mp4', | |
97 | '750': 'mp4', | |
98 | '400': 'mp4', | |
99 | } | |
100 | _video_dimensions = { | |
d93bdee9 PH |
101 | '3500': (1280, 720), |
102 | '2200': (960, 540), | |
103 | '1700': (768, 432), | |
104 | '1200': (640, 360), | |
105 | '750': (512, 288), | |
106 | '400': (384, 216), | |
ea63e499 PH |
107 | } |
108 | ||
d93bdee9 PH |
109 | @staticmethod |
110 | def _transform_rtmp_url(rtmp_video_url): | |
57b62883 | 111 | m = re.match(r'^rtmpe?://.*?/(?P<finalid>gsp\.comedystor/.*)$', rtmp_video_url) |
d93bdee9 | 112 | if not m: |
a4a02832 | 113 | raise ExtractorError('Cannot transform RTMP url') |
d93bdee9 PH |
114 | base = 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/' |
115 | return base + m.group('finalid') | |
ea63e499 PH |
116 | |
117 | def _real_extract(self, url): | |
118 | mobj = re.match(self._VALID_URL, url, re.VERBOSE) | |
119 | if mobj is None: | |
a4a02832 | 120 | raise ExtractorError('Invalid URL: %s' % url) |
ea63e499 PH |
121 | |
122 | if mobj.group('shortname'): | |
123 | if mobj.group('shortname') in ('tds', 'thedailyshow'): | |
99b380c3 | 124 | url = 'http://thedailyshow.cc.com/full-episodes/' |
ea63e499 | 125 | else: |
99b380c3 | 126 | url = 'http://thecolbertreport.cc.com/full-episodes/' |
ea63e499 PH |
127 | mobj = re.match(self._VALID_URL, url, re.VERBOSE) |
128 | assert mobj is not None | |
129 | ||
130 | if mobj.group('clip'): | |
16f4eb72 PH |
131 | if mobj.group('videotitle'): |
132 | epTitle = mobj.group('videotitle') | |
133 | elif mobj.group('showname') == 'thedailyshow': | |
ea63e499 PH |
134 | epTitle = mobj.group('tdstitle') |
135 | else: | |
136 | epTitle = mobj.group('cntitle') | |
137 | dlNewest = False | |
ddbfd0f0 JMF |
138 | elif mobj.group('interview'): |
139 | epTitle = mobj.group('interview_title') | |
140 | dlNewest = False | |
ea63e499 PH |
141 | else: |
142 | dlNewest = not mobj.group('episode') | |
143 | if dlNewest: | |
144 | epTitle = mobj.group('showname') | |
145 | else: | |
146 | epTitle = mobj.group('episode') | |
99b380c3 | 147 | show_name = mobj.group('showname') |
ea63e499 | 148 | |
99b380c3 | 149 | webpage, htmlHandle = self._download_webpage_handle(url, epTitle) |
ea63e499 PH |
150 | if dlNewest: |
151 | url = htmlHandle.geturl() | |
152 | mobj = re.match(self._VALID_URL, url, re.VERBOSE) | |
153 | if mobj is None: | |
a4a02832 | 154 | raise ExtractorError('Invalid redirected URL: ' + url) |
ea63e499 | 155 | if mobj.group('episode') == '': |
a4a02832 | 156 | raise ExtractorError('Redirected URL is still not specific: ' + url) |
60b2dd12 | 157 | epTitle = (mobj.group('episode') or mobj.group('videotitle')).rpartition('/')[-1] |
ea63e499 PH |
158 | |
159 | mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage) | |
ea63e499 PH |
160 | if len(mMovieParams) == 0: |
161 | # The Colbert Report embeds the information in a without | |
162 | # a URL prefix; so extract the alternate reference | |
163 | # and then add the URL prefix manually. | |
164 | ||
24a2aac4 | 165 | altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage) |
ea63e499 | 166 | if len(altMovieParams) == 0: |
a4a02832 | 167 | raise ExtractorError('unable to find Flash URL in webpage ' + url) |
ea63e499 PH |
168 | else: |
169 | mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])] | |
170 | ||
171 | uri = mMovieParams[0][1] | |
865cbf4f PH |
172 | # Correct cc.com in uri |
173 | uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.cc.com', uri) | |
174 | ||
99b380c3 PH |
175 | index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse.urlencode({'uri': uri})) |
176 | idoc = self._download_xml( | |
177 | index_url, epTitle, | |
178 | 'Downloading show index', 'Unable to download episode index') | |
179 | ||
180 | title = idoc.find('./channel/title').text | |
181 | description = idoc.find('./channel/description').text | |
182 | ||
183 | entries = [] | |
184 | item_els = idoc.findall('.//item') | |
185 | for part_num, itemEl in enumerate(item_els): | |
186 | upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text) | |
187 | thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url') | |
188 | ||
189 | content = itemEl.find('.//{http://search.yahoo.com/mrss/}content') | |
43f775e4 | 190 | duration = float_or_none(content.attrib.get('duration')) |
99b380c3 | 191 | mediagen_url = content.attrib['url'] |
9ddaf4ef | 192 | guid = itemEl.find('./guid').text.rpartition(':')[-1] |
99b380c3 PH |
193 | |
194 | cdoc = self._download_xml( | |
195 | mediagen_url, epTitle, | |
196 | 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els))) | |
ea63e499 | 197 | |
ea63e499 PH |
198 | turls = [] |
199 | for rendition in cdoc.findall('.//rendition'): | |
200 | finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text) | |
201 | turls.append(finfo) | |
202 | ||
d93bdee9 PH |
203 | formats = [] |
204 | for format, rtmp_video_url in turls: | |
205 | w, h = self._video_dimensions.get(format, (None, None)) | |
206 | formats.append({ | |
99b380c3 | 207 | 'format_id': 'vhttp-%s' % format, |
d93bdee9 PH |
208 | 'url': self._transform_rtmp_url(rtmp_video_url), |
209 | 'ext': self._video_extensions.get(format, 'mp4'), | |
d93bdee9 PH |
210 | 'height': h, |
211 | 'width': w, | |
212 | }) | |
99b380c3 PH |
213 | formats.append({ |
214 | 'format_id': 'rtmp-%s' % format, | |
6db80ad2 | 215 | 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'), |
99b380c3 PH |
216 | 'ext': self._video_extensions.get(format, 'mp4'), |
217 | 'height': h, | |
218 | 'width': w, | |
219 | }) | |
220 | self._sort_formats(formats) | |
ea63e499 | 221 | |
34cbc7ee | 222 | virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1) |
99b380c3 PH |
223 | entries.append({ |
224 | 'id': guid, | |
225 | 'title': virtual_id, | |
d93bdee9 | 226 | 'formats': formats, |
99b380c3 PH |
227 | 'uploader': show_name, |
228 | 'upload_date': upload_date, | |
229 | 'duration': duration, | |
230 | 'thumbnail': thumbnail, | |
231 | 'description': description, | |
fb7abb31 | 232 | }) |
ea63e499 | 233 | |
99b380c3 PH |
234 | return { |
235 | '_type': 'playlist', | |
236 | 'entries': entries, | |
34cbc7ee | 237 | 'title': show_name + ' ' + title, |
99b380c3 PH |
238 | 'description': description, |
239 | } |