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.

89 lines
3.0 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<video_id>[0-9]+)?/?(?P<url_title>.*)'
  9. _TESTS = [
  10. {
  11. 'url': 'http://teamcoco.com/video/80187/conan-becomes-a-mary-kay-beauty-consultant',
  12. 'file': '80187.mp4',
  13. 'md5': '3f7746aa0dc86de18df7539903d399ea',
  14. 'info_dict': {
  15. 'title': 'Conan Becomes A Mary Kay Beauty Consultant',
  16. 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.'
  17. }
  18. },
  19. {
  20. 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
  21. 'file': '19705.mp4',
  22. 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
  23. 'info_dict': {
  24. "description": "Louis C.K. got starstruck by George W. Bush, so what? Part one.",
  25. "title": "Louis C.K. Interview Pt. 1 11/3/11"
  26. }
  27. }
  28. ]
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. if mobj is None:
  32. raise ExtractorError('Invalid URL: %s' % url)
  33. url_title = mobj.group('url_title')
  34. webpage = self._download_webpage(url, url_title)
  35. video_id = mobj.group("video_id")
  36. if video_id == '':
  37. video_id = self._html_search_regex(
  38. r'<article class="video" data-id="(\d+?)"',
  39. webpage, 'video id')
  40. self.report_extraction(video_id)
  41. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  42. data = self._download_xml(data_url, video_id, 'Downloading data webpage')
  43. qualities = ['500k', '480p', '1000k', '720p', '1080p']
  44. formats = []
  45. for filed in data.findall('files/file'):
  46. if filed.attrib.get('playmode') == 'all':
  47. # it just duplicates one of the entries
  48. break
  49. file_url = filed.text
  50. m_format = re.search(r'(\d+(k|p))\.mp4', file_url)
  51. if m_format is not None:
  52. format_id = m_format.group(1)
  53. else:
  54. format_id = filed.attrib['bitrate']
  55. tbr = (
  56. int(filed.attrib['bitrate'])
  57. if filed.attrib['bitrate'].isdigit()
  58. else None)
  59. try:
  60. quality = qualities.index(format_id)
  61. except ValueError:
  62. quality = -1
  63. formats.append({
  64. 'url': file_url,
  65. 'ext': 'mp4',
  66. 'tbr': tbr,
  67. 'format_id': format_id,
  68. 'quality': quality,
  69. })
  70. self._sort_formats(formats)
  71. return {
  72. 'id': video_id,
  73. 'formats': formats,
  74. 'title': self._og_search_title(webpage),
  75. 'thumbnail': self._og_search_thumbnail(webpage),
  76. 'description': self._og_search_description(webpage),
  77. }