alldebrid plugin optimization and mpv playlist fix
This commit is contained in:
+80
-3
@@ -6,6 +6,7 @@ import json
|
||||
import sqlite3
|
||||
import time
|
||||
import os
|
||||
import re
|
||||
import datetime
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -30,6 +31,7 @@ _LAST_SAVED_CONFIG: Dict[str, Any] = {}
|
||||
_CONFIG_SAVE_MAX_RETRIES = 5
|
||||
_CONFIG_SAVE_RETRY_DELAY = 0.15
|
||||
_CONFIG_MISSING = object()
|
||||
_PATH_ALIAS_TOKEN_RE = re.compile(r"^\$(?:\((?P<braced>[^)]+)\)|(?P<plain>[A-Za-z0-9_.-]+))$")
|
||||
|
||||
|
||||
class ConfigSaveConflict(Exception):
|
||||
@@ -62,6 +64,20 @@ def global_config() -> List[Dict[str, Any]]:
|
||||
"group": "Display",
|
||||
"default": "rainbow",
|
||||
"choices": ["plain", "bw-striped", "rainbow"],
|
||||
},
|
||||
{
|
||||
"key": "download_path_default",
|
||||
"label": "Default Download Path",
|
||||
"group": "Downloads",
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
{
|
||||
"key": "path_aliases",
|
||||
"label": "Path Aliases",
|
||||
"group": "Downloads",
|
||||
"type": "json",
|
||||
"default": {},
|
||||
}
|
||||
]
|
||||
|
||||
@@ -82,6 +98,56 @@ def get_nested_config_value(config: Dict[str, Any], *path: str) -> Any:
|
||||
return cur
|
||||
|
||||
|
||||
def _normalize_path_alias_name(value: Any) -> Optional[str]:
|
||||
raw = str(value or "").strip()
|
||||
if not raw:
|
||||
return None
|
||||
|
||||
match = _PATH_ALIAS_TOKEN_RE.match(raw)
|
||||
if match:
|
||||
raw = str(match.group("braced") or match.group("plain") or "").strip()
|
||||
|
||||
candidate = raw.strip().strip("()")
|
||||
if not candidate:
|
||||
return None
|
||||
return candidate.lower()
|
||||
|
||||
|
||||
def get_path_aliases(config: Dict[str, Any]) -> Dict[str, str]:
|
||||
aliases: Dict[str, str] = {}
|
||||
if not isinstance(config, dict):
|
||||
return aliases
|
||||
|
||||
for block_name in ("path_aliases", "download_paths"):
|
||||
block = config.get(block_name)
|
||||
if not isinstance(block, dict):
|
||||
continue
|
||||
for key, value in block.items():
|
||||
alias = _normalize_path_alias_name(key)
|
||||
if not alias:
|
||||
continue
|
||||
if isinstance(value, str) and value.strip():
|
||||
aliases[alias] = value.strip()
|
||||
|
||||
return aliases
|
||||
|
||||
|
||||
def resolve_path_alias(config: Dict[str, Any], value: Any) -> Optional[Path]:
|
||||
raw = str(value or "").strip()
|
||||
if not raw.startswith("$"):
|
||||
return None
|
||||
|
||||
alias = _normalize_path_alias_name(raw)
|
||||
if not alias:
|
||||
return None
|
||||
|
||||
target = get_path_aliases(config).get(alias)
|
||||
if not target:
|
||||
return None
|
||||
|
||||
return expand_path(target)
|
||||
|
||||
|
||||
def coerce_config_value(
|
||||
value: Any,
|
||||
existing_value: Any = _CONFIG_MISSING,
|
||||
@@ -271,13 +337,24 @@ def resolve_output_dir(config: Dict[str, Any]) -> Path:
|
||||
"""Resolve output directory from config with single source of truth.
|
||||
|
||||
Priority:
|
||||
1. config["temp"] - explicitly set temp/output directory
|
||||
2. config["outfile"] - fallback to outfile setting
|
||||
3. System Temp - default fallback directory
|
||||
1. config["download_path_default"] - default download/output directory
|
||||
2. config["temp"] - explicitly set temp/output directory
|
||||
3. config["outfile"] - fallback to outfile setting
|
||||
4. System Temp - default fallback directory
|
||||
|
||||
Returns:
|
||||
Path to output directory
|
||||
"""
|
||||
default_output = config.get("download_path_default")
|
||||
if default_output:
|
||||
try:
|
||||
aliased = resolve_path_alias(config, default_output)
|
||||
path = aliased if aliased is not None else expand_path(default_output)
|
||||
if path.exists() or path.parent.exists():
|
||||
return path
|
||||
except Exception as exc:
|
||||
logger.debug("resolve_output_dir: failed to expand download_path_default value %r: %s", default_output, exc, exc_info=True)
|
||||
|
||||
# First try explicit temp setting from config
|
||||
temp_value = config.get("temp")
|
||||
if temp_value:
|
||||
|
||||
Reference in New Issue
Block a user