refactor(download): remove ProviderCore/download.py, move sanitize_filename to SYS.utils, replace callers to use API.HTTP.HTTPClient
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
@@ -46,9 +48,51 @@ class SearchResult:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
selection_args = getattr(self, "selection_args", None)
|
||||
except Exception:
|
||||
selection_args = None
|
||||
if selection_args is None:
|
||||
try:
|
||||
fm = getattr(self, "full_metadata", None)
|
||||
if isinstance(fm, dict):
|
||||
selection_args = fm.get("_selection_args") or fm.get("selection_args")
|
||||
except Exception:
|
||||
selection_args = None
|
||||
if selection_args:
|
||||
out["_selection_args"] = selection_args
|
||||
|
||||
return out
|
||||
|
||||
|
||||
def parse_inline_query_arguments(raw_query: str) -> Tuple[str, Dict[str, str]]:
|
||||
"""Extract inline key:value arguments from a provider search query."""
|
||||
|
||||
query_text = str(raw_query or "").strip()
|
||||
if not query_text:
|
||||
return "", {}
|
||||
|
||||
tokens = re.split(r"[,\s]+", query_text)
|
||||
leftover: List[str] = []
|
||||
parsed_args: Dict[str, str] = {}
|
||||
|
||||
for token in tokens:
|
||||
if not token:
|
||||
continue
|
||||
sep_index = token.find(":")
|
||||
if sep_index < 0:
|
||||
sep_index = token.find("=")
|
||||
if sep_index > 0:
|
||||
key = token[:sep_index].strip().lower()
|
||||
value = token[sep_index + 1 :].strip()
|
||||
if key and value:
|
||||
parsed_args[key] = value
|
||||
continue
|
||||
leftover.append(token)
|
||||
|
||||
return " ".join(leftover).strip(), parsed_args
|
||||
|
||||
|
||||
class Provider(ABC):
|
||||
"""Unified provider base class.
|
||||
|
||||
@@ -97,6 +141,12 @@ class Provider(ABC):
|
||||
return []
|
||||
return out
|
||||
|
||||
def extract_query_arguments(self, query: str) -> Tuple[str, Dict[str, Any]]:
|
||||
"""Allow providers to normalize query text and parse inline arguments."""
|
||||
|
||||
normalized = str(query or "").strip()
|
||||
return normalized, {}
|
||||
|
||||
# Standard lifecycle/auth hook.
|
||||
def login(self, **_kwargs: Any) -> bool:
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user