]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
bb198c95 PH |
2 | from __future__ import unicode_literals |
3 | ||
3a105f7b | 4 | import json |
cd8b8302 | 5 | |
e0d42dd4 | 6 | from .turner import TurnerBaseIE |
ce9f47de | 7 | from ..utils import ( |
ff8889cd | 8 | determine_ext, |
ce9f47de | 9 | ExtractorError, |
ff8889cd RA |
10 | int_or_none, |
11 | mimetype2ext, | |
12 | parse_duration, | |
13 | parse_iso8601, | |
ce9f47de NJ |
14 | qualities, |
15 | ) | |
cd8b8302 PH |
16 | |
17 | ||
e0d42dd4 | 18 | class TeamcocoIE(TurnerBaseIE): |
69e6efac | 19 | _VALID_URL = r'https?://(?:\w+\.)?teamcoco\.com/(?P<id>([^/]+/)*[^/?#]+)' |
bb799e81 | 20 | _TESTS = [ |
9e1a5b84 | 21 | { |
ff8889cd RA |
22 | 'url': 'http://teamcoco.com/video/mary-kay-remote', |
23 | 'md5': '55d532f81992f5c92046ad02fec34d7d', | |
9e1a5b84 | 24 | 'info_dict': { |
17d2712d PH |
25 | 'id': '80187', |
26 | 'ext': 'mp4', | |
9e1a5b84 | 27 | 'title': 'Conan Becomes A Mary Kay Beauty Consultant', |
641eb10d | 28 | 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.', |
ff8889cd RA |
29 | 'duration': 495.0, |
30 | 'upload_date': '20140402', | |
31 | 'timestamp': 1396407600, | |
9e1a5b84 JW |
32 | } |
33 | }, { | |
34 | 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush', | |
9e1a5b84 JW |
35 | 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a', |
36 | 'info_dict': { | |
17d2712d PH |
37 | 'id': '19705', |
38 | 'ext': 'mp4', | |
314368c8 NJ |
39 | 'description': 'Louis C.K. got starstruck by George W. Bush, so what? Part one.', |
40 | 'title': 'Louis C.K. Interview Pt. 1 11/3/11', | |
7088f5b5 | 41 | 'duration': 288, |
ff8889cd RA |
42 | 'upload_date': '20111104', |
43 | 'timestamp': 1320405840, | |
9e1a5b84 | 44 | } |
9c5335a0 YCH |
45 | }, { |
46 | 'url': 'http://teamcoco.com/video/timothy-olyphant-drinking-whiskey', | |
47 | 'info_dict': { | |
48 | 'id': '88748', | |
49 | 'ext': 'mp4', | |
50 | 'title': 'Timothy Olyphant Raises A Toast To “Justified”', | |
51 | 'description': 'md5:15501f23f020e793aeca761205e42c24', | |
ff8889cd RA |
52 | 'upload_date': '20150415', |
53 | 'timestamp': 1429088400, | |
9c5335a0 YCH |
54 | }, |
55 | 'params': { | |
56 | 'skip_download': True, # m3u8 downloads | |
57 | } | |
d31573fa YCH |
58 | }, { |
59 | 'url': 'http://teamcoco.com/video/full-episode-mon-6-1-joel-mchale-jake-tapper-and-musical-guest-courtney-barnett?playlist=x;eyJ0eXBlIjoidGFnIiwiaWQiOjl9', | |
60 | 'info_dict': { | |
61 | 'id': '89341', | |
62 | 'ext': 'mp4', | |
63 | 'title': 'Full Episode - Mon. 6/1 - Joel McHale, Jake Tapper, And Musical Guest Courtney Barnett', | |
64 | 'description': 'Guests: Joel McHale, Jake Tapper, And Musical Guest Courtney Barnett', | |
65 | }, | |
66 | 'params': { | |
67 | 'skip_download': True, # m3u8 downloads | |
ff8889cd RA |
68 | }, |
69 | 'skip': 'This video is no longer available.', | |
acd620c9 RA |
70 | }, { |
71 | 'url': 'http://teamcoco.com/video/the-conan-audiencey-awards-for-04/25/18', | |
72 | 'only_matching': True, | |
f2b1fa07 RA |
73 | }, { |
74 | 'url': 'http://teamcoco.com/italy/conan-jordan-schlansky-hit-the-streets-of-florence', | |
75 | 'only_matching': True, | |
76 | }, { | |
77 | 'url': 'http://teamcoco.com/haiti/conan-s-haitian-history-lesson', | |
78 | 'only_matching': True, | |
79 | }, { | |
80 | 'url': 'http://teamcoco.com/israel/conan-hits-the-streets-beaches-of-tel-aviv', | |
81 | 'only_matching': True, | |
69e6efac RA |
82 | }, { |
83 | 'url': 'https://conan25.teamcoco.com/video/ice-cube-kevin-hart-conan-share-lyft', | |
84 | 'only_matching': True, | |
bb799e81 | 85 | } |
bb799e81 | 86 | ] |
48970d5c RA |
87 | _RECORD_TEMPL = '''id |
88 | title | |
89 | teaser | |
90 | publishOn | |
91 | thumb { | |
92 | preview | |
93 | } | |
94 | tags { | |
95 | name | |
96 | } | |
97 | duration | |
98 | turnerMediaId | |
99 | turnerMediaAuthToken''' | |
cd8b8302 | 100 | |
ff8889cd RA |
101 | def _graphql_call(self, query_template, object_type, object_id): |
102 | find_object = 'find' + object_type | |
103 | return self._download_json( | |
69e6efac | 104 | 'https://teamcoco.com/graphql', object_id, data=json.dumps({ |
ff8889cd | 105 | 'query': query_template % (find_object, object_id) |
69e6efac RA |
106 | }).encode(), headers={ |
107 | 'Content-Type': 'application/json', | |
108 | })['data'][find_object] | |
dfb2cb5c | 109 | |
ff8889cd RA |
110 | def _real_extract(self, url): |
111 | display_id = self._match_id(url) | |
112 | ||
113 | response = self._graphql_call('''{ | |
48970d5c | 114 | %%s(slug: "%%s") { |
ff8889cd RA |
115 | ... on RecordSlug { |
116 | record { | |
48970d5c RA |
117 | %s |
118 | } | |
119 | } | |
120 | ... on PageSlug { | |
121 | child { | |
ff8889cd | 122 | id |
ff8889cd RA |
123 | } |
124 | } | |
125 | ... on NotFoundSlug { | |
126 | status | |
127 | } | |
128 | } | |
48970d5c | 129 | }''' % self._RECORD_TEMPL, 'Slug', display_id) |
ff8889cd RA |
130 | if response.get('status'): |
131 | raise ExtractorError('This video is no longer available.', expected=True) | |
132 | ||
48970d5c RA |
133 | child = response.get('child') |
134 | if child: | |
135 | record = self._graphql_call('''{ | |
136 | %%s(id: "%%s") { | |
137 | ... on Video { | |
138 | %s | |
139 | } | |
140 | } | |
141 | }''' % self._RECORD_TEMPL, 'Record', child['id']) | |
142 | else: | |
143 | record = response['record'] | |
ff8889cd RA |
144 | video_id = record['id'] |
145 | ||
e0d42dd4 | 146 | info = { |
bb198c95 | 147 | 'id': video_id, |
dfb2cb5c | 148 | 'display_id': display_id, |
ff8889cd RA |
149 | 'title': record['title'], |
150 | 'thumbnail': record.get('thumb', {}).get('preview'), | |
151 | 'description': record.get('teaser'), | |
152 | 'duration': parse_duration(record.get('duration')), | |
153 | 'timestamp': parse_iso8601(record.get('publishOn')), | |
e7e6b54d | 154 | } |
e0d42dd4 RA |
155 | |
156 | media_id = record.get('turnerMediaId') | |
157 | if media_id: | |
158 | self._initialize_geo_bypass({ | |
159 | 'countries': ['US'], | |
160 | }) | |
161 | info.update(self._extract_ngtv_info(media_id, { | |
162 | 'accessToken': record['turnerMediaAuthToken'], | |
163 | 'accessTokenType': 'jws', | |
164 | })) | |
165 | else: | |
48970d5c | 166 | video_sources = self._download_json( |
69e6efac | 167 | 'https://teamcoco.com/_truman/d/' + video_id, |
48970d5c RA |
168 | video_id)['meta']['src'] |
169 | if isinstance(video_sources, dict): | |
170 | video_sources = video_sources.values() | |
e0d42dd4 RA |
171 | |
172 | formats = [] | |
173 | get_quality = qualities(['low', 'sd', 'hd', 'uhd']) | |
48970d5c | 174 | for src in video_sources: |
e0d42dd4 RA |
175 | if not isinstance(src, dict): |
176 | continue | |
177 | src_url = src.get('src') | |
178 | if not src_url: | |
179 | continue | |
48970d5c | 180 | format_id = src.get('label') |
e0d42dd4 RA |
181 | ext = determine_ext(src_url, mimetype2ext(src.get('type'))) |
182 | if format_id == 'hls' or ext == 'm3u8': | |
183 | # compat_urllib_parse.urljoin does not work here | |
184 | if src_url.startswith('/'): | |
185 | src_url = 'http://ht.cdn.turner.com/tbs/big/teamcoco' + src_url | |
186 | formats.extend(self._extract_m3u8_formats( | |
187 | src_url, video_id, 'mp4', m3u8_id=format_id, fatal=False)) | |
188 | else: | |
189 | if src_url.startswith('/mp4:protected/'): | |
190 | # TODO Correct extraction for these files | |
191 | continue | |
192 | tbr = int_or_none(self._search_regex( | |
193 | r'(\d+)k\.mp4', src_url, 'tbr', default=None)) | |
194 | ||
195 | formats.append({ | |
196 | 'url': src_url, | |
197 | 'ext': ext, | |
198 | 'tbr': tbr, | |
199 | 'format_id': format_id, | |
200 | 'quality': get_quality(format_id), | |
201 | }) | |
e0d42dd4 RA |
202 | self._sort_formats(formats) |
203 | info['formats'] = formats | |
204 | ||
205 | return info |