Looking for a Script to set high priority based on nzb age

Come up with a useful post-processing script? Share it here!
Post Reply
Janis
Newbie
Newbie
Posts: 1
Joined: February 1st, 2020, 4:34 am

Looking for a Script to set high priority based on nzb age

Post by Janis »

Hello guys,
Im looking for a script to set a high priority for incoming nzb‘s, based on file age (let‘s say max. 7 days).
I know there is an option in sonarr/radarr to automatically set high priority for episodes that aired in the last days or movies that just got released. While this works for a lot of files, it doesn‘t work for german dubbed episodes and movies that sometimes get released months after their original air dates.
Most of the time my download queue is huge and it takes several days for these files to get downloaded.
At the moment I have a workaround by calling the API url to sort the download queue by age via cronjob every minute.
While this kinda works, it‘s messing up the download order for all other downloads and sometimes pushing back downloads with very old file age to the end of the queue every time and prevents downloading.
Is it possible to write a pre-queue script for this? I don‘t know where to start and could really use some help.
Thank you very much
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: Looking for a Script to set high priority based on nzb age

Post by safihre »

In Config > Switches there is a switch "Sort by Age" (enable Advanced Settings), which sorts the queue by age every time a new job is added :)
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
polly78
Newbie
Newbie
Posts: 1
Joined: June 23rd, 2022, 9:25 am

Re: Looking for a Script to set high priority based on nzb age

Post by polly78 »

If you're working with a large backlog queue, it's certainly worth looking deeper into the API to do more custom sorting and manipulation of the queue to keep things moving optimally, both inside and outside of sab.

Once you've got to a few hundred items in the queue, here's a few things that's worth looking into, all of which can be handled with metadata available from the queue API

If you work backwards in terms of priority, the only action you need is "put it at the top of the queue"
  • Any nzb that hasn't yet been seen. should be put at the top of the queue for 10 seconds to start downloading - SAB will start working out missing articles near instantly. This is a one-off sweep through the entire queue just to give SAB a chance to build up the mbmissing metadata if appropriate."
  • Extract any queue items with mbmissing > 0 and keep to one side
  • Extract any queue items with avg_age < 30 days keep to one side
  • Sort remaining films by whatever makes sense to you. For me, this is just filename. These (for me) are the lowest priority
  • Sort remaining TV by whatever makes sense to you. For me, this is a massaged filename to remove periods, initial "the" etc and then sort. This generally makes sure tv shows download in a chronological order. You might want to extract season/episode metadata and sort that way so that all "season 1" come first, then "season 2" etc.
  • With the list of queue items for mbmissing > 0, pop them all at the top of the queue, starting with the least missing data. If they're missing some data, they're likely to ultimately fail so get them processing quickly so they can fail, be returned to radar/sonar and required to find another nzb. The sooner you can cycle through this process, the less chance there is of the data not being downloadable by the time you get to a good nzb
  • Finally (and what will be top of the queue) is to bump anything from the avg_age < 30 list. This ensures you get new TV episodes as soon as they're released and also minimises the impact of usenet removals.
Post Reply