Page 1 of 1

Another delete script request

Posted: February 10th, 2017, 4:19 am
by Viktor112
Good morning all!

I was wondering if someone managed to get rid of files by size.

This is the issue: I download a movie, filetype MKV but there is almost always an commercial added as a MP4.
Normally I would say put that extension to the 'Cleanup List' but sometimes the MP4's are needed and I don't want to have it to remove all the times.
I would like to have Sabnzbd or some other way to get rid of the files by a XX filesize.

I did find the special setting: 'movie_rename_limit - 100M - The minimum size of a file to trigger file renaming in the Sort functions' is ignored or misunderstood by me.
The behavior now is when I download TED mkv, movie file is 8gb and the commercial is mp4 and 50mb, I would expect that the renaming part of my sorting would not enable on the commercial.
But the result is: ted.mkv and ted.mp4.

What to do to get this thing sorted ?

Thanks in advance.

Ps. I'm on W10 - SABNZBD Version: 1.1.0 [8abcf08]

Re: Another delete script request

Posted: November 2nd, 2017, 9:54 am
by RikPet
So i had the same issue with this.

I created a post processing script with some help from the internet and especially fire_starr from Reddit. There was 1 error in his example which i fixed.

You can use the following one which will delete any mkv, avi or mp4 file which is less than 100 MB.

Put a file in your scripts folder with the .py extension and assign it to your category. The content of the .py file should be:

Code: Select all

import sys
import os

try:
    (scriptname,directory,orgnzbname,jobname,reportnumber,category,group,postprocstatus,url) = sys.argv
except:
    try:
        # are we testing only?
        directory = sys.argv[1]
    except:
        print "No commandline parameters found"
        sys.exit(1)

# continue script

# Your code goes here
files = os.listdir(directory)


# Size in MB
size = 100

for f in files:
    # Add or remove extensions here:
    
    if os.path.isfile(os.path.join(directory, f)) and f.endswith((".mkv",".avi",".mp4")):
        if os.path.getsize(os.path.join(directory, f)) / (1024.0*1024.0) < size:
            # Removes files with the above extensions less than 100MB of size
            os.remove(os.path.join(directory, f))

# Success code
sys.exit(0)

Re: Another delete script request

Posted: November 3rd, 2017, 9:15 am
by Howitzer
You are saying "commercial" but do you mean "sample"? Have you tried just deleting anything with "sample" in the file name?

Re: Another delete script request

Posted: October 26th, 2020, 5:57 am
by iUseNetter
How do I have to define your script in a way, that I can select it from the dropdown box in the multi-select filter line?
The same script filter box where I can select "CharTranslator.py".

The idea is the possibility to choose between "Delete all files from queue smaller then 50MB.py" or "Delete all files from queue smaller then 100MB.py" on request.

Re: Another delete script request

Posted: October 27th, 2020, 1:52 am
by safihre
You need to put it in your scripts directory, which is listed in Config > Folders.