]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/comedycentral.py
27bd8256e6bf6dfb8dc7ae7997a29c2162d863d2
3 from .common
import InfoExtractor
4 from .mtv
import MTVServicesInfoExtractor
14 class ComedyCentralIE(MTVServicesInfoExtractor
):
15 _VALID_URL
= r
'''(?x)https?://(?:www.)?comedycentral.com/
16 (video-clips|episodes|cc-studios|video-collections)
18 _FEED_URL
= u
'http://comedycentral.com/feeds/mrss/'
21 u
'url': u
'http://www.comedycentral.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother',
22 u
'md5': u
'4167875aae411f903b751a21f357f1ee',
24 u
'id': u
'cef0cbb3-e776-4bc9-b62e-8016deccb354',
26 u
'title': u
'Uncensored - Greg Fitzsimmons - Too Good of a Mother',
27 u
'description': u
'After a certain point, breastfeeding becomes c**kblocking.',
31 def _real_extract(self
, url
):
32 mobj
= re
.match(self
._VALID
_URL
, url
)
33 title
= mobj
.group('title')
34 webpage
= self
._download
_webpage
(url
, title
)
35 mgid
= self
._search
_regex
(r
'data-mgid="(?P<mgid>mgid:.*?)"',
37 return self
._get
_videos
_info
(mgid
)
40 class ComedyCentralShowsIE(InfoExtractor
):
41 IE_DESC
= u
'The Daily Show / Colbert Report'
42 # urls can be abbreviations like :thedailyshow or :colbert
43 # urls for episodes like:
44 # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day
45 # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news
46 # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524
47 _VALID_URL
= r
"""^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport)
49 (?P<showname>thedailyshow|colbertnation)\.com/
50 (full-episodes/(?P<episode>.*)|
52 (the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
53 |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*)))|
55 extended-interviews/(?P<interID>[0-9]+)/playlist_tds_extended_(?P<interview_title>.*?)/.*?)))
58 u
'url': u
'http://www.thedailyshow.com/watch/thu-december-13-2012/kristen-stewart',
59 u
'file': u
'422212.mp4',
60 u
'md5': u
'4e2f5cb088a83cd8cdb7756132f9739d',
62 u
"upload_date": u
"20121214",
63 u
"description": u
"Kristen Stewart",
64 u
"uploader": u
"thedailyshow",
65 u
"title": u
"thedailyshow-kristen-stewart part 1"
69 _available_formats
= ['3500', '2200', '1700', '1200', '750', '400']
89 def suitable(cls
, url
):
90 """Receives a URL and returns True if suitable for this IE."""
91 return re
.match(cls
._VALID
_URL
, url
, re
.VERBOSE
) is not None
94 def _transform_rtmp_url(rtmp_video_url
):
95 m
= re
.match(r
'^rtmpe?://.*?/(?P<finalid>gsp.comedystor/.*)$', rtmp_video_url
)
97 raise ExtractorError(u
'Cannot transform RTMP url')
98 base
= 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/'
99 return base
+ m
.group('finalid')
101 def _real_extract(self
, url
):
102 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
104 raise ExtractorError(u
'Invalid URL: %s' % url
)
106 if mobj
.group('shortname'):
107 if mobj
.group('shortname') in ('tds', 'thedailyshow'):
108 url
= u
'http://www.thedailyshow.com/full-episodes/'
110 url
= u
'http://www.colbertnation.com/full-episodes/'
111 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
112 assert mobj
is not None
114 if mobj
.group('clip'):
115 if mobj
.group('showname') == 'thedailyshow':
116 epTitle
= mobj
.group('tdstitle')
118 epTitle
= mobj
.group('cntitle')
120 elif mobj
.group('interview'):
121 epTitle
= mobj
.group('interview_title')
124 dlNewest
= not mobj
.group('episode')
126 epTitle
= mobj
.group('showname')
128 epTitle
= mobj
.group('episode')
130 self
.report_extraction(epTitle
)
131 webpage
,htmlHandle
= self
._download
_webpage
_handle
(url
, epTitle
)
133 url
= htmlHandle
.geturl()
134 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
136 raise ExtractorError(u
'Invalid redirected URL: ' + url
)
137 if mobj
.group('episode') == '':
138 raise ExtractorError(u
'Redirected URL is still not specific: ' + url
)
139 epTitle
= mobj
.group('episode')
141 mMovieParams
= re
.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage
)
143 if len(mMovieParams
) == 0:
144 # The Colbert Report embeds the information in a without
145 # a URL prefix; so extract the alternate reference
146 # and then add the URL prefix manually.
148 altMovieParams
= re
.findall('data-mgid="([^"]*(?:episode|video).*?:.*?)"', webpage
)
149 if len(altMovieParams
) == 0:
150 raise ExtractorError(u
'unable to find Flash URL in webpage ' + url
)
152 mMovieParams
= [("http://media.mtvnservices.com/" + altMovieParams
[0], altMovieParams
[0])]
154 uri
= mMovieParams
[0][1]
155 indexUrl
= 'http://shadow.comedycentral.com/feeds/video_player/mrss/?' + compat_urllib_parse
.urlencode({'uri': uri
})
156 idoc
= self
._download
_xml
(indexUrl
, epTitle
,
157 u
'Downloading show index',
158 u
'unable to download episode index')
162 itemEls
= idoc
.findall('.//item')
163 for partNum
,itemEl
in enumerate(itemEls
):
164 mediaId
= itemEl
.findall('./guid')[0].text
165 shortMediaId
= mediaId
.split(':')[-1]
166 showId
= mediaId
.split(':')[-2].replace('.com', '')
167 officialTitle
= itemEl
.findall('./title')[0].text
168 officialDate
= unified_strdate(itemEl
.findall('./pubDate')[0].text
)
170 configUrl
= ('http://www.comedycentral.com/global/feeds/entertainment/media/mediaGenEntertainment.jhtml?' +
171 compat_urllib_parse
.urlencode({'uri': mediaId
}))
172 cdoc
= self
._download
_xml
(configUrl
, epTitle
,
173 u
'Downloading configuration for %s' % shortMediaId
)
176 for rendition
in cdoc
.findall('.//rendition'):
177 finfo
= (rendition
.attrib
['bitrate'], rendition
.findall('./src')[0].text
)
181 self
._downloader
.report_error(u
'unable to download ' + mediaId
+ ': No videos found')
185 for format
, rtmp_video_url
in turls
:
186 w
, h
= self
._video
_dimensions
.get(format
, (None, None))
188 'url': self
._transform
_rtmp
_url
(rtmp_video_url
),
189 'ext': self
._video
_extensions
.get(format
, 'mp4'),
195 effTitle
= showId
+ u
'-' + epTitle
+ u
' part ' + compat_str(partNum
+1)
200 'upload_date': officialDate
,
203 'description': compat_str(officialTitle
),