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.

73 lines
2.8 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|embed|e)/(?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. youtubeIdNode = videoNode.find('./youtubeID')
  38. if youtubeIdNode is not None:
  39. return self.url_result(youtubeIdNode.text, 'Youtube')
  40. info['description'] = videoNode.findall('./description')[0].text
  41. info['title'] = videoNode.findall('./caption')[0].text
  42. info['thumbnail'] = videoNode.findall('./thumbnail')[0].text
  43. manifest_url = videoNode.findall('./file')[0].text
  44. except IndexError:
  45. raise ExtractorError(u'Invalid metadata XML file')
  46. manifest_url += '?hdcore=2.10.3'
  47. manifestXml = self._download_webpage(manifest_url, video_id,
  48. u'Downloading XML manifest',
  49. u'Unable to download video info XML')
  50. adoc = xml.etree.ElementTree.fromstring(manifestXml)
  51. try:
  52. media_node = adoc.findall('./{http://ns.adobe.com/f4m/1.0}media')[0]
  53. node_id = media_node.attrib['url']
  54. video_id = adoc.findall('./{http://ns.adobe.com/f4m/1.0}id')[0].text
  55. except IndexError as err:
  56. raise ExtractorError(u'Invalid manifest file')
  57. url_pr = compat_urllib_parse_urlparse(info['thumbnail'])
  58. info['url'] = url_pr.scheme + '://' + url_pr.netloc + video_id[:-2].replace('.csmil','').replace(',','')
  59. info['ext'] = 'mp4'
  60. return [info]