Add YAPF style + ignore, and format tracked Python files
This commit is contained in:
@@ -15,7 +15,9 @@ class SearchResult:
|
||||
path: str # Download target (URL, path, magnet, identifier)
|
||||
|
||||
detail: str = "" # Additional description
|
||||
annotations: List[str] = field(default_factory=list) # Tags: ["120MB", "flac", "ready"]
|
||||
annotations: List[str] = field(
|
||||
default_factory=list
|
||||
) # Tags: ["120MB", "flac", "ready"]
|
||||
media_kind: str = "other" # Type: "book", "audio", "video", "game", "magnet"
|
||||
size_bytes: Optional[int] = None
|
||||
tag: set[str] = field(default_factory=set) # Searchable tag values
|
||||
@@ -63,7 +65,8 @@ class Provider(ABC):
|
||||
self,
|
||||
query: str,
|
||||
limit: int = 50,
|
||||
filters: Optional[Dict[str, Any]] = None,
|
||||
filters: Optional[Dict[str,
|
||||
Any]] = None,
|
||||
**kwargs: Any,
|
||||
) -> List[SearchResult]:
|
||||
"""Search for items matching the query."""
|
||||
@@ -84,7 +87,12 @@ class Provider(ABC):
|
||||
return True
|
||||
|
||||
def selector(
|
||||
self, selected_items: List[Any], *, ctx: Any, stage_is_last: bool = True, **_kwargs: Any
|
||||
self,
|
||||
selected_items: List[Any],
|
||||
*,
|
||||
ctx: Any,
|
||||
stage_is_last: bool = True,
|
||||
**_kwargs: Any
|
||||
) -> bool:
|
||||
"""Optional hook for handling `@N` selection semantics.
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ def download_file(
|
||||
*,
|
||||
session: Optional[requests.Session] = None,
|
||||
timeout_s: float = 30.0,
|
||||
progress_callback: Optional[Callable[[int, Optional[int], str], None]] = None,
|
||||
progress_callback: Optional[Callable[[int,
|
||||
Optional[int],
|
||||
str],
|
||||
None]] = None,
|
||||
) -> bool:
|
||||
output_path = Path(output_path)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
@@ -69,7 +72,10 @@ def download_file(
|
||||
progress_callback(downloaded, total, label)
|
||||
elif bar is not None:
|
||||
bar.update(
|
||||
downloaded=downloaded, total=total, label=label, file=sys.stderr
|
||||
downloaded=downloaded,
|
||||
total=total,
|
||||
label=label,
|
||||
file=sys.stderr
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -26,23 +26,23 @@ from Provider.zeroxzero import ZeroXZero
|
||||
from Provider.loc import LOC
|
||||
from Provider.internetarchive import InternetArchive
|
||||
|
||||
|
||||
_PROVIDERS: Dict[str, Type[Provider]] = {
|
||||
# Search-capable providers
|
||||
"alldebrid": AllDebrid,
|
||||
"libgen": Libgen,
|
||||
"openlibrary": OpenLibrary,
|
||||
"internetarchive": InternetArchive,
|
||||
"soulseek": Soulseek,
|
||||
"bandcamp": Bandcamp,
|
||||
"youtube": YouTube,
|
||||
"telegram": Telegram,
|
||||
"loc": LOC,
|
||||
# Upload-capable providers
|
||||
"0x0": ZeroXZero,
|
||||
"file.io": FileIO,
|
||||
"matrix": Matrix,
|
||||
}
|
||||
_PROVIDERS: Dict[str,
|
||||
Type[Provider]] = {
|
||||
# Search-capable providers
|
||||
"alldebrid": AllDebrid,
|
||||
"libgen": Libgen,
|
||||
"openlibrary": OpenLibrary,
|
||||
"internetarchive": InternetArchive,
|
||||
"soulseek": Soulseek,
|
||||
"bandcamp": Bandcamp,
|
||||
"youtube": YouTube,
|
||||
"telegram": Telegram,
|
||||
"loc": LOC,
|
||||
# Upload-capable providers
|
||||
"0x0": ZeroXZero,
|
||||
"file.io": FileIO,
|
||||
"matrix": Matrix,
|
||||
}
|
||||
|
||||
|
||||
def is_known_provider_name(name: str) -> bool:
|
||||
@@ -64,7 +64,9 @@ def _supports_upload(provider: Provider) -> bool:
|
||||
return provider.__class__.upload is not Provider.upload
|
||||
|
||||
|
||||
def get_provider(name: str, config: Optional[Dict[str, Any]] = None) -> Optional[Provider]:
|
||||
def get_provider(name: str,
|
||||
config: Optional[Dict[str,
|
||||
Any]] = None) -> Optional[Provider]:
|
||||
"""Get a provider by name (unified registry)."""
|
||||
|
||||
provider_class = _PROVIDERS.get((name or "").lower())
|
||||
@@ -86,7 +88,8 @@ def get_provider(name: str, config: Optional[Dict[str, Any]] = None) -> Optional
|
||||
def list_providers(config: Optional[Dict[str, Any]] = None) -> Dict[str, bool]:
|
||||
"""List all providers and their availability."""
|
||||
|
||||
availability: Dict[str, bool] = {}
|
||||
availability: Dict[str,
|
||||
bool] = {}
|
||||
for name, provider_class in _PROVIDERS.items():
|
||||
try:
|
||||
provider = provider_class(config)
|
||||
@@ -96,9 +99,9 @@ def list_providers(config: Optional[Dict[str, Any]] = None) -> Dict[str, bool]:
|
||||
return availability
|
||||
|
||||
|
||||
def get_search_provider(
|
||||
name: str, config: Optional[Dict[str, Any]] = None
|
||||
) -> Optional[SearchProvider]:
|
||||
def get_search_provider(name: str,
|
||||
config: Optional[Dict[str,
|
||||
Any]] = None) -> Optional[SearchProvider]:
|
||||
"""Get a search-capable provider by name (compat API)."""
|
||||
|
||||
provider = get_provider(name, config)
|
||||
@@ -113,17 +116,22 @@ def get_search_provider(
|
||||
def list_search_providers(config: Optional[Dict[str, Any]] = None) -> Dict[str, bool]:
|
||||
"""List all search providers and their availability."""
|
||||
|
||||
availability: Dict[str, bool] = {}
|
||||
availability: Dict[str,
|
||||
bool] = {}
|
||||
for name, provider_class in _PROVIDERS.items():
|
||||
try:
|
||||
provider = provider_class(config)
|
||||
availability[name] = bool(provider.validate() and _supports_search(provider))
|
||||
availability[name] = bool(
|
||||
provider.validate() and _supports_search(provider)
|
||||
)
|
||||
except Exception:
|
||||
availability[name] = False
|
||||
return availability
|
||||
|
||||
|
||||
def get_file_provider(name: str, config: Optional[Dict[str, Any]] = None) -> Optional[FileProvider]:
|
||||
def get_file_provider(name: str,
|
||||
config: Optional[Dict[str,
|
||||
Any]] = None) -> Optional[FileProvider]:
|
||||
"""Get an upload-capable provider by name (compat API)."""
|
||||
|
||||
provider = get_provider(name, config)
|
||||
@@ -138,11 +146,14 @@ def get_file_provider(name: str, config: Optional[Dict[str, Any]] = None) -> Opt
|
||||
def list_file_providers(config: Optional[Dict[str, Any]] = None) -> Dict[str, bool]:
|
||||
"""List all file providers and their availability."""
|
||||
|
||||
availability: Dict[str, bool] = {}
|
||||
availability: Dict[str,
|
||||
bool] = {}
|
||||
for name, provider_class in _PROVIDERS.items():
|
||||
try:
|
||||
provider = provider_class(config)
|
||||
availability[name] = bool(provider.validate() and _supports_upload(provider))
|
||||
availability[name] = bool(
|
||||
provider.validate() and _supports_upload(provider)
|
||||
)
|
||||
except Exception:
|
||||
availability[name] = False
|
||||
return availability
|
||||
@@ -177,10 +188,8 @@ def match_provider_name_for_url(url: str) -> Optional[str]:
|
||||
if host == "archive.org" or host.endswith(".archive.org"):
|
||||
low_path = str(path or "").lower()
|
||||
is_borrowish = (
|
||||
low_path.startswith("/borrow/")
|
||||
or low_path.startswith("/stream/")
|
||||
or low_path.startswith("/services/loans/")
|
||||
or "/services/loans/" in low_path
|
||||
low_path.startswith("/borrow/") or low_path.startswith("/stream/")
|
||||
or low_path.startswith("/services/loans/") or "/services/loans/" in low_path
|
||||
)
|
||||
if is_borrowish:
|
||||
return "openlibrary" if "openlibrary" in _PROVIDERS else None
|
||||
@@ -200,7 +209,9 @@ def match_provider_name_for_url(url: str) -> Optional[str]:
|
||||
return None
|
||||
|
||||
|
||||
def get_provider_for_url(url: str, config: Optional[Dict[str, Any]] = None) -> Optional[Provider]:
|
||||
def get_provider_for_url(url: str,
|
||||
config: Optional[Dict[str,
|
||||
Any]] = None) -> Optional[Provider]:
|
||||
"""Instantiate and return the matching provider for a URL, if any."""
|
||||
|
||||
name = match_provider_name_for_url(url)
|
||||
|
||||
Reference in New Issue
Block a user