Add YAPF style + ignore, and format tracked Python files
This commit is contained in:
@@ -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