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.

92 lines
3.2 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 qualities
  6. class TeamcocoIE(InfoExtractor):
  7. _VALID_URL = r'http://teamcoco\.com/video/(?P<video_id>[0-9]+)?/?(?P<display_id>.*)'
  8. _TESTS = [
  9. {
  10. 'url': 'http://teamcoco.com/video/80187/conan-becomes-a-mary-kay-beauty-consultant',
  11. 'md5': '3f7746aa0dc86de18df7539903d399ea',
  12. 'info_dict': {
  13. 'id': '80187',
  14. 'ext': 'mp4',
  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. 'age_limit': 0,
  18. }
  19. }, {
  20. 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
  21. 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
  22. 'info_dict': {
  23. 'id': '19705',
  24. 'ext': 'mp4',
  25. 'description': 'Louis C.K. got starstruck by George W. Bush, so what? Part one.',
  26. 'title': 'Louis C.K. Interview Pt. 1 11/3/11',
  27. 'age_limit': 0,
  28. }
  29. }
  30. ]
  31. _VIDEO_ID_REGEXES = (
  32. r'"eVar42"\s*:\s*(\d+)',
  33. r'Ginger\.TeamCoco\.openInApp\("video",\s*"([^"]+)"',
  34. r'"id_not"\s*:\s*(\d+)'
  35. )
  36. def _real_extract(self, url):
  37. mobj = re.match(self._VALID_URL, url)
  38. display_id = mobj.group('display_id')
  39. webpage = self._download_webpage(url, display_id)
  40. video_id = mobj.group('video_id')
  41. if not video_id:
  42. video_id = self._html_search_regex(
  43. self._VIDEO_ID_REGEXES, webpage, 'video id')
  44. embed_url = 'http://teamcoco.com/embed/v/%s' % video_id
  45. embed = self._download_webpage(
  46. embed_url, video_id, 'Downloading embed page')
  47. encoded_data = self._search_regex(
  48. r'"preload"\s*:\s*"([^"]+)"', embed, 'encoded data')
  49. data = self._parse_json(
  50. base64.b64decode(encoded_data.encode('ascii')).decode('utf-8'), video_id)
  51. formats = []
  52. get_quality = qualities(['500k', '480p', '1000k', '720p', '1080p'])
  53. for filed in data['files']:
  54. m_format = re.search(r'(\d+(k|p))\.mp4', filed['url'])
  55. if m_format is not None:
  56. format_id = m_format.group(1)
  57. else:
  58. format_id = filed['bitrate']
  59. tbr = (
  60. int(filed['bitrate'])
  61. if filed['bitrate'].isdigit()
  62. else None)
  63. formats.append({
  64. 'url': filed['url'],
  65. 'ext': 'mp4',
  66. 'tbr': tbr,
  67. 'format_id': format_id,
  68. 'quality': get_quality(format_id),
  69. })
  70. self._sort_formats(formats)
  71. return {
  72. 'id': video_id,
  73. 'display_id': display_id,
  74. 'formats': formats,
  75. 'title': data['title'],
  76. 'thumbnail': data.get('thumb', {}).get('href'),
  77. 'description': data.get('teaser'),
  78. 'age_limit': self._family_friendly_search(webpage),
  79. }