mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-25 10:25:09 +00:00
fix(api): sync REST API download endpoint with updated dl command (#98)
The REST API download endpoint was broken after recent dl command changes. - Add missing vbitrate_range, abitrate_range, and worst parameters to the API call and DEFAULT_DOWNLOAD_PARAMS - Convert wanted episode strings (S01E01) to internal SxE format via SeasonRange so episode filtering works correctly - Track completed output files via dl.completed_files instead of returning an empty list Closes #98
This commit is contained in:
@@ -573,6 +573,7 @@ class dl:
|
||||
raise ValueError("A subcommand to invoke was not specified, the main code cannot continue.")
|
||||
|
||||
self.log = logging.getLogger("download")
|
||||
self.completed_files: list[Path] = []
|
||||
|
||||
if not config.output_template:
|
||||
raise click.ClickException(
|
||||
@@ -2559,6 +2560,7 @@ class dl:
|
||||
final_path = final_dir / f"{base_filename}{track_path.suffix}"
|
||||
|
||||
shutil.move(track_path, final_path)
|
||||
self.completed_files.append(final_path)
|
||||
self.log.debug(f"Saved: {final_path.name}")
|
||||
else:
|
||||
# Handle muxed files
|
||||
@@ -2596,6 +2598,7 @@ class dl:
|
||||
final_path.unlink()
|
||||
shutil.move(muxed_path, final_path)
|
||||
used_final_paths.add(final_path)
|
||||
self.completed_files.append(final_path)
|
||||
tags.tag_file(final_path, title, self.tmdb_id, self.imdb_id)
|
||||
|
||||
title_dl_time = time_elapsed_since(dl_start_time)
|
||||
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
@@ -149,6 +150,20 @@ def _perform_download(
|
||||
if params.get("export"):
|
||||
params["export"] = bool(params["export"])
|
||||
|
||||
# Convert wanted episode strings to internal "SxE" format
|
||||
# Accepts: "S01E01", "S01-S03", "s1e1", "1x1", or already-parsed format
|
||||
wanted_raw = params.get("wanted")
|
||||
if wanted_raw:
|
||||
from unshackle.core.utils.click_types import SeasonRange
|
||||
|
||||
if isinstance(wanted_raw, str):
|
||||
wanted_raw = [wanted_raw]
|
||||
# Only convert if not already in internal "SxE" format
|
||||
needs_conversion = any(not re.match(r"^\d+x\d+$", w) for w in wanted_raw)
|
||||
if needs_conversion:
|
||||
season_range = SeasonRange()
|
||||
params["wanted"] = season_range.parse_tokens(*wanted_raw)
|
||||
|
||||
# Load service configuration
|
||||
service_config_path = Services.get_path(service) / config.filenames.config
|
||||
if service_config_path.exists():
|
||||
@@ -271,6 +286,8 @@ def _perform_download(
|
||||
acodec=params.get("acodec"),
|
||||
vbitrate=params.get("vbitrate"),
|
||||
abitrate=params.get("abitrate"),
|
||||
vbitrate_range=params.get("vbitrate_range"),
|
||||
abitrate_range=params.get("abitrate_range"),
|
||||
range_=params.get("range", ["SDR"]),
|
||||
channels=params.get("channels"),
|
||||
no_atmos=params.get("no_atmos", False),
|
||||
@@ -306,6 +323,7 @@ def _perform_download(
|
||||
no_mux=params.get("no_mux", False),
|
||||
workers=params.get("workers"),
|
||||
downloads=params.get("downloads", 1),
|
||||
worst=params.get("worst", False),
|
||||
best_available=params.get("best_available", False),
|
||||
split_audio=params.get("split_audio"),
|
||||
)
|
||||
@@ -327,9 +345,10 @@ def _perform_download(
|
||||
log.error(f"Stderr: {stderr_str}")
|
||||
raise
|
||||
|
||||
log.info(f"Download completed for job {job_id}, files in {original_download_dir}")
|
||||
output_files = [str(p) for p in dl_instance.completed_files]
|
||||
log.info(f"Download completed for job {job_id}, {len(output_files)} file(s) in {original_download_dir}")
|
||||
|
||||
return []
|
||||
return output_files
|
||||
|
||||
|
||||
class DownloadQueueManager:
|
||||
|
||||
@@ -29,6 +29,8 @@ DEFAULT_DOWNLOAD_PARAMS = {
|
||||
"acodec": None,
|
||||
"vbitrate": None,
|
||||
"abitrate": None,
|
||||
"vbitrate_range": None,
|
||||
"abitrate_range": None,
|
||||
"range": ["SDR"],
|
||||
"channels": None,
|
||||
"no_atmos": False,
|
||||
@@ -62,6 +64,7 @@ DEFAULT_DOWNLOAD_PARAMS = {
|
||||
"no_mux": False,
|
||||
"workers": None,
|
||||
"downloads": 1,
|
||||
"worst": False,
|
||||
"best_available": False,
|
||||
"repack": False,
|
||||
"imdb_id": None,
|
||||
@@ -981,6 +984,14 @@ def validate_download_parameters(data: Dict[str, Any]) -> Optional[str]:
|
||||
if not isinstance(data["abitrate"], int) or data["abitrate"] <= 0:
|
||||
return "abitrate must be a positive integer"
|
||||
|
||||
if "vbitrate_range" in data and data["vbitrate_range"] is not None:
|
||||
if not isinstance(data["vbitrate_range"], str) or "-" not in data["vbitrate_range"]:
|
||||
return "vbitrate_range must be a string in 'MIN-MAX' format (e.g., '6000-7000')"
|
||||
|
||||
if "abitrate_range" in data and data["abitrate_range"] is not None:
|
||||
if not isinstance(data["abitrate_range"], str) or "-" not in data["abitrate_range"]:
|
||||
return "abitrate_range must be a string in 'MIN-MAX' format (e.g., '128-256')"
|
||||
|
||||
if "channels" in data and data["channels"] is not None:
|
||||
if not isinstance(data["channels"], (int, float)) or data["channels"] <= 0:
|
||||
return "channels must be a positive number"
|
||||
|
||||
Reference in New Issue
Block a user