tuning job log views and deep scan archive processing.

This commit is contained in:
Bryan Van Deusen
2026-02-02 18:48:01 -05:00
parent 042a69f9c3
commit 09883960d4
9 changed files with 1078 additions and 103 deletions
+61
View File
@@ -846,8 +846,69 @@ def is_first_volume(path: str) -> bool:
return True
def extract_archive_name(filename: str) -> str:
"""
Extract a clean archive name from a filename by removing common prefixes.
Handles patterns like:
- "43387617_attachment_83109081_October 2020 Rewards.rar" -> "October 2020 Rewards"
- "01_Archive Name.zip" -> "Archive Name"
- "Archive Name.rar" -> "Archive Name"
Returns the cleaned name without extension.
"""
import re
from pathlib import Path
# Remove extension
stem = Path(filename).stem
# Pattern 1: Gallery-DL style "{id}_attachment_{id}_{name}" or "{id}_{name}"
# Match one or more numeric_prefix patterns at the start
cleaned = re.sub(r'^(\d+_)+(attachment_)?(\d+_)?', '', stem)
# Pattern 2: Simple numeric prefix "01_name" or "001_name"
if cleaned == stem: # No match from pattern 1
cleaned = re.sub(r'^\d+_', '', stem)
# If we stripped everything or got empty, fall back to original stem
if not cleaned.strip():
cleaned = stem
return cleaned.strip()
def compute_archive_tag_name(artist: str, archive_filename: str) -> str:
"""
Generate an archive tag name in the format: '{artist}:{archive_name}'
Examples:
- artist="InCaseArt", filename="43387617_attachment_83109081_October 2020 Rewards.rar"
-> "InCaseArt:October 2020 Rewards"
If a tag with the same name already exists, appends a numeric suffix.
"""
archive_name = extract_archive_name(archive_filename)
base_tag = f"{artist}:{archive_name}"
# Check if tag already exists
existing = Tag.query.filter_by(name=base_tag, kind='archive').first()
if not existing:
return base_tag
# Tag exists, add numeric suffix
n = 2
while True:
candidate = f"{base_tag} ({n})"
if not Tag.query.filter_by(name=candidate, kind='archive').first():
return candidate
n += 1
def compute_next_archive_tag_name(artist: str, width: int = ARCHIVE_NUM_WIDTH) -> str:
"""
DEPRECATED: Use compute_archive_tag_name() instead.
Return a unique incremental tag name like: 'archive:{artist}/0001', '0002', ...
- Looks only at Tag(kind='archive') with names starting 'archive:{artist}/'
- Finds max numeric suffix and returns next number (zero-padded).