updating and refining plugin system refactor
This commit is contained in:
+13
-13
@@ -55,12 +55,13 @@ class Download_File(Cmdlet):
|
||||
name="download-file",
|
||||
summary="Download files or streaming media",
|
||||
usage=
|
||||
"download-file <url> [-path DIR] [options] OR @N | download-file [-path DIR|DIR] [options]",
|
||||
"download-file <url> [-plugin NAME] [-instance NAME] [-path DIR] [options] OR @N | download-file [-plugin NAME] [-instance NAME] [-path DIR] [options]",
|
||||
alias=["dl-file",
|
||||
"download-http"],
|
||||
arg=[
|
||||
SharedArgs.URL,
|
||||
SharedArgs.PLUGIN,
|
||||
SharedArgs.INSTANCE,
|
||||
SharedArgs.PATH,
|
||||
SharedArgs.QUERY,
|
||||
QueryArg(
|
||||
@@ -85,6 +86,7 @@ class Download_File(Cmdlet):
|
||||
],
|
||||
detail=[
|
||||
"Download files directly via HTTP or streaming media via yt-dlp.",
|
||||
"Use -plugin with -instance to target a named provider config when a plugin exposes multiple instances.",
|
||||
"For Internet Archive item pages (archive.org/details/...), shows a selectable file/format list; pick with @N to download.",
|
||||
],
|
||||
exec=self.run,
|
||||
@@ -522,13 +524,13 @@ class Download_File(Cmdlet):
|
||||
config: Dict[str,
|
||||
Any],
|
||||
) -> List[Any]:
|
||||
get_search_plugin = registry.get("get_search_plugin")
|
||||
get_provider = registry.get("get_plugin")
|
||||
expanded_items: List[Any] = []
|
||||
|
||||
for item in piped_items:
|
||||
try:
|
||||
provider_key = self._provider_key_from_item(item)
|
||||
provider = get_search_plugin(provider_key, config) if provider_key and get_search_plugin else None
|
||||
provider = get_provider(provider_key, config) if provider_key and get_provider else None
|
||||
|
||||
# Generic hook: If provider has expand_item(item), use it.
|
||||
if provider and hasattr(provider, "expand_item") and callable(provider.expand_item):
|
||||
@@ -566,7 +568,7 @@ class Download_File(Cmdlet):
|
||||
) -> tuple[int, int]:
|
||||
downloaded_count = 0
|
||||
queued_magnet_submissions = 0
|
||||
get_search_plugin = registry.get("get_search_plugin")
|
||||
get_provider = registry.get("get_plugin")
|
||||
SearchResult = registry.get("SearchResult")
|
||||
|
||||
expanded_items = self._expand_provider_items(
|
||||
@@ -622,15 +624,15 @@ class Download_File(Cmdlet):
|
||||
|
||||
transfer_label = label
|
||||
|
||||
# If this looks like a provider item and providers are available, prefer provider.download()
|
||||
# If this looks like a plugin-owned item and a plugin is available, prefer plugin.download().
|
||||
downloaded_path: Optional[Path] = None
|
||||
attempted_provider_download = False
|
||||
provider_sr = None
|
||||
provider_obj = None
|
||||
provider_key = self._provider_key_from_item(item)
|
||||
if provider_key and get_search_plugin and SearchResult:
|
||||
# Reuse helper to derive the provider key from table/provider/source hints.
|
||||
provider_obj = get_search_plugin(provider_key, config)
|
||||
if provider_key and get_provider and SearchResult:
|
||||
# Reuse helper to derive the plugin key from table/plugin/source hints.
|
||||
provider_obj = get_provider(provider_key, config)
|
||||
|
||||
if provider_obj is not None and getattr(provider_obj, "prefers_transfer_progress", False):
|
||||
try:
|
||||
@@ -697,7 +699,7 @@ class Download_File(Cmdlet):
|
||||
)
|
||||
continue
|
||||
|
||||
# Allow providers to add/enrich tags and metadata during download.
|
||||
# Allow plugins to add or enrich tags and metadata during download.
|
||||
if provider_sr is not None:
|
||||
try:
|
||||
sr_md = getattr(provider_sr, "full_metadata", None)
|
||||
@@ -838,9 +840,9 @@ class Download_File(Cmdlet):
|
||||
notes: Optional[Dict[str, str]] = None
|
||||
try:
|
||||
if isinstance(full_metadata, dict):
|
||||
# Providers attach pre-built notes under the generic "_notes" key
|
||||
# Plugins attach pre-built notes under the generic "_notes" key
|
||||
# (e.g. Tidal sets {"lyric": subtitles} during download enrichment).
|
||||
# This keeps provider-specific metadata handling inside the provider.
|
||||
# This keeps plugin-specific metadata handling inside the plugin.
|
||||
_provider_notes = full_metadata.get("_notes")
|
||||
if isinstance(_provider_notes, dict) and _provider_notes:
|
||||
notes = {str(k): str(v) for k, v in _provider_notes.items() if k and v}
|
||||
@@ -949,7 +951,6 @@ class Download_File(Cmdlet):
|
||||
|
||||
return {
|
||||
"get_plugin": getattr(provider_registry, "get_plugin", None),
|
||||
"get_search_plugin": getattr(provider_registry, "get_search_plugin", None),
|
||||
"match_plugin_name_for_url": getattr(provider_registry, "match_plugin_name_for_url", None),
|
||||
"list_selection_url_prefixes": getattr(provider_registry, "list_selection_url_prefixes", None),
|
||||
"SearchResult": SearchResult,
|
||||
@@ -957,7 +958,6 @@ class Download_File(Cmdlet):
|
||||
except Exception:
|
||||
return {
|
||||
"get_plugin": None,
|
||||
"get_search_plugin": None,
|
||||
"match_plugin_name_for_url": None,
|
||||
"list_selection_url_prefixes": None,
|
||||
"SearchResult": None,
|
||||
|
||||
Reference in New Issue
Block a user