-
-
Save Ravencentric/38002d8e056fd6c226d4460fb82f251a to your computer and use it in GitHub Desktop.
| # Script to trigger the RefreshMonitoredDownloads task in Sonarr and Radarr | |
| # Sonarr/Radarr only checks the monitored downloads every 60 seconds which | |
| # means that your download could be done in 20 seconds but it'll sit there | |
| # for an additional 40 seconds before Sonarr/Radarr check again. This script | |
| # will run when a download finishes and trigger the RefreshMonitoredDownloads | |
| # task. | |
| import os | |
| import requests | |
| def RefreshMonitoredDownloads(API_KEY: str, URL: str) -> None: | |
| PAYLOAD = {"name": "RefreshMonitoredDownloads"} | |
| headers = { | |
| "Content-Type": "application/json", | |
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36", | |
| "X-Api-Key": API_KEY, | |
| "X-Requested-With": "XMLHttpRequest", | |
| } | |
| requests.post(URL, headers=headers, json=PAYLOAD) | |
| SONARR_API_KEY = "abc123" | |
| SONARR_URL = "http://127.0.0.1:8989/api/v3/command" | |
| RADARR_API_KEY = "abc123" | |
| RADARR_URL = "http://127.0.0.1:7878/api/v3/command" | |
| RefreshMonitoredDownloads(SONARR_API_KEY, SONARR_URL) | |
| RefreshMonitoredDownloads(RADARR_API_KEY, RADARR_URL) |
Hey @Warbs816,
Hmm interesting I didn't even realize that, maybe because I have a few different download clients and my Sonarr check SAB last?
But even manually checking it seems like SAB first completes all the needed steps like unpacking etc and then triggers the script which is where radarr etc. jumps in and does a perfect job with importing (at least in my case). Not sure why in your case SAB would trigger the script before being done with processing.
The simplest solution I can think of just adding a 5 second sleep timer in the script before making the call to Radarr. If that doesn't work, make the above script trigger a second script (at this point the execution of the first script is finished). The second script can then wait 5 seconds before sending the API call.
The 5 seconds is just an arbitrary number, if what you're saying is true and SAB executes the script as the last step then you can also wait for just 1 second or even less before triggering the second script.
Thanks @dodofarm - sleeping in the same script didn't work, SABnzbd again just waits for the entire script to finish before marking a job as complete.
I had tried a second trigger script, but initially the first script that SABnzbd runs was waiting for that to finish before also completing, but after some tweaks I got it to work!
Thanks again!
Trigger script:
import subprocess
import os
subprocess.Popen(
["/config/scripts/sonarr_refresh_downloads.py"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL,
start_new_session=True,
close_fds=True
)Great @Warbs816! Yea what you posted is something I had in mind.
Maybe worth checking if you have some old version of SAB or some switch flipped in the settings that marks a download only complete after a the script finishes running?
But obviously if SAB waits for the script to finish it will also wait for the sleep call to finish hence rendering it useless. Triggering a second script might be the only way for you then.
Thanks @dodofarm - this does work to refresh monitored downloads in Sonarr/Radarr but because when the script runs the download is still technically not complete in SABnzbd (not complete until after the script has finished), Sonarr still thinks the item is downloading and does not mark it as complete/waiting to import. I'm struggling to work out a workaround for this. Any ideas?