- mobj = re.match(self._VALID_URL, url)
-
- if mobj.group('shortname'):
- if mobj.group('shortname') in ('tds', 'thedailyshow'):
- url = 'http://thedailyshow.cc.com/full-episodes/'
- else:
- url = 'http://thecolbertreport.cc.com/full-episodes/'
- mobj = re.match(self._VALID_URL, url, re.VERBOSE)
- assert mobj is not None
-
- if mobj.group('clip'):
- if mobj.group('videotitle'):
- epTitle = mobj.group('videotitle')
- elif mobj.group('showname') == 'thedailyshow':
- epTitle = mobj.group('tdstitle')
- else:
- epTitle = mobj.group('cntitle')
- dlNewest = False
- elif mobj.group('interview'):
- epTitle = mobj.group('interview_title')
- dlNewest = False
- else:
- dlNewest = not mobj.group('episode')
- if dlNewest:
- epTitle = mobj.group('showname')
- else:
- epTitle = mobj.group('episode')
- show_name = mobj.group('showname')
-
- webpage, htmlHandle = self._download_webpage_handle(url, epTitle)
- if dlNewest:
- url = htmlHandle.geturl()
- mobj = re.match(self._VALID_URL, url, re.VERBOSE)
- if mobj is None:
- raise ExtractorError('Invalid redirected URL: ' + url)
- if mobj.group('episode') == '':
- raise ExtractorError('Redirected URL is still not specific: ' + url)
- epTitle = (mobj.group('episode') or mobj.group('videotitle')).rpartition('/')[-1]
-
- mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
- if len(mMovieParams) == 0:
- # The Colbert Report embeds the information in a without
- # a URL prefix; so extract the alternate reference
- # and then add the URL prefix manually.
-
- altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage)
- if len(altMovieParams) == 0:
- raise ExtractorError('unable to find Flash URL in webpage ' + url)
- else:
- mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
-
- uri = mMovieParams[0][1]
- # Correct cc.com in uri
- uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.cc.com', uri)
-
- index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse.urlencode({'uri': uri}))
- idoc = self._download_xml(
- index_url, epTitle,
- 'Downloading show index', 'Unable to download episode index')
-
- title = idoc.find('./channel/title').text
- description = idoc.find('./channel/description').text
-
- entries = []
- item_els = idoc.findall('.//item')
- for part_num, itemEl in enumerate(item_els):
- upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text)
- thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url')
-
- content = itemEl.find('.//{http://search.yahoo.com/mrss/}content')
- duration = float_or_none(content.attrib.get('duration'))
- mediagen_url = content.attrib['url']
- guid = itemEl.find('./guid').text.rpartition(':')[-1]
-
- cdoc = self._download_xml(
- mediagen_url, epTitle,
- 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els)))
-
- turls = []
- for rendition in cdoc.findall('.//rendition'):
- finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
- turls.append(finfo)
-
- formats = []
- for format, rtmp_video_url in turls:
- w, h = self._video_dimensions.get(format, (None, None))
- formats.append({
- 'format_id': 'vhttp-%s' % format,
- 'url': self._transform_rtmp_url(rtmp_video_url),
- 'ext': self._video_extensions.get(format, 'mp4'),
- 'height': h,
- 'width': w,
- })
- formats.append({
- 'format_id': 'rtmp-%s' % format,
- 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'),
- 'ext': self._video_extensions.get(format, 'mp4'),
- 'height': h,
- 'width': w,
- })
- self._sort_formats(formats)
-
- virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1)
- entries.append({
- 'id': guid,
- 'title': virtual_id,
- 'formats': formats,
- 'uploader': show_name,
- 'upload_date': upload_date,
- 'duration': duration,
- 'thumbnail': thumbnail,
- 'description': description,
- })
-
- return {
- '_type': 'playlist',
- 'entries': entries,
- 'title': show_name + ' ' + title,
- 'description': description,