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.

71 lines
2.4 KiB

  1. import re
  2. import xml.etree.ElementTree
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  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_xml = self._download_webpage(data_url, video_id, 'Downloading data webpage')
  29. data = xml.etree.ElementTree.fromstring(data_xml.encode('utf-8'))
  30. qualities = ['500k', '480p', '1000k', '720p', '1080p']
  31. formats = []
  32. for file in data.findall('files/file'):
  33. if file.attrib.get('playmode') == 'all':
  34. # it just duplicates one of the entries
  35. break
  36. file_url = file.text
  37. m_format = re.search(r'(\d+(k|p))\.mp4', file_url)
  38. if m_format is not None:
  39. format_id = m_format.group(1)
  40. else:
  41. format_id = file.attrib['bitrate']
  42. formats.append({
  43. 'url': file_url,
  44. 'ext': 'mp4',
  45. 'format_id': format_id,
  46. })
  47. def sort_key(f):
  48. try:
  49. return qualities.index(f['format_id'])
  50. except ValueError:
  51. return -1
  52. formats.sort(key=sort_key)
  53. if not formats:
  54. raise RegexNotFoundError(u'Unable to extract video URL')
  55. return {
  56. 'id': video_id,
  57. 'formats': formats,
  58. 'title': self._og_search_title(webpage),
  59. 'thumbnail': self._og_search_thumbnail(webpage),
  60. 'description': self._og_search_description(webpage),
  61. }