cmdlet refactor

This commit is contained in:
2026-05-04 18:41:01 -07:00
parent 3ce339b3c1
commit 24f983473f
44 changed files with 1320 additions and 309 deletions
+5 -5
View File
@@ -30,21 +30,21 @@ PIPELINE_PRESETS: List[PipelinePreset] = [
PipelinePreset(
label="Download → Merge → Local",
description=
"Use download-file with playlist auto-selection, merge the pieces, tag, then import into local storage.",
"Use file -download with playlist auto-selection, merge the pieces, tag, then import into local storage.",
pipeline=
'download-file "<url>" | merge-file | add-tags -instance local | add-file -storage local',
'file -download "<url>" | file -merge | metadata -add -instance local | file -add -storage local',
),
PipelinePreset(
label="Download → Hydrus",
description="Fetch media, auto-tag, and push directly into Hydrus.",
pipeline=
'download-file "<url>" | merge-file | add-tags -instance hydrus | add-file -storage hydrus',
'file -download "<url>" | file -merge | metadata -add -instance hydrus | file -add -storage hydrus',
),
PipelinePreset(
label="Search Local Library",
description=
"Run search-file against the local library and emit a result table for further piping.",
pipeline='search-file -library local -query "<keywords>"',
"Run file -search against the local library and emit a result table for further piping.",
pipeline='file -search -library local -query "<keywords>"',
),
]
+28 -27
View File
@@ -404,7 +404,7 @@ class DownloadModal(ModalScreen):
download_succeeded = False
download_stderr_text = "" # Store for merge stage
if download_enabled:
download_cmdlet_name = "download-file"
download_cmdlet_name = "file"
download_cmdlet = get_cmdlet(download_cmdlet_name)
if download_cmdlet:
logger.info(f"📥 Executing {download_cmdlet_name} stage")
@@ -416,7 +416,7 @@ class DownloadModal(ModalScreen):
worker.log_step(f"Starting {download_cmdlet_name} stage...")
# Build yt-dlp playlist arguments for download-file streaming (if applicable).
cmdlet_args = []
cmdlet_args = ["-download"]
if self.is_playlist:
# Always use yt-dlp's native --playlist-items for playlists
if playlist_selection:
@@ -807,7 +807,7 @@ class DownloadModal(ModalScreen):
# Stage 2: Merge files if enabled and this is a playlist (BEFORE tagging)
merged_file_path = None
if merge_enabled and download_succeeded and self.is_playlist:
merge_cmdlet = get_cmdlet("merge-file")
merge_cmdlet = get_cmdlet("file")
if merge_cmdlet:
from pathlib import Path
@@ -818,6 +818,7 @@ class DownloadModal(ModalScreen):
worker.log_step("Starting merge-file stage...")
merge_args = [
"-merge",
"-delete",
"-format",
"mka",
@@ -963,10 +964,10 @@ class DownloadModal(ModalScreen):
else:
logger.info("merge-file cmdlet not found")
# Stage 3: Add tags (now after merge, if merge happened)
# Stage 3: Add metadata tags (now after merge, if merge happened)
# If merge succeeded, result_obj now points to merged file
if tags and (download_succeeded or not download_enabled):
add_tags_cmdlet = get_cmdlet("add-tags")
add_tags_cmdlet = get_cmdlet("metadata")
if add_tags_cmdlet:
logger.info(f"Executing add-tags stage with {len(tags)} tags")
logger.info(f" Tags: {tags}")
@@ -980,9 +981,9 @@ class DownloadModal(ModalScreen):
f"Starting add-tags stage with {len(tags)} tags..."
)
# Build add-tags arguments. add-tags requires a store; for downloads, default to local sidecar tagging.
# Build metadata-tag arguments. Default to local sidecar tagging for downloads.
tag_args = (
["-instance",
["-add", "-instance",
"local"] + [str(t) for t in tags] + ["--source",
str(source)]
)
@@ -1051,7 +1052,7 @@ class DownloadModal(ModalScreen):
self.app.call_from_thread(self._hide_progress)
return
else:
logger.error("add-tags cmdlet not found")
logger.error("metadata cmdlet not found for add stage")
else:
if tags and download_enabled and not download_succeeded:
skip_msg = "⚠️ Skipping add-tags stage because download failed"
@@ -1455,7 +1456,7 @@ class DownloadModal(ModalScreen):
# Tag the file if tags provided
if tags and get_cmdlet:
tag_cmdlet = get_cmdlet("add-tags")
tag_cmdlet = get_cmdlet("metadata")
if tag_cmdlet:
logger.info(f"Tagging merged PDF with {len(tags)} tags")
@@ -1475,7 +1476,7 @@ class DownloadModal(ModalScreen):
stdout_buf = io.StringIO()
stderr_buf = io.StringIO()
tag_args = ["-instance", "local"] + [str(t) for t in tags]
tag_args = ["-add", "-instance", "local"] + [str(t) for t in tags]
with redirect_stdout(stdout_buf), redirect_stderr(stderr_buf):
tag_returncode = tag_cmdlet(
result_obj,
@@ -1548,7 +1549,7 @@ class DownloadModal(ModalScreen):
wipe_tags_and_source: bool = False,
skip_tag_scraping: bool = False
) -> None:
"""Background worker to scrape metadata using get-tag cmdlet.
"""Background worker to scrape metadata using metadata -get.
Args:
url: URL to scrape metadata from
@@ -1558,7 +1559,7 @@ class DownloadModal(ModalScreen):
try:
logger.info(f"Metadata worker started for: {url}")
# Call get-tag cmdlet to scrape URL
# Call metadata cmdlet to scrape URL
if not get_cmdlet:
logger.error("cmdlet module not available")
self.app.call_from_thread(
@@ -1569,13 +1570,13 @@ class DownloadModal(ModalScreen):
)
return
# Get the get-tag cmdlet
get_tag_cmdlet = get_cmdlet("get-tag")
# Get the metadata cmdlet
get_tag_cmdlet = get_cmdlet("metadata")
if not get_tag_cmdlet:
logger.error("get-tag cmdlet not found")
logger.error("metadata cmdlet not found")
self.app.call_from_thread(
self.app.notify,
"get-tag cmdlet not found",
"metadata cmdlet not found",
title="Error",
severity="error"
)
@@ -1591,7 +1592,7 @@ class DownloadModal(ModalScreen):
result_obj = URLResult(url)
# Call the cmdlet with -scrape flag (unless skipping tag scraping)
# Call the cmdlet with -get/-scrape flags (unless skipping tag scraping)
import io
from contextlib import redirect_stdout, redirect_stderr
@@ -1599,7 +1600,7 @@ class DownloadModal(ModalScreen):
error_buffer = io.StringIO()
# Only scrape if not skipping tag scraping
args = [] if skip_tag_scraping else ["-scrape", url]
args = ["-get"] if skip_tag_scraping else ["-get", "-scrape", url]
with redirect_stdout(output_buffer), redirect_stderr(error_buffer):
returncode = get_tag_cmdlet(result_obj,
@@ -1608,7 +1609,7 @@ class DownloadModal(ModalScreen):
if returncode != 0:
error_msg = error_buffer.getvalue()
logger.error(f"get-tag cmdlet failed: {error_msg}")
logger.error(f"metadata cmdlet failed: {error_msg}")
try:
self.app.call_from_thread(
self.app.notify,
@@ -1623,11 +1624,11 @@ class DownloadModal(ModalScreen):
# Parse the JSON output
output = output_buffer.getvalue().strip()
if not output:
logger.warning("get-tag returned no output")
logger.warning("metadata -get returned no output")
try:
self.app.call_from_thread(
self.app.notify,
"No metadata returned from get-tag",
"No metadata returned from metadata -get",
title="Error",
severity="error",
)
@@ -1635,7 +1636,7 @@ class DownloadModal(ModalScreen):
logger.debug(f"Could not notify user: {e}")
return
# Extract the JSON line (skip debug messages that start with [get-tag])
# Extract the JSON line (skip debug messages that start with [tag])
json_line = None
for line in output.split("\n"):
if line.strip().startswith("{"):
@@ -1643,7 +1644,7 @@ class DownloadModal(ModalScreen):
break
if not json_line:
logger.error("No JSON found in get-tag output")
logger.error("No JSON found in metadata -get output")
logger.debug(f"Raw output: {output}")
try:
self.app.call_from_thread(
@@ -1832,7 +1833,7 @@ class DownloadModal(ModalScreen):
# Stage 1: Download data if enabled
if download_enabled:
download_cmdlet_name = "download-file"
download_cmdlet_name = "file"
download_cmdlet = get_cmdlet(download_cmdlet_name)
if download_cmdlet:
stage_msg = f"📥 Executing {download_cmdlet_name} stage"
@@ -1853,7 +1854,7 @@ class DownloadModal(ModalScreen):
)
if isinstance(cmd_config, dict):
cmd_config["_quiet_background_output"] = True
returncode = download_cmdlet(result_obj, [], cmd_config)
returncode = download_cmdlet(result_obj, ["-download"], cmd_config)
stdout_text = stdout_buf.getvalue()
stderr_text = stderr_buf.getvalue()
@@ -1902,14 +1903,14 @@ class DownloadModal(ModalScreen):
# Stage 2: Tag the file if tags provided
if tags:
tag_cmdlet = get_cmdlet("add-tags")
tag_cmdlet = get_cmdlet("metadata")
if tag_cmdlet and result_obj.get("path"):
stage_msg = f"🏷️ Tagging with {len(tags)} tags"
logger.info(stage_msg)
if worker:
worker.append_stdout(f"{stage_msg}\n")
try:
tag_args = tags
tag_args = ["-add"] + [str(t) for t in tags]
import io
from contextlib import redirect_stdout, redirect_stderr