Skip to content

Instantly share code, notes, and snippets.

@JudsonHat
Last active November 7, 2023 13:23
Show Gist options
  • Save JudsonHat/a9651628e1a31557f450f8e427f31d73 to your computer and use it in GitHub Desktop.
Save JudsonHat/a9651628e1a31557f450f8e427f31d73 to your computer and use it in GitHub Desktop.
nzbget script to rename file to the nzb name
#!/bin/bash
#######################################
### NZBGET POST-PROCESSING SCRIPT ###
#
# This script will rename the file to
# the nzb name.
#
### NZBGET POST-PROCESSING SCRIPT ###
#######################################
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]; then
echo "[ERROR] This nzb-file was not processed correctly, terminating the script"
exit 95
fi
echo "[INFO] ###############################################"
echo "[INFO] RENAME FILE"
# this if for files with spaces
OIFS="$IFS"
IFS=$'\n'
#go into the download's directory and show the contents on the log
cd "$NZBPP_DIRECTORY"
echo "[INFO] DIR Listing"
pwd
ls -sh1
# Check if more than 1 file bigger than 50 MB exists
if [ `find . -type f -size +102300 -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mp4" -o -iname "*.ts" | wc -l` -gt 1 ]; then
echo "[WARNING] More than one file found over 50 MB. Requires manual procecessing."
exit $POSTPROCESS_ERROR
# Check if no files bigger than 50 MB exists
elif [ `find . -type f -size +102300 -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mp4" -o -iname "*.ts" | wc -l` -eq 0 ]; then
echo "[WARNING] No files found over 50 MB. Requires manual procecessing."
exit $POSTPROCESS_ERROR
fi
for file in `find . -type f -size +102300 -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mp4" -o -iname "*.ts"`; do
# create the new name to be same as nzb name
# https://nzbget.net/post-processing-scripts
nzbname="$NZBPP_NZBNAME"
filename="$(basename "$file")"
extension="${filename##*.}"
filename="${filename%.*}"
newname="$nzbname.$extension"
# check if file needs to be renamed
if [ "$nzbname" = "$filename" ]; then
echo "[INFO] File name is already the same as the NZB name."
# try to rename file
elif mv -v "$file" "$newname"; then
echo "[INFO] Success!"
else
echo "[ERROR] Could not rename "$file" to "$newname""
exit $POSTPROCESS_ERROR
fi
done
IFS="$OIFS"
exit $POSTPROCESS_SUCCESS
@jhughesco
Copy link

Thanks for this handy Extension script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment