From 994f39d308be350768ca01753da61e6d454f9299 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 29 Apr 2026 11:36:18 -0400 Subject: [PATCH] arr-search: shuffle and do more --- services/arr/arr-search.nix | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/services/arr/arr-search.nix b/services/arr/arr-search.nix index 81e5867..580d334 100644 --- a/services/arr/arr-search.nix +++ b/services/arr/arr-search.nix @@ -13,6 +13,7 @@ let curl = "${pkgs.curl}/bin/curl"; jq = "${pkgs.jq}/bin/jq"; + shuf = "${pkgs.coreutils}/bin/shuf"; # Max items to search per cycle per category (missing + cutoff) per app maxPerCycle = 5; @@ -54,10 +55,16 @@ let local label="$2" local series_ids - series_ids=$(${curl} -sf --max-time 30 \ + # Fetch the full wanted list, dedupe to seriesIds, then randomly + # sample maxPerCycle. Sonarr's wanted endpoint returns one record + # per episode, so a small pageSize collapses to a single seriesId + # whenever any one show dominates the alphabetical head of the + # backlog -- which starves every other show indefinitely. + series_ids=$(${curl} -sf --max-time 60 \ -H "X-Api-Key: $SONARR_KEY" \ - "${sonarrUrl}/api/v3/wanted/$endpoint?page=1&pageSize=${builtins.toString maxPerCycle}&monitored=true&sortKey=title&sortDirection=ascending&includeSeries=true" \ - | ${jq} -r '[.records[].seriesId] | unique | .[] // empty') + "${sonarrUrl}/api/v3/wanted/$endpoint?page=1&pageSize=5000&monitored=true" \ + | ${jq} -r '[.records[].seriesId] | unique | .[]' \ + | ${shuf} -n ${builtins.toString maxPerCycle}) if [ -z "$series_ids" ]; then echo "sonarr: no $label items"