You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
9.7 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .mtv import MTVServicesInfoExtractor
  4. from ..compat import (
  5. compat_str,
  6. compat_urllib_parse,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. float_or_none,
  11. unified_strdate,
  12. )
  13. class ComedyCentralIE(MTVServicesInfoExtractor):
  14. _VALID_URL = r'''(?x)https?://(?:www\.)?cc\.com/
  15. (video-clips|episodes|cc-studios|video-collections|full-episodes)
  16. /(?P<title>.*)'''
  17. _FEED_URL = 'http://comedycentral.com/feeds/mrss/'
  18. _TEST = {
  19. 'url': 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother',
  20. 'md5': 'c4f48e9eda1b16dd10add0744344b6d8',
  21. 'info_dict': {
  22. 'id': 'cef0cbb3-e776-4bc9-b62e-8016deccb354',
  23. 'ext': 'mp4',
  24. 'title': 'CC:Stand-Up|Greg Fitzsimmons: Life on Stage|Uncensored - Too Good of a Mother',
  25. 'description': 'After a certain point, breastfeeding becomes c**kblocking.',
  26. },
  27. }
  28. class ComedyCentralShowsIE(MTVServicesInfoExtractor):
  29. IE_DESC = 'The Daily Show / The Colbert Report'
  30. # urls can be abbreviations like :thedailyshow or :colbert
  31. # urls for episodes like:
  32. # or urls for clips like: http://www.thedailyshow.com/watch/mon-december-10-2012/any-given-gun-day
  33. # or: http://www.colbertnation.com/the-colbert-report-videos/421667/november-29-2012/moon-shattering-news
  34. # or: http://www.colbertnation.com/the-colbert-report-collections/422008/festival-of-lights/79524
  35. _VALID_URL = r'''(?x)^(:(?P<shortname>tds|thedailyshow|cr|colbert|colbertnation|colbertreport)
  36. |https?://(:www\.)?
  37. (?P<showname>thedailyshow|thecolbertreport)\.(?:cc\.)?com/
  38. ((?:full-)?episodes/(?:[0-9a-z]{6}/)?(?P<episode>.*)|
  39. (?P<clip>
  40. (?:(?:guests/[^/]+|videos|video-playlists|special-editions|news-team/[^/]+)/[^/]+/(?P<videotitle>[^/?#]+))
  41. |(the-colbert-report-(videos|collections)/(?P<clipID>[0-9]+)/[^/]*/(?P<cntitle>.*?))
  42. |(watch/(?P<date>[^/]*)/(?P<tdstitle>.*))
  43. )|
  44. (?P<interview>
  45. extended-interviews/(?P<interID>[0-9a-z]+)/(?:playlist_tds_extended_)?(?P<interview_title>.*?)(/.*?)?)))
  46. (?:[?#].*|$)'''
  47. _TESTS = [{
  48. 'url': 'http://thedailyshow.cc.com/watch/thu-december-13-2012/kristen-stewart',
  49. 'md5': '4e2f5cb088a83cd8cdb7756132f9739d',
  50. 'info_dict': {
  51. 'id': 'ab9ab3e7-5a98-4dbe-8b21-551dc0523d55',
  52. 'ext': 'mp4',
  53. 'upload_date': '20121213',
  54. 'description': 'Kristen Stewart learns to let loose in "On the Road."',
  55. 'uploader': 'thedailyshow',
  56. 'title': 'thedailyshow kristen-stewart part 1',
  57. }
  58. }, {
  59. 'url': 'http://thedailyshow.cc.com/extended-interviews/xm3fnq/andrew-napolitano-extended-interview',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'http://thecolbertreport.cc.com/videos/29w6fx/-realhumanpraise-for-fox-news',
  63. 'only_matching': True,
  64. }, {
  65. 'url': 'http://thecolbertreport.cc.com/videos/gh6urb/neil-degrasse-tyson-pt--1?xrs=eml_col_031114',
  66. 'only_matching': True,
  67. }, {
  68. 'url': 'http://thedailyshow.cc.com/guests/michael-lewis/3efna8/exclusive---michael-lewis-extended-interview-pt--3',
  69. 'only_matching': True,
  70. }, {
  71. 'url': 'http://thedailyshow.cc.com/episodes/sy7yv0/april-8--2014---denis-leary',
  72. 'only_matching': True,
  73. }, {
  74. 'url': 'http://thecolbertreport.cc.com/episodes/8ase07/april-8--2014---jane-goodall',
  75. 'only_matching': True,
  76. }, {
  77. 'url': 'http://thedailyshow.cc.com/video-playlists/npde3s/the-daily-show-19088-highlights',
  78. 'only_matching': True,
  79. }, {
  80. 'url': 'http://thedailyshow.cc.com/special-editions/2l8fdb/special-edition---a-look-back-at-food',
  81. 'only_matching': True,
  82. }, {
  83. 'url': 'http://thedailyshow.cc.com/news-team/michael-che/7wnfel/we-need-to-talk-about-israel',
  84. 'only_matching': True,
  85. }]
  86. _available_formats = ['3500', '2200', '1700', '1200', '750', '400']
  87. _video_extensions = {
  88. '3500': 'mp4',
  89. '2200': 'mp4',
  90. '1700': 'mp4',
  91. '1200': 'mp4',
  92. '750': 'mp4',
  93. '400': 'mp4',
  94. }
  95. _video_dimensions = {
  96. '3500': (1280, 720),
  97. '2200': (960, 540),
  98. '1700': (768, 432),
  99. '1200': (640, 360),
  100. '750': (512, 288),
  101. '400': (384, 216),
  102. }
  103. def _real_extract(self, url):
  104. mobj = re.match(self._VALID_URL, url)
  105. if mobj.group('shortname'):
  106. if mobj.group('shortname') in ('tds', 'thedailyshow'):
  107. url = 'http://thedailyshow.cc.com/full-episodes/'
  108. else:
  109. url = 'http://thecolbertreport.cc.com/full-episodes/'
  110. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  111. assert mobj is not None
  112. if mobj.group('clip'):
  113. if mobj.group('videotitle'):
  114. epTitle = mobj.group('videotitle')
  115. elif mobj.group('showname') == 'thedailyshow':
  116. epTitle = mobj.group('tdstitle')
  117. else:
  118. epTitle = mobj.group('cntitle')
  119. dlNewest = False
  120. elif mobj.group('interview'):
  121. epTitle = mobj.group('interview_title')
  122. dlNewest = False
  123. else:
  124. dlNewest = not mobj.group('episode')
  125. if dlNewest:
  126. epTitle = mobj.group('showname')
  127. else:
  128. epTitle = mobj.group('episode')
  129. show_name = mobj.group('showname')
  130. webpage, htmlHandle = self._download_webpage_handle(url, epTitle)
  131. if dlNewest:
  132. url = htmlHandle.geturl()
  133. mobj = re.match(self._VALID_URL, url, re.VERBOSE)
  134. if mobj is None:
  135. raise ExtractorError('Invalid redirected URL: ' + url)
  136. if mobj.group('episode') == '':
  137. raise ExtractorError('Redirected URL is still not specific: ' + url)
  138. epTitle = (mobj.group('episode') or mobj.group('videotitle')).rpartition('/')[-1]
  139. mMovieParams = re.findall('(?:<param name="movie" value="|var url = ")(http://media.mtvnservices.com/([^"]*(?:episode|video).*?:.*?))"', webpage)
  140. if len(mMovieParams) == 0:
  141. # The Colbert Report embeds the information in a without
  142. # a URL prefix; so extract the alternate reference
  143. # and then add the URL prefix manually.
  144. altMovieParams = re.findall('data-mgid="([^"]*(?:episode|video|playlist).*?:.*?)"', webpage)
  145. if len(altMovieParams) == 0:
  146. raise ExtractorError('unable to find Flash URL in webpage ' + url)
  147. else:
  148. mMovieParams = [("http://media.mtvnservices.com/" + altMovieParams[0], altMovieParams[0])]
  149. uri = mMovieParams[0][1]
  150. # Correct cc.com in uri
  151. uri = re.sub(r'(episode:[^.]+)(\.cc)?\.com', r'\1.cc.com', uri)
  152. index_url = 'http://%s.cc.com/feeds/mrss?%s' % (show_name, compat_urllib_parse.urlencode({'uri': uri}))
  153. idoc = self._download_xml(
  154. index_url, epTitle,
  155. 'Downloading show index', 'Unable to download episode index')
  156. title = idoc.find('./channel/title').text
  157. description = idoc.find('./channel/description').text
  158. entries = []
  159. item_els = idoc.findall('.//item')
  160. for part_num, itemEl in enumerate(item_els):
  161. upload_date = unified_strdate(itemEl.findall('./pubDate')[0].text)
  162. thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url')
  163. content = itemEl.find('.//{http://search.yahoo.com/mrss/}content')
  164. duration = float_or_none(content.attrib.get('duration'))
  165. mediagen_url = content.attrib['url']
  166. guid = itemEl.find('./guid').text.rpartition(':')[-1]
  167. cdoc = self._download_xml(
  168. mediagen_url, epTitle,
  169. 'Downloading configuration for segment %d / %d' % (part_num + 1, len(item_els)))
  170. turls = []
  171. for rendition in cdoc.findall('.//rendition'):
  172. finfo = (rendition.attrib['bitrate'], rendition.findall('./src')[0].text)
  173. turls.append(finfo)
  174. formats = []
  175. for format, rtmp_video_url in turls:
  176. w, h = self._video_dimensions.get(format, (None, None))
  177. formats.append({
  178. 'format_id': 'vhttp-%s' % format,
  179. 'url': self._transform_rtmp_url(rtmp_video_url),
  180. 'ext': self._video_extensions.get(format, 'mp4'),
  181. 'height': h,
  182. 'width': w,
  183. })
  184. formats.append({
  185. 'format_id': 'rtmp-%s' % format,
  186. 'url': rtmp_video_url.replace('viacomccstrm', 'viacommtvstrm'),
  187. 'ext': self._video_extensions.get(format, 'mp4'),
  188. 'height': h,
  189. 'width': w,
  190. })
  191. self._sort_formats(formats)
  192. virtual_id = show_name + ' ' + epTitle + ' part ' + compat_str(part_num + 1)
  193. entries.append({
  194. 'id': guid,
  195. 'title': virtual_id,
  196. 'formats': formats,
  197. 'uploader': show_name,
  198. 'upload_date': upload_date,
  199. 'duration': duration,
  200. 'thumbnail': thumbnail,
  201. 'description': description,
  202. })
  203. return {
  204. '_type': 'playlist',
  205. 'entries': entries,
  206. 'title': show_name + ' ' + title,
  207. 'description': description,
  208. }