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.

76 lines
2.4 KiB

  1. from __future__ import unicode_literals
  2. import re
  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. 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
  11. 'file': '19705.mp4',
  12. 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
  13. 'info_dict': {
  14. "description": "Louis C.K. got starstruck by George W. Bush, so what? Part one.",
  15. "title": "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('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(
  25. r'<article class="video" data-id="(\d+?)"',
  26. webpage, 'video id')
  27. self.report_extraction(video_id)
  28. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  29. data = self._download_xml(data_url, video_id, 'Downloading data webpage')
  30. qualities = ['500k', '480p', '1000k', '720p', '1080p']
  31. formats = []
  32. for filed in data.findall('files/file'):
  33. if filed.attrib.get('playmode') == 'all':
  34. # it just duplicates one of the entries
  35. break
  36. file_url = filed.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 = filed.attrib['bitrate']
  42. tbr = (
  43. int(filed.attrib['bitrate'])
  44. if filed.attrib['bitrate'].isdigit()
  45. else None)
  46. try:
  47. quality = qualities.index(format_id)
  48. except ValueError:
  49. quality = -1
  50. formats.append({
  51. 'url': file_url,
  52. 'ext': 'mp4',
  53. 'tbr': tbr,
  54. 'format_id': format_id,
  55. 'quality': quality,
  56. })
  57. self._sort_formats(formats)
  58. return {
  59. 'id': video_id,
  60. 'formats': formats,
  61. 'title': self._og_search_title(webpage),
  62. 'thumbnail': self._og_search_thumbnail(webpage),
  63. 'description': self._og_search_description(webpage),
  64. }