This commit is contained in:
2026-01-01 20:37:27 -08:00
parent f3c79609d8
commit deb05c0d44
35 changed files with 5030 additions and 4879 deletions

View File

@@ -519,8 +519,11 @@ class Add_File(Cmdlet):
# - If the sample URL only has one available format, force it for the batch.
# - If the sample URL appears audio-only (no video codecs), prefer audio mode.
try:
from cmdlet.download_media import is_url_supported_by_ytdlp, list_formats
from tool.ytdlp import YtDlpTool
from tool.ytdlp import (
YtDlpTool,
is_url_supported_by_ytdlp,
list_formats,
)
sample_url = unique_urls[0] if unique_urls else None
if sample_url and is_url_supported_by_ytdlp(str(sample_url)):
@@ -677,6 +680,59 @@ class Add_File(Cmdlet):
# Update pipe_obj with resolved path
pipe_obj.path = str(media_path_or_url)
table = None
full_metadata = None
if isinstance(pipe_obj.extra, dict):
table = pipe_obj.extra.get("table")
full_metadata = pipe_obj.extra.get("full_metadata")
provider_table = str(
table or getattr(pipe_obj, "provider", "")
).strip().lower()
if (provider_table == "alldebrid"
and isinstance(media_path_or_url, str)
and media_path_or_url.lower().startswith(
("http://", "https://"))
and (provider_name or location)):
url_str = str(media_path_or_url)
if url_str in skip_url_downloads:
log(
f"Skipping download (already stored): {url_str}",
file=sys.stderr,
)
successes += 1
continue
temp_dir_candidate = Path(
tempfile.mkdtemp(prefix="medios_alldebrid_")
)
downloaded_path: Optional[Path] = None
try:
from ProviderCore.registry import get_search_provider
provider = get_search_provider("alldebrid", config)
if provider is not None:
downloaded = provider.download(
pipe_obj,
temp_dir_candidate,
)
if downloaded:
downloaded_path = Path(downloaded)
except Exception as exc:
log(
f"[add-file] AllDebrid download failed: {exc}",
file=sys.stderr,
)
if downloaded_path and downloaded_path.exists():
media_path_or_url = downloaded_path
pipe_obj.path = str(downloaded_path)
pipe_obj.is_temp = True
delete_after_item = True
temp_dir_to_cleanup = temp_dir_candidate
processed_url_items.add(url_str)
else:
shutil.rmtree(temp_dir_candidate, ignore_errors=True)
# URL targets: prefer provider-aware download for OpenLibrary selections.
if isinstance(media_path_or_url,
str) and media_path_or_url.lower().startswith(
@@ -684,12 +740,6 @@ class Add_File(Cmdlet):
"https://",
"magnet:",
"torrent:")):
table = None
full_metadata = None
if isinstance(pipe_obj.extra, dict):
table = pipe_obj.extra.get("table")
full_metadata = pipe_obj.extra.get("full_metadata")
is_openlibrary = (str(table or "").lower() == "openlibrary") or (
"openlibrary.org/books/" in media_path_or_url.lower()
)
@@ -1079,7 +1129,7 @@ class Add_File(Cmdlet):
continue
# No destination specified: keep legacy behavior (download-media only).
code = self._delegate_to_download_media(
code = self._delegate_to_download_file(
item,
url_str,
location,
@@ -2052,7 +2102,7 @@ class Add_File(Cmdlet):
pass
return None
def _delegate_to_download_media(
def _delegate_to_download_file(
self,
result: Any,
url_str: str,
@@ -2062,13 +2112,13 @@ class Add_File(Cmdlet):
config: Dict[str,
Any],
) -> int:
"""Delegate URL handling to download-media cmdlet."""
"""Delegate URL handling to download-file cmdlet (yt-dlp path)."""
log(
f"Target is a URL, delegating to download-media: {url_str}",
f"Target is a URL, delegating to download-file: {url_str}",
file=sys.stderr
)
# Reuse the globally-registered cmdlet instance to avoid duplicative registration
from cmdlet.download_media import CMDLET as dl_cmdlet
from cmdlet.download_file import CMDLET as dl_cmdlet
dl_args = list(args) if args else []
@@ -2087,11 +2137,11 @@ class Add_File(Cmdlet):
if selection_args:
dl_args.extend(selection_args)
# download-media doesn't support -storage flag
# download-file doesn't support -storage flag
# It downloads to the configured directory, then add-file will handle storage
# Note: Provider uploads (0x0) are not supported via this path
# Call download-media with the URL in args
# Call download-file with the URL in args
return dl_cmdlet.run(None, dl_args, config)
@staticmethod
@@ -2832,17 +2882,16 @@ class Add_File(Cmdlet):
return []
try:
from cmdlet.download_media import (
CMDLET as dl_cmdlet,
from SYS.models import DownloadOptions
from tool.ytdlp import (
YtDlpTool,
_best_subtitle_sidecar,
_download_with_timeout,
_format_chapters_note,
_read_text_file,
is_url_supported_by_ytdlp,
list_formats,
_format_chapters_note,
_best_subtitle_sidecar,
_read_text_file,
)
from SYS.models import DownloadOptions
from tool.ytdlp import YtDlpTool
except Exception:
return []