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.

82 lines
3.1 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. compat_urllib_parse_urlparse,
  5. determine_ext,
  6. ExtractorError,
  7. )
  8. class CollegeHumorIE(InfoExtractor):
  9. _VALID_URL = r'^(?:https?://)?(?:www\.)?collegehumor\.com/(video|embed|e)/(?P<videoid>[0-9]+)/?(?P<shorttitle>.*)$'
  10. _TESTS = [{
  11. u'url': u'http://www.collegehumor.com/video/6902724/comic-con-cosplay-catastrophe',
  12. u'file': u'6902724.mp4',
  13. u'md5': u'1264c12ad95dca142a9f0bf7968105a0',
  14. u'info_dict': {
  15. u'title': u'Comic-Con Cosplay Catastrophe',
  16. u'description': u'Fans get creative this year at San Diego. Too creative. And yes, that\'s really Joss Whedon.',
  17. },
  18. },
  19. {
  20. u'url': u'http://www.collegehumor.com/video/3505939/font-conference',
  21. u'file': u'3505939.mp4',
  22. u'md5': u'c51ca16b82bb456a4397987791a835f5',
  23. u'info_dict': {
  24. u'title': u'Font Conference',
  25. u'description': u'This video wasn\'t long enough, so we made it double-spaced.',
  26. },
  27. }]
  28. def _real_extract(self, url):
  29. mobj = re.match(self._VALID_URL, url)
  30. if mobj is None:
  31. raise ExtractorError(u'Invalid URL: %s' % url)
  32. video_id = mobj.group('videoid')
  33. info = {
  34. 'id': video_id,
  35. 'uploader': None,
  36. 'upload_date': None,
  37. }
  38. self.report_extraction(video_id)
  39. xmlUrl = 'http://www.collegehumor.com/moogaloop/video/' + video_id
  40. mdoc = self._download_xml(xmlUrl, video_id,
  41. u'Downloading info XML',
  42. u'Unable to download video info XML')
  43. try:
  44. videoNode = mdoc.findall('./video')[0]
  45. youtubeIdNode = videoNode.find('./youtubeID')
  46. if youtubeIdNode is not None:
  47. return self.url_result(youtubeIdNode.text, 'Youtube')
  48. info['description'] = videoNode.findall('./description')[0].text
  49. info['title'] = videoNode.findall('./caption')[0].text
  50. info['thumbnail'] = videoNode.findall('./thumbnail')[0].text
  51. next_url = videoNode.findall('./file')[0].text
  52. except IndexError:
  53. raise ExtractorError(u'Invalid metadata XML file')
  54. if next_url.endswith(u'manifest.f4m'):
  55. manifest_url = next_url + '?hdcore=2.10.3'
  56. adoc = self._download_xml(manifest_url, video_id,
  57. u'Downloading XML manifest',
  58. u'Unable to download video info XML')
  59. try:
  60. video_id = adoc.findall('./{http://ns.adobe.com/f4m/1.0}id')[0].text
  61. except IndexError:
  62. raise ExtractorError(u'Invalid manifest file')
  63. url_pr = compat_urllib_parse_urlparse(info['thumbnail'])
  64. info['url'] = url_pr.scheme + '://' + url_pr.netloc + video_id[:-2].replace('.csmil','').replace(',','')
  65. info['ext'] = 'mp4'
  66. else:
  67. # Old-style direct links
  68. info['url'] = next_url
  69. info['ext'] = determine_ext(info['url'])
  70. return info