detect: remove leftover if-True indent marker
Dead syntax left over from a prior refactor. No behavior change.
This commit is contained in:
parent
cf8bc0ad89
commit
0f26475f52
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
### Refactored
|
### Refactored
|
||||||
- `category_fetcher` batch tag-API params are now built by a shared `_build_tag_api_params` helper instead of duplicated across `fetch_via_tag_api` and `_probe_batch_api`
|
- `category_fetcher` batch tag-API params are now built by a shared `_build_tag_api_params` helper instead of duplicated across `fetch_via_tag_api` and `_probe_batch_api`
|
||||||
|
- `detect.detect_site_type` — removed the leftover `if True:` indent marker; no behavior change
|
||||||
|
|
||||||
## v0.2.7
|
## v0.2.7
|
||||||
|
|
||||||
|
|||||||
@ -46,78 +46,77 @@ async def detect_site_type(
|
|||||||
limits=httpx.Limits(max_connections=10, max_keepalive_connections=5),
|
limits=httpx.Limits(max_connections=10, max_keepalive_connections=5),
|
||||||
)
|
)
|
||||||
client = _BC._shared_client
|
client = _BC._shared_client
|
||||||
if True: # keep indent level
|
# Try Danbooru / e621 first — /posts.json is a definitive endpoint
|
||||||
# Try Danbooru / e621 first — /posts.json is a definitive endpoint
|
try:
|
||||||
try:
|
params: dict = {"limit": 1}
|
||||||
params: dict = {"limit": 1}
|
if api_key and api_user:
|
||||||
if api_key and api_user:
|
params["login"] = api_user
|
||||||
params["login"] = api_user
|
params["api_key"] = api_key
|
||||||
params["api_key"] = api_key
|
resp = await client.get(f"{url}/posts.json", params=params)
|
||||||
resp = await client.get(f"{url}/posts.json", params=params)
|
if resp.status_code == 200:
|
||||||
if resp.status_code == 200:
|
data = resp.json()
|
||||||
data = resp.json()
|
if isinstance(data, dict) and "posts" in data:
|
||||||
if isinstance(data, dict) and "posts" in data:
|
# e621/e926 wraps in {"posts": [...]}, with nested file/tags dicts
|
||||||
# e621/e926 wraps in {"posts": [...]}, with nested file/tags dicts
|
posts = data["posts"]
|
||||||
posts = data["posts"]
|
if isinstance(posts, list) and posts:
|
||||||
if isinstance(posts, list) and posts:
|
p = posts[0]
|
||||||
p = posts[0]
|
if isinstance(p.get("file"), dict) and isinstance(p.get("tags"), dict):
|
||||||
if isinstance(p.get("file"), dict) and isinstance(p.get("tags"), dict):
|
return "e621"
|
||||||
return "e621"
|
|
||||||
return "danbooru"
|
|
||||||
elif isinstance(data, list) and data:
|
|
||||||
# Danbooru returns a flat list of post objects
|
|
||||||
if isinstance(data[0], dict) and any(
|
|
||||||
k in data[0] for k in ("tag_string", "image_width", "large_file_url")
|
|
||||||
):
|
|
||||||
return "danbooru"
|
|
||||||
elif resp.status_code in (401, 403):
|
|
||||||
if "e621" in url or "e926" in url:
|
|
||||||
return "e621"
|
|
||||||
return "danbooru"
|
return "danbooru"
|
||||||
except Exception as e:
|
elif isinstance(data, list) and data:
|
||||||
log.warning("Danbooru/e621 probe failed for %s: %s: %s",
|
# Danbooru returns a flat list of post objects
|
||||||
url, type(e).__name__, e)
|
if isinstance(data[0], dict) and any(
|
||||||
|
k in data[0] for k in ("tag_string", "image_width", "large_file_url")
|
||||||
|
):
|
||||||
|
return "danbooru"
|
||||||
|
elif resp.status_code in (401, 403):
|
||||||
|
if "e621" in url or "e926" in url:
|
||||||
|
return "e621"
|
||||||
|
return "danbooru"
|
||||||
|
except Exception as e:
|
||||||
|
log.warning("Danbooru/e621 probe failed for %s: %s: %s",
|
||||||
|
url, type(e).__name__, e)
|
||||||
|
|
||||||
# Try Gelbooru — /index.php?page=dapi
|
# Try Gelbooru — /index.php?page=dapi
|
||||||
try:
|
try:
|
||||||
params = {
|
params = {
|
||||||
"page": "dapi", "s": "post", "q": "index", "json": "1", "limit": 1,
|
"page": "dapi", "s": "post", "q": "index", "json": "1", "limit": 1,
|
||||||
}
|
}
|
||||||
if api_key and api_user:
|
if api_key and api_user:
|
||||||
params["api_key"] = api_key
|
params["api_key"] = api_key
|
||||||
params["user_id"] = api_user
|
params["user_id"] = api_user
|
||||||
resp = await client.get(f"{url}/index.php", params=params)
|
resp = await client.get(f"{url}/index.php", params=params)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
if isinstance(data, list) and data and isinstance(data[0], dict):
|
if isinstance(data, list) and data and isinstance(data[0], dict):
|
||||||
if any(k in data[0] for k in ("file_url", "preview_url", "directory")):
|
if any(k in data[0] for k in ("file_url", "preview_url", "directory")):
|
||||||
return "gelbooru"
|
|
||||||
elif isinstance(data, dict):
|
|
||||||
if "post" in data or "@attributes" in data:
|
|
||||||
return "gelbooru"
|
|
||||||
elif resp.status_code in (401, 403):
|
|
||||||
if "gelbooru" in url or "safebooru.org" in url or "rule34" in url:
|
|
||||||
return "gelbooru"
|
return "gelbooru"
|
||||||
except Exception as e:
|
elif isinstance(data, dict):
|
||||||
log.warning("Gelbooru probe failed for %s: %s: %s",
|
if "post" in data or "@attributes" in data:
|
||||||
url, type(e).__name__, e)
|
return "gelbooru"
|
||||||
|
elif resp.status_code in (401, 403):
|
||||||
|
if "gelbooru" in url or "safebooru.org" in url or "rule34" in url:
|
||||||
|
return "gelbooru"
|
||||||
|
except Exception as e:
|
||||||
|
log.warning("Gelbooru probe failed for %s: %s: %s",
|
||||||
|
url, type(e).__name__, e)
|
||||||
|
|
||||||
# Try Moebooru — /post.json (singular)
|
# Try Moebooru — /post.json (singular)
|
||||||
try:
|
try:
|
||||||
params = {"limit": 1}
|
params = {"limit": 1}
|
||||||
if api_key and api_user:
|
if api_key and api_user:
|
||||||
params["login"] = api_user
|
params["login"] = api_user
|
||||||
params["password_hash"] = api_key
|
params["password_hash"] = api_key
|
||||||
resp = await client.get(f"{url}/post.json", params=params)
|
resp = await client.get(f"{url}/post.json", params=params)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
if isinstance(data, list) or (isinstance(data, dict) and "posts" in data):
|
if isinstance(data, list) or (isinstance(data, dict) and "posts" in data):
|
||||||
return "moebooru"
|
|
||||||
elif resp.status_code in (401, 403):
|
|
||||||
return "moebooru"
|
return "moebooru"
|
||||||
except Exception as e:
|
elif resp.status_code in (401, 403):
|
||||||
log.warning("Moebooru probe failed for %s: %s: %s",
|
return "moebooru"
|
||||||
url, type(e).__name__, e)
|
except Exception as e:
|
||||||
|
log.warning("Moebooru probe failed for %s: %s: %s",
|
||||||
|
url, type(e).__name__, e)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user