fix: wire settings.json to actually drive runtime behavior

Settings page saved to /config/settings.json but nothing downstream read
that file. Schedule changes were silently ignored; max_quality and
sleep_interval changes were silently ignored. The "Settings saved
successfully" flash was a lie.

Fix:
- sync.sh reads max_quality + sleep_interval from settings.json on each
  run (jq -er ... // empty, falling back to env vars on missing/malformed
  file)
- entrypoint.sh reads sync_schedule from settings.json before setting up
  cron, and writes the crond PID to /var/run/crond.pid so Flask can
  SIGHUP it
- app.py adds apply_schedule(): rewrites /etc/crontabs/root, signals
  crond via the recorded PID, restarts crond if the PID is stale, drops
  the crontab when schedule is set to "manual". save_settings_route
  invokes it only when the schedule actually changed; any failure
  flashes a warning so the save still succeeds with the user informed
- bare `except: pass` in get_settings replaced with explicit exception
  types + stderr warning so debugging malformed settings is possible
- sync.sh: one bad channel no longer aborts the whole loop under set -e
- Dockerfile adds jq for the JSON reads in sync.sh / entrypoint.sh
- README: two stale github.com URLs fixed to Gitea; new Running Tests
  section under Building From Source
- tests/test_settings.py: 3 pytest cases covering get_settings()'s
  three branches (missing file, valid file, malformed JSON)

Settings hierarchy unchanged: env-var defaults seed the UI; settings.json
wins when present and parseable.

Timezone (TZ) is not applied live - tzdata is locked in at process start.
Same behavior as before; not in scope for this commit.
This commit is contained in:
ComputerGuru
2026-05-31 19:21:43 -07:00
parent 71ba63ffe3
commit ef903c86d1
8 changed files with 216 additions and 5 deletions

18
sync.sh
View File

@@ -8,9 +8,21 @@ DOWNLOAD_DIR="${DOWNLOAD_DIR:-/downloads}"
CONFIG_DIR="${CONFIG_DIR:-/config}"
COOKIES_FILE="${CONFIG_DIR}/cookies.txt"
CHANNELS_FILE="${CONFIG_DIR}/channels.txt"
SETTINGS_FILE="${CONFIG_DIR}/settings.json"
MAX_QUALITY="${MAX_QUALITY:-1080}"
SLEEP_INTERVAL="${SLEEP_INTERVAL:-2}"
# Override env-var defaults with values from settings.json when present and parseable.
# Missing or malformed settings.json silently falls back to env-var defaults.
if [ -f "$SETTINGS_FILE" ]; then
if VAL=$(jq -er '.max_quality // empty' "$SETTINGS_FILE" 2>/dev/null); then
MAX_QUALITY="$VAL"
fi
if VAL=$(jq -er '.sleep_interval // empty' "$SETTINGS_FILE" 2>/dev/null); then
SLEEP_INTERVAL="$VAL"
fi
fi
# Check if channels file exists
if [ ! -f "$CHANNELS_FILE" ]; then
echo "[ERROR] Channels file not found: $CHANNELS_FILE"
@@ -57,6 +69,9 @@ while IFS='|' read -r CHANNEL_ID CHANNEL_NAME || [ -n "$CHANNEL_ID" ]; do
echo "Channel ID: $CHANNEL_ID"
echo "=========================================="
# Don't let one bad channel kill the whole loop. yt-dlp can exit non-zero
# for individual videos even with --ignore-errors (e.g. age-gated, geo-blocked,
# member-only). We log and continue rather than aborting the entire sync.
yt-dlp \
$COOKIES_PARAM \
--format "bestvideo[ext=mp4][height<=${MAX_QUALITY}]+bestaudio[ext=m4a]/best[ext=mp4]/best" \
@@ -73,7 +88,8 @@ while IFS='|' read -r CHANNEL_ID CHANNEL_NAME || [ -n "$CHANNEL_ID" ]; do
--ignore-errors \
--sleep-interval "$SLEEP_INTERVAL" \
--max-sleep-interval 5 \
"https://www.youtube.com/channel/$CHANNEL_ID/videos"
"https://www.youtube.com/channel/$CHANNEL_ID/videos" \
|| echo "[WARNING] channel $CHANNEL_NAME ($CHANNEL_ID) failed; continuing with remaining channels"
# Create tvshow.nfo for Emby/Plex
echo ""