Small windows VBScript to automate .rar releases in Sonarr/Radarr API using Windows and Torrents


#1

Hey Folks,

So before I begin, this script was designed originally for my Torrent client as I don’t use USENET, however I believe I may be able to include USENET in a future version, at the moment I only use Torrents, but after some research I believe it might be possible to include USENET, I would need to download and look through SabNZB in order to figure that out.

Now, for this to work on a torrent client it needs to run the script with the required parameters once a download has completed, so after a download has reached 100% it will send the following arguments to the script.

  • Label
    The default is Sonarr|Radarr but these can be customised within the script.

  • Path
    This is the completed download path/ final directory.

  • Name: Torrent Title (Usenet Original NZB filename)
    This will be used to create the folder we will extract to.

  • downloadClientID: Torrent Info Hash, (nzoid for SabNZB)
    “so Sonarr knows that a particular download has already been imported.”

Download
You can get the script from Pastebin
Give it any name you want but save it as a .vbs, for example, I named mine AutoScript.vbs

In your Torrent client you would have something like this
C:\AutoScript.vbs “Label” “Directory” “Name” “InfoHash”

REQUIREMENTS

  • Windows Operating System
    To my knowledge all windows systems created after 1996 can run visual basic scripts.

  • A Torrent client
    As long as the client can run a script once a download has reached 100% and call the arguments mentioned above, then you shouldn’t have any issues, my server runs torrent, I have plans to replace this with deluge or qBittorent in the future but at the moment it would be too much hassle.

  • Winrar
    I stuck with this out of laziness, it was already on my server and I used it with my old script for drone factory, but I might change to 7zip. On a side note, if you know the command line to extract in 7zip you could easily change this yourself.

CONFIGURATION
Configuring the script is pretty straight forward, for those who don’t code or know anything about VBScript, please don’t get intimidated, I’ve made it pretty easy to use.

Note: All labels in the script are case-insensitive.

Sonarr/Radarr
In my script, about 18 lines down, you want to look for the following snippet of code.

'allowedLabels.Add “sonarr”,“localhost:port^^APIKEYHERE^^DownloadedEpisodesScan”
'allowedLabels.Add “radarr”,“localhost:port^^APIKEYHERE^^DownloadedMoviesScan”

Let’s break this down.
The single quote at the beginning of each line tells the script to ignore that line, so you will want to remove the single quote (’) at the beginning of sonarr, radarr, or both, depending on what you use.

If you are using a different label for Sonarr or Radarr, then you simply replace the word sonarr or radarr with your custom label.

You then replace localhost:port with the address that links to your sonarr or radarr site, if your address uses https:// then make sure to include this, and don’t add a forward slash (/) at the end of the address.

Lastly, APIKEYHERE, is where you put your API key, which you can get in Sonarr and Radarr by going to Settings > General > Security > API Key.

You DO NOT want to edit DownloadedEpisodesScan or DownloadedMoviesScan, as these are required by Sonarr and Radarr

So, once you’re done, you should have something that looks like this.

allowedLabels.Add “series”,"127.0.0.1:9899^^13281w1w85w8d1w1w858dqdw^^DownloadedEpisodesScan"
allowedLabels.Add “movies”,“127.0.0.1:9891^^132ab8wc18qc918et81wf1w85w^^DownloadedMoviesScan”

If you have winrar installed in a different directory, you will need to change the code on line 53 so that it points to that directory.

And speaking of winrar, for those who want to replace winrar with 7zip, you would also need to edit the code on line 67 & WinZip & “Unrar.exe”" e –y

WinZip is the variable that points to the Winrar directory.

OTHER NOTES
I have not thoroughly tested this yet as I only made my first script three days ago and have been slowly improving it, this pretty much means I don’t know it’s limits, but so far it is extracting my shows and movies once completed and then notifying Sonarr and Radarr to scan the location the files where extracted to. Once a torrent has finished, Sonarr and Radarr will remove the torrent if you have that option enabled.

Now this script is 100% dependant on the torrent client notifying it once a download has completed, it also relies on having an active authorised connection to sonarr/radarr, it won’t continuously monitor folders and it will only make one attempt to extract the file and call sonarr/radarr, so if sonarr/radarr goes down or if the extraction fails it won’t make another attempt.

Currently, this script doesn’t scan subfolders and it doesn’t queue each extraction, it’s pretty much in its Alpha stage, my reason for sharing this is to try and inspire other users to either improve upon my script or to build their own.

WHY I’M HERE/HOW I GOT HERE
Now this is my first time in the forums and thought I would share my script with those who may need it or who may be inspired to create something better, I rarely need to jump on Sonnar but I went on three nights ago and discovered the dreaded notification telling me that drone factory was pretty much being removed/replaced, like many other users this felt like a slap to the face as I relied on drone factory for my extracted files, but I understood why it has to go.

So I searched the web looking for a solution, something that didn’t require me to install and configure more software, I wanted something light that could just run on windows, instead I was faced with threads of users complaining about this decision instead of working together for a solution, so with little to no option I was forced to build this script, it only took me about an hour to figure out the API and to get a working script, but for the past two-three days, in my spare time, I’ve been slowly improving my original script and I plan do more improvements and possibly add other features as I go.

Anyway, enjoy.


Importing extracted files without Drone Factory [unrar]
#2

Hey Skullzy, nice work. It’s been a while since I saw a vbscript. But hey, it works.

Btw. you don’t need a usenet version, sabnzbd/nzbget etc support unrar out of the box.


#3

Hey Taloth,

Thank you, yeah I wasn’t too sure if a vbscript would be a good way to go, it was one of the first languages I learnt asides from batch lol.

Btw. you don’t need a usenet version, sabnzbd/nzbget etc support unrar out of the box.

Oh right, I saw other users complaining about needing a script for usenet now that drone factory was depcrated, I take it the only process needed is to call sonarr’s API for the path and downloadClientId… I’m gonna look into that lol, thanks for letting me know.


#4

Script for usenet was mostly for transcoding, and there’s already a script for that, nzbToMedia.

Come to think of it, I recall nzbToMedia did mention torrents too. Lemme check…
And holy crap, clinton actually implemented it for a bunch of clients… https://github.com/clinton-hall/nzbToMedia/wiki#torrent
And actually can unrar https://github.com/clinton-hall/nzbToMedia/wiki/deluge#deluge


#5

That’s awesome!

Just checked it out, the only problem is that I’d have to manually compile a .exe for windows every time an update is released and install python, which isn’t too bad, but currently it doesn’t support Radarr… I’m definitely going to keep an eye on that and the next time I plan to upgrade my server I’m pushing Linux, it’ll be so much easier lol.


#6

I don’t think you need to compile it. Just run it with ‘python nzbToYYYY.py’ afaik. Although I agree, the install process might be a bit tricky.

As for Radarr support, mention it to clinton, the Radarr api is 99% the same as Sonarr so it should be fairly trivial to add. And might benefit people wishing to transcode movies.


#7

You’re absolutely right, I misread his wiki, where he said under the windows section.

Support of the compiled versions of this code has ceased.

I instantly assumed it required compiling :expressionless:, I noticed someone mentioned Radarr in the request section, it would just be a matter of biding my time or trying to implement it myself, I know bits and bobs when it comes to Python so I could probably implement Radarr by copying the Sonarr code…

To be honest, I should really consider putting my head down and learning Python, it seems like everything I need can be solved by it lol.

P.S Thanks for all your help and suggestions, I hope other windows users find there way here and “fingers crossed” to nzbToMedia.