2 import xml.etree.ElementTree
4 from .common import InfoExtractor
5 from .mtv import MTVIE, _media_xml_tag
15 class ComedyCentralIE(MTVIE):
16 _VALID_URL = r'http://www.comedycentral.com/(video-clips|episodes|cc-studios)/(?P<title>.*)'
17 _FEED_URL = u'http://comedycentral.com/feeds/mrss/'
20 u'url': u'http://www.comedycentral.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother',
21 u'md5': u'4167875aae411f903b751a21f357f1ee',
23 u'id': u'cef0cbb3-e776-4bc9-b62e-8016deccb354',
25 u'title': u'Uncensored - Greg Fitzsimmons - Too Good of a Mother',
26 u'description': u'After a certain point, breastfeeding becomes c**kblocking.',
29 # Overwrite MTVIE properties we don't want
32 def _get_thumbnail_url(self, uri, itemdoc):
33 search_path = '%s/%s' % (_media_xml_tag('group'), _media_xml_tag('thumbnail'))
34 return itemdoc.find(search_path).attrib['url']
36 def _real_extract(self, url):
37 mobj = re.match(self._VALID_URL, url)
38 title = mobj.group('title')
39 webpage = self._download_webpage(url, title)
40 mgid = self._search_regex(r'data-mgid="(?P<mgid>mgid:.*?)"',
42 return self._get_videos_info(mgid)
45 class ComedyCentralShowsIE(InfoExtractor):
46 IE_DESC = u'The Daily Show / Colbert Report'
47 # urls can be abbreviations like :thedailyshow or :colbert
48 # urls for episodes like:
49 # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day
50 # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news
51 # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524
52 _VALID_URL = r"""^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport)
54 (?P<showname>thedailyshow|colbertnation)\.com/
55 (full-episodes/(?P<episode>.*)|
57 (the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
58 |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*)))|
60 extended-interviews/(?P<interID>[0-9]+)/playlist_tds_extended_(?P<interview_title>.*?)/.*?)))
63 u'url': u'http://www.thedailyshow.com/watch/thu-december-13-2012/kristen-stewart',
64 u'file': u'422212.mp4',
65 u'md5': u'4e2f5cb088a83cd8cdb7756132f9739d',
67 u"upload_date": u"20121214",
68 u"description": u"Kristen Stewart",
69 u"uploader": u"thedailyshow",
70 u"title": u"thedailyshow-kristen-stewart part 1"
74 _available_formats = ['3500', '2200', '1700', '1200', '750', '400']
94 def suitable(cls, url):
95 """Receives a URL and returns True if suitable for this IE."""
96 return re.match(cls._VALID_URL, url, re.VERBOSE) is not None
99 def _transform_rtmp_url(rtmp_video_url):
100 m = re.match(r'^rtmpe?://.*?/(?P<finalid>gsp.comedystor/.*)$', rtmp_video_url)
102 raise ExtractorError(u'Cannot transform RTMP url')
103 base = 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/'
104 return base + m.group('finalid')
106 def _real_extract(self, url):
107 mobj = re.match(self._VALID_URL, url, re.VERBOSE)
109 raise ExtractorError(u'Invalid URL: %s' % url)
111 if mobj.group('shortname'):
112 if mobj.group('shortname') in ('tds', 'thedailyshow'):
113 url = u'http://www.thedailyshow.com/full-episodes/'
115 url = u'http://www.colbertnation.com/full-episodes/'
116 mobj = re.match(self._VALID_URL, url, re.VERBOSE)
117 assert mobj is not None
119 if mobj.group('clip'):
120 if mobj.group('showname') == 'thedailyshow':
121 epTitle = mobj.group('tdstitle')
123 epTitle = mobj.group('cntitle')
125 elif mobj.group('interview'):
126 epTitle = mobj.group('interview_title')
129 dlNewest = not mobj.group('episode')
131 epTitle = mobj.group('showname')
133 epTitle = mobj.group('episode')
135 self.report_extraction(epTitle)
136 webpage,htmlHandle = self._download_webpage_handle(url, epTitle)
138 url = htmlHandle.geturl()
139 mobj = re.match(self._VALID_URL, url, re.VERBOSE)
141 raise ExtractorError(u'Invalid redirected URL: ' + url)
142 if mobj.group('episode') == '':
143 raise ExtractorError(u'Redirected URL is still not specific: ' + url)
144 epTitle = mobj.group('episode')
146 mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
148 if len(mMovieParams) == 0:
149 # The Colbert Report embeds the information in a without
150 # a URL prefix; so extract the alternate reference
151 # and then add the URL prefix manually.
153 altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video).*?:.*?)"', webpage)
154 if len(altMovieParams) == 0:
155 raise ExtractorError(u'unable to find Flash URL in webpage ' + url)
157 mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
159 uri = mMovieParams[0][1]
160 indexUrl = 'http://shadow.comedycentral.com/feeds/video_player/mrss/?' + compat_urllib_parse.urlencode({'uri': uri})
161 indexXml = self._download_webpage(indexUrl, epTitle,
162 u'Downloading show index',
163 u'unable to download episode index')
167 idoc = xml.etree.ElementTree.fromstring(indexXml)
168 itemEls = idoc.findall('.//item')
169 for partNum,itemEl in enumerate(itemEls):
170 mediaId = itemEl.findall('./guid')[0].text
171 shortMediaId = mediaId.split(':')[-1]
172 showId = mediaId.split(':')[-2].replace('.com', '')
173 officialTitle = itemEl.findall('./title')[0].text
174 officialDate = unified_strdate(itemEl.findall('./pubDate')[0].text)
176 configUrl = ('http://www.comedycentral.com/global/feeds/entertainment/media/mediaGenEntertainment.jhtml?' +
177 compat_urllib_parse.urlencode({'uri': mediaId}))
178 configXml = self._download_webpage(configUrl, epTitle,
179 u'Downloading configuration for %s' % shortMediaId)
181 cdoc = xml.etree.ElementTree.fromstring(configXml)
183 for rendition in cdoc.findall('.//rendition'):
184 finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
188 self._downloader.report_error(u'unable to download ' + mediaId + ': No videos found')
192 for format, rtmp_video_url in turls:
193 w, h = self._video_dimensions.get(format, (None, None))
195 'url': self._transform_rtmp_url(rtmp_video_url),
196 'ext': self._video_extensions.get(format, 'mp4'),
202 effTitle = showId + u'-' + epTitle + u' part ' + compat_str(partNum+1)
207 'upload_date': officialDate,
210 'description': compat_str(officialTitle),
213 # TODO: Remove when #980 has been merged
214 info.update(info['formats'][-1])