added discord functionality to extension and polished some of downloader process.

This commit is contained in:
Bryan Van Deusen
2026-01-24 23:15:03 -05:00
parent b9b8048a2d
commit 058901cd05
6 changed files with 186 additions and 28 deletions
+3 -2
View File
@@ -172,11 +172,12 @@ async def verify_credentials():
# TODO: Implement actual verification by making test request
# For now, just mark as verified
credential.last_verified = datetime.utcnow()
verified_at = datetime.utcnow()
credential.last_verified = verified_at
await session.commit()
return jsonify({
"platform": platform,
"is_valid": True,
"last_verified": credential.last_verified.isoformat(),
"last_verified": verified_at.isoformat(),
})
+25 -4
View File
@@ -134,13 +134,16 @@ class GalleryDLService:
- Managing temporary config files
"""
# Platform-specific default content types
# Platform-specific default content types and options
# Directory patterns are relative - subscription_name/platform is prepended automatically
PLATFORM_DEFAULTS = {
"patreon": {
"content_types": ["images", "image_large", "attachments", "postfile", "content"],
"directory": ["{date:%Y-%m-%d}_{id}_{title[:40]}"],
"filename": "{num:>02}_{filename}.{extension}",
# Additional options
"videos": True, # Download video content
"embeds": True, # Download embedded URLs (YouTube, etc.)
},
"subscribestar": {
"content_types": ["all"],
@@ -151,11 +154,16 @@ class GalleryDLService:
"content_types": ["pictures"],
"directory": [], # Flat structure within platform folder
"filename": "{category}_{index:>03}_{title[:50]}.{extension}",
"include": "all", # Include all content types
},
"discord": {
"content_types": ["all"],
"directory": ["{channel}"],
"filename": "{date:%Y%m%d}_{message_id}_{filename}.{extension}",
"directory": ["{channel[name]}"],
"filename": "{date:%Y%m%d}_{id}_{filename}.{extension}",
# Additional options
"embeds": True, # Download embedded URLs
"stickers": True, # Download stickers
"reactions": False, # Skip reaction images
},
}
@@ -256,6 +264,11 @@ class GalleryDLService:
# Build platform-specific section
platform_config = {}
# Apply all platform defaults first (videos, embeds, stickers, etc.)
for key, value in platform_defaults.items():
if key not in ["content_types", "directory", "filename"]:
platform_config[key] = value
# Content types (platform-specific handling)
if platform == "patreon":
# Patreon uses "files" array for content types
@@ -266,7 +279,7 @@ class GalleryDLService:
elif platform == "hentaifoundry":
# HentaiFoundry uses "include" for content filtering
if "pictures" in source_config.content_types or "all" in source_config.content_types:
platform_config["include"] = "pictures"
platform_config["include"] = "all"
# Directory pattern
if source_config.directory_pattern:
@@ -342,6 +355,7 @@ class GalleryDLService:
platform: str,
source_config: Optional[SourceConfig] = None,
cookies_path: Optional[str] = None,
auth_token: Optional[str] = None,
) -> DownloadResult:
"""Execute a gallery-dl download.
@@ -351,6 +365,7 @@ class GalleryDLService:
platform: Platform name (patreon, subscribestar, etc.)
source_config: Optional per-source configuration overrides
cookies_path: Optional path to cookies file
auth_token: Optional auth token (for Discord and other token-based platforms)
Returns:
DownloadResult with success status and details
@@ -377,6 +392,12 @@ class GalleryDLService:
if cookies_path:
config["extractor"]["cookies"] = cookies_path
# Add auth token for Discord
if auth_token and platform == "discord":
if "discord" not in config["extractor"]:
config["extractor"]["discord"] = {}
config["extractor"]["discord"]["token"] = auth_token
# Write temporary config file
with tempfile.NamedTemporaryFile(
mode="w",
+12 -3
View File
@@ -95,10 +95,18 @@ async def _download_source_async(source_id: int) -> dict:
try:
# Get credentials
cred_manager = CredentialManager(session)
cookies_path = await cred_manager.get_cookies_path(source.platform)
cookies_path = None
auth_token = None
if not cookies_path and source.platform in ["patreon", "subscribestar"]:
logger.warning(f"No credentials for {source.platform}, download may fail")
# Discord uses token auth, others use cookies
if source.platform == "discord":
auth_token = await cred_manager.get_token(source.platform)
if not auth_token:
logger.warning(f"No token for {source.platform}, download may fail")
else:
cookies_path = await cred_manager.get_cookies_path(source.platform)
if not cookies_path and source.platform in ["patreon", "subscribestar"]:
logger.warning(f"No credentials for {source.platform}, download may fail")
# Build source config from metadata
source_config = SourceConfig.from_dict(source.metadata_ or {})
@@ -111,6 +119,7 @@ async def _download_source_async(source_id: int) -> dict:
platform=source.platform,
source_config=source_config,
cookies_path=cookies_path,
auth_token=auth_token,
)
# Update download record