]>
Commit | Line | Data |
---|---|---|
9c5335a0 | 1 | # -*- coding: utf-8 -*- |
bb198c95 PH |
2 | from __future__ import unicode_literals |
3 | ||
314368c8 | 4 | import base64 |
cd8b8302 PH |
5 | import re |
6 | ||
7 | from .common import InfoExtractor | |
ce9f47de NJ |
8 | from ..utils import ( |
9 | ExtractorError, | |
10 | qualities, | |
11 | ) | |
cd8b8302 PH |
12 | |
13 | ||
14 | class TeamcocoIE(InfoExtractor): | |
dfb2cb5c | 15 | _VALID_URL = r'http://teamcoco\.com/video/(?P<video_id>[0-9]+)?/?(?P<display_id>.*)' |
bb799e81 | 16 | _TESTS = [ |
9e1a5b84 JW |
17 | { |
18 | 'url': 'http://teamcoco.com/video/80187/conan-becomes-a-mary-kay-beauty-consultant', | |
9e1a5b84 JW |
19 | 'md5': '3f7746aa0dc86de18df7539903d399ea', |
20 | 'info_dict': { | |
17d2712d PH |
21 | 'id': '80187', |
22 | 'ext': 'mp4', | |
9e1a5b84 | 23 | 'title': 'Conan Becomes A Mary Kay Beauty Consultant', |
641eb10d | 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.', |
7088f5b5 | 25 | 'duration': 504, |
641eb10d | 26 | 'age_limit': 0, |
9e1a5b84 JW |
27 | } |
28 | }, { | |
29 | 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush', | |
9e1a5b84 JW |
30 | 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a', |
31 | 'info_dict': { | |
17d2712d PH |
32 | 'id': '19705', |
33 | 'ext': 'mp4', | |
314368c8 NJ |
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', | |
7088f5b5 | 36 | 'duration': 288, |
641eb10d | 37 | 'age_limit': 0, |
9e1a5b84 | 38 | } |
9c5335a0 YCH |
39 | }, { |
40 | 'url': 'http://teamcoco.com/video/timothy-olyphant-drinking-whiskey', | |
41 | 'info_dict': { | |
42 | 'id': '88748', | |
43 | 'ext': 'mp4', | |
44 | 'title': 'Timothy Olyphant Raises A Toast To “Justified”', | |
45 | 'description': 'md5:15501f23f020e793aeca761205e42c24', | |
46 | }, | |
47 | 'params': { | |
48 | 'skip_download': True, # m3u8 downloads | |
49 | } | |
bb799e81 | 50 | } |
bb799e81 | 51 | ] |
3811c567 NJ |
52 | _VIDEO_ID_REGEXES = ( |
53 | r'"eVar42"\s*:\s*(\d+)', | |
54 | r'Ginger\.TeamCoco\.openInApp\("video",\s*"([^"]+)"', | |
55 | r'"id_not"\s*:\s*(\d+)' | |
56 | ) | |
cd8b8302 PH |
57 | |
58 | def _real_extract(self, url): | |
59 | mobj = re.match(self._VALID_URL, url) | |
dfb2cb5c PH |
60 | |
61 | display_id = mobj.group('display_id') | |
62 | webpage = self._download_webpage(url, display_id) | |
5f6a1245 | 63 | |
314368c8 | 64 | video_id = mobj.group('video_id') |
dfb2cb5c | 65 | if not video_id: |
04ee53ec | 66 | video_id = self._html_search_regex( |
3811c567 | 67 | self._VIDEO_ID_REGEXES, webpage, 'video id') |
cd8b8302 | 68 | |
9c5335a0 | 69 | preload = None |
ce9f47de | 70 | preloads = re.findall(r'"preload":\s*"([^"]+)"', webpage) |
9c5335a0 YCH |
71 | if preloads: |
72 | preload = max([(len(p), p) for p in preloads])[1] | |
73 | ||
74 | if not preload: | |
75 | preload = ''.join(re.findall(r'this\.push\("([^"]+)"\);', webpage)) | |
76 | ||
77 | if not preload: | |
78 | preload = self._html_search_regex([ | |
79 | r'player,\[?"([^"]+)"\]?', r'player.init\(\[?"([^"]+)"\]?\)' | |
80 | ], webpage.replace('","', ''), 'preload data', default=None) | |
81 | ||
82 | if not preload: | |
83 | raise ExtractorError( | |
84 | 'Preload information could not be extracted', expected=True) | |
85 | ||
314368c8 | 86 | data = self._parse_json( |
ce9f47de | 87 | base64.b64decode(preload.encode('ascii')).decode('utf-8'), video_id) |
cd8b8302 | 88 | |
e7e6b54d | 89 | formats = [] |
314368c8 NJ |
90 | get_quality = qualities(['500k', '480p', '1000k', '720p', '1080p']) |
91 | for filed in data['files']: | |
5bb6328c NJ |
92 | if filed['type'] == 'hls': |
93 | formats.extend(self._extract_m3u8_formats( | |
94 | filed['url'], video_id, ext='mp4')) | |
e7e6b54d | 95 | else: |
5bb6328c NJ |
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) | |
99 | else: | |
100 | format_id = filed['bitrate'] | |
101 | tbr = ( | |
102 | int(filed['bitrate']) | |
103 | if filed['bitrate'].isdigit() | |
104 | else None) | |
befdc8f3 | 105 | |
5bb6328c NJ |
106 | formats.append({ |
107 | 'url': filed['url'], | |
108 | 'ext': 'mp4', | |
109 | 'tbr': tbr, | |
110 | 'format_id': format_id, | |
111 | 'quality': get_quality(format_id), | |
112 | }) | |
befdc8f3 PH |
113 | |
114 | self._sort_formats(formats) | |
cd8b8302 | 115 | |
e7e6b54d | 116 | return { |
bb198c95 | 117 | 'id': video_id, |
dfb2cb5c | 118 | 'display_id': display_id, |
e7e6b54d | 119 | 'formats': formats, |
314368c8 NJ |
120 | 'title': data['title'], |
121 | 'thumbnail': data.get('thumb', {}).get('href'), | |
122 | 'description': data.get('teaser'), | |
7088f5b5 | 123 | 'duration': data.get('duration'), |
641eb10d | 124 | 'age_limit': self._family_friendly_search(webpage), |
e7e6b54d | 125 | } |