changes to mobile styling in modal view, complete reword of backend worker system

This commit is contained in:
Bryan Van Deusen
2026-01-20 13:14:13 -05:00
parent 96f72718bd
commit cb3897c0b0
22 changed files with 2432 additions and 487 deletions
+30 -9
View File
@@ -28,12 +28,10 @@ def find_sidecar_json(image_path: str) -> Optional[str]:
"""
Find the Gallery-DL sidecar JSON file for an image.
Gallery-DL creates JSON files with the UUID portion of the filename.
For example:
Image: 01_BBEFD45F-8775-4DF9-8BCA-99E6063E3616.jpg
JSON: BBEFD45F-8775-4DF9-8BCA-99E6063E3616.json
Also checks for direct {filename}.json pattern.
Gallery-DL creates JSON files with various naming patterns:
- Patreon: {filename}.json in same directory
- HentaiFoundry: {artist}-{index}-{title}.json (may differ from image filename)
- UUID-based: {uuid}.json where UUID is extracted from filename
Returns the path to the sidecar JSON if found, None otherwise.
"""
@@ -41,12 +39,18 @@ def find_sidecar_json(image_path: str) -> Optional[str]:
parent_dir = image_path.parent
stem = image_path.stem # filename without extension
# Pattern 1: Direct {filename}.json (e.g., image.jpg -> image.jpg.json)
# Pattern 1: Same stem with .json extension (most common)
# e.g., "Artist-12345-title.jpg" -> "Artist-12345-title.json"
stem_json = parent_dir / f"{stem}.json"
if stem_json.exists():
return str(stem_json)
# Pattern 2: Direct {filename}.json (e.g., image.jpg -> image.jpg.json)
direct_json = image_path.with_suffix(image_path.suffix + ".json")
if direct_json.exists():
return str(direct_json)
# Pattern 2: Extract UUID from filename and look for {uuid}.json
# Pattern 3: Extract UUID from filename and look for {uuid}.json
# Common patterns: "01_UUID", "UUID", "{num}_{UUID}"
uuid_pattern = re.compile(r'([A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12})', re.IGNORECASE)
match = uuid_pattern.search(stem)
@@ -56,7 +60,7 @@ def find_sidecar_json(image_path: str) -> Optional[str]:
if uuid_json.exists():
return str(uuid_json)
# Pattern 3: Just the stem without prefix numbers
# Pattern 4: Just the stem without prefix numbers
# e.g., "01_filename" -> look for "filename.json"
stem_no_prefix = re.sub(r'^\d+_', '', stem)
if stem_no_prefix != stem:
@@ -64,6 +68,18 @@ def find_sidecar_json(image_path: str) -> Optional[str]:
if alt_json.exists():
return str(alt_json)
# Pattern 5: Extract numeric ID from filename and find JSON with same ID
# Handles HentaiFoundry where image is "hentaifoundry_1000220_title.jpg"
# but JSON is "Artist-1000220-title.json"
# Look for a 5-7 digit number that could be a post ID
id_match = re.search(r'[_-](\d{5,8})[_-]', stem)
if id_match:
post_id = id_match.group(1)
# Search for any JSON file in the directory containing this ID
for json_file in parent_dir.glob("*.json"):
if f"-{post_id}-" in json_file.name or f"_{post_id}_" in json_file.name:
return str(json_file)
return None
@@ -122,9 +138,14 @@ def extract_artist(metadata: dict) -> Optional[str]:
def extract_post_id(metadata: dict) -> Optional[str]:
"""Extract the post ID from metadata."""
# Patreon, general
if "id" in metadata:
return str(metadata["id"])
# HentaiFoundry uses "index" as the post ID
if "index" in metadata:
return str(metadata["index"])
if "post_id" in metadata:
return str(metadata["post_id"])