update download plugin

This commit is contained in:
2026-07-14 17:56:54 -07:00
parent 5e71a3cf54
commit a156700e6e
6 changed files with 125 additions and 81 deletions
+53 -2
View File
@@ -165,6 +165,43 @@ class Local(Provider):
def validate(self) -> bool:
return True
@staticmethod
def _folder_name_from_pipe(pipe_obj: Any) -> str:
metadata = getattr(pipe_obj, "metadata", None)
extra = getattr(pipe_obj, "extra", None)
if not isinstance(metadata, dict):
metadata = {}
if not isinstance(extra, dict):
extra = {}
plugin_name = str(
getattr(pipe_obj, "plugin", None)
or metadata.get("plugin")
or extra.get("plugin")
or ""
).strip().lower()
has_alldebrid_metadata = any(
isinstance(source, dict)
and (source.get("magnet_id") is not None or source.get("plugin") == "alldebrid")
for source in (metadata, extra)
)
if plugin_name != "alldebrid" and not has_alldebrid_metadata:
return ""
for source in (metadata, extra):
for key in ("folder_name", "folder", "magnet_name"):
value = str(source.get(key) or "").strip()
if value:
return value
magnet = source.get("magnet")
if isinstance(magnet, dict):
for key in ("filename", "name", "hash"):
value = str(magnet.get(key) or "").strip()
if value:
return value
return ""
def upload(self, file_path: str, **kwargs: Any) -> Dict[str, Any]:
source_path = Path(str(file_path or "")).expanduser()
if not source_path.exists() or not source_path.is_file():
@@ -210,6 +247,19 @@ class Local(Provider):
elif not destination_root.is_dir():
raise NotADirectoryError(f"Destination is not a directory: {destination_root}")
direct_export_download = bool(kwargs.get("direct_export_download", False))
folder_name = str(kwargs.get("folder_name") or "").strip()
if not folder_name and not direct_export_download:
folder_name = self._folder_name_from_pipe(kwargs.get("pipe_obj"))
export_root = destination_root
if folder_name and not direct_export_download:
export_root = destination_root / sanitize_filename(folder_name)
if create_dirs:
export_root.mkdir(parents=True, exist_ok=True)
elif not export_root.is_dir():
raise FileNotFoundError(f"Destination directory does not exist: {export_root}")
title = str(kwargs.get("title") or "").strip()
if not title:
title = source_path.stem.replace("_", " ").strip()
@@ -221,8 +271,7 @@ class Local(Provider):
else:
target_name = base_name + file_ext
direct_export_download = bool(kwargs.get("direct_export_download", False))
target_path = source_path if direct_export_download else destination_root / target_name
target_path = source_path if direct_export_download else export_root / target_name
if not direct_export_download:
if target_path.exists():
@@ -271,6 +320,8 @@ class Local(Provider):
"url": urls,
"export_path": str(destination_root),
}
if export_root != destination_root:
extra_updates["export_folder"] = str(export_root)
if resolved_name:
extra_updates["instance"] = resolved_name
if relationships: