Skip to content

Instantly share code, notes, and snippets.

@dennisoderwald
Forked from werkkrew/filebot-process.sh
Created April 2, 2021 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennisoderwald/e8b9ca90dd3f91b96b6bdd04bf7699bc to your computer and use it in GitHub Desktop.
Save dennisoderwald/e8b9ca90dd3f91b96b6bdd04bf7699bc to your computer and use it in GitHub Desktop.
Filebot Process
#!/bin/bash
#### Media file processing script for Filebot
# This script gets triggered by some means (inotify, auditd, cron, etc.) and processes media files in some locations.
# It will run the filebot amc.groovy script against these files and output them into user defined locations for HTPC use.
#
# Known Limitations:
# Not dealing with music files, just video files. I use beets for music tagging.
# Not dealing with unique video types just yet, such as comedy specials, concerts, etc. Filebot might match it okay but I am not confident about it.
command -v filebot >/dev/null 2>&1 || { echo >&2 "I require filebot but it's not installed or in my $PATH. Aborting."; exit 1; }
# Set up some logging
NOW=$(date +"%m%d%Y")
LOGDIR="/var/log/htpc"
LOGFILE="filebot-wrapper-$NOW.log"
# base destinations to move files, no trailing slash. The subfolder is defined in the format string.
DESTINATION="/storage/videos"
# path(s) to search for files to process
SEARCH_PATH=("/storage/downloads/completed" "/storage/downloads/seedbox")
# gmail username:password (app password)
GMAIL="xxxxxxxx:yyyyyyyyy"
# format strings for filebot, please see: http://www.filebot.net/naming.html
TV_FORMAT="seriesFormat=TV Shows/{n}/{episode.special ? 'Season 0' : 'Season '+s}/{n}.{episode.special ? 'S00E'+special.pad(2) : s00e00}.{t}"
ANIME_FORMAT="animeFormat=Anime/{n}/{n}.S{(episode.season ? s : 1).pad(2)}E{e.pad(2)}.{t}"
MOVIE_FORMAT="movieFormat=Movies/{n} ({y})/{n} ({y})"
UNSORTED_FORMAT="unsortedFormat=Unsorted/{file.structurePathTail}"
# filebot is much more accurate when we tell it what type of media it is looking at, so we do that
MEDIA_TAGS=('movie' 'tv' 'anime');
# Test if script is run interactively, do not log the output if so
if [ -v PS1 ]
then
exec 1>> $LOGDIR/$LOGFILE 2>&1
echo "Logging to: ${LOGDIR}/${LOGFILE}"
# Delete old log files, comment this out if you just want to use logrotate or something
echo "Deleting log files older than 7 days..."
find $LOGDIR/ -name '*.log' -type f -mtime +7 -delete
fi
METHOD="auto"
# parameter 1 can override the search path
# parameter 2 can override the download tag (type of file)
if [ $# -gt 0 ]
then
SEARCH_PATH=($1)
unset $MEDIA_TAGS
MEDIA_TAGS=($2)
METHOD="manual"
echo "User provided parameters, using manual mode."
fi
# Fix the IFS to deal with spaces in files
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
echo "Start Processing - ${0} on $(date)"
for path in "${SEARCH_PATH[@]}"; do
for tag in "${MEDIA_TAGS[@]}"; do
echo "Current tag: <$tag>"
if [ $METHOD == "auto" ]
then
MEDIA_PATH=$path/$tag
else
MEDIA_PATH=$path
fi
if find "$MEDIA_PATH" -mindepth 1 -print -quit | grep -q .; then
echo "Running Filebot in $MEDIA_PATH using media tag <$tag>"
filebot -script fn:amc \
--output $DESTINATION \
--log-file $LOGDIR/filebot-amc.log \
--action move \
--conflict override \
-non-strict \
-no-xattr \
"$MEDIA_PATH" \
--def \
excludeList=$LOGDIR/filebot-history.log \
music=n \
subtitles=en \
artwork=y \
extras=y \
gmail=$GMAIL \
clean=y \
unsorted=y \
"ut_kind=$tag"
"seriesFormat=$TV_FORMAT" \
"animeFormat=$ANIME_FORMAT" \
"movieFormat=$MOVIE_FORMAT"
echo "Finished processing for tag: <$tag> in $MEDIA_PATH"
else
echo "$MEDIA_PATH is empty, moving on..."
fi
done
done
echo "Finished Searching for files."
IFS=$SAVEIFS
echo "Script Complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment