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.

85 lines
2.9 KiB

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