Sonarr version (exact version): 4.0.5.1710
Mono version (if Sonarr is not running on Windows):
OS: Ubuntu 24.04 LTS, but running in docker (release-fffea1f by hotio)
Debug logs: Check in the description of the issue
Description of issue:
Hello :). I need help with figuring out how to work with historyid’s in Sonarr’s Custom Scripts. I have tried looking through the API documentation and Custom Scripts documentation, but I’m kind of stumped.
The (working) Radarr version of the script
So I have made this script for Radarr, that checks every file on Import, if it has a danish audio track. If it doesn’t, it’ll delete the file and mark the download as failed, triggering a new search. It works great at this point:
https://logs.notifiarr.com/?9d7a1b8a50184ed0#7j1FnNkaZApxJxpKpZFzpnesJA5Kt19VxyGYxs3hKvpj
I tried making the script work for Sonarr as well. I tried using the corresponding API calls and adjusting it with its own variables from the Custom Scripts documentation.
But I simply can’t get it to grab the historyId
of the file/download it’s trying to import.
The (non-working) Sonarr version of the script
For reference, here’s the Sonarr script that I’m using, where I tried using the same methods and functions as much as possible, from the Radarr script:
https://logs.notifiarr.com/?82874d25d3ae26a9#3m9ZucsxmAp7NqUo51yShJJQqnf1um4Vz63etTwPjwFH
The script correctsly detects if there’s a danish audio track or not, and it’ll delete the file, but it seems Sonarr works differently than Radarr from this point on.
Radarr can successfully grab the historyId “On Import”, while Sonarr for some reason can’t?
Successful run log from Radarr
Here’s a log from a successful Radarr run with the script (downloading a movie without a danish audio track):
https://logs.notifiarr.com/?fe3bbf0cceb2bad6#uQuffFa3hTCxc5KT2cE9sKoaWE6SaU11jUDhQX1umBp (trace log, huge)
In the log, we can see it fetches movie file, deletes it, finding historyId and then marking it as failed, and then initiates a new search.
Non-succesful run log from Sonarr
But here’s a run from the Sonarr script, using the exact same function for grabbing the historyId, where it can’t find it:
https://logs.notifiarr.com/?b6558b07dd5505ce#GJLvWZoyywb3pC1EPyWqPFq5QL2USuuez9BkYE4Vzb3L
My guess is that Sonarr and Radarr works slightly differently with importing files? Radarr seems to generate the historyId earlier, while Sonarr seems to generate it later, so the script can’t find it before it’s done executing its main loop. I also might’ve just botched the execution loop in the Sonarr script.
Maybe Sonarr only generates the historyId upon the script exiting/completing? Again, not sure.
What I’ve tried so far:
- Adding a retry function to the
find_history_record_id()
function:
- This only had the result, that Sonarr “hangs” on import, where it’ll just wait to actually import the file, until the retries have completed
- Adding a sleep function after the file has been deleted
- This did not work, for some reason. It still can’t find the download id. It again just seems to wait for 5 seconds, before it imports the file. This means there still won’t be a historyId generated.
- Tried creating a simple bash script, that just has the
find_history_record_id()
function (for Sonarr):
https://logs.notifiarr.com/?0635d61d6cae8f3f#HQGTbWPcAvUGNxHtzjdUXYpAymzXSpyuUabKEn6GrrZz
- This confirms that the historyId can’t be grabbed, if the download “just” is in the queue.
- It has to get imported, otherwise it won’t return a historyId.
- After importing, it’ll give the historyId.
- You can check it with e.g.
./test.sh SABnzbd_nzo_downloadIdHere
Answering other questions
- Why don’t you just filter out languages via custom formats?
- Since danish is a quite “small” language, almost no indexers will register the language correctly. This means it’s quite unreliable.
- How about a download profile, that only downloads releases using scene-based or p2p tags for language?
- That’s what I’m already doing. I’m using
DANiSH
andNORDiC
, but sometimes people upload wrong stuff to both usenet and torrent indexers, which also makes this method slightly unreliable.
- Have you tried making a script for this on SABnzbd instead?
- Yes, and I have one working, but this means I can’t use qBittorrent, since I can’t seem to figure out how to make a similar one for qBittorrent.
I’m stumped on how to continue from here.
I know it’s a huge ask to look through all this log and code, but if anyone finds it interesting, or feeling charitable and helpful, I would appreciate any help
Kind regards,
Engels