How to not delete file in Completed Download Handling

Version: 2.0.0.4949
FreeNAS: 9.10.2-U6
NZBGet: 19.1

Sonarr and NZBGet are in different jails (Sonarr was created using the official plugin).
Heres my folder structure for my pool

mainshare --/
Videos --/
Archive --/
HD --/
TV --/
Lost --/
Season 1 --/
Lost.S01E01.720p…mkv
HD Movies --/
TV --/
Lost --/
Season 1 --/
Lost.S01E01.720p…mkv

Storage space is not a concern which is why I’m doing this. I have an archive folder which has previous releases of files in the off chance that the new on I got is bad and I keep them around for a good length of time. (And yes, I’ve had to go back to a handful of them over the years). What I want to happen is when a show is finished downloading, to not delete the file that it is replacing, but move it to the archive folder in the proper location. Is it possible to hook into the Completed Download Handler in some fashion to do this? I know there are ‘Custom Scripts’ in the Connections, so I’m assuming it can be done there but I’m not 100% sure. I just want to make sure it can be done before I invest the time into it. I’m sure someone here has done something similar. Thanks!

Sonarr will move the files during importing unless it’s for a seeding torrent, which in your case it isn’t.

If you setup a Recycle Bin in Sonarr (Media Management settings), Sonarr will move files there instead of permanently deleting when importing an upgrade so you can store the archive copy. Alternatively you could have a post processing script in NZBGet that copies the file to an archive folder.

How would NZBGet know where the original file is located though? That’s what Sonarr knows so wouldn’t the post processing script have to be in Sonarr?
And for your original suggestion for the Recycle bin, how would it move from the Recycle Bin to the archive folder? In Sonarr’s eyes, once its moved there, its washed its hands of that file. If I write a monitoring program to watch that folder and move it, how would I know where it came from?

One more thing…what language does the script have to be in for bsd? I see powershell for windows (from the example) but there’s nothing for unix/bsd. Thanks

Nevermind, I understand what needs to be done here. Ignore this reply.

NZBGet would know about the file it just downloaded, you’d be archiving before Sonarr processes it (unlike using the recycle bin).

A custom script in Sonarr to do it would be option 3, which sounds like the route you’re most interested in.

It would’t either something would need to check that folder of that would become the archive.

To watch the recycle bin folder? it wouldn’t know the source.

I think you’ve already started looking at a custom script in Sonarr as opposed to in NZBGet which would work as well, just depends if you want to have the script archive the file before Sonarr processes it or afterwards.

Here’s what I have done and seems to be working. Please let me know if you find any flaws in this or situations where errors can occur.

I have a custom script which does the following:
–If its not an upgrade, skip (don’t apply to new/missing episodes)
–Get the path to the deleted episode (in the recycle bin; to create the source path)
–Grab the series name from the source path (since it’s how I named it from the original directory, not the official name)
----(I tested this with Aaahh Real Monsters by removing the !!! after Aaahh in my folder name)
----(When an episode was upgraded, the series folder name in the recycle bin was Aaahh, not Aaahh!!!)
–Create the destination path by combining the archive path with my series named folder.
–Move the series folder to the archive TV folder

Pretty straight forward, as I’m also trusting Sonarr’s episode check before importing. Since this is a Sonarr specific task, I want to keep it with Sonarr and not NZBGet.

This could be error prone if there were multiple files with the same name or the structure ever changed, it might be better to instead always run the script (for new files and upgrades) and store them in the archive, that’d come at the cost of storing the current file twice, but you could hardlink the file (as long as it’s on the same volume) and save the extra space and do away with the recycle bin altogether.

For new files, nothing would get put in the recycle bin, right? Only for upgrades?

Multiple files with the same name? How could that happen? They would have to be in different folders.

How could the structure ever change? I’m providing Sonarr with the recycle bin folder.
Lets say /media/sonarr/recycle
Then from the deletefiles_path, say /media/sonarr/recycle/Aaahh!!! Real Monsters/Season 1/Aaahh!!! Real Monsters.S01E01.avi, I grab the series folder name (after the known recycle bin path to the next slash) Aaahh!!! Real Monsters
Create the source folder: /media/sonarr/recycle/Aaahh!!! Real Monsters
Use the archive folder to append on the series name: /media/archive/Aaahh!!! Real Monsters
And finally move all files and subdirectories and sub files to destination folder
That’s what it currently does. It can handle 1 or 100 files.

Correct.

Depends on your naming scheme and if the files sit in the recycle bin folder.

The fact that the files end up in a folder structure matching the series folder structure is new, it’s possible that changes (just like it changed before).

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.