postprocess - AdvancedCleanup.sh (*nix only)

Share your scripts or request scripts with specific features.
Forum rules
Please keep the forum clean - one topic per script. Questions not related to a specific script should be posted in Support forum.
Post Reply
theparnic
Posts: 28
Joined: 30 Apr 2013, 19:56

postprocess - AdvancedCleanup.sh (*nix only)

Post by theparnic » 06 May 2013, 03:25

I needed a simple script to clean up a few more files that get left behind sometimes, so I created a cleanup script that will match a set of shell glob patterns to remove files. In my case I'm using it for "proof" files and samples. Maybe someone else will find it handy.

Code: Select all

#!/bin/bash

##############################################################################
### NZBGET POST-PROCESSING SCRIPT                                          ###

# Cleans up files matching bash glob patterns.

##############################################################################
### OPTIONS                                                       ###

# Patterns to match. Separate each entry with commas, no spaces
#Patterns=*.proof.jpg,*-proof.jpg

### NZBGET POST-PROCESSING SCRIPT                                          ###
##############################################################################

POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94

# Check if the script is called from nzbget 11.0 or later
if [ "$NZBOP_SCRIPTDIR" = "" ]; then
        echo "*** NZBGet post-processing script ***"
        echo "This script is supposed to be called from nzbget (11.0 or later)."
        exit $POSTPROCESS_ERROR
fi

echo "[INFO] Cleaning up"

IFS=',' read -a array <<< "$NZBPO_PATTERNS"

for element in "${array[@]}"
do
  echo "[DETAIL] Cleaning up files matching pattern $element"
  rm "$element" >/dev/null 2>&1
done

exit $POSTPROCESS_SUCCESS

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: postprocess - AdvancedCleanup.sh (*nix only)

Post by hugbug » 06 May 2013, 19:56

I would add a check if the download was successful before deleting anything.

In r667 the option ExtCleanupDisk was extended. Now it checks the substring at the end of file name, not just extension. This should work:

Code: Select all

ExtCleanupDisk=.proof.jpg,-proof.jpg

theparnic
Posts: 28
Joined: 30 Apr 2013, 19:56

Re: postprocess - AdvancedCleanup.sh (*nix only)

Post by theparnic » 06 May 2013, 19:59

hugbug wrote:I would add a check if the download was successful before deleting anything.
Good note, I'll make that change in the OP.
hugbug wrote:In r667 the option ExtCleanupDisk was extended. Now it checks the substring at the end of file name, not just extension. This should work:

Code: Select all

ExtCleanupDisk=.proof.jpg,-proof.jpg
Cool, that'll handle the "proof" case. I also use a glob for deleting samples and I figured the script could be extended for other types of files too. E.g.:
*[-._]sample[-._][maMA][kpvKPV][v4igVIG]
(mkv, avi, mp4, mpg, etc.) Sadly, that is still not quite sufficient when the filename is something like *-sample-groupname.ext, but i didn't wanna clear anything with [._-]sample-[._-] in it.

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: postprocess - AdvancedCleanup.sh (*nix only)

Post by hugbug » 06 May 2013, 20:08

For samples I use DeleteSamples.py. It processes only media files and has an extra check for file size preventing the deletion of movies having "sample" in their names.

reiniervanrutten
Posts: 17
Joined: 19 Apr 2013, 14:30
Location: Netherlands, Amsterdam

Re: postprocess - AdvancedCleanup.sh (*nix only)

Post by reiniervanrutten » 07 May 2013, 09:22

it's great to hear that In r667 the option ExtCleanupDisk is extended. But I would say; less scripts the better. I think you should go a step further and add the sample deletion as a separate option in nzbget, on/off, to delete sample files. Instead of again an extra script to maintain. :?

An other, or additional, option is the switch that sabnzbd has: Ignore sample files. (Do not download files whose names contain the word "sample".)
http://wiki.sabnzbd.org/configure-switches

I mean, why delete it, if you can skip downloading them. :D

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: postprocess - AdvancedCleanup.sh (*nix only)

Post by hugbug » 07 May 2013, 09:37

There are many reasons to not have "ignore samples" feature:
  • Sample files are sometimes part of par-set. Not downloading them could mean a long par-repair process;
  • A lot of nzbs have misnamed files nowadays. It's not possible to distinguish samples from other files until the download is completed and post-processed;
  • A solution with DeleteSamples-script works fine;
  • Just ignoring files containing word "sample" is not good, there are movies with word "sample". The check must be more sophisticated. That's what DeleteSamples-script does, it's smarter than just delete all files with word "sample";
  • If you really want to ignore files with word "sample" this can be achieved via NzbAddedProcess-option with a command like this (didn't tested it):

    Code: Select all

    "$NZBOP_APPBIN" -c "$NZBOP_CONFIGFILE" -E FR D "$NZBNA_NAME/.*sample.*";
  • I do have many more important things to work on.

reiniervanrutten
Posts: 17
Joined: 19 Apr 2013, 14:30
Location: Netherlands, Amsterdam

Re: postprocess - AdvancedCleanup.sh (*nix only)

Post by reiniervanrutten » 07 May 2013, 10:13

hugbug wrote:There are many reasons to not have "ignore samples" feature:
  • Sample files are sometimes part of par-set. Not downloading them could mean a long par-repair process;
  • A lot of nzbs have misnamed files nowadays. It's not possible to distinguish samples from other files until the download is completed and post-processed;
I agree, so lets focus on deleting the right files after downloading.
hugbug wrote: [*]A solution with DeleteSamples-script works fine;
[*]Just ignoring files containing word "sample" is not good, there are movies with word "sample". The check must be more sophisticated. That's what DeleteSamples-script does, it's smarter than just delete all files with word "sample";
Would love to see this as core feature in nzbget, or as a script that comes with nzbget. Really hate maintaining these things myself.
hugbug wrote: [*]I do have many more important things to work on.[/list]
Thanks! Your work is appreciated!

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests