Code: Select all
Rename episodes using [TheTVDB]
Auto-detected query: [Sons of Anarchy]
Failure (?_?)
Code: Select all
#!/bin/bash
{
##############################
### TURN ON ERROR CHECKING ###
##############################
# exit immediately upon failure
set -e
#################################
### Set Environment Variables ###
#################################
# sets hdd variable
hdd="/hdd_1"
# sets new_movie_name varaible
new_movie_name=$(find "$TR_TORRENT_DIR/$TR_TORRENT_NAME" -type f -size +500M -not -iname "*sample*" -not -iname "*hdtv*" -not -iname "*s[0-9]*" -not -iname "*s[0-9][0-9]*" -not -iname "*s[0-9][0-9][0-9]*" -not -iname "*e[0-9]*" -not -iname "*e[0-9][0-9]*" -not -iname "*e[0-9][0-9][0-9]*" -not -iname "*s[0-9][0-9]e[0-9][0-9]*" -not -iname "*s[0-9][0-9]e[0-9][0-9][0-9]*" -not -iname "*s[0-9][0-9][0-9]e[0-9][0-9][0-9]*" -not -iname "*s[0-9]e[0-9][0-9]*" -not -iname "*s[0-9]e[0-9][0-9][0-9]*" -not -iname "*[0-9]x[0-9]*" -not -iname "*[0-9]x[0-9][0-9]*" -not -iname "*[0-9][0-9]x[0-9][0-9]*" -not -iname "*[0-9][0-9][0-9]x[0-9][0-9][0-9]*" \( -iname "*19[0-9][0-9]*" -o -iname "*20[0-9][0-9]*" \) -exec basename {} \;)
# sets new_movie_directory variable
new_movie_directory=$(find "$TR_TORRENT_DIR/$TR_TORRENT_NAME" -type f -size +500M -not -iname "*sample*" -not -iname "*hdtv*" -not -iname "*s[0-9]*" -not -iname "*s[0-9][0-9]*" -not -iname "*s[0-9][0-9][0-9]*" -not -iname "*e[0-9]*" -not -iname "*e[0-9][0-9]*" -not -iname "*e[0-9][0-9][0-9]*" -not -iname "*s[0-9][0-9]e[0-9][0-9]*" -not -iname "*s[0-9][0-9]e[0-9][0-9][0-9]*" -not -iname "*s[0-9][0-9][0-9]e[0-9][0-9][0-9]*" -not -iname "*s[0-9]e[0-9][0-9]*" -not -iname "*s[0-9]e[0-9][0-9][0-9]*" -not -iname "*[0-9]x[0-9]*" -not -iname "*[0-9]x[0-9][0-9]*" -not -iname "*[0-9][0-9]x[0-9][0-9]*" -not -iname "*[0-9][0-9][0-9]x[0-9][0-9][0-9]*" \( -iname "*19[0-9][0-9]*" -o -iname "*20[0-9][0-9]*" \) -exec dirname {} \;)
# sets new_tv_name variable
new_tv_name=$(find "$TR_TORRENT_DIR/$TR_TORRENT_NAME" -type f -not -size -100M -not -size +2G -not -iname "*sample*" \( -iname "*s[0-9]*" -o -iname "*s[0-9][0-9]*" -o -iname "*s[0-9][0-9][0-9]*" -o -iname "*e[0-9]*" -o -iname "*e[0-9][0-9]*" -o -iname "*e[0-9][0-9][0-9]*" -o -iname "*s[0-9][0-9]e[0-9][0-9]*" -o -iname "*s[0-9][0-9]e[0-9][0-9][0-9]*" -o -iname "*s[0-9][0-9][0-9]e[0-9][0-9][0-9]*" -o -iname "*s[0-9]e[0-9][0-9]*" -o -iname "*s[0-9]e[0-9][0-9][0-9]*" -o -iname "*[0-9]x[0-9]*" -o -iname "*[0-9]x[0-9][0-9]*" -o -iname "*[0-9][0-9]x[0-9][0-9]*" -o -iname "*[0-9][0-9][0-9]x[0-9][0-9][0-9]*" -o -iname "*hdtv*" \) -exec basename {} \;)
# sets new_tv_directory variable
new_tv_directory=$(find "$TR_TORRENT_DIR/$TR_TORRENT_NAME" -type f -not -size -100M -not -size +2G -not -iname "*sample*" \( -iname "*s[0-9]*" -o -iname "*s[0-9][0-9]*" -o -iname "*s[0-9][0-9][0-9]*" -o -iname "*e[0-9]*" -o -iname "*e[0-9][0-9]*" -o -iname "*e[0-9][0-9][0-9]*" -o -iname "*s[0-9][0-9]e[0-9][0-9]*" -o -iname "*s[0-9][0-9]e[0-9][0-9][0-9]*" -o -iname "*s[0-9][0-9][0-9]e[0-9][0-9][0-9]*" -o -iname "*s[0-9]e[0-9][0-9]*" -o -iname "*s[0-9]e[0-9][0-9][0-9]*" -o -iname "*[0-9]x[0-9]*" -o -iname "*[0-9]x[0-9][0-9]*" -o -iname "*[0-9][0-9]x[0-9][0-9]*" -o -iname "*[0-9][0-9][0-9]x[0-9][0-9][0-9]*" -o -iname "*hdtv*" \) -exec dirname {} \;)
# sets plex_movie_directory variable
plex_movie_directory="$hdd/plex/movie"
# sets plex_tv_directory varaible
plex_tv_directory="$hdd/plex/tv"
# sets filebot_movie_directory variable
filebot_movie_directory="$hdd/filebot/movie"
# sets fielbot_tv_directory variable
filebot_tv_directory="$hdd/filebot/tv"
######################
### Process Movies ###
######################
# lets user know if movie was found
[[ -z "$new_movie_name" ]] && echo "Not a Movie!" || echo "Found a Movie!"
# creates movie hard link if movie was found
[[ -z "$new_movie_name" ]] && : || ln "$new_movie_directory/$new_movie_name" "$filebot_movie_directory/$new_movie_name"
# renames the movie if it was found
[[ -z "$new_movie_name" ]] && : || filebot -rename "$filebot_movie_directory" --db themoviedb --format "$plex_movie_directory/{n} ({y})" -non-strict
# defines LD_LIBRARY_PATH environemnt variable if movie was found
[[ -z "$new_movie_name" ]] && : || export LD_LIBRARY_PATH=/usr/lib/plexmediaserver
# updates plex movies if movie was found
[[ -z "$new_movie_name" ]] && : || /usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --refresh --section 1
# undefines LD_LIBRARY_PATH environemnt variable if movie was found
[[ -z "$new_movie_name" ]] && : || export LD_LIBRARY_PATH=""
########################
### Process TV Shows ###
########################
# lets user know if tv show was found
[[ -z "$new_tv_name" ]] && echo "Not a TV Show!" || echo "Found a TV Show!"
# creates tv show hard link if tv show was found
[[ -z "$new_tv_name" ]] && : || ln "$new_tv_directory/$new_tv_name" "$filebot_tv_directory/$new_tv_name"
# renames the tv show if it was found
[[ -z "$new_tv_name" ]] && : || filebot -rename "$filebot_tv_directory" --db thetvdb --format "$plex_tv_directory/{n}/Season {s.pad(2)}/{n} - {s00e00}" -non-strict
# defines LD_LIBRARY_PATH environemnt variable if tv show was found
[[ -z "$new_tv_name" ]] && : || export LD_LIBRARY_PATH=/usr/lib/plexmediaserver
# updates plex tv shows if tv show was found
[[ -z "$new_tv_name" ]] && : || /usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --refresh --section 2
# undefines LD_LIBRARY_PATH environemnt variable if tv show was found
[[ -z "$new_tv_name" ]] && : || export LD_LIBRARY_PATH=""
#############
### Ohter ###
#############
# find and remove empty directories in the plex tv directory
find "$plex_tv_directory" -type d -empty -not -name "tv" -delete
# remove and delete torrents that have finished seeding
transmission-remote -l | grep Finished | awk '{print $1}' | xargs -n 1 -I % transmission-remote -t % --remove-and-delete
} > /hdd_1/transmission/script/log
exit 0
# if start_transcode is not running, then run
if ! fuser /hdd_bottom-left/handbrake/script/start_transcode
then
/hdd_bottom-left/handbrake/script/start_transcode
fi