]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/comedycentral.py
8d27af5e57348e56a924d1d633df8799343245e4
1 from __future__
import unicode_literals
5 from .mtv
import MTVServicesInfoExtractor
17 class ComedyCentralIE(MTVServicesInfoExtractor
):
18 _VALID_URL
= r
'''(?x)https?://(?:www\.)?cc\.com/
19 (video-clips|episodes|cc-studios|video-collections|full-episodes)
21 _FEED_URL
= 'http://comedycentral.com/feeds/mrss/'
24 'url': 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother',
25 'md5': 'c4f48e9eda1b16dd10add0744344b6d8',
27 'id': 'cef0cbb3-e776-4bc9-b62e-8016deccb354',
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.',
35 class ComedyCentralShowsIE(MTVServicesInfoExtractor
):
36 IE_DESC
= 'The Daily Show / The Colbert Report'
37 # urls can be abbreviations like :thedailyshow or :colbert
38 # urls for episodes like:
39 # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day
40 # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news
41 # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524
42 _VALID_URL
= r
'''(?x)^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport)
44 (?P<showname>thedailyshow|thecolbertreport)\.(?:cc\.)?com/
45 ((?:full-)?episodes/(?:[0-9a-z]{6}/)?(?P<episode>.*)|
47 (?:(?:guests/[^/]+|videos|video-playlists|special-editions|news-team/[^/]+)/[^/]+/(?P<videotitle>[^/?#]+))
48 |(the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
49 |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*))
52 extended-interviews/(?P<interID>[0-9a-z]+)/(?:playlist_tds_extended_)?(?P<interview_title>.*?)(/.*?)?)))
55 'url': 'http://thedailyshow.cc.com/watch/thu-december-13-2012/kristen-stewart',
56 'md5': '4e2f5cb088a83cd8cdb7756132f9739d',
58 'id': 'ab9ab3e7-5a98-4dbe-8b21-551dc0523d55',
60 'upload_date': '20121213',
61 'description': 'Kristen Stewart learns to let loose in "On the Road."',
62 'uploader': 'thedailyshow',
63 'title': 'thedailyshow kristen-stewart part 1',
66 'url': 'http://thedailyshow.cc.com/extended-interviews/xm3fnq/andrew-napolitano-extended-interview',
67 'only_matching': True,
69 'url': 'http://thecolbertreport.cc.com/videos/29w6fx/-realhumanpraise-for-fox-news',
70 'only_matching': True,
72 'url': 'http://thecolbertreport.cc.com/videos/gh6urb/neil-degrasse-tyson-pt--1?xrs=eml_col_031114',
73 'only_matching': True,
75 'url': 'http://thedailyshow.cc.com/guests/michael-lewis/3efna8/exclusive---michael-lewis-extended-interview-pt--3',
76 'only_matching': True,
78 'url': 'http://thedailyshow.cc.com/episodes/sy7yv0/april-8--2014---denis-leary',
79 'only_matching': True,
81 'url': 'http://thecolbertreport.cc.com/episodes/8ase07/april-8--2014---jane-goodall',
82 'only_matching': True,
84 'url': 'http://thedailyshow.cc.com/video-playlists/npde3s/the-daily-show-19088-highlights',
85 'only_matching': True,
87 'url': 'http://thedailyshow.cc.com/video-playlists/t6d9sg/the-daily-show-20038-highlights/be3cwo',
88 'only_matching': True,
90 'url': 'http://thedailyshow.cc.com/special-editions/2l8fdb/special-edition---a-look-back-at-food',
91 'only_matching': True,
93 'url': 'http://thedailyshow.cc.com/news-team/michael-che/7wnfel/we-need-to-talk-about-israel',
94 'only_matching': True,
97 _available_formats
= ['3500', '2200', '1700', '1200', '750', '400']
107 _video_dimensions
= {
116 def _real_extract(self
, url
):
117 mobj
= re
.match(self
._VALID
_URL
, url
)
119 if mobj
.group('shortname'):
120 if mobj
.group('shortname') in ('tds', 'thedailyshow'):
121 url
= 'http://thedailyshow.cc.com/full-episodes/'
123 url
= 'http://thecolbertreport.cc.com/full-episodes/'
124 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
125 assert mobj
is not None
127 if mobj
.group('clip'):
128 if mobj
.group('videotitle'):
129 epTitle
= mobj
.group('videotitle')
130 elif mobj
.group('showname') == 'thedailyshow':
131 epTitle
= mobj
.group('tdstitle')
133 epTitle
= mobj
.group('cntitle')
135 elif mobj
.group('interview'):
136 epTitle
= mobj
.group('interview_title')
139 dlNewest
= not mobj
.group('episode')
141 epTitle
= mobj
.group('showname')
143 epTitle
= mobj
.group('episode')
144 show_name
= mobj
.group('showname')
146 webpage
, htmlHandle
= self
._download
_webpage
_handle
(url
, epTitle
)
148 url
= htmlHandle
.geturl()
149 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
151 raise ExtractorError('Invalid redirected URL: ' + url
)
152 if mobj
.group('episode') == '':
153 raise ExtractorError('Redirected URL is still not specific: ' + url
)
154 epTitle
= (mobj
.group('episode') or mobj
.group('videotitle')).rpartition('/')[-1]
156 mMovieParams
= re
.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage
)
157 if len(mMovieParams
) == 0:
158 # The Colbert Report embeds the information in a without
159 # a URL prefix; so extract the alternate reference
160 # and then add the URL prefix manually.
162 altMovieParams
= re
.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage
)
163 if len(altMovieParams
) == 0:
164 raise ExtractorError('unable to find Flash URL in webpage ' + url
)
166 mMovieParams
= [("http://media.mtvnservices.com/" + altMovieParams
[0], altMovieParams
[0])]
168 uri
= mMovieParams
[0][1]
169 # Correct cc.com in uri
170 uri
= re
.sub(r
'(episode:[^.]+)(\.cc)?\.com', r
'\1.cc.com', uri
)
172 index_url
= 'http://%s.cc.com/feeds/mrss?%s' % (show_name
, compat_urllib_parse
.urlencode({'uri': uri
}))
173 idoc
= self
._download
_xml
(
175 'Downloading show index', 'Unable to download episode index')
177 title
= idoc
.find('./channel/title').text
178 description
= idoc
.find('./channel/description').text
181 item_els
= idoc
.findall('.//item')
182 for part_num
, itemEl
in enumerate(item_els
):
183 upload_date
= unified_strdate(itemEl
.findall('./pubDate')[0].text
)
184 thumbnail
= itemEl
.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib
.get('url')
186 content
= itemEl
.find('.//{http://search.yahoo.com/mrss/}content')
187 duration
= float_or_none(content
.attrib
.get('duration'))
188 mediagen_url
= content
.attrib
['url']
189 guid
= itemEl
.find('./guid').text
.rpartition(':')[-1]
191 cdoc
= self
._download
_xml
(
192 mediagen_url
, epTitle
,
193 'Downloading configuration for segment %d / %d' % (part_num
+ 1, len(item_els
)))
196 for rendition
in cdoc
.findall('.//rendition'):
197 finfo
= (rendition
.attrib
['bitrate'], rendition
.findall('./src')[0].text
)
201 for format
, rtmp_video_url
in turls
:
202 w
, h
= self
._video
_dimensions
.get(format
, (None, None))
204 'format_id': 'vhttp-%s' % format
,
205 'url': self
._transform
_rtmp
_url
(rtmp_video_url
),
206 'ext': self
._video
_extensions
.get(format
, 'mp4'),
211 'format_id': 'rtmp-%s' % format
,
212 'url': rtmp_video_url
.replace('viacomccstrm', 'viacommtvstrm'),
213 'ext': self
._video
_extensions
.get(format
, 'mp4'),
217 self
._sort
_formats
(formats
)
219 virtual_id
= show_name
+ ' ' + epTitle
+ ' part ' + compat_str(part_num
+ 1)
224 'uploader': show_name
,
225 'upload_date': upload_date
,
226 'duration': duration
,
227 'thumbnail': thumbnail
,
228 'description': description
,
234 'title': show_name
+ ' ' + title
,
235 'description': description
,