arr-search: shuffle and do more
Some checks failed
Build and Deploy / mreow (push) Successful in 1m5s
Build and Deploy / yarn (push) Successful in 48s
Build and Deploy / muffin (push) Failing after 33s

This commit is contained in:
2026-04-29 11:36:18 -04:00
parent a31c82d184
commit 994f39d308

View File

@@ -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"