- addrename.sh: replace dead TheTVDB HTML scrape (404 since site overhaul) with new v4 API (api.thetvdb.com) using optional TVDB_API_KEY from JDAutoConfig; fall back to manual name entry when name cannot be fetched - rename.sh: per-entry provider stored as renamelist line 6 (IDs are provider-specific: TVDB id != TMDB id); old 6-line entries fall back to the configured category default - rename.sh: filebot_rename() validates db value and logs provider/id; movie fallback now uses config (FileBotLang, Movies path) instead of hardcoded German//mnt/Medien/Filme; drop dead names() TVDB scraper - fix pre-existing syntax error: three prompt lines in addrename.sh had unbalanced quotes (odd count) - bash -n failed on the whole script - README: filebot 4.8.5 note replaced (new TVDB v4 API needs 5.x+), new 'Metadata providers' section incl. TMDB German episode caveat - JDAutoConfig: document provider options + optional TVDB_API_KEY - i18n: add tvdb_key_missing/name_fetch_failed/enter_manually (addrename) and no_db/using_db (rename) for de_DE, en_GB, en_US
162 lines
5.4 KiB
Bash
162 lines
5.4 KiB
Bash
#!/bin/bash
|
|
|
|
## Farben für das Log
|
|
red='\033[0;31m'
|
|
green='\033[0;32m'
|
|
white='\033[0;37m'
|
|
yellow='\033[0;33m'
|
|
purple='\033[0;35m' # ${purple}
|
|
|
|
log="$1"
|
|
config="$2"
|
|
count=$(($3 + 1))
|
|
|
|
# shellcheck disable=SC1090
|
|
source "$config"
|
|
|
|
JDAutoConfig="$config"
|
|
# shellcheck disable=SC1091
|
|
source "$(dirname "$0")/i18n.sh"
|
|
|
|
log_msg() {
|
|
echo -e "${yellow}$(date +"%d.%m.%y %T")${white} $1${white}" >>"${log[@]}"
|
|
}
|
|
|
|
discord_msg() {
|
|
curl -s -H "Content-Type: application/json" -X POST -d "{\"content\": \"$1\"}" "$discord" &>/dev/null
|
|
}
|
|
|
|
nextcloud_msg() {
|
|
curl -d '{"token":"'"$NextcloudTalkToken"'", "message":"'"$1"'"}' -H "Content-Type: application/json" -H "Accept:application/json" -H "OCS-APIRequest:true" -u "$NextcloudUser:$NextcloudPassword" "$NextcloudDomain"/ocs/v1.php/apps/spreed/api/v1/chat/tokenid &>/dev/null
|
|
}
|
|
|
|
apprise_msg() {
|
|
if [[ -n $apprisetag ]]; then
|
|
curl -d '{"body":"'"$1"'", "title":"#### jdautoenc.sh ####","tag":"'"$apprisetag"'"}' -H "Content-Type: application/json" "$appriseurl" &>/dev/null
|
|
else
|
|
curl -d '{"body":"'"$1"'", "title":"#### jdautoenc.sh ####"}' -H "Content-Type: application/json" "$appriseurl" &>/dev/null
|
|
fi
|
|
}
|
|
|
|
# Provider-agnostic: works with any db value filebot supports (TheMovieDB, TheMovieDB::TV, TheTVDB, AniDB, ...)
|
|
# The db is passed through from the config / renamelist entry untouched.
|
|
filebot_rename() {
|
|
if [[ -z "$1" ]]; then
|
|
log_msg "${red}$(tr "no_db") $5 -> $v"
|
|
return 1
|
|
fi
|
|
log_msg "$(tr "using_db") $1 id $5 -> $v"
|
|
filebot -rename "$v" --db "$1" -non-strict --lang "$2" --format "$3/$4" --q "$5" >>"${log[@]}" 2>>"${log[@]}"
|
|
}
|
|
|
|
if [[ -f /tmp/jdautoenc.lock ]]; then # ignore
|
|
log_msg "$(tr "wait_encoding")"
|
|
sleep 2
|
|
fi
|
|
|
|
while [ -f /tmp/jdautoenc.lock ]; do
|
|
sleep 1m
|
|
done
|
|
|
|
sleep $(((RANDOM % 6) + 1))s
|
|
|
|
while [ -f /tmp/jdautoenc.lock ]; do
|
|
sleep 1m
|
|
done
|
|
|
|
# Erstelle lock Datei, Warte 5 Sekunden und überprüfe nochmals
|
|
while [ -f /tmp/rename.lock ]; do
|
|
sleep $(((RANDOM % 6) + 1))s
|
|
done
|
|
|
|
if [[ -f /tmp/rename.lock ]]; then # ignore
|
|
log_msg "$(tr "renaming_running")"
|
|
sleep $(((RANDOM % 2) + 1))s
|
|
fi
|
|
|
|
echo $$ >/tmp/rename.lock
|
|
|
|
## Script start
|
|
|
|
log_msg ""
|
|
log_msg "#######################"
|
|
log_msg "$(tr "start") ${green}rename.sh${white} $(tr "script")"
|
|
log_msg "#######################"
|
|
log_msg ""
|
|
|
|
while read -r name; do
|
|
read -r keyword1
|
|
read -r keyword2
|
|
read -r format
|
|
read -r dbid
|
|
# Line 6 = provider stored per entry by addrename.sh (IDs are provider-specific!
|
|
# e.g. a TVDB series id is NOT a TMDB id). Old entries have an empty separator
|
|
# line here and fall back to the category default from the config.
|
|
read -r entrydb
|
|
if [[ -z "$entrydb" ]]; then
|
|
nextentry=""
|
|
else
|
|
read -r nextentry
|
|
fi
|
|
|
|
find -L "${encodes[@]}" -name '*.mkv' -or -name '*.mp4' 2>/dev/null | while IFS= read -r v; do
|
|
|
|
if [[ ${v,,} == *"${keyword1,,}"*"${keyword2,,}"* ]]; then
|
|
log_msg "$(tr "name") $(basename "$v" | sed 's/\./ /g;s/AAC\|1080p\|WebDL\|[a-z]26[0-9]\|[hH][eE][Vv][Cc]\|[tT]anuki\| dl \| web \|repack\|wayne\|\|[-]\|[gG]er\|[eE]ng\|[sS]ub//g;s/\[[^][]*\]\|WebDL\|JapDub\|CR\|REPACK\|V2DK\|man\|BluRay\|RSG//g;s/_/ /g;s/\( \)*/\1/g')"
|
|
case ${format,,} in
|
|
anime)
|
|
filebot_rename "${entrydb:-$AnimeDB}" "$FileBotLang" "$Animes" "$AnimeName" "$dbid"
|
|
;;
|
|
series)
|
|
filebot_rename "${entrydb:-$SeriesDB}" "$FileBotLang" "$Series" "$SeriesName" "$dbid"
|
|
;;
|
|
movie)
|
|
filebot_rename "${entrydb:-$MovieDB}" "$FileBotLang" "$Movies" "$MovieName" "$dbid"
|
|
;;
|
|
*)
|
|
log_msg "${red}$v $(tr "does_not_match") $name $(tr "match")"
|
|
log_msg "${red}$(tr "next_entry")"
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
done
|
|
done <"$renamelist"
|
|
|
|
find -L "${encodes[@]}" -name '*.mkv' -or -name '*.mp4' 2>/dev/null | while IFS= read -r v; do
|
|
duration=$(ffprobe -hide_banner -loglevel error -v quiet -stats -i "$v" -show_entries format=duration -v quiet -of csv="p=0" | sed -e 's/\..*//g')
|
|
if [ "$duration" -gt "4751" ]; then # ignore
|
|
log_msg "${purple}$v${white} $(tr "is_movie")"
|
|
movie=$(basename "$v")
|
|
folder=$(basename "$v" .mkv)
|
|
## Hier wird nun ein Ordner mit dem Namen des Videos erstellt. Dies ist eine Vorsichtsmaßnahme, da mein Ordner (encoded) auch bei eindeutigen Film
|
|
## Namen immer wieder dazu führte, dass der Film als "ENCODED EXPLODED" umbenannt wurde -.-
|
|
|
|
log_msg "$(tr "create_folder") $folder" "$yellow" "$white" "$folder"
|
|
mkdir "$encodes""$folder" 2>/dev/null
|
|
log_msg "$(tr "move") ${purple}$v${white} $(tr "to") $folder"
|
|
mv "$v" "$encodes""$folder" >>"${log[@]}" 2>/dev/null
|
|
log_msg "$(tr "start_renaming")"
|
|
# Heuristic movie fallback: always TheMovieDB, but lang/target dir come from the config
|
|
filebot -rename "$encodes""$folder"/"$movie" --db TheMovieDB -non-strict --lang "$FileBotLang" --format "${Movies}/{n} ({y})" >>"${log[@]}"
|
|
log_msg "$(tr "if_successful") ${red}$(tr "delete")${white} $(tr "folder")"
|
|
sleep 5s
|
|
rmdir "$encodes"* 2>/dev/null
|
|
fi
|
|
done
|
|
|
|
rm -f /tmp/rename.lock
|
|
|
|
if tail -n 20 "$log" | grep "Failure" &>/dev/null; then
|
|
if [ "$count" -lt 3 ]; then
|
|
/bin/bash "$0" "$log" "$config" "$count" &
|
|
exit
|
|
else
|
|
log_msg "$(tr "error_renaming") $count $(tr "failed_attempts")"
|
|
discord_msg "$(tr "error_renaming") $count $(tr "failed_attempts")"
|
|
nextcloud_msg "$(tr "error_renaming") $count $(tr "failed_attempts")"
|
|
apprise_msg "$(tr "error_renaming") $count $(tr "failed_attempts")"
|
|
fi
|
|
else
|
|
log_msg "$(tr "completed_successfully")"
|
|
fi |