Files
JDownloader-Autoenc-rename/addrename.sh
T
ARIA 7a05877139 fix: TheTVDB v4 API compatibility + provider-specific renamelist entries
- 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
2026-11-08 21:31:30 +01:00

162 lines
6.4 KiB
Bash

#!/bin/bash
## Farben für das Log
white='\033[0;37m' # ${white}
yellow='\033[0;33m' # ${yellow}
purple='\033[0;35m' # ${purple}
blue='\033[0;34m' # ${blue}
lblue='\033[1;34m' # ${lblue}
cyan='\033[0;36m' # ${cyan}
## Rename Skript Pfad:
JDAutoConfig=$(find ~ -type f -name "JDAutoConfig" 2>/dev/null)
renamelist=$(grep "renamelist=" "$JDAutoConfig" | sed 's/renamelist=//g')
# Optional: TheTVDB v4 API project key for the name check (see JDAutoConfig)
TVDB_API_KEY=$(grep "TVDB_API_KEY=" "$JDAutoConfig" 2>/dev/null | sed 's/.*=//g')
# shellcheck disable=SC1091
source "$(dirname "$0")/i18n.sh"
get_DB() {
grep "$1DB=" "$JDAutoConfig" | sed 's/.*=//g'
}
curl_name() {
if [[ $dbid == "TheTVDB" ]]; then
# The old HTML scrape (thetvdb.com/dereferrer/series/<id>) is dead since the TVDB site/API
# overhaul (returns 404 now). Use the new v4 API with an optional project key from JDAutoConfig.
if [[ -n "$TVDB_API_KEY" ]]; then
local token
token=$(curl -s -X POST https://api.thetvdb.com/login -H "Content-Type: application/json" -d '{"apikey":"'"$TVDB_API_KEY"'"}' | sed -n 's/.*"token":"\([^"]*\)".*/\1/p')
if [[ -n "$token" ]]; then
curl -s "https://api.thetvdb.com/v4/series/$dbentry/basic?language=de" -H "Authorization: Bearer $token" | sed -n 's/.*"name":"\([^"]*\)".*/\1/p' | head -n 1
else
echo "TVDB login failed (check TVDB_API_KEY in JDAutoConfig)." >&2
fi
else
echo "$(tr "tvdb_key_missing")" >&2
fi
elif [[ $dbid == "TheMovieDB::TV" ]]; then
curl -sL https://www.themoviedb.org/tv/"$dbentry" | grep -i "TV Series" | sed -e 's/<[^>]*>\|(TV.*//g'
elif [[ $dbid == "TheMovieDB" ]]; then
curl -sL https://www.themoviedb.org/movie/"$dbentry" | grep -i "The Movie Database (TMDB)" | grep title | sed -e 's/<[^>]*>\|&#.*//g'
elif [[ $dbid == "AniDB" ]]; then
curl -sL -A "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0" https://anidb.net/anime/"$dbentry" | grep -i -A1 "Synonym" | sed 's/<[^>]*>\|Synonym\|\t//g' | sed '/^$/d'
fi
}
curl_movie_name() {
curl -sL "https://themoviedb.org/movie/$dbentry" | grep -i "<title>" | sed -e 's/<[^>]*>//g' | sed 's/&#[0-9].*//g'
}
get_db_id() {
if [[ $dbid == "TheTVDB" ]]; then
if [ -z "$key2" ]; then
echo -e "${purple}https://thetvdb.com/search?query=""$key1""${white}"
else
echo -e "${purple}https://thetvdb.com/search?query=""$key1""%20""$key2""${white}"
fi
elif [[ $dbid == "TheMovieDB" ]] || [[ $dbid == "TheMovieDB::TV" ]]; then
if [ -z "$key2" ]; then
echo -e "${purple}https://www.themoviedb.org/search?language=de&query=""$key1""${white}"
else
echo -e "${purple}https://www.themoviedb.org/search?language=de&query=""$key1""%20""$key2""${white}"
fi
elif [[ $dbid == "AniDB" ]]; then
if [ -z "$key2" ]; then
echo -e "${purple}https://anidb.net/anime/?adb.search=$key1&do.update=Search&noalias=1${white}"
else
echo -e "${purple}https://anidb.net/anime/?adb.search=$key1%20$key2&do.update=Search&noalias=1${white}"
fi
fi
}
while true; do
read -rp "$(echo -e "$(tr "add_prompt")" "${cyan}""$(tr "film")""${white}" "$(tr "or_a")" "${blue}""$(tr "anime")""${white}"/"${lblue}""$(tr "series")""${white}" "$(tr "to_rename")") ($(tr "enter_type")): " adding
if [[ ${adding,,} == *"anime"* ]]; then
read -rp "$(echo -e "$(tr "by_which") ${purple}$(tr "keyword")${white} $(tr "should_the") $adding $(tr "entry_matched")") " key1
read -rp "$(echo -e "${yellow}""$(tr "if_you_want")""${white}", "$(tr "second_keyword")") " key2
dbid=$(get_DB "Anime")
get_db_id
read -rp "$(echo -e "$(tr "enter_now")" "${purple}""$dbid""${white}" "$(tr "number")") " dbentry
showname=$(curl_name)
if [[ -z "$showname" ]]; then
read -rp "$(echo -e "$(tr "name_fetch_failed") $(tr "enter_manually")") " showname
fi
echo "$(tr "this_is_anime") $showname"
read -rp "$(tr "is_correct")" wrongformat
if [ "${wrongformat,,}" == "n" ]; then
tr "manual_add"
exit
else
{
echo "$showname"
echo "$key1"
echo "$key2"
echo "Anime"
echo "$dbentry"
# Per-entry provider (IDs are provider-specific! Old entries omit this line.)
echo "$dbid"
echo ""
} >>"$renamelist"
fi
elif [[ ${adding,,} == *"serie"* ]]; then
read -rp "$(echo -e "$(tr "by_which") ${purple}$(tr "keyword")${white} $(tr "should_the") $adding $(tr "entry_matched")") " key1
read -rp "$(echo -e "${yellow}""$(tr "if_you_want")""${white}", "$(tr "second_keyword")") " key2
dbid=$(get_DB "Series")
get_db_id
read -rp "$(echo -e "$(tr "enter_now")" "${purple}""$dbid""${white}" "$(tr "number")") " dbentry
showname=$(curl_name)
if [[ -z "$showname" ]]; then
read -rp "$(echo -e "$(tr "name_fetch_failed") $(tr "enter_manually")") " showname
fi
echo "$(tr "this_is_series") $showname"
read -rp "$(tr "is_correct")" wrongformat
if [ "${wrongformat,,}" == "n" ]; then
tr "manual_add"
exit
else
{
echo "$showname"
echo "$key1"
echo "$key2"
echo "Series"
echo "$dbentry"
# Per-entry provider (IDs are provider-specific! Old entries omit this line.)
echo "$dbid"
echo ""
} >>"$renamelist"
fi
elif [[ ${adding,,} == *"film"* ]]; then
read -rp "$(echo -e "$(tr "by_which") ${purple}$(tr "keyword")${white} $(tr "should_the") $adding $(tr "entry_matched")") " key1
read -rp "$(echo -e "${yellow}""$(tr "if_you_want")""${white}", "$(tr "second_keyword")") " key2
dbid=$(get_DB "Movie")
get_db_id
read -rp "$(echo -e "$(tr "enter_now")" ${purple}TheMovieDB ID${white} "$(tr "number")""\n($(tr "url_number"))") " dbentry
showname=$(curl_movie_name)
if [[ -z "$showname" ]]; then
read -rp "$(echo -e "$(tr "name_fetch_failed") $(tr "enter_manually")") " showname
fi
echo "$(tr "this_is_movie") $showname"
read -rp "$(tr "is_correct")" wrongformat
if [ "${wrongformat,,}" == "n" ]; then
tr "manual_add"
exit
else
{
echo "$showname"
echo "$key1"
echo "$key2"
echo "Movie"
echo "$dbentry"
# Per-entry provider (IDs are provider-specific! Old entries omit this line.)
echo "$dbid"
echo ""
} >>"$renamelist"
fi
elif [[ ${adding,,} == *"beenden"* ]] || [[ ${adding,,} == *"exit"* ]]; then
break
fi
done