j
This commit is contained in:
@@ -49,6 +49,38 @@ _PROVIDERS: Dict[str,
|
||||
}
|
||||
|
||||
|
||||
def get_provider_class(name: str) -> Optional[Type[Provider]]:
|
||||
"""Return the provider class for a registered provider name, if any."""
|
||||
key = str(name or "").strip().lower()
|
||||
return _PROVIDERS.get(key)
|
||||
|
||||
|
||||
def selection_auto_stage_for_table(
|
||||
table_type: str,
|
||||
stage_args: Optional[Sequence[str]] = None,
|
||||
) -> Optional[list[str]]:
|
||||
"""Return the provider-suggested stage to auto-run for a selected table.
|
||||
|
||||
This is used by the CLI to avoid hardcoding table names and behaviors.
|
||||
"""
|
||||
t = str(table_type or "").strip().lower()
|
||||
if not t:
|
||||
return None
|
||||
|
||||
# Provider tables are usually either:
|
||||
# - "youtube" (no dot)
|
||||
# - "hifi.tracks" (prefix = provider name)
|
||||
provider_key = t.split(".", 1)[0] if "." in t else t
|
||||
provider_class = get_provider_class(provider_key) or get_provider_class(t)
|
||||
if provider_class is None:
|
||||
return None
|
||||
|
||||
try:
|
||||
return provider_class.selection_auto_stage(t, stage_args)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def is_known_provider_name(name: str) -> bool:
|
||||
"""Return True if `name` matches a registered provider key.
|
||||
|
||||
@@ -251,4 +283,6 @@ __all__ = [
|
||||
"match_provider_name_for_url",
|
||||
"get_provider_for_url",
|
||||
"download_soulseek_file",
|
||||
"get_provider_class",
|
||||
"selection_auto_stage_for_table",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user