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.

100 lines
3.5 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import base64
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. qualities,
  8. )
  9. class TeamcocoIE(InfoExtractor):
  10. _VALID_URL = r'http://teamcoco\.com/video/(?P<video_id>[0-9]+)?/?(?P<display_id>.*)'
  11. _TESTS = [
  12. {
  13. 'url': 'http://teamcoco.com/video/80187/conan-becomes-a-mary-kay-beauty-consultant',
  14. 'md5': '3f7746aa0dc86de18df7539903d399ea',
  15. 'info_dict': {
  16. 'id': '80187',
  17. 'ext': 'mp4',
  18. 'title': 'Conan Becomes A Mary Kay Beauty Consultant',
  19. 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.',
  20. 'duration': 504,
  21. 'age_limit': 0,
  22. }
  23. }, {
  24. 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
  25. 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
  26. 'info_dict': {
  27. 'id': '19705',
  28. 'ext': 'mp4',
  29. 'description': 'Louis C.K. got starstruck by George W. Bush, so what? Part one.',
  30. 'title': 'Louis C.K. Interview Pt. 1 11/3/11',
  31. 'duration': 288,
  32. 'age_limit': 0,
  33. }
  34. }
  35. ]
  36. _VIDEO_ID_REGEXES = (
  37. r'"eVar42"\s*:\s*(\d+)',
  38. r'Ginger\.TeamCoco\.openInApp\("video",\s*"([^"]+)"',
  39. r'"id_not"\s*:\s*(\d+)'
  40. )
  41. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. display_id = mobj.group('display_id')
  44. webpage = self._download_webpage(url, display_id)
  45. video_id = mobj.group('video_id')
  46. if not video_id:
  47. video_id = self._html_search_regex(
  48. self._VIDEO_ID_REGEXES, webpage, 'video id')
  49. preloads = re.findall(r'"preload":\s*"([^"]+)"', webpage)
  50. if not preloads:
  51. raise ExtractorError('Preload information could not be extracted')
  52. preload = max([(len(p), p) for p in preloads])[1]
  53. data = self._parse_json(
  54. base64.b64decode(preload.encode('ascii')).decode('utf-8'), video_id)
  55. formats = []
  56. get_quality = qualities(['500k', '480p', '1000k', '720p', '1080p'])
  57. for filed in data['files']:
  58. if filed['type'] == 'hls':
  59. formats.extend(self._extract_m3u8_formats(
  60. filed['url'], video_id, ext='mp4'))
  61. else:
  62. m_format = re.search(r'(\d+(k|p))\.mp4', filed['url'])
  63. if m_format is not None:
  64. format_id = m_format.group(1)
  65. else:
  66. format_id = filed['bitrate']
  67. tbr = (
  68. int(filed['bitrate'])
  69. if filed['bitrate'].isdigit()
  70. else None)
  71. formats.append({
  72. 'url': filed['url'],
  73. 'ext': 'mp4',
  74. 'tbr': tbr,
  75. 'format_id': format_id,
  76. 'quality': get_quality(format_id),
  77. })
  78. self._sort_formats(formats)
  79. return {
  80. 'id': video_id,
  81. 'display_id': display_id,
  82. 'formats': formats,
  83. 'title': data['title'],
  84. 'thumbnail': data.get('thumb', {}).get('href'),
  85. 'description': data.get('teaser'),
  86. 'duration': data.get('duration'),
  87. 'age_limit': self._family_friendly_search(webpage),
  88. }