Skip to content

Instantly share code, notes, and snippets.

@JudsonHat
Last active May 9, 2025 00:45
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.

Revisions

  1. JudsonHat revised this gist Nov 7, 2023. 2 changed files with 71 additions and 71 deletions.
    71 changes: 71 additions & 0 deletions RenameToNzbName.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    #!/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
    71 changes: 0 additions & 71 deletions rename.sh
    Original file line number Diff line number Diff line change
    @@ -1,71 +0,0 @@
    #!/bin/bash

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

    #
    # This script will rename the mkv 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

    # this if for files with spaces
    OIFS="$IFS"
    IFS=$'\n'

    cd "$NZBPP_DIRECTORY"

    for file in `find . -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mp4" -o -iname "*.ts"`; do

    # check if mkv is bigger than 200 MB; size is kilobytes
    minimumsize=200000
    actualsize=$(du -k "$file" | cut -f 1)
    if [ $actualsize -ge $minimumsize ]; then
    # size is over the minimum size, so rename mkv

    # create the new name to be same as nzb name

    # https://nzbget.net/post-processing-scripts
    nzbname="$NZBPP_NZBNAME"

    filename="$(basename "$file")"
    extension="${filename##*.}"

    # remove extention from filename to compare to nzb name
    filename="${filename%.*}"

    # desired new name
    newname="$nzbname.$extension"

    # if file name is nzb name already, then exit
    if [ "$nzbname" = "$filename" ]; then
    echo "[INFO] File name is already the same as the NZB name."
    exit $POSTPROCESS_SUCCESS
    fi

    # try to rename file
    if mv -v "$file" "$newname"; then
    echo "[INFO] Success!"
    else
    echo "[ERROR] Could not rename "$file" to "$newname""
    exit $POSTPROCESS_ERROR
    fi
    else
    # file too small
    echo "[INFO] "$file" is under 200 MB: $actualsize"
    fi
    done

    IFS="$OIFS"

    exit $POSTPROCESS_SUCCESS
  2. judhat2 created this gist Jun 28, 2017.
    71 changes: 71 additions & 0 deletions rename.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    #!/bin/bash

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

    #
    # This script will rename the mkv 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

    # this if for files with spaces
    OIFS="$IFS"
    IFS=$'\n'

    cd "$NZBPP_DIRECTORY"

    for file in `find . -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mp4" -o -iname "*.ts"`; do

    # check if mkv is bigger than 200 MB; size is kilobytes
    minimumsize=200000
    actualsize=$(du -k "$file" | cut -f 1)
    if [ $actualsize -ge $minimumsize ]; then
    # size is over the minimum size, so rename mkv

    # create the new name to be same as nzb name

    # https://nzbget.net/post-processing-scripts
    nzbname="$NZBPP_NZBNAME"

    filename="$(basename "$file")"
    extension="${filename##*.}"

    # remove extention from filename to compare to nzb name
    filename="${filename%.*}"

    # desired new name
    newname="$nzbname.$extension"

    # if file name is nzb name already, then exit
    if [ "$nzbname" = "$filename" ]; then
    echo "[INFO] File name is already the same as the NZB name."
    exit $POSTPROCESS_SUCCESS
    fi

    # try to rename file
    if mv -v "$file" "$newname"; then
    echo "[INFO] Success!"
    else
    echo "[ERROR] Could not rename "$file" to "$newname""
    exit $POSTPROCESS_ERROR
    fi
    else
    # file too small
    echo "[INFO] "$file" is under 200 MB: $actualsize"
    fi
    done

    IFS="$OIFS"

    exit $POSTPROCESS_SUCCESS