]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/comedycentral.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from .mtv
import MTVServicesInfoExtractor
16 class ComedyCentralIE(MTVServicesInfoExtractor
):
17 _VALID_URL
= r
'''(?x)https?://(?:www\.)?cc\.com/
18 (video-clips|episodes|cc-studios|video-collections|full-episodes)
20 _FEED_URL
= 'http://comedycentral.com/feeds/mrss/'
23 'url': 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother',
24 'md5': 'c4f48e9eda1b16dd10add0744344b6d8',
26 'id': 'cef0cbb3-e776-4bc9-b62e-8016deccb354',
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.',
34 class ComedyCentralShowsIE(InfoExtractor
):
35 IE_DESC
= 'The Daily Show / The Colbert Report'
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
41 _VALID_URL
= r
'''(?x)^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport)
43 (?P<showname>thedailyshow|thecolbertreport)\.(?:cc\.)?com/
44 ((?:full-)?episodes/(?:[0-9a-z]{6}/)?(?P<episode>.*)|
46 (?:(?:guests/[^/]+|videos|video-playlists|special-editions|news-team/[^/]+)/[^/]+/(?P<videotitle>[^/?#]+))
47 |(the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
48 |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*))
51 extended-interviews/(?P<interID>[0-9a-z]+)/(?:playlist_tds_extended_)?(?P<interview_title>.*?)(/.*?)?)))
54 'url': 'http://thedailyshow.cc.com/watch/thu-december-13-2012/kristen-stewart',
55 'md5': '4e2f5cb088a83cd8cdb7756132f9739d',
57 'id': 'ab9ab3e7-5a98-4dbe-8b21-551dc0523d55',
59 'upload_date': '20121213',
60 'description': 'Kristen Stewart learns to let loose in "On the Road."',
61 'uploader': 'thedailyshow',
62 'title': 'thedailyshow kristen-stewart part 1',
65 'url': 'http://thedailyshow.cc.com/extended-interviews/xm3fnq/andrew-napolitano-extended-interview',
66 'only_matching': True,
68 'url': 'http://thecolbertreport.cc.com/videos/29w6fx/-realhumanpraise-for-fox-news',
69 'only_matching': True,
71 'url': 'http://thecolbertreport.cc.com/videos/gh6urb/neil-degrasse-tyson-pt--1?xrs=eml_col_031114',
72 'only_matching': True,
74 'url': 'http://thedailyshow.cc.com/guests/michael-lewis/3efna8/exclusive---michael-lewis-extended-interview-pt--3',
75 'only_matching': True,
77 'url': 'http://thedailyshow.cc.com/episodes/sy7yv0/april-8--2014---denis-leary',
78 'only_matching': True,
80 'url': 'http://thecolbertreport.cc.com/episodes/8ase07/april-8--2014---jane-goodall',
81 'only_matching': True,
83 'url': 'http://thedailyshow.cc.com/video-playlists/npde3s/the-daily-show-19088-highlights',
84 'only_matching': True,
86 'url': 'http://thedailyshow.cc.com/special-editions/2l8fdb/special-edition---a-look-back-at-food',
87 'only_matching': True,
89 'url': 'http://thedailyshow.cc.com/news-team/michael-che/7wnfel/we-need-to-talk-about-israel',
90 'only_matching': True,
93 _available_formats
= ['3500', '2200', '1700', '1200', '750', '400']
103 _video_dimensions
= {
113 def _transform_rtmp_url(rtmp_video_url
):
114 m
= re
.match(r
'^rtmpe?://.*?/(?P<finalid>gsp\.comedystor/.*)$', rtmp_video_url
)
116 raise ExtractorError('Cannot transform RTMP url')
117 base
= 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/'
118 return base
+ m
.group('finalid')
120 def _real_extract(self
, url
):
121 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
123 raise ExtractorError('Invalid URL: %s' % url
)
125 if mobj
.group('shortname'):
126 if mobj
.group('shortname') in ('tds', 'thedailyshow'):
127 url
= 'http://thedailyshow.cc.com/full-episodes/'
129 url
= 'http://thecolbertreport.cc.com/full-episodes/'
130 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
131 assert mobj
is not None
133 if mobj
.group('clip'):
134 if mobj
.group('videotitle'):
135 epTitle
= mobj
.group('videotitle')
136 elif mobj
.group('showname') == 'thedailyshow':
137 epTitle
= mobj
.group('tdstitle')
139 epTitle
= mobj
.group('cntitle')
141 elif mobj
.group('interview'):
142 epTitle
= mobj
.group('interview_title')
145 dlNewest
= not mobj
.group('episode')
147 epTitle
= mobj
.group('showname')
149 epTitle
= mobj
.group('episode')
150 show_name
= mobj
.group('showname')
152 webpage
, htmlHandle
= self
._download
_webpage
_handle
(url
, epTitle
)
154 url
= htmlHandle
.geturl()
155 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
157 raise ExtractorError('Invalid redirected URL: ' + url
)
158 if mobj
.group('episode') == '':
159 raise ExtractorError('Redirected URL is still not specific: ' + url
)
160 epTitle
= (mobj
.group('episode') or mobj
.group('videotitle')).rpartition('/')[-1]
162 mMovieParams
= re
.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage
)
163 if len(mMovieParams
) == 0:
164 # The Colbert Report embeds the information in a without
165 # a URL prefix; so extract the alternate reference
166 # and then add the URL prefix manually.
168 altMovieParams
= re
.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage
)
169 if len(altMovieParams
) == 0:
170 raise ExtractorError('unable to find Flash URL in webpage ' + url
)
172 mMovieParams
= [("http://media.mtvnservices.com/" + altMovieParams
[0], altMovieParams
[0])]
174 uri
= mMovieParams
[0][1]
175 # Correct cc.com in uri
176 uri
= re
.sub(r
'(episode:[^.]+)(\.cc)?\.com', r
'\1.cc.com', uri
)
178 index_url
= 'http://%s.cc.com/feeds/mrss?%s' % (show_name
, compat_urllib_parse
.urlencode({'uri': uri}
))
179 idoc
= self
._download
_xml
(
181 'Downloading show index', 'Unable to download episode index')
183 title
= idoc
.find('./channel/title').text
184 description
= idoc
.find('./channel/description').text
187 item_els
= idoc
.findall('.//item')
188 for part_num
, itemEl
in enumerate(item_els
):
189 upload_date
= unified_strdate(itemEl
.findall('./pubDate')[0].text
)
190 thumbnail
= itemEl
.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib
.get('url')
192 content
= itemEl
.find('.//{http://search.yahoo.com/mrss/}content')
193 duration
= float_or_none(content
.attrib
.get('duration'))
194 mediagen_url
= content
.attrib
['url']
195 guid
= itemEl
.find('./guid').text
.rpartition(':')[-1]
197 cdoc
= self
._download
_xml
(
198 mediagen_url
, epTitle
,
199 'Downloading configuration for segment %d / %d' % (part_num
+ 1, len(item_els
)))
202 for rendition
in cdoc
.findall('.//rendition'):
203 finfo
= (rendition
.attrib
['bitrate'], rendition
.findall('./src')[0].text
)
207 for format
, rtmp_video_url
in turls
:
208 w
, h
= self
._video
_dimensions
.get(format
, (None, None))
210 'format_id': 'vhttp-%s' % format
,
211 'url': self
._transform
_rtmp
_url
(rtmp_video_url
),
212 'ext': self
._video
_extensions
.get(format
, 'mp4'),
216 'format_note': 'HTTP 400 at the moment (patches welcome!)',
220 'format_id': 'rtmp-%s' % format
,
221 'url': rtmp_video_url
.replace('viacomccstrm', 'viacommtvstrm'),
222 'ext': self
._video
_extensions
.get(format
, 'mp4'),
226 self
._sort
_formats
(formats
)
228 virtual_id
= show_name
+ ' ' + epTitle
+ ' part ' + compat_str(part_num
+ 1)
233 'uploader': show_name
,
234 'upload_date': upload_date
,
235 'duration': duration
,
236 'thumbnail': thumbnail
,
237 'description': description
,
243 'title': show_name
+ ' ' + title
,
244 'description': description
,