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
+66
View File
@@ -83,6 +83,72 @@ def find_sidecar_json(image_path: str) -> Optional[str]:
return None
def find_archive_sidecar(archive_path: str) -> Optional[str]:
"""
Find the Gallery-DL sidecar JSON file for an archive.
Gallery-DL names sidecars based on the archive's content filename,
which may differ from the archive filename due to prefixes added
during download (e.g., "02_HolyMeh July 2023.rar" -> "HolyMeh July 2023.json").
Args:
archive_path: Path to the archive file (e.g., "02_Filename.rar")
Returns:
Path to the sidecar JSON if found, None otherwise.
"""
archive_path = Path(archive_path)
parent_dir = archive_path.parent
stem = archive_path.stem # filename without extension
# Pattern 1: Exact stem match (most common case)
# e.g., "HolyMeh July 2023.rar" -> "HolyMeh July 2023.json"
stem_json = parent_dir / f"{stem}.json"
if stem_json.exists():
return str(stem_json)
# Pattern 2: Strip numeric prefix from archive name
# e.g., "02_HolyMeh July 2023.rar" -> "HolyMeh July 2023.json"
stem_no_prefix = re.sub(r'^\d+_', '', stem)
if stem_no_prefix != stem:
alt_json = parent_dir / f"{stem_no_prefix}.json"
if alt_json.exists():
return str(alt_json)
# Pattern 3: Look for any JSON in the directory that references this archive
# by checking the 'file_name' or 'filename' field in the JSON
for json_file in parent_dir.glob("*.json"):
try:
with open(json_file, "r", encoding="utf-8") as f:
data = json.load(f)
# Check if this JSON references our archive
# Gallery-DL uses 'file.file_name' or 'filename' + 'extension'
file_info = data.get("file", {})
json_filename = file_info.get("file_name", "")
if not json_filename:
# Try filename + extension pattern
fn = data.get("filename", "")
ext = data.get("extension", "")
if fn and ext:
json_filename = f"{fn}.{ext}"
# Compare with archive filename (with or without prefix)
archive_filename = archive_path.name
archive_filename_no_prefix = re.sub(r'^\d+_', '', archive_filename)
if json_filename and (
json_filename == archive_filename or
json_filename == archive_filename_no_prefix
):
return str(json_file)
except (json.JSONDecodeError, IOError):
continue
return None
def load_sidecar_metadata(json_path: str) -> Optional[dict]:
"""Load and parse a Gallery-DL sidecar JSON file."""
try: