This commit is contained in:
2026-02-08 01:35:44 -08:00
parent 60c2cc062c
commit d2e571b6f1
5 changed files with 160 additions and 9 deletions

View File

@@ -23,13 +23,46 @@ _KNOWN_EXTS = {
def _resolve_ext_from_meta(meta: Dict[str, Any], mime_type: Optional[str]) -> str:
ext = str(meta.get("ext") or "").strip().lstrip(".")
ext = ""
for key in ("ext", "file_ext", "extension", "file_extension"):
raw = meta.get(key)
if raw:
ext = str(raw).strip().lstrip(".")
break
if ext and ext not in _KNOWN_EXTS:
ext = ""
if ext.lower() == "ebook":
ext = ""
if not ext:
filetype_human = (
meta.get("filetype_human")
or meta.get("mime_human")
or meta.get("mime_string")
or meta.get("filetype")
)
ft = str(filetype_human or "").strip().lstrip(".").lower()
if ft and ft != "unknown filetype":
if ft.isalnum() and len(ft) <= 8:
ext = ft
else:
try:
for token in re.findall(r"[a-z0-9]+", ft):
if token in _KNOWN_EXTS:
ext = token
break
except Exception:
pass
if not ext:
if not mime_type or not isinstance(mime_type, str) or "/" not in mime_type:
mime_type = meta.get("mime_string") or meta.get("mime_human") or meta.get("filetype_mime") or mime_type
if not ext and mime_type:
try:
mime_type = str(mime_type).split(";", 1)[0].strip().lower()
except Exception:
mime_type = str(mime_type)
for category in mime_maps.values():
for _ext_key, info in category.items():
if mime_type in info.get("mimes", []):
@@ -1070,14 +1103,36 @@ class HydrusNetwork(Store):
except Exception:
pass
# Extra pass: match a full title phrase when the query includes
# spaces or punctuation (e.g., "i've been down").
try:
payloads.append(
client.search_files(
tags=freeform_predicates,
return_hashes=True,
return_file_ids=True,
)
if query_lower and query_lower != "*" and "*" not in query_lower:
if any(ch in query_lower for ch in (" ", "'", "-", "_")):
payloads.append(
client.search_files(
tags=[f"title:{query_lower}*"],
return_hashes=True,
return_file_ids=True,
)
)
except Exception:
pass
try:
title_ids, title_hashes = _extract_search_ids(
payloads[0] if payloads else None
)
# Optimization: for single-term queries, skip the freeform query
# to avoid duplicate requests.
single_term = bool(search_terms and len(search_terms) == 1)
if not single_term:
payloads.append(
client.search_files(
tags=freeform_predicates,
return_hashes=True,
return_file_ids=True,
)
)
except Exception:
pass