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.

69 lines
2.3 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. )
  6. class TeamcocoIE(InfoExtractor):
  7. _VALID_URL = r'http://teamcoco\.com/video/(?P<url_title>.*)'
  8. _TEST = {
  9. u'url': u'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
  10. u'file': u'19705.mp4',
  11. u'md5': u'cde9ba0fa3506f5f017ce11ead928f9a',
  12. u'info_dict': {
  13. u"description": u"Louis C.K. got starstruck by George W. Bush, so what? Part one.",
  14. u"title": u"Louis C.K. Interview Pt. 1 11/3/11"
  15. }
  16. }
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. if mobj is None:
  20. raise ExtractorError(u'Invalid URL: %s' % url)
  21. url_title = mobj.group('url_title')
  22. webpage = self._download_webpage(url, url_title)
  23. video_id = self._html_search_regex(r'<article class="video" data-id="(\d+?)"',
  24. webpage, u'video id')
  25. self.report_extraction(video_id)
  26. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  27. data = self._download_xml(data_url, video_id, 'Downloading data webpage')
  28. qualities = ['500k', '480p', '1000k', '720p', '1080p']
  29. formats = []
  30. for file in data.findall('files/file'):
  31. if file.attrib.get('playmode') == 'all':
  32. # it just duplicates one of the entries
  33. break
  34. file_url = file.text
  35. m_format = re.search(r'(\d+(k|p))\.mp4', file_url)
  36. if m_format is not None:
  37. format_id = m_format.group(1)
  38. else:
  39. format_id = file.attrib['bitrate']
  40. formats.append({
  41. 'url': file_url,
  42. 'ext': 'mp4',
  43. 'format_id': format_id,
  44. })
  45. def sort_key(f):
  46. try:
  47. return qualities.index(f['format_id'])
  48. except ValueError:
  49. return -1
  50. formats.sort(key=sort_key)
  51. if not formats:
  52. raise ExtractorError(u'Unable to extract video URL')
  53. return {
  54. 'id': video_id,
  55. 'formats': formats,
  56. 'title': self._og_search_title(webpage),
  57. 'thumbnail': self._og_search_thumbnail(webpage),
  58. 'description': self._og_search_description(webpage),
  59. }