Add sonarr.sh monitor command for shows still actively airing
Migrated shows default to unmonitored/no-search since they're back-catalog imports. For a show still marked "continuing" on TVDB (e.g. 3 Body Problem), this flips it (and all its seasons) to monitored so new episodes flow through the automated tv-sonarr pipeline instead of needing a manual scan/import each time one drops. --search optionally triggers an immediate missing-episode search. Claude-Session: https://claude.ai/code/session_01HZQK6jHmdTpFjFZM8FUnqA
This commit is contained in:
@@ -138,6 +138,55 @@ for r in json.load(sys.stdin):
|
||||
"
|
||||
}
|
||||
|
||||
cmd_monitor() {
|
||||
local series_id="${1:-}"
|
||||
local do_search="${2:-}"
|
||||
if [[ -z "$series_id" ]]; then
|
||||
echo "Usage: $0 monitor <seriesId> [--search]" >&2
|
||||
echo " Flips a show from unmonitored (migration-only) to monitored - Sonarr will" >&2
|
||||
echo " pick up new episodes via the tv-sonarr qBittorrent category going forward." >&2
|
||||
echo " --search also triggers an immediate search for any missing episodes." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local series_json
|
||||
series_json=$(api_get "series/$series_id")
|
||||
local not_found
|
||||
not_found=$(python3 -c "import json,sys; d=json.loads(sys.argv[1]); print('yes' if 'title' not in d else 'no')" "$series_json")
|
||||
if [[ "$not_found" == "yes" ]]; then
|
||||
echo "Error: no series with id $series_id (see: ./sonarr.sh list)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local payload
|
||||
payload=$(python3 -c "
|
||||
import json, sys
|
||||
s = json.loads(sys.argv[1])
|
||||
s['monitored'] = True
|
||||
# Also monitor all seasons - a series-level monitored flag alone won't pull
|
||||
# individual season/episode monitoring along with it.
|
||||
for season in s.get('seasons', []):
|
||||
season['monitored'] = True
|
||||
print(json.dumps(s))
|
||||
" "$series_json")
|
||||
|
||||
local response
|
||||
response=$(api_put "series/$series_id" "$payload")
|
||||
python3 -c "
|
||||
import json, sys
|
||||
d = json.loads(sys.argv[1])
|
||||
if 'message' in d and 'id' not in d:
|
||||
print('Error:', d.get('message'))
|
||||
sys.exit(1)
|
||||
print(f\"Monitoring: {d['title']} ({d['year']}) - new episodes will auto-import via the tv-sonarr download client category.\")
|
||||
" "$response"
|
||||
|
||||
if [[ "$do_search" == "--search" ]]; then
|
||||
api_post "command" "{\"name\": \"SeriesSearch\", \"seriesId\": $series_id}" > /dev/null
|
||||
echo "Triggered a search for missing/upcoming episodes."
|
||||
fi
|
||||
}
|
||||
|
||||
cmd_scan() {
|
||||
local folder="${1:-}"
|
||||
if [[ -z "$folder" ]]; then
|
||||
@@ -302,6 +351,7 @@ case "$command" in
|
||||
add) cmd_add "${2:-}" "${3:-}" ;;
|
||||
list) cmd_list ;;
|
||||
rootfolders) cmd_rootfolders ;;
|
||||
monitor) cmd_monitor "${2:-}" "${3:-}" ;;
|
||||
scan) cmd_scan "${2:-}" ;;
|
||||
import) cmd_import "${2:-}" ;;
|
||||
queue) cmd_queue ;;
|
||||
@@ -314,6 +364,9 @@ case "$command" in
|
||||
echo " add <tvdbId> [root] Add show to Sonarr (unmonitored, no search)"
|
||||
echo " list List series already in Sonarr"
|
||||
echo " rootfolders List root folders + unmapped folder counts"
|
||||
echo " monitor <seriesId> [--search] Switch a show to monitored (auto-import new"
|
||||
echo " episodes via tv-sonarr going forward); --search"
|
||||
echo " also searches now for anything missing"
|
||||
echo " scan <folder> Preview manual-import mapping for a raw folder"
|
||||
echo " import <folder> Scan + apply import (aborts if any file is unmatched)"
|
||||
echo " queue Show current download queue"
|
||||
|
||||
Reference in New Issue
Block a user