]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/comedycentral.py
ed3986f313a149f0db4a69dc92762730297ced1a
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\.)?comedycentral\.com/
18 (video-clips|episodes|cc-studios|video-collections)
20 _FEED_URL
= 'http://comedycentral.com/feeds/mrss/'
23 'url': 'http://www.comedycentral.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother',
24 'md5': '4167875aae411f903b751a21f357f1ee',
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 / 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
"""^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport)
43 (?P<showname>thedailyshow|colbertnation)\.com/
44 (full-episodes/(?P<episode>.*)|
46 (the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
47 |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*)))|
49 extended-interviews/(?P<interID>[0-9]+)/playlist_tds_extended_(?P<interview_title>.*?)/.*?)))
52 'url': 'http://www.thedailyshow.com/watch/thu-december-13-2012/kristen-stewart',
54 'md5': '4e2f5cb088a83cd8cdb7756132f9739d',
56 "upload_date": "20121214",
57 "description": "Kristen Stewart",
58 "uploader": "thedailyshow",
59 "title": "thedailyshow-kristen-stewart part 1"
63 _available_formats
= ['3500', '2200', '1700', '1200', '750', '400']
83 def suitable(cls
, url
):
84 """Receives a URL and returns True if suitable for this IE."""
85 return re
.match(cls
._VALID
_URL
, url
, re
.VERBOSE
) is not None
88 def _transform_rtmp_url(rtmp_video_url
):
89 m
= re
.match(r
'^rtmpe?://.*?/(?P<finalid>gsp\.comedystor/.*)$', rtmp_video_url
)
91 raise ExtractorError('Cannot transform RTMP url')
92 base
= 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/'
93 return base
+ m
.group('finalid')
95 def _real_extract(self
, url
):
96 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
98 raise ExtractorError('Invalid URL: %s' % url
)
100 if mobj
.group('shortname'):
101 if mobj
.group('shortname') in ('tds', 'thedailyshow'):
102 url
= 'http://www.thedailyshow.com/full-episodes/'
104 url
= 'http://www.colbertnation.com/full-episodes/'
105 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
106 assert mobj
is not None
108 if mobj
.group('clip'):
109 if mobj
.group('showname') == 'thedailyshow':
110 epTitle
= mobj
.group('tdstitle')
112 epTitle
= mobj
.group('cntitle')
114 elif mobj
.group('interview'):
115 epTitle
= mobj
.group('interview_title')
118 dlNewest
= not mobj
.group('episode')
120 epTitle
= mobj
.group('showname')
122 epTitle
= mobj
.group('episode')
124 self
.report_extraction(epTitle
)
125 webpage
,htmlHandle
= self
._download
_webpage
_handle
(url
, epTitle
)
127 url
= htmlHandle
.geturl()
128 mobj
= re
.match(self
._VALID
_URL
, url
, re
.VERBOSE
)
130 raise ExtractorError('Invalid redirected URL: ' + url
)
131 if mobj
.group('episode') == '':
132 raise ExtractorError('Redirected URL is still not specific: ' + url
)
133 epTitle
= mobj
.group('episode')
135 mMovieParams
= re
.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage
)
137 if len(mMovieParams
) == 0:
138 # The Colbert Report embeds the information in a without
139 # a URL prefix; so extract the alternate reference
140 # and then add the URL prefix manually.
142 altMovieParams
= re
.findall('data-mgid="([^"]*(?:episode|video).*?:.*?)"', webpage
)
143 if len(altMovieParams
) == 0:
144 raise ExtractorError('unable to find Flash URL in webpage ' + url
)
146 mMovieParams
= [("http://media.mtvnservices.com/" + altMovieParams
[0], altMovieParams
[0])]
148 uri
= mMovieParams
[0][1]
149 indexUrl
= 'http://shadow.comedycentral.com/feeds/video_player/mrss/?' + compat_urllib_parse
.urlencode({'uri': uri
})
150 idoc
= self
._download
_xml
(indexUrl
, epTitle
,
151 'Downloading show index',
152 'unable to download episode index')
156 itemEls
= idoc
.findall('.//item')
157 for partNum
,itemEl
in enumerate(itemEls
):
158 mediaId
= itemEl
.findall('./guid')[0].text
159 shortMediaId
= mediaId
.split(':')[-1]
160 showId
= mediaId
.split(':')[-2].replace('.com', '')
161 officialTitle
= itemEl
.findall('./title')[0].text
162 officialDate
= unified_strdate(itemEl
.findall('./pubDate')[0].text
)
164 configUrl
= ('http://www.comedycentral.com/global/feeds/entertainment/media/mediaGenEntertainment.jhtml?' +
165 compat_urllib_parse
.urlencode({'uri': mediaId
}))
166 cdoc
= self
._download
_xml
(configUrl
, epTitle
,
167 'Downloading configuration for %s' % shortMediaId
)
170 for rendition
in cdoc
.findall('.//rendition'):
171 finfo
= (rendition
.attrib
['bitrate'], rendition
.findall('./src')[0].text
)
175 self
._downloader
.report_error('unable to download ' + mediaId
+ ': No videos found')
179 for format
, rtmp_video_url
in turls
:
180 w
, h
= self
._video
_dimensions
.get(format
, (None, None))
182 'url': self
._transform
_rtmp
_url
(rtmp_video_url
),
183 'ext': self
._video
_extensions
.get(format
, 'mp4'),
189 effTitle
= showId
+ '-' + epTitle
+ ' part ' + compat_str(partNum
+1)
194 'upload_date': officialDate
,
197 'description': compat_str(officialTitle
),