endoreg-db 0.8.4.7__py3-none-any.whl → 0.8.4.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of endoreg-db might be problematic. Click here for more details.
- endoreg_db/models/media/video/video_file.py +24 -38
- endoreg_db/services/pdf_import.py +326 -246
- endoreg_db/services/video_import.py +29 -16
- endoreg_db/views/media/video_segments.py +187 -259
- {endoreg_db-0.8.4.7.dist-info → endoreg_db-0.8.4.9.dist-info}/METADATA +1 -1
- {endoreg_db-0.8.4.7.dist-info → endoreg_db-0.8.4.9.dist-info}/RECORD +8 -8
- {endoreg_db-0.8.4.7.dist-info → endoreg_db-0.8.4.9.dist-info}/WHEEL +0 -0
- {endoreg_db-0.8.4.7.dist-info → endoreg_db-0.8.4.9.dist-info}/licenses/LICENSE +0 -0
|
@@ -4,6 +4,7 @@ import logging
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
import uuid
|
|
6
6
|
from typing import TYPE_CHECKING, Optional, Union, cast
|
|
7
|
+
import os
|
|
7
8
|
|
|
8
9
|
from django.db import models
|
|
9
10
|
from django.core.files import File
|
|
@@ -208,46 +209,25 @@ class VideoFile(models.Model):
|
|
|
208
209
|
return ffmpeg_meta
|
|
209
210
|
|
|
210
211
|
|
|
212
|
+
# Exception message constants
|
|
213
|
+
NO_ACTIVE_FILE = "Has no raw file"
|
|
214
|
+
NO_FILE_ASSOCIATED = "Active file has no associated file."
|
|
215
|
+
|
|
211
216
|
@property
|
|
212
|
-
def
|
|
213
|
-
"""
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
str: The URL of the active video file.
|
|
218
|
-
|
|
219
|
-
Raises:
|
|
220
|
-
Value Error if no active VideoFile is available.
|
|
221
|
-
"""
|
|
222
|
-
active = self.active_file
|
|
223
|
-
if not isinstance(active, FieldFile):
|
|
224
|
-
raise ValueError("Active file is not a stored FieldFile instance.")
|
|
225
|
-
if not active.name:
|
|
226
|
-
raise ValueError("Active file has no associated name.")
|
|
227
|
-
return active.url
|
|
228
|
-
|
|
229
|
-
@property
|
|
230
|
-
def active_raw_file(self) -> FieldFile:
|
|
231
|
-
raw = self.raw_file
|
|
232
|
-
if isinstance(raw, FieldFile) and raw.name:
|
|
233
|
-
return raw
|
|
234
|
-
raise ValueError("No raw file available for this video")
|
|
235
|
-
|
|
236
|
-
@property
|
|
237
|
-
def active_raw_file_url(self)-> str:
|
|
238
|
-
"""
|
|
239
|
-
Return the path of the URL of the active raw file for name reading.
|
|
217
|
+
def active_raw_file(self) -> File:
|
|
218
|
+
"""Return the raw file if available, otherwise raise ValueError."""
|
|
219
|
+
if self.has_raw:
|
|
220
|
+
return self.raw_file
|
|
221
|
+
raise ValueError(self.NO_ACTIVE_FILE)
|
|
240
222
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return raw.url
|
|
250
|
-
|
|
223
|
+
@property
|
|
224
|
+
def active_raw_file_url(self) -> str:
|
|
225
|
+
"""Return the URL of the active raw file, or raise ValueError if unavailable."""
|
|
226
|
+
_file = self.active_raw_file
|
|
227
|
+
assert _file is not None, self.NO_ACTIVE_FILE
|
|
228
|
+
if not _file or not _file.name:
|
|
229
|
+
raise ValueError(self.NO_FILE_ASSOCIATED)
|
|
230
|
+
return _file.url
|
|
251
231
|
|
|
252
232
|
# Pipeline Functions
|
|
253
233
|
pipe_1 = _pipe_1
|
|
@@ -414,6 +394,12 @@ class VideoFile(models.Model):
|
|
|
414
394
|
if isinstance(file_path, str):
|
|
415
395
|
file_path = Path(file_path)
|
|
416
396
|
# Pass center_name and other kwargs to the helper function
|
|
397
|
+
if not center_name:
|
|
398
|
+
try:
|
|
399
|
+
center_name = os.environ["CENTER_NAME"]
|
|
400
|
+
except KeyError:
|
|
401
|
+
logger.error("Center name must be provided to create VideoFile from file. You can set CENTER_NAME in environment variables.")
|
|
402
|
+
return None
|
|
417
403
|
return _create_from_file(cls, file_path, center_name=center_name, **kwargs)
|
|
418
404
|
|
|
419
405
|
@classmethod
|