updated panel display
This commit is contained in:
+80
-40
@@ -18,7 +18,7 @@ from contextlib import AbstractContextManager, nullcontext
|
||||
|
||||
from API.HTTP import _download_direct_file
|
||||
from SYS.models import DownloadError, DownloadOptions, DownloadMediaResult
|
||||
from SYS.logger import log, debug, is_debug_enabled
|
||||
from SYS.logger import log, debug, debug_panel, is_debug_enabled
|
||||
from SYS.payload_builders import build_file_result_payload, build_table_result_payload
|
||||
from SYS.pipeline_progress import PipelineProgress
|
||||
from SYS.result_table import Table
|
||||
@@ -113,7 +113,17 @@ class Download_File(Cmdlet):
|
||||
|
||||
def run(self, result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
"""Main execution method."""
|
||||
debug(f"[download-file] run invoked with args: {list(args)}")
|
||||
try:
|
||||
debug_panel(
|
||||
"download-file",
|
||||
[
|
||||
("args", list(args)),
|
||||
("has_piped_input", bool(result)),
|
||||
],
|
||||
border_style="cyan",
|
||||
)
|
||||
except Exception:
|
||||
debug(f"[download-file] run invoked with args: {list(args)}")
|
||||
return self._run_impl(result, args, config)
|
||||
|
||||
@staticmethod
|
||||
@@ -1008,7 +1018,6 @@ class Download_File(Cmdlet):
|
||||
from Store import Store
|
||||
from API.HydrusNetwork import is_hydrus_available
|
||||
|
||||
debug("[download-file] Initializing storage interface...")
|
||||
storage = Store(config=config or {}, suppress_debug=True)
|
||||
hydrus_available = bool(is_hydrus_available(config or {}))
|
||||
|
||||
@@ -1126,7 +1135,6 @@ class Download_File(Cmdlet):
|
||||
@staticmethod
|
||||
def _canonicalize_url_for_storage(*, requested_url: str, ytdlp_tool: YtDlpTool, playlist_items: Optional[str]) -> str:
|
||||
if playlist_items:
|
||||
debug(f"[download-file] Skipping canonicalization for playlist item(s): {playlist_items}")
|
||||
return str(requested_url)
|
||||
try:
|
||||
cf = None
|
||||
@@ -1136,16 +1144,13 @@ class Download_File(Cmdlet):
|
||||
cf = str(cookie_path)
|
||||
except Exception:
|
||||
cf = None
|
||||
|
||||
debug(f"[download-file] Canonicalizing URL: {requested_url}")
|
||||
|
||||
pr = probe_url(requested_url, no_playlist=False, timeout_seconds=15, cookiefile=cf)
|
||||
if isinstance(pr, dict):
|
||||
for key in ("webpage_url", "original_url", "url", "requested_url"):
|
||||
value = pr.get(key)
|
||||
if isinstance(value, str) and value.strip():
|
||||
canon = value.strip()
|
||||
if canon != requested_url:
|
||||
debug(f"[download-file] Resolved canonical URL: {requested_url} -> {canon}")
|
||||
return canon
|
||||
except Exception as e:
|
||||
debug(f"[download-file] Canonicalization error for {requested_url}: {e}")
|
||||
@@ -1180,7 +1185,8 @@ class Download_File(Cmdlet):
|
||||
urls=unique_to_check,
|
||||
storage=storage,
|
||||
hydrus_available=hydrus_available,
|
||||
final_output_dir=final_output_dir
|
||||
final_output_dir=final_output_dir,
|
||||
auto_continue_duplicates=False,
|
||||
)
|
||||
|
||||
def _preflight_url_duplicates_bulk(
|
||||
@@ -1204,7 +1210,8 @@ class Download_File(Cmdlet):
|
||||
urls=unique_urls,
|
||||
storage=storage,
|
||||
hydrus_available=hydrus_available,
|
||||
final_output_dir=final_output_dir
|
||||
final_output_dir=final_output_dir,
|
||||
auto_continue_duplicates=False,
|
||||
)
|
||||
|
||||
|
||||
@@ -1512,6 +1519,7 @@ class Download_File(Cmdlet):
|
||||
download_timeout_seconds: int,
|
||||
) -> int:
|
||||
downloaded_count = 0
|
||||
duplicate_skipped_count = 0
|
||||
downloaded_pipe_objects: List[Dict[str, Any]] = []
|
||||
pipe_seq = 0
|
||||
clip_sections_spec = self._build_clip_sections_spec(clip_ranges)
|
||||
@@ -1527,9 +1535,6 @@ class Download_File(Cmdlet):
|
||||
|
||||
for url_index, url in enumerate(supported_url, 1):
|
||||
try:
|
||||
debug(f"[download-file] Processing URL in loop: {url}")
|
||||
debug(f"[download-file] ytdl_format parameter passed in: {ytdl_format}")
|
||||
|
||||
display_total = batch_total if batch_total > 0 else total_urls
|
||||
display_index = batch_index if batch_total > 0 else url_index
|
||||
display_label = batch_label or str(url)
|
||||
@@ -1543,7 +1548,6 @@ class Download_File(Cmdlet):
|
||||
)
|
||||
|
||||
if not skip_per_url_preflight:
|
||||
debug(f"[download-file] Running duplicate preflight for: {canonical_url}")
|
||||
if not self._preflight_url_duplicate(
|
||||
storage=storage,
|
||||
hydrus_available=hydrus_available,
|
||||
@@ -1551,9 +1555,25 @@ class Download_File(Cmdlet):
|
||||
candidate_url=canonical_url,
|
||||
extra_urls=[url],
|
||||
):
|
||||
duplicate_skipped_count += 1
|
||||
log(f"Skipping download (duplicate found): {url}", file=sys.stderr)
|
||||
continue
|
||||
|
||||
try:
|
||||
debug_panel(
|
||||
f"Download item {display_index}/{display_total or total_urls}",
|
||||
[
|
||||
("url", url),
|
||||
("canonical_url", canonical_url),
|
||||
("mode", mode),
|
||||
("format", ytdl_format or "auto"),
|
||||
("duplicate_preflight", not skip_per_url_preflight),
|
||||
],
|
||||
border_style="green",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if aggregate_status_mode:
|
||||
try:
|
||||
if display_total > 0:
|
||||
@@ -1682,11 +1702,7 @@ class Download_File(Cmdlet):
|
||||
actual_format = f"{actual_format}+bestaudio"
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
debug(
|
||||
"[download-file] Resolved format for download: "
|
||||
f"mode={mode}, format={actual_format or 'default'}, playlist_items={actual_playlist_items}"
|
||||
)
|
||||
|
||||
|
||||
attempted_single_format_fallback = False
|
||||
attempted_audio_fallback_specific = False
|
||||
@@ -1709,9 +1725,7 @@ class Download_File(Cmdlet):
|
||||
|
||||
if not aggregate_status_mode:
|
||||
PipelineProgress(pipeline_context).step("downloading")
|
||||
debug(f"Starting download for {url} (format: {actual_format or 'default'}) with {download_timeout_seconds}s activity timeout...")
|
||||
result_obj = _download_with_timeout(opts, timeout_seconds=download_timeout_seconds, config=config)
|
||||
debug(f"Download completed for {url}, building pipe object...")
|
||||
break
|
||||
except DownloadError as e:
|
||||
cause = getattr(e, "__cause__", None)
|
||||
@@ -2028,8 +2042,6 @@ class Download_File(Cmdlet):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
debug(f"Emitting {len(pipe_objects)} result(s) to pipeline...")
|
||||
|
||||
if not aggregate_status_mode:
|
||||
PipelineProgress(pipeline_context).step("finalized")
|
||||
|
||||
@@ -2049,7 +2061,17 @@ class Download_File(Cmdlet):
|
||||
pass
|
||||
|
||||
downloaded_count += len(pipe_objects)
|
||||
debug("✓ Downloaded and emitted")
|
||||
try:
|
||||
debug_panel(
|
||||
"download-file result",
|
||||
[
|
||||
("emitted", len(pipe_objects)),
|
||||
("url", url),
|
||||
],
|
||||
border_style="green",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
except DownloadError as e:
|
||||
log(f"Download failed for {url}: {e}", file=sys.stderr)
|
||||
@@ -2057,7 +2079,8 @@ class Download_File(Cmdlet):
|
||||
log(f"Error processing {url}: {e}", file=sys.stderr)
|
||||
|
||||
if downloaded_count > 0:
|
||||
debug(f"✓ Successfully processed {downloaded_count} URL(s)")
|
||||
return 0
|
||||
if duplicate_skipped_count > 0:
|
||||
return 0
|
||||
|
||||
log("No downloads completed", file=sys.stderr)
|
||||
@@ -2072,7 +2095,6 @@ class Download_File(Cmdlet):
|
||||
parsed: Dict[str, Any],
|
||||
) -> int:
|
||||
try:
|
||||
debug("Starting streaming download handler")
|
||||
suppress_nested, _batch_total, _batch_index, _batch_label = self._batch_progress_state(config)
|
||||
|
||||
ytdlp_tool = YtDlpTool(config)
|
||||
@@ -2091,21 +2113,18 @@ class Download_File(Cmdlet):
|
||||
if not final_output_dir:
|
||||
return 1
|
||||
|
||||
debug(f"Output directory: {final_output_dir}")
|
||||
|
||||
progress = PipelineProgress(pipeline_context)
|
||||
using_shared_ui = pipeline_context.get_stage_context() is not None
|
||||
try:
|
||||
# If we are already in a pipeline stage, the parent UI is already handling progress.
|
||||
# Calling ensure_local_ui can cause re-initialization hangs on some platforms.
|
||||
if pipeline_context.get_stage_context() is None:
|
||||
debug("[download-file] Initializing local UI...")
|
||||
if not using_shared_ui:
|
||||
progress.ensure_local_ui(
|
||||
label="download-file",
|
||||
total_items=len(supported_url),
|
||||
items_preview=supported_url,
|
||||
)
|
||||
else:
|
||||
debug("[download-file] Skipping local UI: running inside pipeline stage")
|
||||
try:
|
||||
if not suppress_nested:
|
||||
progress.begin_pipe(
|
||||
@@ -2116,8 +2135,6 @@ class Download_File(Cmdlet):
|
||||
debug(f"[download-file] PipelineProgress begin_pipe error: {err}")
|
||||
except Exception as e:
|
||||
debug(f"[download-file] PipelineProgress update error: {e}")
|
||||
|
||||
debug("[download-file] Parsing clip and query specs...")
|
||||
clip_spec = parsed.get("clip")
|
||||
query_spec = parsed.get("query")
|
||||
|
||||
@@ -2223,7 +2240,6 @@ class Download_File(Cmdlet):
|
||||
ytdl_format = query_format
|
||||
|
||||
if not ytdl_format:
|
||||
debug(f"[download-file] Checking for playlist at {candidate_url}...")
|
||||
if self._maybe_show_playlist_table(url=candidate_url, ytdlp_tool=ytdlp_tool):
|
||||
playlist_selection_handled = True
|
||||
# ... (existing logging code) ...
|
||||
@@ -2270,7 +2286,6 @@ class Download_File(Cmdlet):
|
||||
forced_single_format_id = None
|
||||
forced_single_format_for_batch = False
|
||||
|
||||
debug("[download-file] Checking if format table should be shown...")
|
||||
early_ret = self._maybe_show_format_table_for_single_url(
|
||||
mode=mode,
|
||||
clip_spec=clip_spec,
|
||||
@@ -2343,7 +2358,23 @@ class Download_File(Cmdlet):
|
||||
except Exception:
|
||||
timeout_seconds = 300
|
||||
|
||||
debug(f"[download-file] Proceeding to final download call for {len(supported_url)} URL(s)...")
|
||||
try:
|
||||
debug_panel(
|
||||
"Streaming download",
|
||||
[
|
||||
("urls", len(supported_url)),
|
||||
("mode", mode),
|
||||
("format", ytdl_format or "auto"),
|
||||
("output_dir", final_output_dir),
|
||||
("ui", "shared pipeline" if using_shared_ui else "local"),
|
||||
("playlist_items", playlist_items),
|
||||
("skip_preflight", skip_per_url_preflight),
|
||||
("timeout_seconds", timeout_seconds),
|
||||
],
|
||||
border_style="blue",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return self._download_supported_urls(
|
||||
supported_url=supported_url,
|
||||
ytdlp_tool=ytdlp_tool,
|
||||
@@ -2855,8 +2886,6 @@ class Download_File(Cmdlet):
|
||||
prev_progress = None
|
||||
had_progress_key = False
|
||||
try:
|
||||
debug("Starting download-file")
|
||||
|
||||
# Allow providers to tap into the active PipelineProgress (optional).
|
||||
try:
|
||||
if isinstance(config, dict):
|
||||
@@ -3117,7 +3146,6 @@ class Download_File(Cmdlet):
|
||||
streaming_exit_code: Optional[int] = None
|
||||
streaming_downloaded = 0
|
||||
if supported_streaming:
|
||||
debug(f"[download-file] Using ytdlp provider for {len(supported_streaming)} URL(s)")
|
||||
streaming_exit_code = self._run_streaming_urls(
|
||||
streaming_urls=supported_streaming,
|
||||
args=args,
|
||||
@@ -3161,7 +3189,19 @@ class Download_File(Cmdlet):
|
||||
if not final_output_dir:
|
||||
return 1
|
||||
|
||||
debug(f"Output directory: {final_output_dir}")
|
||||
try:
|
||||
debug_panel(
|
||||
"download-file plan",
|
||||
[
|
||||
("output_dir", final_output_dir),
|
||||
("streaming_urls", len(supported_streaming)),
|
||||
("remaining_urls", len(raw_url)),
|
||||
("piped_items", len(piped_items) if isinstance(piped_items, list) else int(bool(piped_items))),
|
||||
],
|
||||
border_style="cyan",
|
||||
)
|
||||
except Exception:
|
||||
debug(f"Output directory: {final_output_dir}")
|
||||
|
||||
# If the caller isn't running the shared pipeline Live progress UI (e.g. direct
|
||||
# cmdlet execution), start a minimal local pipeline progress panel so downloads
|
||||
|
||||
Reference in New Issue
Block a user