1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
7 from .common import InfoExtractor
14 class TeamcocoIE(InfoExtractor):
15 _VALID_URL = r'http://teamcoco\.com/video/(?P<video_id>[0-9]+)?/?(?P<display_id>.*)'
18 'url': 'http://teamcoco.com/video/80187/conan-becomes-a-mary-kay-beauty-consultant',
19 'md5': '3f7746aa0dc86de18df7539903d399ea',
23 'title': 'Conan Becomes A Mary Kay Beauty Consultant',
24 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.',
29 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
30 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
34 'description': 'Louis C.K. got starstruck by George W. Bush, so what? Part one.',
35 'title': 'Louis C.K. Interview Pt. 1 11/3/11',
40 'url': 'http://teamcoco.com/video/timothy-olyphant-drinking-whiskey',
44 'title': 'Timothy Olyphant Raises A Toast To “Justified”',
45 'description': 'md5:15501f23f020e793aeca761205e42c24',
48 'skip_download': True, # m3u8 downloads
53 r'"eVar42"\s*:\s*(\d+)',
54 r'Ginger\.TeamCoco\.openInApp\("video",\s*"([^"]+)"',
55 r'"id_not"\s*:\s*(\d+)'
58 def _real_extract(self, url):
59 mobj = re.match(self._VALID_URL, url)
61 display_id = mobj.group('display_id')
62 webpage = self._download_webpage(url, display_id)
64 video_id = mobj.group('video_id')
66 video_id = self._html_search_regex(
67 self._VIDEO_ID_REGEXES, webpage, 'video id')
70 preloads = re.findall(r'"preload":\s*"([^"]+)"', webpage)
72 preload = max([(len(p), p) for p in preloads])[1]
75 preload = ''.join(re.findall(r'this\.push\("([^"]+)"\);', webpage))
78 preload = self._html_search_regex([
79 r'player,\[?"([^"]+)"\]?', r'player.init\(\[?"([^"]+)"\]?\)'
80 ], webpage.replace('","', ''), 'preload data', default=None)
84 'Preload information could not be extracted', expected=True)
86 data = self._parse_json(
87 base64.b64decode(preload.encode('ascii')).decode('utf-8'), video_id)
90 get_quality = qualities(['500k', '480p', '1000k', '720p', '1080p'])
91 for filed in data['files']:
92 if filed['type'] == 'hls':
93 formats.extend(self._extract_m3u8_formats(
94 filed['url'], video_id, ext='mp4'))
96 m_format = re.search(r'(\d+(k|p))\.mp4', filed['url'])
97 if m_format is not None:
98 format_id = m_format.group(1)
100 format_id = filed['bitrate']
102 int(filed['bitrate'])
103 if filed['bitrate'].isdigit()
110 'format_id': format_id,
111 'quality': get_quality(format_id),
114 self._sort_formats(formats)
118 'display_id': display_id,
120 'title': data['title'],
121 'thumbnail': data.get('thumb', {}).get('href'),
122 'description': data.get('teaser'),
123 'duration': data.get('duration'),
124 'age_limit': self._family_friendly_search(webpage),