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.

60 lines
2.2 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. RegexNotFoundError,
  6. )
  7. class TeamcocoIE(InfoExtractor):
  8. _VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)'
  9. _TEST = {
  10. u'url': u'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
  11. u'file': u'19705.mp4',
  12. u'md5': u'cde9ba0fa3506f5f017ce11ead928f9a',
  13. u'info_dict': {
  14. u"description": u"Louis C.K. got starstruck by George W. Bush, so what? Part one.",
  15. u"title": u"Louis C.K. Interview Pt. 1 11/3/11"
  16. }
  17. }
  18. def _real_extract(self, url):
  19. mobj = re.match(self._VALID_URL, url)
  20. if mobj is None:
  21. raise ExtractorError(u'Invalid URL: %s' % url)
  22. url_title = mobj.group('url_title')
  23. webpage = self._download_webpage(url, url_title)
  24. video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"',
  25. webpage, u'video id')
  26. self.report_extraction(video_id)
  27. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  28. data = self._download_webpage(data_url, video_id, 'Downloading data webpage')
  29. qualities = [ '1080p', '720p', '1000k', '480p', '500k' ]
  30. best_quality_idx = len(qualities)+1 # First regex match may not be optimal
  31. for idx, quality in enumerate(qualities):
  32. regex = r'<file [^>]*type="(?:high|standard)".*?>(.*%s.*)</file>' % quality
  33. try:
  34. url = self._html_search_regex(regex, data, u'video URL')
  35. if idx < best_quality_idx:
  36. video_url = url
  37. best_quality_idx = idx
  38. except RegexNotFoundError:
  39. # Just catch fatal exc. Don't want the fatal=False warning
  40. continue
  41. if not video_url:
  42. raise RegexNotFoundError(u'Unable to extract video URL')
  43. return [{
  44. 'id': video_id,
  45. 'url': video_url,
  46. 'ext': 'mp4',
  47. 'title': self._og_search_title(webpage),
  48. 'thumbnail': self._og_search_thumbnail(webpage),
  49. 'description': self._og_search_description(webpage),
  50. }]