abafc3265e
Operator-requested 2026-05-27: centralize the per-platform quirks that
had been accumulating across credential_service, sidecar, and platforms
into a single per-platform module so adding/updating quirks becomes
"edit one file."
**Layout**
services/platforms/
base.py PlatformInfo dataclass + module-default key
chains + shared helpers (str_id_value, str_field)
__init__.py PLATFORMS dict + public API (auth_type_for,
known_platform_keys, to_dict,
external_post_id_keys_for, description_keys_for)
patreon.py metadata only — the reference platform, no quirks
subscribestar.py metadata + augment_cookies (18+ agreement) +
derive_post_url (synthetic /posts/<post_id>)
hentaifoundry.py metadata + augment_cookies (host-only PHPSESSID
duplicate) + derive_post_url (/pictures/user/...)
pixiv.py metadata + derive_post_url (/artworks/<id>)
discord.py metadata + derive_post_url
(channels/<server>/<channel>/<message>)
deviantart.py metadata only — un-audited; quirks to be added
when an operator first exercises DA
**PlatformInfo extensions**
Existing fields preserved. Four new optional fields:
external_post_id_keys: tuple[str, ...] | None
Override the sidecar external_post_id lookup chain. None falls
back to DEFAULT_EXTERNAL_POST_ID_KEYS in base.py
("post_id", "id", "index", "message_id") — covers every current
platform.
description_keys: tuple[str, ...] | None
Override the description body lookup chain. None falls back to
DEFAULT_DESCRIPTION_KEYS ("content", "description", "caption",
"message") — Discord's "message" body field is covered by the
default's trailing entry.
derive_post_url: Callable[[dict], str | None] | None
Synthesize the post permalink from sidecar metadata. None = trust
the bare `url` / `post_url` field (patreon, deviantart).
subscribestar/pixiv/hf/discord override this because their `url`
is the file CDN URL.
augment_cookies: Callable[[str], str] | None
Post-process the materialized cookies.txt before gallery-dl
consumes it. None = no-op. Used by subscribestar (age cookie) and
hentaifoundry (host-only PHPSESSID duplicate).
**Consumer changes**
- credential_service._augment_cookies(platform, netscape) shrunk from a
per-platform-conditional dispatcher (~80 lines of inlined helpers) to
a 5-line lookup: `info.augment_cookies(netscape) if info and
info.augment_cookies else netscape`. The platform-specific helper
bodies moved verbatim into the per-platform modules.
- sidecar.parse_sidecar similarly delegates: external_post_id chain via
external_post_id_keys_for(category), description chain via
description_keys_for(category), post_url via
PLATFORMS[category].derive_post_url. The _DERIVED_URL_PLATFORMS set
and inline _derive_post_url body both gone. Added a shared `_first_id`
helper for bool-safe id coercion.
**Public API preserved**
PLATFORMS, PlatformInfo, auth_type_for, known_platform_keys, to_dict
are all re-exported from the package's __init__.py. test_platforms_registry
test_credential_service, and test_sidecar_util pass without changes
because the behavior is identical; only the implementation moved.
**Adding a new platform**
1. Create services/platforms/<name>.py with `INFO = PlatformInfo(...)`
and any of the four optional hooks.
2. Import it in services/platforms/__init__.py + add to the PLATFORMS
tuple-comprehension.
3. Done. sidecar parsing, cookie materialization, /api/platforms all
pick it up automatically.
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
"""SubscribeStar — three quirks colocated.
|
|
|
|
1. external_post_id: gallery-dl puts the per-attachment id in `id`
|
|
(e.g. 711509) and the actual post id in `post_id` (e.g. 360360).
|
|
The default chain in base.py already prefers `post_id`; this module
|
|
doesn't need to override it but the comment lives here too so a
|
|
future reader knows the chain's order was driven by this platform.
|
|
|
|
2. post_url: gallery-dl's `url` is the file CDN URL
|
|
(`/post_uploads?payload=...`). Synthesize the post permalink from
|
|
`post_id`.
|
|
|
|
3. augment_cookies: the server gates artist pages behind a
|
|
`_personalization_id` age-confirmation cookie that the user can't
|
|
easily refresh — SubscribeStar's frontend JS uses localStorage to
|
|
suppress the age popup once dismissed. gallery-dl's own login flow
|
|
sidesteps this by setting `18_plus_agreement_generic=true` on
|
|
`.subscribestar.adult`; we mirror that for cookies captured via the
|
|
extension.
|
|
"""
|
|
|
|
from .base import GD_DEFAULTS, PlatformInfo, str_id_value
|
|
|
|
|
|
def derive_post_url(data: dict) -> str | None:
|
|
pid = str_id_value(data.get("post_id"))
|
|
if pid:
|
|
return f"https://www.subscribestar.com/posts/{pid}"
|
|
return None
|
|
|
|
|
|
def augment_cookies(netscape: str) -> str:
|
|
if "18_plus_agreement_generic" in netscape:
|
|
return netscape
|
|
# Far-future expiry — gallery-dl's own login flow sets this with no
|
|
# explicit expiry; the server only checks presence/value.
|
|
expiry = 4102444800 # 2100-01-01 UTC
|
|
line = "\t".join([
|
|
".subscribestar.adult", "TRUE", "/", "TRUE",
|
|
str(expiry), "18_plus_agreement_generic", "true",
|
|
])
|
|
body = netscape.rstrip("\n")
|
|
if not body:
|
|
body = "# Netscape HTTP Cookie File"
|
|
return body + "\n" + line + "\n"
|
|
|
|
|
|
INFO = PlatformInfo(
|
|
key="subscribestar",
|
|
name="SubscribeStar",
|
|
description="Download posts from SubscribeStar creators",
|
|
auth_type="cookies",
|
|
requires_auth=True,
|
|
url_pattern=r"^https?://(www\.)?subscribestar\.(com|adult)/",
|
|
url_examples=[
|
|
"https://subscribestar.adult/example_artist",
|
|
"https://www.subscribestar.com/example_artist",
|
|
],
|
|
default_config={**GD_DEFAULTS, "content_types": ["all"]},
|
|
derive_post_url=derive_post_url,
|
|
augment_cookies=augment_cookies,
|
|
)
|