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.

93 lines
3.2 KiB

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