This commit is contained in:
2026-06-04 17:42:38 +02:00
parent 5e941e6e6a
commit da07b55798
8 changed files with 1554 additions and 1480 deletions
+48 -7
View File
@@ -52,6 +52,11 @@ def init_db() -> None:
segments_count INTEGER NOT NULL,
intro_seconds REAL NOT NULL,
outro_seconds REAL NOT NULL,
reencode_enabled INTEGER NOT NULL DEFAULT 0,
encoding_passes INTEGER NOT NULL DEFAULT 1,
target_os TEXT NOT NULL DEFAULT 'windows',
ffmpeg_pass1_template TEXT,
ffmpeg_pass2_template TEXT,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
@@ -65,6 +70,7 @@ def init_db() -> None:
filename TEXT NOT NULL,
file_path TEXT NOT NULL,
duration_seconds REAL NOT NULL,
is_exported INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS markers (
@@ -80,6 +86,7 @@ def init_db() -> None:
segment_key TEXT NOT NULL,
start_seconds REAL NOT NULL,
end_seconds REAL NOT NULL,
color TEXT,
modified_at TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_markers_video_id ON markers(video_id);
@@ -90,6 +97,10 @@ def init_db() -> None:
columns = {row[1] for row in cur.fetchall()}
if "reencode_enabled" not in columns:
cur.execute("ALTER TABLE projects ADD COLUMN reencode_enabled INTEGER NOT NULL DEFAULT 0")
if "encoding_passes" not in columns:
cur.execute("ALTER TABLE projects ADD COLUMN encoding_passes INTEGER NOT NULL DEFAULT 1")
if "target_os" not in columns:
cur.execute("ALTER TABLE projects ADD COLUMN target_os TEXT NOT NULL DEFAULT 'windows'")
if "ffmpeg_pass1_template" not in columns:
cur.execute("ALTER TABLE projects ADD COLUMN ffmpeg_pass1_template TEXT")
if "ffmpeg_pass2_template" not in columns:
@@ -99,6 +110,13 @@ def init_db() -> None:
if "modified_at" not in segment_edit_columns:
cur.execute("ALTER TABLE segment_edits ADD COLUMN modified_at TEXT")
cur.execute("UPDATE segment_edits SET modified_at = ?", (_now(),))
if "color" not in segment_edit_columns:
cur.execute("ALTER TABLE segment_edits ADD COLUMN color TEXT")
cur.execute("PRAGMA table_info(videos)")
video_columns = {row[1] for row in cur.fetchall()}
if "is_exported" not in video_columns:
cur.execute("ALTER TABLE videos ADD COLUMN is_exported INTEGER NOT NULL DEFAULT 0")
cur.execute(
"UPDATE projects SET ffmpeg_pass1_template = ? WHERE ffmpeg_pass1_template IS NULL",
(DEFAULT_FFMPEG_PASS1_TEMPLATE,),
@@ -111,10 +129,19 @@ def init_db() -> None:
conn.close()
def mark_video_exported(video_id: str) -> None:
with _DB_LOCK:
conn = get_conn()
cur = conn.cursor()
cur.execute("UPDATE videos SET is_exported = 1 WHERE id = ?", (video_id,))
conn.commit()
def _normalize_project(project: dict | None) -> dict | None:
if not project:
return None
project["reencode_enabled"] = bool(project.get("reencode_enabled", 0))
project["encoding_passes"] = int(project.get("encoding_passes", 1))
project["target_os"] = project.get("target_os", "windows")
project["ffmpeg_pass1_template"] = project.get("ffmpeg_pass1_template") or DEFAULT_FFMPEG_PASS1_TEMPLATE
project["ffmpeg_pass2_template"] = project.get("ffmpeg_pass2_template") or DEFAULT_FFMPEG_PASS2_TEMPLATE
return project
@@ -126,6 +153,8 @@ def create_project(
intro_seconds: float,
outro_seconds: float,
reencode_enabled: bool = False,
encoding_passes: int = 1,
target_os: str = "windows",
ffmpeg_pass1_template: str | None = None,
ffmpeg_pass2_template: str | None = None,
) -> dict:
@@ -138,10 +167,11 @@ def create_project(
"""
INSERT INTO projects (
id, name, segments_count, intro_seconds, outro_seconds,
reencode_enabled, ffmpeg_pass1_template, ffmpeg_pass2_template,
reencode_enabled, encoding_passes, target_os,
ffmpeg_pass1_template, ffmpeg_pass2_template,
created_at, updated_at
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
project_id,
@@ -150,6 +180,8 @@ def create_project(
intro_seconds,
outro_seconds,
1 if reencode_enabled else 0,
encoding_passes,
target_os,
ffmpeg_pass1_template or DEFAULT_FFMPEG_PASS1_TEMPLATE,
ffmpeg_pass2_template or DEFAULT_FFMPEG_PASS2_TEMPLATE,
now,
@@ -199,6 +231,8 @@ def update_current_project(
intro_seconds: float | None = None,
outro_seconds: float | None = None,
reencode_enabled: bool | None = None,
encoding_passes: int | None = None,
target_os: str | None = None,
ffmpeg_pass1_template: str | None = None,
ffmpeg_pass2_template: str | None = None,
) -> dict | None:
@@ -222,6 +256,12 @@ def update_current_project(
if reencode_enabled is not None:
fields.append("reencode_enabled = ?")
params.append(1 if reencode_enabled else 0)
if encoding_passes is not None:
fields.append("encoding_passes = ?")
params.append(encoding_passes)
if target_os is not None:
fields.append("target_os = ?")
params.append(target_os)
if ffmpeg_pass1_template is not None:
fields.append("ffmpeg_pass1_template = ?")
params.append(ffmpeg_pass1_template or DEFAULT_FFMPEG_PASS1_TEMPLATE)
@@ -252,8 +292,8 @@ def create_video(project_id: str, filename: str, file_path: str, duration_second
cur = conn.cursor()
cur.execute(
"""
INSERT INTO videos (id, project_id, filename, file_path, duration_seconds, created_at)
VALUES (?, ?, ?, ?, ?, ?)
INSERT INTO videos (id, project_id, filename, file_path, duration_seconds, is_exported, created_at)
VALUES (?, ?, ?, ?, ?, 0, ?)
""",
(video_id, project_id, filename, file_path, duration_seconds, now),
)
@@ -342,9 +382,9 @@ def replace_segment_edits(video_id: str, segments: list[dict]) -> list[dict]:
cur.execute(
"""
INSERT INTO segment_edits (
id, video_id, segment_key, start_seconds, end_seconds, modified_at
id, video_id, segment_key, start_seconds, end_seconds, color, modified_at
)
VALUES (?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?)
""",
(
uuid.uuid4().hex,
@@ -352,13 +392,14 @@ def replace_segment_edits(video_id: str, segments: list[dict]) -> list[dict]:
segment["segment_key"],
float(segment["start_seconds"]),
float(segment["end_seconds"]),
segment.get("color"),
now,
),
)
conn.commit()
cur.execute(
"""
SELECT segment_key, start_seconds, end_seconds, modified_at
SELECT segment_key, start_seconds, end_seconds, color, modified_at
FROM segment_edits
WHERE video_id = ?
ORDER BY rowid