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.

70 lines
2.7 KiB

  1. import re
  2. import xml.etree.ElementTree
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse_urlparse,
  6. ExtractorError,
  7. )
  8. class CollegeHumorIE(InfoExtractor):
  9. _VALID_URL = r'^(?:https?://)?(?:www\.)?collegehumor\.com/video/(?P<videoid>[0-9]+)/(?P<shorttitle>.*)$'
  10. _TEST = {
  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. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. if mobj is None:
  22. raise ExtractorError(u'Invalid URL: %s' % url)
  23. video_id = mobj.group('videoid')
  24. info = {
  25. 'id': video_id,
  26. 'uploader': None,
  27. 'upload_date': None,
  28. }
  29. self.report_extraction(video_id)
  30. xmlUrl = 'http://www.collegehumor.com/moogaloop/video/' + video_id
  31. metaXml = self._download_webpage(xmlUrl, video_id,
  32. u'Downloading info XML',
  33. u'Unable to download video info XML')
  34. mdoc = xml.etree.ElementTree.fromstring(metaXml)
  35. try:
  36. videoNode = mdoc.findall('./video')[0]
  37. info['description'] = videoNode.findall('./description')[0].text
  38. info['title'] = videoNode.findall('./caption')[0].text
  39. info['thumbnail'] = videoNode.findall('./thumbnail')[0].text
  40. manifest_url = videoNode.findall('./file')[0].text
  41. except IndexError:
  42. raise ExtractorError(u'Invalid metadata XML file')
  43. manifest_url += '?hdcore=2.10.3'
  44. manifestXml = self._download_webpage(manifest_url, video_id,
  45. u'Downloading XML manifest',
  46. u'Unable to download video info XML')
  47. adoc = xml.etree.ElementTree.fromstring(manifestXml)
  48. try:
  49. media_node = adoc.findall('./{http://ns.adobe.com/f4m/1.0}media')[0]
  50. node_id = media_node.attrib['url']
  51. video_id = adoc.findall('./{http://ns.adobe.com/f4m/1.0}id')[0].text
  52. except IndexError as err:
  53. raise ExtractorError(u'Invalid manifest file')
  54. url_pr = compat_urllib_parse_urlparse(info['thumbnail'])
  55. info['url'] = url_pr.scheme + '://' + url_pr.netloc + video_id[:-2].replace('.csmil','').replace(',','')
  56. info['ext'] = 'mp4'
  57. return [info]