implement post metadata import and views. implemented series paging and reader view.

This commit is contained in:
Bryan Van Deusen
2026-01-22 22:19:11 -05:00
parent f41acb40f6
commit a05aee5a07
16 changed files with 2298 additions and 8 deletions
+98 -1
View File
@@ -157,7 +157,95 @@ def extract_post_id(metadata: dict) -> Optional[str]:
def extract_post_title(metadata: dict) -> Optional[str]:
"""Extract the post title from metadata."""
return metadata.get("title")
title = metadata.get("title")
# Return None for empty strings
if title and isinstance(title, str) and title.strip():
return title.strip()
return None
def extract_description(metadata: dict) -> Optional[str]:
"""
Extract the post description/content from metadata.
Platform-specific fields:
- Patreon: 'content' (may be HTML)
- SubscribeStar: 'content' (may be HTML)
- HentaiFoundry: 'description' (plain text)
"""
# Try description first (HentaiFoundry uses this)
if "description" in metadata:
desc = metadata["description"]
if desc and isinstance(desc, str) and desc.strip():
return desc.strip()
# Try content (Patreon/SubscribeStar use this)
if "content" in metadata:
content = metadata["content"]
if content and isinstance(content, str) and content.strip():
return content.strip()
# Try teaser_text as fallback (Patreon)
if "teaser_text" in metadata:
teaser = metadata["teaser_text"]
if teaser and isinstance(teaser, str) and teaser.strip():
return teaser.strip()
return None
def extract_source_url(metadata: dict) -> Optional[str]:
"""
Extract the URL to the original post.
Platform-specific fields:
- Patreon: 'url' (direct post link)
- SubscribeStar: construct from author_name and post_id
- HentaiFoundry: construct from user and index
"""
platform = extract_platform(metadata)
# Direct URL field (Patreon)
if "url" in metadata:
url = metadata["url"]
if url and isinstance(url, str) and url.startswith("http"):
return url
# Construct URL for SubscribeStar
if platform == "subscribestar":
author = metadata.get("author_name")
post_id = metadata.get("post_id")
if author and post_id:
return f"https://subscribestar.adult/{author}/posts/{post_id}"
# Construct URL for HentaiFoundry
if platform == "hentaifoundry":
user = metadata.get("user") or metadata.get("artist")
index = metadata.get("index")
if user and index:
return f"https://www.hentai-foundry.com/pictures/user/{user}/{index}"
return None
def extract_attachment_count(metadata: dict) -> int:
"""
Extract the number of attachments/images in the post.
"""
# Patreon: check images array or post_metadata.image_order
if "images" in metadata and isinstance(metadata["images"], list):
return len(metadata["images"])
if "post_metadata" in metadata:
pm = metadata["post_metadata"]
if isinstance(pm, dict) and "image_order" in pm:
return len(pm["image_order"])
# Default to 1 if we have a file
if "filename" in metadata or "file" in metadata:
return 1
return 0
def extract_date(metadata: dict) -> Optional[datetime]:
@@ -336,6 +424,9 @@ def enrich_from_sidecar(image_path: str, existing_metadata: Optional[dict] = Non
"artist": str or None,
"post_id": str or None,
"post_title": str or None,
"description": str or None,
"source_url": str or None,
"attachment_count": int,
"taken_at": datetime or None,
"tags": [{"name": str, "kind": str}, ...],
"raw_metadata": dict or None (the full sidecar content)
@@ -346,6 +437,9 @@ def enrich_from_sidecar(image_path: str, existing_metadata: Optional[dict] = Non
"artist": None,
"post_id": None,
"post_title": None,
"description": None,
"source_url": None,
"attachment_count": 0,
"taken_at": None,
"tags": [],
"raw_metadata": None,
@@ -367,6 +461,9 @@ def enrich_from_sidecar(image_path: str, existing_metadata: Optional[dict] = Non
result["artist"] = extract_artist(metadata)
result["post_id"] = extract_post_id(metadata)
result["post_title"] = extract_post_title(metadata)
result["description"] = extract_description(metadata)
result["source_url"] = extract_source_url(metadata)
result["attachment_count"] = extract_attachment_count(metadata)
# Extract date and resolve conflicts with existing
sidecar_date = extract_date(metadata)