@clipen/clipen-cli 1.0.0 → 1.0.1
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.
- package/README.md +60 -50
- package/package.json +7 -4
- package/pyproject.toml +18 -2
- package/requirements/dev.txt +2 -0
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/__init__.py +7 -7
- package/src/clipen/analysis/artifacts.py +4 -10
- package/src/clipen/analysis/audio.py +10 -8
- package/src/clipen/analysis/evidence_service.py +345 -167
- package/src/clipen/analysis/image_similarity.py +5 -14
- package/src/clipen/analysis/keyframes.py +5 -17
- package/src/clipen/analysis/models.py +5 -7
- package/src/clipen/analysis/qwen_worker.py +19 -54
- package/src/clipen/analysis/resources.py +2 -1
- package/src/clipen/analysis/runtime.py +1 -3
- package/src/clipen/analysis/service.py +16 -48
- package/src/clipen/analysis/setup.py +11 -25
- package/src/clipen/analysis/setup_cli.py +5 -15
- package/src/clipen/analysis/storage.py +96 -278
- package/src/clipen/analysis/transcription.py +40 -82
- package/src/clipen/analysis/visual.py +109 -48
- package/src/clipen/annotations/__init__.py +5 -2
- package/src/clipen/annotations/models.py +1 -1
- package/src/clipen/annotations/storage.py +132 -84
- package/src/clipen/annotations/suggestions.py +3 -8
- package/src/clipen/asr_release.py +4 -11
- package/src/clipen/bootstrap.py +65 -54
- package/src/clipen/{planning/models.py → candidates.py} +29 -47
- package/src/clipen/cli.py +2 -2
- package/src/clipen/controller/app.py +401 -214
- package/src/clipen/controller/server.py +28 -38
- package/src/clipen/domain/__init__.py +1 -1
- package/src/clipen/domain/media_time.py +3 -10
- package/src/clipen/domain/timeline.py +45 -47
- package/src/clipen/domain/validation.py +0 -1
- package/src/clipen/editing/__init__.py +1 -1
- package/src/clipen/editing/agent_models.py +4 -11
- package/src/clipen/editing/agent_repository.py +391 -170
- package/src/clipen/editing/agent_tools.py +180 -99
- package/src/clipen/editing/alignment.py +92 -52
- package/src/clipen/editing/alignment_setup.py +118 -70
- package/src/clipen/editing/alignment_worker.py +11 -9
- package/src/clipen/editing/change_report.py +95 -38
- package/src/clipen/editing/compiler.py +0 -1
- package/src/clipen/editing/component_looks.py +58 -34
- package/src/clipen/editing/component_review.py +34 -38
- package/src/clipen/editing/coordinator.py +213 -90
- package/src/clipen/editing/editorial_review.py +217 -95
- package/src/clipen/editing/evidence_jobs.py +457 -200
- package/src/clipen/editing/history_changes.py +129 -68
- package/src/clipen/editing/music_choices.py +8 -5
- package/src/clipen/editing/production_catalog.py +573 -136
- package/src/clipen/editing/production_limits.py +43 -17
- package/src/clipen/editing/production_media.py +376 -167
- package/src/clipen/editing/production_preview.py +322 -129
- package/src/clipen/editing/production_progress.py +164 -69
- package/src/clipen/editing/production_requirements.py +106 -39
- package/src/clipen/editing/production_tools.py +1064 -462
- package/src/clipen/editing/program_audio.py +211 -81
- package/src/clipen/editing/program_direction.py +59 -25
- package/src/clipen/editing/program_story.py +83 -45
- package/src/clipen/editing/program_subtitles.py +194 -96
- package/src/clipen/editing/programme_review.py +98 -50
- package/src/clipen/editing/prompt_history.py +64 -27
- package/src/clipen/editing/recut.py +65 -25
- package/src/clipen/editing/refinement_references.py +176 -86
- package/src/clipen/editing/resolve_export.py +449 -218
- package/src/clipen/editing/resolve_titles.py +162 -105
- package/src/clipen/editing/skill_tools.py +530 -154
- package/src/clipen/editing/source_dialogue.py +177 -67
- package/src/clipen/editing/speech_coverage.py +42 -22
- package/src/clipen/editing/speech_quality.py +6 -1
- package/src/clipen/editing/tool_receipts.py +78 -32
- package/src/clipen/editing/versions.py +122 -64
- package/src/clipen/editing/visual_preview.py +157 -61
- package/src/clipen/editing/workbench.py +104 -42
- package/src/clipen/finishing/audio.py +69 -30
- package/src/clipen/finishing/catalog.py +176 -93
- package/src/clipen/finishing/models.py +1 -1
- package/src/clipen/finishing/renderer.py +33 -14
- package/src/clipen/mcp_editing/__main__.py +3 -1
- package/src/clipen/mcp_editing/server.py +77 -34
- package/src/clipen/media/__init__.py +3 -3
- package/src/clipen/media/discovery.py +7 -20
- package/src/clipen/media/models.py +7 -18
- package/src/clipen/media/preview.py +14 -24
- package/src/clipen/media/probe.py +16 -44
- package/src/clipen/media/service.py +6 -19
- package/src/clipen/media/storage.py +33 -81
- package/src/clipen/music_vocabulary.py +33 -4
- package/src/clipen/power.py +8 -3
- package/src/clipen/projects/__init__.py +1 -1
- package/src/clipen/projects/deletion.py +19 -32
- package/src/clipen/projects/finishing_schema.py +3 -1
- package/src/clipen/projects/models.py +2 -5
- package/src/clipen/projects/picker.py +13 -37
- package/src/clipen/projects/service.py +8 -24
- package/src/clipen/projects/storage.py +226 -246
- package/src/clipen/provider_registry.py +4 -2
- package/src/clipen/providers/account.py +86 -35
- package/src/clipen/providers/claude.py +59 -25
- package/src/clipen/providers/claude_editing.py +14 -7
- package/src/clipen/providers/codex.py +73 -118
- package/src/clipen/providers/codex_editing.py +2 -2
- package/src/clipen/providers/editing_agent.py +19 -17
- package/src/clipen/providers/recovery.py +7 -8
- package/src/clipen/rendering/cover.py +18 -5
- package/src/clipen/rendering/custom_components.py +167 -79
- package/src/clipen/rendering/custom_render.py +62 -41
- package/src/clipen/rendering/production_effects.py +77 -45
- package/src/clipen/rendering/program_components.py +134 -73
- package/src/clipen/rendering/program_creator.py +432 -277
- package/src/clipen/rendering/program_identities.py +277 -182
- package/src/clipen/rendering/program_motion.py +140 -95
- package/src/clipen/rendering/program_studio.py +175 -116
- package/src/clipen/rendering/program_styles.py +231 -145
- package/src/clipen/rendering/program_subtitles.py +71 -34
- package/src/clipen/rendering/renderer.py +150 -121
- package/src/clipen/rendering/storage.py +9 -22
- package/src/clipen/rendering/titles.py +193 -86
- package/src/clipen/skills/__init__.py +1 -0
- package/src/clipen/skills/catalog.py +151 -55
- package/src/clipen/skills/library.py +13 -7
- package/src/clipen/skills/package.py +46 -23
- package/src/clipen/skills/visual_styles.py +29 -18
- package/src/clipen/workspace.py +15 -44
- package/src/clipen/planning/__init__.py +0 -9
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Local media inventory domain and persistence."""
|
|
2
2
|
|
|
3
|
+
from .discovery import DiscoveredAsset, DiscoveryError, MediaDiscovery
|
|
3
4
|
from .models import (
|
|
4
5
|
AssetCandidate,
|
|
5
6
|
AssetKind,
|
|
@@ -13,8 +14,7 @@ from .models import (
|
|
|
13
14
|
MediaStream,
|
|
14
15
|
ProbeStatus,
|
|
15
16
|
)
|
|
16
|
-
from .
|
|
17
|
-
from .discovery import DiscoveredAsset, DiscoveryError, MediaDiscovery
|
|
17
|
+
from .preview import MediaPreview, MediaPreviewRepository
|
|
18
18
|
from .probe import (
|
|
19
19
|
FFprobeAdapter,
|
|
20
20
|
MediaProbeError,
|
|
@@ -22,7 +22,7 @@ from .probe import (
|
|
|
22
22
|
bounded_file_fingerprint,
|
|
23
23
|
)
|
|
24
24
|
from .service import InventoryCoordinator
|
|
25
|
-
from .
|
|
25
|
+
from .storage import InventoryRepository
|
|
26
26
|
|
|
27
27
|
__all__ = [
|
|
28
28
|
"AssetCandidate",
|
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from dataclasses import dataclass
|
|
6
5
|
import os
|
|
7
|
-
from pathlib import PurePosixPath
|
|
8
6
|
import stat
|
|
9
7
|
import threading
|
|
10
8
|
import time
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from pathlib import PurePosixPath
|
|
11
11
|
from typing import Iterator
|
|
12
12
|
|
|
13
13
|
from clipen.projects.models import DirectoryRole
|
|
14
14
|
|
|
15
15
|
from .models import AssetKind, InventoryRoot, validate_relative_path
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
_VIDEO_EXTENSIONS = frozenset(
|
|
19
18
|
{
|
|
20
19
|
".avi",
|
|
@@ -30,12 +29,8 @@ _VIDEO_EXTENSIONS = frozenset(
|
|
|
30
29
|
".webm",
|
|
31
30
|
}
|
|
32
31
|
)
|
|
33
|
-
_AUDIO_EXTENSIONS = frozenset(
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
_IMAGE_EXTENSIONS = frozenset(
|
|
37
|
-
{".bmp", ".heic", ".heif", ".jpeg", ".jpg", ".png", ".tif", ".tiff", ".webp"}
|
|
38
|
-
)
|
|
32
|
+
_AUDIO_EXTENSIONS = frozenset({".aac", ".aif", ".aiff", ".flac", ".m4a", ".mp3", ".ogg", ".opus", ".wav"})
|
|
33
|
+
_IMAGE_EXTENSIONS = frozenset({".bmp", ".heic", ".heif", ".jpeg", ".jpg", ".png", ".tif", ".tiff", ".webp"})
|
|
39
34
|
_SYSTEM_NAMES = frozenset({".DS_Store", "Thumbs.db", "desktop.ini"})
|
|
40
35
|
# Clipen writes Resolve packages here, beside the footage; they are not footage.
|
|
41
36
|
EXPORT_FOLDER = "Clipen 匯出"
|
|
@@ -80,15 +75,9 @@ class MediaDiscovery:
|
|
|
80
75
|
self.maximum_depth = maximum_depth
|
|
81
76
|
self.maximum_seconds = maximum_seconds
|
|
82
77
|
|
|
83
|
-
def scan(
|
|
84
|
-
self, root: InventoryRoot, cancel: threading.Event | None = None
|
|
85
|
-
) -> Iterator[DiscoveredAsset]:
|
|
78
|
+
def scan(self, root: InventoryRoot, cancel: threading.Event | None = None) -> Iterator[DiscoveredAsset]:
|
|
86
79
|
deadline = time.monotonic() + self.maximum_seconds
|
|
87
|
-
flags = (
|
|
88
|
-
os.O_RDONLY
|
|
89
|
-
| getattr(os, "O_DIRECTORY", 0)
|
|
90
|
-
| getattr(os, "O_NOFOLLOW", 0)
|
|
91
|
-
)
|
|
80
|
+
flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0)
|
|
92
81
|
try:
|
|
93
82
|
root_fd = os.open(root.canonical_path, flags)
|
|
94
83
|
except OSError as error:
|
|
@@ -238,9 +227,7 @@ def _entries(directory_fd: int) -> Iterator[os.DirEntry[str]]:
|
|
|
238
227
|
def open_file_beneath(root: InventoryRoot, relative_path: str) -> int:
|
|
239
228
|
"""Open one regular file without following any component symlink."""
|
|
240
229
|
path = PurePosixPath(validate_relative_path(relative_path))
|
|
241
|
-
directory_flags = (
|
|
242
|
-
os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0)
|
|
243
|
-
)
|
|
230
|
+
directory_flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | getattr(os, "O_NOFOLLOW", 0)
|
|
244
231
|
file_flags = os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0)
|
|
245
232
|
try:
|
|
246
233
|
current = os.open(root.canonical_path, directory_flags)
|
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
from enum import Enum
|
|
7
5
|
import hashlib
|
|
8
6
|
import json
|
|
9
|
-
from pathlib import PurePosixPath
|
|
10
7
|
import re
|
|
11
|
-
from
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from enum import Enum
|
|
10
|
+
from pathlib import PurePosixPath
|
|
11
|
+
from typing import Any, Mapping
|
|
12
12
|
|
|
13
13
|
from clipen.projects.models import DirectoryRole, ProjectError, validate_project_id
|
|
14
14
|
|
|
15
|
-
|
|
16
15
|
_RUN_ID = re.compile(r"inv_[0-9a-f]{32}\Z")
|
|
17
16
|
_SHA256 = re.compile(r"[0-9a-f]{64}\Z")
|
|
18
17
|
_CODE = re.compile(r"[a-z][a-z0-9_]{0,63}\Z")
|
|
@@ -61,10 +60,7 @@ class InventoryCounts:
|
|
|
61
60
|
|
|
62
61
|
def __post_init__(self) -> None:
|
|
63
62
|
values = (self.discovered, self.probed, self.usable, self.issues, self.ignored)
|
|
64
|
-
if any(
|
|
65
|
-
isinstance(value, bool) or not isinstance(value, int) or value < 0
|
|
66
|
-
for value in values
|
|
67
|
-
):
|
|
63
|
+
if any(isinstance(value, bool) or not isinstance(value, int) or value < 0 for value in values):
|
|
68
64
|
raise ValueError("inventory counts must be non-negative integers")
|
|
69
65
|
if self.usable + self.issues + self.ignored > self.discovered:
|
|
70
66
|
raise ValueError("inventory categorized counts exceed discovered count")
|
|
@@ -243,10 +239,7 @@ class AssetCandidate:
|
|
|
243
239
|
def version_id(self, project_id: str) -> str | None:
|
|
244
240
|
if self.fingerprint is None:
|
|
245
241
|
return None
|
|
246
|
-
value = (
|
|
247
|
-
f"clipen-version:v1:{self.asset_id(project_id)}:{self.size_bytes}:"
|
|
248
|
-
f"{self.mtime_ns}:{self.fingerprint}"
|
|
249
|
-
)
|
|
242
|
+
value = f"clipen-version:v1:{self.asset_id(project_id)}:{self.size_bytes}:{self.mtime_ns}:{self.fingerprint}"
|
|
250
243
|
return "av_" + hashlib.sha256(value.encode("utf-8")).hexdigest()[:32]
|
|
251
244
|
|
|
252
245
|
|
|
@@ -345,11 +338,7 @@ def validate_relative_path(value: object) -> str:
|
|
|
345
338
|
if "\x00" in value or "\\" in value:
|
|
346
339
|
raise ValueError("asset relative path is invalid")
|
|
347
340
|
path = PurePosixPath(value)
|
|
348
|
-
if (
|
|
349
|
-
path.is_absolute()
|
|
350
|
-
or path.as_posix() != value
|
|
351
|
-
or any(part in {"", ".", ".."} for part in path.parts)
|
|
352
|
-
):
|
|
341
|
+
if path.is_absolute() or path.as_posix() != value or any(part in {"", ".", ".."} for part in path.parts):
|
|
353
342
|
raise ValueError("asset relative path is unsafe")
|
|
354
343
|
return value
|
|
355
344
|
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from dataclasses import dataclass
|
|
6
5
|
import json
|
|
7
6
|
import mimetypes
|
|
8
7
|
import os
|
|
9
|
-
from pathlib import Path, PurePosixPath
|
|
10
8
|
import re
|
|
11
9
|
import sqlite3
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from pathlib import Path, PurePosixPath
|
|
12
12
|
from typing import Iterator
|
|
13
13
|
|
|
14
14
|
from clipen.projects import DirectoryRole, ProjectError, ProjectRepository
|
|
@@ -17,7 +17,6 @@ from clipen.projects.models import validate_project_id
|
|
|
17
17
|
from .discovery import DiscoveryError, open_file_beneath
|
|
18
18
|
from .models import InventoryRoot
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
_VERSION_ID = re.compile(r"av_[0-9a-f]{32}\Z")
|
|
22
21
|
_VIDEO_TYPES = {".mp4": "video/mp4", ".m4v": "video/mp4", ".mov": "video/quicktime"}
|
|
23
22
|
_AUDIO_TYPES = {".m4a": "audio/mp4", ".mp3": "audio/mpeg", ".wav": "audio/wav", ".aac": "audio/aac"}
|
|
@@ -68,8 +67,7 @@ class MediaPreviewRepository:
|
|
|
68
67
|
).fetchall()
|
|
69
68
|
path = Path(row["canonical_path"]).joinpath(*PurePosixPath(row["relative_path"]).parts)
|
|
70
69
|
return path, {
|
|
71
|
-
stream["stream_index"]: {**json.loads(stream["details_json"]), "kind": stream["kind"]}
|
|
72
|
-
for stream in streams
|
|
70
|
+
stream["stream_index"]: {**json.loads(stream["details_json"]), "kind": stream["kind"]} for stream in streams
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
def open(self, project_id: str, version_id: str) -> MediaPreview:
|
|
@@ -88,35 +86,31 @@ class MediaPreviewRepository:
|
|
|
88
86
|
(version_id, project_id),
|
|
89
87
|
).fetchone()
|
|
90
88
|
streams = database.execute(
|
|
91
|
-
"SELECT stream_index,kind,details_json FROM media_streams "
|
|
92
|
-
"WHERE version_id=? ORDER BY stream_index",
|
|
89
|
+
"SELECT stream_index,kind,details_json FROM media_streams WHERE version_id=? ORDER BY stream_index",
|
|
93
90
|
(version_id,),
|
|
94
91
|
).fetchall()
|
|
95
92
|
if row is None:
|
|
96
93
|
raise ProjectError("media_not_found", "找不到這個素材。", status_code=404)
|
|
97
|
-
audio_stream_indices = tuple(
|
|
98
|
-
stream["stream_index"] for stream in streams if stream["kind"] == "audio"
|
|
99
|
-
)
|
|
94
|
+
audio_stream_indices = tuple(stream["stream_index"] for stream in streams if stream["kind"] == "audio")
|
|
100
95
|
video_streams = [stream for stream in streams if stream["kind"] == "video"]
|
|
101
96
|
primary_video_streams = tuple(
|
|
102
97
|
stream["stream_index"]
|
|
103
98
|
for stream in video_streams
|
|
104
99
|
if not json.loads(stream["details_json"]).get("attached_pic", False)
|
|
105
100
|
)
|
|
106
|
-
video_stream_indices = primary_video_streams or tuple(
|
|
107
|
-
stream["stream_index"] for stream in video_streams
|
|
108
|
-
)
|
|
101
|
+
video_stream_indices = primary_video_streams or tuple(stream["stream_index"] for stream in video_streams)
|
|
109
102
|
root = InventoryRoot(
|
|
110
|
-
DirectoryRole(row["role"]),
|
|
111
|
-
row["
|
|
103
|
+
DirectoryRole(row["role"]),
|
|
104
|
+
row["canonical_path"],
|
|
105
|
+
row["device"],
|
|
106
|
+
row["inode"],
|
|
107
|
+
row["saved_at"],
|
|
112
108
|
)
|
|
113
109
|
descriptor = open_file_beneath(root, row["relative_path"])
|
|
114
110
|
details = os.fstat(descriptor)
|
|
115
111
|
if details.st_size != row["size_bytes"] or details.st_mtime_ns != row["mtime_ns"]:
|
|
116
112
|
os.close(descriptor)
|
|
117
|
-
raise ProjectError(
|
|
118
|
-
"media_changed", "素材已變更,請重新檢查素材。", status_code=409
|
|
119
|
-
)
|
|
113
|
+
raise ProjectError("media_changed", "素材已變更,請重新檢查素材。", status_code=409)
|
|
120
114
|
suffix = PurePosixPath(row["relative_path"]).suffix.lower()
|
|
121
115
|
media_type = _VIDEO_TYPES.get(suffix) or _AUDIO_TYPES.get(suffix)
|
|
122
116
|
if media_type is None:
|
|
@@ -138,10 +132,6 @@ class MediaPreviewRepository:
|
|
|
138
132
|
except ProjectError:
|
|
139
133
|
raise
|
|
140
134
|
except DiscoveryError as error:
|
|
141
|
-
raise ProjectError(
|
|
142
|
-
"media_offline", "目前無法讀取素材,請確認外接硬碟已連接。", status_code=409
|
|
143
|
-
) from error
|
|
135
|
+
raise ProjectError("media_offline", "目前無法讀取素材,請確認外接硬碟已連接。", status_code=409) from error
|
|
144
136
|
except (json.JSONDecodeError, OSError, sqlite3.Error, TypeError, ValueError) as error:
|
|
145
|
-
raise ProjectError(
|
|
146
|
-
"media_unavailable", "Clipen 無法安全開啟這個素材。", status_code=500
|
|
147
|
-
) from error
|
|
137
|
+
raise ProjectError("media_unavailable", "Clipen 無法安全開啟這個素材。", status_code=500) from error
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
from decimal import Decimal, InvalidOperation
|
|
7
|
-
from fractions import Fraction
|
|
8
5
|
import hashlib
|
|
9
6
|
import json
|
|
10
7
|
import os
|
|
@@ -16,19 +13,19 @@ import subprocess
|
|
|
16
13
|
import tempfile
|
|
17
14
|
import threading
|
|
18
15
|
import time
|
|
19
|
-
from
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from decimal import Decimal, InvalidOperation
|
|
18
|
+
from fractions import Fraction
|
|
19
|
+
from typing import Any, Mapping
|
|
20
20
|
|
|
21
21
|
from .discovery import DiscoveredAsset, DiscoveryError, open_file_beneath
|
|
22
22
|
from .models import AssetKind, InventoryRoot, MediaStream
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
_MAX_CAPTURE_BYTES = 4 * 1024 * 1024
|
|
26
25
|
_MAX_STREAMS = 64
|
|
27
26
|
_POLL_SECONDS = 0.05
|
|
28
27
|
_CODEC = re.compile(r"[A-Za-z0-9_.-]{1,80}\Z")
|
|
29
|
-
_CAPTURE_TIME = re.compile(
|
|
30
|
-
r"\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:?\d{2})?\Z"
|
|
31
|
-
)
|
|
28
|
+
_CAPTURE_TIME = re.compile(r"\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:?\d{2})?\Z")
|
|
32
29
|
_ISO6709 = re.compile(r"([+-]\d{2,3}(?:\.\d+)?)([+-]\d{3}(?:\.\d+)?)(?:[+-]\d+(?:\.\d+)?)?/?\Z")
|
|
33
30
|
|
|
34
31
|
|
|
@@ -49,10 +46,7 @@ class MediaProbeError(RuntimeError):
|
|
|
49
46
|
|
|
50
47
|
@property
|
|
51
48
|
def has_version(self) -> bool:
|
|
52
|
-
return all(
|
|
53
|
-
value is not None
|
|
54
|
-
for value in (self.fingerprint, self.size_bytes, self.mtime_ns)
|
|
55
|
-
)
|
|
49
|
+
return all(value is not None for value in (self.fingerprint, self.size_bytes, self.mtime_ns))
|
|
56
50
|
|
|
57
51
|
|
|
58
52
|
@dataclass(frozen=True)
|
|
@@ -242,9 +236,7 @@ def bounded_file_fingerprint(descriptor: int, size: int) -> str:
|
|
|
242
236
|
return digest.hexdigest()
|
|
243
237
|
|
|
244
238
|
|
|
245
|
-
def _parse_probe(
|
|
246
|
-
raw: bytes, expected_kind: AssetKind
|
|
247
|
-
) -> tuple[dict[str, object], tuple[MediaStream, ...]]:
|
|
239
|
+
def _parse_probe(raw: bytes, expected_kind: AssetKind) -> tuple[dict[str, object], tuple[MediaStream, ...]]:
|
|
248
240
|
try:
|
|
249
241
|
value = json.loads(raw.decode("utf-8"))
|
|
250
242
|
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
|
@@ -278,16 +270,10 @@ def _parse_probe(
|
|
|
278
270
|
for key in ("start_pts", "duration_ts"):
|
|
279
271
|
candidate = raw_stream.get(key)
|
|
280
272
|
if candidate is not None:
|
|
281
|
-
details[key] = str(
|
|
282
|
-
_integer(candidate, minimum=-(2**63), maximum=2**63 - 1)
|
|
283
|
-
)
|
|
273
|
+
details[key] = str(_integer(candidate, minimum=-(2**63), maximum=2**63 - 1))
|
|
284
274
|
if kind == "video":
|
|
285
|
-
details["width"] = _integer(
|
|
286
|
-
|
|
287
|
-
)
|
|
288
|
-
details["height"] = _integer(
|
|
289
|
-
raw_stream.get("height"), minimum=1, maximum=131_072
|
|
290
|
-
)
|
|
275
|
+
details["width"] = _integer(raw_stream.get("width"), minimum=1, maximum=131_072)
|
|
276
|
+
details["height"] = _integer(raw_stream.get("height"), minimum=1, maximum=131_072)
|
|
291
277
|
rotation = _rotation(raw_stream)
|
|
292
278
|
if rotation is not None:
|
|
293
279
|
details["rotation"] = rotation
|
|
@@ -296,22 +282,14 @@ def _parse_probe(
|
|
|
296
282
|
if isinstance(candidate, str) and 1 <= len(candidate) <= 80:
|
|
297
283
|
details[key] = candidate
|
|
298
284
|
else:
|
|
299
|
-
details["sample_rate"] = _integer(
|
|
300
|
-
|
|
301
|
-
)
|
|
302
|
-
details["channels"] = _integer(
|
|
303
|
-
raw_stream.get("channels"), minimum=1, maximum=64
|
|
304
|
-
)
|
|
285
|
+
details["sample_rate"] = _integer(raw_stream.get("sample_rate"), minimum=1, maximum=768_000)
|
|
286
|
+
details["channels"] = _integer(raw_stream.get("channels"), minimum=1, maximum=64)
|
|
305
287
|
streams.append(MediaStream(index, kind, codec, details))
|
|
306
288
|
if not streams:
|
|
307
289
|
raise MediaProbeError("unsupported")
|
|
308
|
-
if expected_kind is AssetKind.AUDIO and not any(
|
|
309
|
-
stream.kind == "audio" for stream in streams
|
|
310
|
-
):
|
|
290
|
+
if expected_kind is AssetKind.AUDIO and not any(stream.kind == "audio" for stream in streams):
|
|
311
291
|
raise MediaProbeError("unsupported")
|
|
312
|
-
if expected_kind in {AssetKind.VIDEO, AssetKind.IMAGE} and not any(
|
|
313
|
-
stream.kind == "video" for stream in streams
|
|
314
|
-
):
|
|
292
|
+
if expected_kind in {AssetKind.VIDEO, AssetKind.IMAGE} and not any(stream.kind == "video" for stream in streams):
|
|
315
293
|
raise MediaProbeError("unsupported")
|
|
316
294
|
raw_format = value.get("format", {})
|
|
317
295
|
if not isinstance(raw_format, dict):
|
|
@@ -353,9 +331,7 @@ def _parse_probe(
|
|
|
353
331
|
return summary, tuple(streams)
|
|
354
332
|
|
|
355
333
|
|
|
356
|
-
def _metadata_value(
|
|
357
|
-
groups: list[Mapping[str, object]], keys: tuple[str, ...], maximum: int
|
|
358
|
-
) -> str | None:
|
|
334
|
+
def _metadata_value(groups: list[Mapping[str, object]], keys: tuple[str, ...], maximum: int) -> str | None:
|
|
359
335
|
for key in keys:
|
|
360
336
|
lowered = key.casefold()
|
|
361
337
|
for group in groups:
|
|
@@ -401,11 +377,7 @@ def _decimal(value: object, *, non_negative: bool) -> str:
|
|
|
401
377
|
result = Decimal(str(value))
|
|
402
378
|
except (InvalidOperation, ValueError) as error:
|
|
403
379
|
raise MediaProbeError("invalid_probe_output") from error
|
|
404
|
-
if (
|
|
405
|
-
not result.is_finite()
|
|
406
|
-
or (non_negative and result < 0)
|
|
407
|
-
or abs(result) > Decimal("1e12")
|
|
408
|
-
):
|
|
380
|
+
if not result.is_finite() or (non_negative and result < 0) or abs(result) > Decimal("1e12"):
|
|
409
381
|
raise MediaProbeError("invalid_probe_output")
|
|
410
382
|
return format(result.normalize(), "f")
|
|
411
383
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from dataclasses import dataclass
|
|
6
5
|
import queue
|
|
7
6
|
import threading
|
|
7
|
+
from dataclasses import dataclass
|
|
8
8
|
from typing import Callable, Iterable, Protocol
|
|
9
9
|
|
|
10
10
|
from clipen.projects.models import ProjectError
|
|
@@ -21,7 +21,6 @@ from .models import (
|
|
|
21
21
|
from .probe import FFprobeAdapter, MediaProbeError, MediaProbeResult
|
|
22
22
|
from .storage import InventoryRepository
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
_ITEM_PROBE_ERRORS = {
|
|
26
25
|
"unsupported": ProbeStatus.UNSUPPORTED,
|
|
27
26
|
"unreadable": ProbeStatus.UNREADABLE,
|
|
@@ -34,9 +33,7 @@ _STAGE_BATCH_SIZE = 32
|
|
|
34
33
|
|
|
35
34
|
|
|
36
35
|
class _Discovery(Protocol):
|
|
37
|
-
def scan(
|
|
38
|
-
self, root: InventoryRoot, cancel: threading.Event | None = None
|
|
39
|
-
) -> Iterable[DiscoveredAsset]: ...
|
|
36
|
+
def scan(self, root: InventoryRoot, cancel: threading.Event | None = None) -> Iterable[DiscoveredAsset]: ...
|
|
40
37
|
|
|
41
38
|
|
|
42
39
|
class _Probe(Protocol):
|
|
@@ -83,12 +80,8 @@ class InventoryCoordinator:
|
|
|
83
80
|
recovered += self.repository.interrupt_incomplete(project_id)
|
|
84
81
|
return recovered
|
|
85
82
|
|
|
86
|
-
def start(
|
|
87
|
-
|
|
88
|
-
) -> InventoryRun:
|
|
89
|
-
run, created = self.repository.create_run_with_status(
|
|
90
|
-
project_id, request_id, expected_revision
|
|
91
|
-
)
|
|
83
|
+
def start(self, project_id: str, request_id: object, expected_revision: object) -> InventoryRun:
|
|
84
|
+
run, created = self.repository.create_run_with_status(project_id, request_id, expected_revision)
|
|
92
85
|
if not created:
|
|
93
86
|
return run
|
|
94
87
|
with self._lock:
|
|
@@ -180,9 +173,7 @@ class InventoryCoordinator:
|
|
|
180
173
|
candidate = self._inspect(prober, root, discovered, cancel)
|
|
181
174
|
batch.append(candidate)
|
|
182
175
|
if len(batch) >= _STAGE_BATCH_SIZE:
|
|
183
|
-
self.repository.stage_items(
|
|
184
|
-
job.project_id, job.run_id, tuple(batch)
|
|
185
|
-
)
|
|
176
|
+
self.repository.stage_items(job.project_id, job.run_id, tuple(batch))
|
|
186
177
|
batch.clear()
|
|
187
178
|
if cancel.is_set():
|
|
188
179
|
self._finish_cancel(job)
|
|
@@ -217,11 +208,7 @@ class InventoryCoordinator:
|
|
|
217
208
|
) -> AssetCandidate:
|
|
218
209
|
if not discovered.should_probe:
|
|
219
210
|
issue_code = discovered.issue_code or "non_media"
|
|
220
|
-
status =
|
|
221
|
-
ItemStatus.NEEDS_ATTENTION
|
|
222
|
-
if issue_code == "entry_unreadable"
|
|
223
|
-
else ItemStatus.IGNORED
|
|
224
|
-
)
|
|
211
|
+
status = ItemStatus.NEEDS_ATTENTION if issue_code == "entry_unreadable" else ItemStatus.IGNORED
|
|
225
212
|
return AssetCandidate(
|
|
226
213
|
discovered.role,
|
|
227
214
|
discovered.relative_path,
|