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.

85 lines
3.3 KiB

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