|
4 | 4 | from concurrent.futures import ThreadPoolExecutor |
5 | 5 | from enum import Enum |
6 | 6 | from itertools import repeat |
7 | | -from json import JSONDecodeError |
8 | 7 | from typing import List, Optional |
9 | 8 |
|
10 | 9 | from kili.core.helpers import get_mime_type, is_url |
@@ -168,101 +167,20 @@ def get_data_type(self, assets): |
168 | 167 | return VideoDataType.HOSTED_FILE |
169 | 168 | return VideoDataType.LOCAL_FILE |
170 | 169 |
|
171 | | - @staticmethod |
172 | | - def are_native_videos(assets) -> bool: |
173 | | - """Determine if assets should be imported asynchronously and cut into frames.""" |
174 | | - should_use_native_video_array = [] |
175 | | - for asset in assets: |
176 | | - # json_metadata stringification is done later on the call |
177 | | - json_metadata_ = asset.get("json_metadata") |
178 | | - if not json_metadata_: |
179 | | - return False |
180 | | - |
181 | | - processing_parameters = json_metadata_.get("processingParameters") |
182 | | - if not processing_parameters: |
183 | | - return False |
184 | | - |
185 | | - should_use_native_video_array.append( |
186 | | - processing_parameters.get("shouldUseNativeVideo", True) |
187 | | - ) |
188 | | - if all(should_use_native_video_array): |
189 | | - return True |
190 | | - if all(not b for b in should_use_native_video_array): |
191 | | - return False |
192 | | - raise ImportValidationError( |
193 | | - """ |
194 | | - Cannot upload videos to split into frames |
195 | | - and video to keep as native in the same time. |
196 | | - Please separate the assets into 2 calls |
197 | | - """ |
198 | | - ) |
199 | | - |
200 | | - @staticmethod |
201 | | - def has_complete_processing_parameters(asset) -> bool: |
202 | | - """Determine if assets should be imported asynchronously and cut into frames.""" |
203 | | - try: |
204 | | - # json_metadata stringification is done later on the call |
205 | | - json_metadata = asset.get("json_metadata") |
206 | | - if not json_metadata: |
207 | | - return False |
208 | | - |
209 | | - processing_parameters = json_metadata.get("processingParameters") |
210 | | - |
211 | | - if not processing_parameters: |
212 | | - return False |
213 | | - |
214 | | - required_keys = [ |
215 | | - "codec", |
216 | | - "delayDueToMinPts", |
217 | | - "framesPlayedPerSecond", |
218 | | - "numberOfFrames", |
219 | | - "startTime", |
220 | | - ] |
221 | | - required_types = [str, (int, float), (int, float), (int, float), (int, float)] |
222 | | - |
223 | | - for key, required_type in zip(required_keys, required_types): |
224 | | - value = processing_parameters.get(key) |
225 | | - if value is None or not isinstance(value, required_type): |
226 | | - return False |
227 | | - |
228 | | - if not float(processing_parameters.get("numberOfFrames")).is_integer(): |
229 | | - return False |
230 | | - |
231 | | - return True |
232 | | - except JSONDecodeError: |
233 | | - return False |
234 | | - |
235 | | - def videos_have_complete_processing_parameters(self, assets) -> bool: |
236 | | - """Determine if assets should be imported asynchronously and cut into frames.""" |
237 | | - for asset in assets: |
238 | | - if not self.has_complete_processing_parameters(asset): |
239 | | - return False |
240 | | - return True |
241 | | - |
242 | 170 | def import_assets(self, assets: List[AssetLike], input_type: InputType): |
243 | 171 | """Import video assets into Kili.""" |
244 | 172 | self._check_upload_is_allowed(assets) |
245 | 173 | data_type = self.get_data_type(assets) |
246 | 174 | assets = self.filter_duplicate_external_ids(assets) |
247 | 175 | if data_type == VideoDataType.LOCAL_FILE: |
248 | 176 | assets = self.filter_local_assets(assets, self.raise_error) |
249 | | - are_native_videos = self.are_native_videos(assets) |
250 | | - videos_have_complete_processing_parameters = ( |
251 | | - self.videos_have_complete_processing_parameters(assets) |
252 | | - ) |
253 | | - is_synchronous = are_native_videos and videos_have_complete_processing_parameters |
254 | | - batch_params = BatchParams(is_hosted=False, is_asynchronous=not is_synchronous) |
| 177 | + batch_params = BatchParams(is_hosted=False, is_asynchronous=True) |
255 | 178 | batch_importer = VideoContentBatchImporter( |
256 | 179 | self.kili, self.project_params, batch_params, self.pbar |
257 | 180 | ) |
258 | 181 | batch_size = IMPORT_BATCH_SIZE |
259 | 182 | elif data_type == VideoDataType.HOSTED_FILE: |
260 | | - are_native_videos = self.are_native_videos(assets) |
261 | | - videos_have_complete_processing_parameters = ( |
262 | | - self.videos_have_complete_processing_parameters(assets) |
263 | | - ) |
264 | | - is_synchronous = are_native_videos and videos_have_complete_processing_parameters |
265 | | - batch_params = BatchParams(is_hosted=True, is_asynchronous=not is_synchronous) |
| 183 | + batch_params = BatchParams(is_hosted=True, is_asynchronous=True) |
266 | 184 | batch_importer = VideoContentBatchImporter( |
267 | 185 | self.kili, self.project_params, batch_params, self.pbar |
268 | 186 | ) |
|
0 commit comments