Skip to content

Instantly share code, notes, and snippets.

@lifeofguenter
Last active November 11, 2018 21:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lifeofguenter/d3e6d50999eac73dd60e to your computer and use it in GitHub Desktop.
Save lifeofguenter/d3e6d50999eac73dd60e to your computer and use it in GitHub Desktop.
NZBGet Transcoders
#!/bin/bash
##############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
# Transcode mkv to mp4 (Sony Bravia compatible).
# Version: 0.1.0
#
#
# NOTE: For support visit the forum thread: http://nzbget.net/forum/viewtopic.php?f=8&t=1265
##############################################################################
### OPTIONS ###
# Full path to ffmpeg executable
#
#
# Example: /usr/bin/ffmpeg
#
#
# If ffmpeg is in your PATH you may leave the path part and set only the executable name (e.g. "ffmpeg")
#FfmpegCmd=ffmpeg
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
# TODO:
# http://nzbget.net/Extension_scripts#Testing_NZBGet_version
# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_SKIP=95
# only post process 100% ok files
if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]; then
exit $POSTPROCESS_SKIP
fi
# check for valid executable
command -v "$NZBPO_FFMPEGCMD" >/dev/null 2>&1 || { echo >&2 "[ERROR] ffmpeg not found."; exit $POSTPROCESS_ERROR; }
# change to working dir
cd "$NZBPP_DIRECTORY"
# get all avi files
RAN=0
for FILE in *.mkv *.MKV; do
if [[ ! -e "$FILE" ]]; then
continue
fi
BASENAME=$(basename "$FILE")
EXTENSION="${BASENAME##*.}"
FILENAME="${BASENAME%.*}"
RESULT=`$NZBPO_FFMPEGCMD -y -loglevel error -i "$BASENAME" -c:v copy -c:a libfaac -b:a 192k -ac 2 "$FILENAME.mp4" > /dev/null 2>/dev/stdout`
RC=$?
if [ "$RC" -ne "0" ]; then
echo "[ERROR] $NZBPP_NZBNAME ($BASENAME): $RESULT"
exit $POSTPROCESS_ERROR
else
RAN=1
rm "$FILE"
fi
done
if [ "$RAN" -ne "1"]; then
exit $POSTPROCESS_SKIP
else
exit $POSTPROCESS_SUCCESS
fi
#!/bin/bash
##############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
# Transcode xvid to mp4 (Sony Bravia compatible).
# Version: 0.1.0
#
#
# NOTE: For support visit the forum thread: http://nzbget.net/forum/viewtopic.php?f=8&t=1265
##############################################################################
### OPTIONS ###
# Full path to ffmpeg executable
#
#
# Example: /usr/bin/ffmpeg
#
#
# If ffmpeg is in your PATH you may leave the path part and set only the executable name (e.g. "ffmpeg")
#FfmpegCmd=ffmpeg
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
# TODO:
# http://nzbget.net/Extension_scripts#Testing_NZBGet_version
# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_SKIP=95
# only post process 100% ok files
if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]; then
exit $POSTPROCESS_SKIP
fi
# check for valid executable
command -v "$NZBPO_FFMPEGCMD" >/dev/null 2>&1 || { echo >&2 "[ERROR] ffmpeg not found."; exit $POSTPROCESS_ERROR; }
# change to working dir
cd "$NZBPP_DIRECTORY"
# get all avi files
RAN=0
for FILE in *.avi *.AVI; do
if [[ ! -e "$FILE" ]]; then
continue
fi
BASENAME=$(basename "$FILE")
EXTENSION="${BASENAME##*.}"
FILENAME="${BASENAME%.*}"
RESULT=`$NZBPO_FFMPEGCMD -y -loglevel error -i "$BASENAME" -c:v libx264 -crf 20 -pix_fmt yuv420p -profile:v high -level 4.0 -c:a libfaac -b:a 192k -ac 2 "$FILENAME.mp4" > /dev/null 2>/dev/stdout`
RC=$?
if [ "$RC" -ne "0" ]; then
echo "[ERROR] $NZBPP_NZBNAME ($BASENAME): $RESULT"
exit $POSTPROCESS_ERROR
else
RAN=1
rm "$FILE"
fi
done
if [ "$RAN" -ne "1"]; then
exit $POSTPROCESS_SKIP
else
exit $POSTPROCESS_SUCCESS
fi
#!/bin/bash
##############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
# Move files if all daisy-chained PP prior succeeded.
# Version: 0.1.0
#
#
# NOTE: For support visit the forum thread: http://nzbget.net/forum/viewtopic.php?f=8&t=1265
##############################################################################
### OPTIONS ###
# The final directory for post-processed files
#FinalDestination=~/downloads/z
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_SKIP=95
# only post process 100% ok files
if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]; then
exit $POSTPROCESS_SKIP
fi
# only move files if there was no error prior
if [ "$NZBPP_SCRIPTSTATUS" = "FAILURE" ]; then
exit $POSTPROCESS_SKIP
fi
# move complete folder
mv "$NZBPP_DIRECTORY" "$NZBPO_FINALDESTINATION"
exit $POSTPROCESS_SUCCESS
@sbcrumb
Copy link

sbcrumb commented Nov 11, 2018

I am using this to transcode audio only. How can I get it to not delete the file when it is done with the command? IE keep it a MKV

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