Skip to content

Instantly share code, notes, and snippets.

@vdrover
Created May 11, 2023 18:40
Show Gist options
  • Save vdrover/e4039e7d313abe0d2e6000d6059a5088 to your computer and use it in GitHub Desktop.
Save vdrover/e4039e7d313abe0d2e6000d6059a5088 to your computer and use it in GitHub Desktop.
Postprocessing script for comskip & Emby
#!/bin/bash
# files and directory used in script :
# file saved in /usr/local/sbin/emby_preprocessing.sh
# sudo chmod +x /usr/local/sbin//emby_preprocessing.sh -to make it executable
# comskip ini file /etc/comskip.ini or in media directory
# log file saved in /var/lib/emby/logs/media.txt
log_message()
{
# Function. Parameter 1 message to log
# Log available in emby
# need a logrotate script to run once a day in cron job
echo $(date +"%Y-%m-%d%t%H:%M:%S") : ${1} >> /var/lib/emby/logs/media.txt
}
check_errs()
{
# Function. Parameter 1 is the return code
# Para. 2 is text to display on failure
if [ "${1}" -ne "0" ]; then
log_message "ERROR # ${1} : ${2}"
exit ${1}
fi
}
if [ ! -z "$1" ]; then
# The if selection statement proceeds to the script if $1 is not empty.
if [ ! -f "$1" ]; then
log_message "$1 does not exist"
exit 0
fi
# The above if selection statement checks if the file exists before proceeding.
FILENAME=$1 # %FILE% - Filename of original file
DIRECTORY="$(dirname """$1""")"
BASENAME="$(basename """$1""")"
BASEDIR="$(dirname """$(dirname """$1""")""")"
if [[ "$DIRECTORY" == *"Season"* ]]; then
BASEDIR="$(dirname """$(dirname """$1""")""")"
else
BASEDIR="$(dirname """$1""")"
fi
log_message "Starting preprocessing script $BASENAME"
# Uncomment if you want to adjust the bandwidth for this thread
MYPID=$$ # Process ID for current script
# Adjust niceness of CPU priority for the current process
renice 19 $MYPID
# wait a minute before starting comskip
sleep 65
if [ -f "$FILENAME" ]; then
log_message "Start comskip of $BASENAME from $BASEDIR"
edlfile="${FILENAME%.ts}.edl"
# a specific ini file can be used if found in media folder - if not /etc/comskip.ini is default
# use $DIRECTORY or $BASEDIR to build path depending where you put comskipini and logofile in season or in show folder
comskipini="$DIRECTORY/comskip.ini"
logfile="${FILENAME%.ts}.log"
logofile="$DIRECTORY/logo.txt"
newlogofile="${FILENAME%.ts}.logo.txt"
txtfile="${FILENAME%.ts}.txt"
#build command line
#if comskipini exist in file directory use it else use default comskipini
#use logo file if exist in file directory
if [ -f "$comskipini" ]; then
# echo use local ini
if [ -f "$logofile" ]; then
log_message "got a local ini and logo file "
comskip --ini="$comskipini" --logo="$logofile" "$FILENAME"
else
log_message "got a local ini file only"
comskip --ini="$comskipini" "$FILENAME"
fi
else
# echo use default ini
if [ -f "$logofile" ]; then
log_message "use default ini and local logo"
comskip --ini="/etc/comskip.ini" --logo="$logofile" "$FILENAME"
else
log_message "use default ini and no logofile"
comskip --ini="/etc/comskip.ini" "$FILENAME"
fi
fi
if [ -f "$logfile" ]; then
rm "$logfile";
log_message "delete log file"
fi
#move logo file to be use on same show next time
if [ -f "$newlogofile" ]; then
mv "$newlogofile" "$logofile"
log_message "moved logo file to $logofile"
else
log_message "no logo file to move"
fi
if [ -f "$txtfile" ]; then
rm "$txtfile";
log_message "delete txt file"
fi
fi
log_message "Finished prepostprocessing script $BASENAME"
else
log_message "********************************************************"
log_message "Usage: $0 FileName"
log_message "********************************************************"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment