Add watchlist auto-download settings

This commit is contained in:
Dymas
2026-05-25 09:50:20 +02:00
parent 46af0ff47d
commit 3d42657837
10 changed files with 555 additions and 45 deletions
+54 -1
View File
@@ -10,6 +10,7 @@ import sqlite3
import subprocess
import threading
import time
import re
from app_support import (
MAX_LOG_LINES,
@@ -291,7 +292,12 @@ class WatchlistRefreshJobs:
skipped = False
error_message = ""
try:
item = self.store.refresh(show_id, include_thumbnail=False)
try:
item = self.store.refresh(show_id, include_thumbnail=False, refresh_source=source_name)
except TypeError as exc:
if "refresh_source" not in str(exc):
raise
item = self.store.refresh(show_id, include_thumbnail=False)
if item is None:
skipped = True
else:
@@ -813,6 +819,53 @@ class DownloadQueue:
self.wakeup.set()
return job
def _expand_episode_spec(self, episode_spec, available_episodes):
spec = str(episode_spec or "").strip()
values = [str(value).strip() for value in available_episodes or [] if str(value).strip()]
if not spec or not values:
return []
expanded = []
seen = set()
parts = [part for part in re.split(r"\s+", spec) if part]
index_map = {value: index for index, value in enumerate(values)}
for part in parts:
if "-" in part:
start, end = [piece.strip() for piece in part.split("-", 1)]
if start in index_map and end in index_map:
start_index = index_map[start]
end_index = index_map[end]
if start_index > end_index:
start_index, end_index = end_index, start_index
for value in values[start_index : end_index + 1]:
if value not in seen:
seen.add(value)
expanded.append(value)
continue
if part in index_map and part not in seen:
seen.add(part)
expanded.append(part)
return expanded
def covered_episodes(self, show_id, mode, available_episodes):
normalized_show_id = str(show_id or "").strip()
normalized_mode = str(mode or "").strip().lower()
if not normalized_show_id or not normalized_mode:
return set()
with self.lock, self._connect() as conn:
rows = conn.execute(
"""
SELECT episodes
FROM jobs
WHERE show_id = ? AND mode = ? AND status IN ('pending', 'running', 'done')
ORDER BY created_at ASC
""",
(normalized_show_id, normalized_mode),
).fetchall()
covered = set()
for row in rows:
covered.update(self._expand_episode_spec((row["episodes"] if isinstance(row, sqlite3.Row) else row[0]), available_episodes))
return covered
def retry(self, job_id):
with self.lock:
job = self._find(job_id)