From f2fc3f9344193155c8324a33a8c48f1b9c0d6475 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 26 Feb 2024 23:08:38 +0100 Subject: [PATCH 01/86] limit API call for airing info --- functions.sh | 46 +++++----------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/functions.sh b/functions.sh index c7853c6..51a420e 100644 --- a/functions.sh +++ b/functions.sh @@ -76,7 +76,7 @@ function get-anilist-infos () { curl -s 'https://graphql.anilist.co/' \ -X POST \ -H 'content-type: application/json' \ - --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { title { romaji(stylised:false), english(stylised:false), native(stylised:false) }, averageScore, genres, tags { name, rank },studios { edges { node { name, isAnimationStudio } } },startDate {year, month} season, seasonYear, coverImage { extraLarge }, status, idMal} }" }' > "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" + --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { relations { edges { relationType node { id type format title { romaji } status } } } title { romaji(stylised: false) english(stylised: false) native(stylised: false) } averageScore genres tags { name rank } studios { edges { node { name isAnimationStudio } } } startDate { year month } season seasonYear coverImage { extraLarge } status idMal} }" }' > "anilist-$anilist_id.json" -D "anilist-limit-rate.txt" rate_limit=0 rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") ((wait_time++)) @@ -275,42 +275,6 @@ function get-animes-season-year () { anime_season=$(printf "%s %s" "$name_season" "$year_season") fi } -function download-airing-info () { - if [ ! -f "$SCRIPT_FOLDER/config/data/relations-$anilist_id.json" ] - then - wait_time=0 - while [ $wait_time -lt 5 ]; - do - printf "%s\t\t\t - Downloading airing info for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" - curl -s 'https://graphql.anilist.co/' \ - -X POST \ - -H 'content-type: application/json' \ - --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { relations { edges { relationType node { id type format title { romaji } status } } } } }" }' > "$SCRIPT_FOLDER/config/data/relations-$anilist_id.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" - rate_limit=0 - rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") - ((wait_time++)) - if [[ -z $rate_limit ]] - then - printf "%s\t\t\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - sleep 61 - elif [[ $rate_limit -ge 3 ]] - then - sleep 0.8 - printf "%s\t\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - break - elif [[ $rate_limit -lt 3 ]] - then - printf "%s\t\t\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" - sleep 30 - break - elif [[ $wait_time == 4 ]] - then - printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - exit 1 - fi - done - fi -} function get-airing-status () { if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" then @@ -328,8 +292,8 @@ function get-airing-status () { :> "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.json" while IFS=$'\n' read -r anilist_id do - download-airing-info - cat "$SCRIPT_FOLDER/config/data/relations-$anilist_id.json" >> "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.json" + get-anilist-infos + cat "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" >> "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.json" done < "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.txt" anilist_id=$anilist_multi_id_backup sequel_data=$(jq '.data.Media.relations.edges[] | select ( .relationType == "SEQUEL" ) | .node | select ( .format == "TV" or .format == "ONA" or .format == "MOVIE" or .format == "OVA" )' -r "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.json") @@ -359,8 +323,8 @@ function get-airing-status () { fi fi else - download-airing-info - sequel_data=$(jq '.data.Media.relations.edges[] | select ( .relationType == "SEQUEL" ) | .node | select ( .format == "TV" or .format == "ONA" or .format == "MOVIE" or .format == "OVA" )' -r "$SCRIPT_FOLDER/config/data/relations-$anilist_id.json") + get-anilist-infos + sequel_data=$(jq '.data.Media.relations.edges[] | select ( .relationType == "SEQUEL" ) | .node | select ( .format == "TV" or .format == "ONA" or .format == "MOVIE" or .format == "OVA" )' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json") if [ -z "$sequel_data" ] then airing_status="Ended" From 2abe0c7019044bb9e2c5c3365c23be3e5946aa28 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 26 Feb 2024 23:14:57 +0100 Subject: [PATCH 02/86] Fix json download folder --- functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 51a420e..e74dce3 100644 --- a/functions.sh +++ b/functions.sh @@ -76,7 +76,7 @@ function get-anilist-infos () { curl -s 'https://graphql.anilist.co/' \ -X POST \ -H 'content-type: application/json' \ - --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { relations { edges { relationType node { id type format title { romaji } status } } } title { romaji(stylised: false) english(stylised: false) native(stylised: false) } averageScore genres tags { name rank } studios { edges { node { name isAnimationStudio } } } startDate { year month } season seasonYear coverImage { extraLarge } status idMal} }" }' > "anilist-$anilist_id.json" -D "anilist-limit-rate.txt" + --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { relations { edges { relationType node { id type format title { romaji } status } } } title { romaji(stylised: false) english(stylised: false) native(stylised: false) } averageScore genres tags { name rank } studios { edges { node { name isAnimationStudio } } } startDate { year month } season seasonYear coverImage { extraLarge } status idMal} }" }' > "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" rate_limit=0 rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") ((wait_time++)) From 207808699d860ca86cb5063135e83035bdf03ae7 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 26 Feb 2024 23:19:12 +0100 Subject: [PATCH 03/86] Re add log for airing info --- functions.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions.sh b/functions.sh index e74dce3..cce516a 100644 --- a/functions.sh +++ b/functions.sh @@ -292,6 +292,7 @@ function get-airing-status () { :> "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.json" while IFS=$'\n' read -r anilist_id do + printf "%s\t\t\t - Downloading airing info for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" get-anilist-infos cat "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" >> "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.json" done < "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.txt" @@ -323,6 +324,7 @@ function get-airing-status () { fi fi else + printf "%s\t\t\t - Downloading airing info for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" get-anilist-infos sequel_data=$(jq '.data.Media.relations.edges[] | select ( .relationType == "SEQUEL" ) | .node | select ( .format == "TV" or .format == "ONA" or .format == "MOVIE" or .format == "OVA" )' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json") if [ -z "$sequel_data" ] From 68e6dc0b360d201b6f2857205b6b655810246430 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 26 Feb 2024 23:24:46 +0100 Subject: [PATCH 04/86] Fix log --- functions.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index cce516a..e74d1f1 100644 --- a/functions.sh +++ b/functions.sh @@ -70,6 +70,9 @@ function get-anilist-infos () { if [[ "$season_loop" == 1 ]] then printf "%s\t\t - Downloading data for S%s anilist : %s\n" "$(date +%H:%M:%S)" "$season_number" "$anilist_id" | tee -a "$LOG" + elif [[ "$airing_loop" == 1 ]] + then + printf "%s\t\t\t - Downloading airing info for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" else printf "%s\t\t - Downloading data for anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" fi @@ -280,19 +283,20 @@ function get-airing-status () { then airing_status="Planned" else + airing_loop=0 anilist_backup_id=$anilist_id airing_status="Ended" last_sequel_found=0 sequel_multi_check=0 while [ $last_sequel_found -lt 50 ]; do + airing_loop=1 if [[ $sequel_multi_check -gt 0 ]] then anilist_multi_id_backup=$anilist_id :> "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.json" while IFS=$'\n' read -r anilist_id do - printf "%s\t\t\t - Downloading airing info for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" get-anilist-infos cat "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" >> "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.json" done < "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.txt" @@ -324,7 +328,6 @@ function get-airing-status () { fi fi else - printf "%s\t\t\t - Downloading airing info for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" get-anilist-infos sequel_data=$(jq '.data.Media.relations.edges[] | select ( .relationType == "SEQUEL" ) | .node | select ( .format == "TV" or .format == "ONA" or .format == "MOVIE" or .format == "OVA" )' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json") if [ -z "$sequel_data" ] @@ -354,6 +357,7 @@ function get-airing-status () { fi fi done + airing_loop=0 anilist_id=$anilist_backup_id if [[ $last_sequel_found -ge 50 ]] then From 6cc8ee58bf0088e640372c7e2def8d9b624075d6 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 26 Feb 2024 23:39:01 +0100 Subject: [PATCH 05/86] Fix airing loop wrong log indent --- functions.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index e74d1f1..d974075 100644 --- a/functions.sh +++ b/functions.sh @@ -90,7 +90,12 @@ function get-anilist-infos () { elif [[ $rate_limit -ge 3 ]] then sleep 0.8 - printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + if [[ "$airing_loop" == 1 ]] + then + printf "%s\t\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + else + printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + fi break elif [[ $rate_limit -lt 3 ]] then From 4982e7e699c1795eb20de375ad17465b5fca0a24 Mon Sep 17 00:00:00 2001 From: Arial-Z <100593180+Arial-Z@users.noreply.github.com> Date: Tue, 27 Feb 2024 07:21:05 +0100 Subject: [PATCH 06/86] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 9cf2240..26bceff 100644 --- a/VERSION +++ b/VERSION @@ -1,3 +1,3 @@ #!/bin/bash -version=1.24 +version=1.24+ From 14dd13914c8f542789040fdc3c83f0bf28eeb86a Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 6 Mar 2024 19:10:42 +0100 Subject: [PATCH 07/86] Fix ignore seasons in override --- animes-renamer.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/animes-renamer.sh b/animes-renamer.sh index 68d27ab..b2a2691 100755 --- a/animes-renamer.sh +++ b/animes-renamer.sh @@ -42,8 +42,13 @@ printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" # create ID/animes.tsv create-override printf "%s\t - Sorting Plex animes library\n" "$(date +%H:%M:%S)" | tee -a "$LOG" -while IFS=$'\t' read -r tvdb_id anilist_id title_override studio override_seasons_ignore notes +while IFS= read -r line do + tvdb_id=$(printf "%s" "$line" | awk -F"\t" '{print $1}') + anilist_id=$(printf "%s" "$line" | awk -F"\t" '{print $2}') + title_override=$(printf "%s" "$line" | awk -F"\t" '{print $3}') + studio=$(printf "%s" "$line" | awk -F"\t" '{print $4}') + override_seasons_ignore=$(printf "%s" "$line" | awk -F"\t" '{print $5}') if ! awk -F"\t" '{print $1}' "$SCRIPT_FOLDER/config/ID/animes.tsv" | grep -q -w "$tvdb_id" then if awk -F"\t" '{print $1}' "$SCRIPT_FOLDER/config/tmp/plex_animes_export.tsv" | grep -q -w "$tvdb_id" From b2f99a972494cdd231ebea1ba9809970bc295249 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 6 Mar 2024 19:54:18 +0100 Subject: [PATCH 08/86] Fix ignore seasons override --- functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index d974075..04f6a60 100644 --- a/functions.sh +++ b/functions.sh @@ -854,7 +854,7 @@ function write-metadata () { get-poster if [[ $media_type == "animes" ]] then - if [[ $IGNORE_SEASONS == "Yes" ]] || [[ $override_seasons_ignore == "Yes" ]] + if [[ $IGNORE_SEASONS == "Yes" ]] || [[ $override_seasons_ignore == "yes" ]] || [[ $override_seasons_ignore == "Yes" ]] then get-rating-1 get-rating-2 From daee82550e67372f07a78429cc9f00008cc2f97b Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 6 Mar 2024 20:11:54 +0100 Subject: [PATCH 09/86] Add version check and clean data folder if new --- plex-romaji-renamer.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plex-romaji-renamer.sh b/plex-romaji-renamer.sh index 6290b59..9bd36a1 100755 --- a/plex-romaji-renamer.sh +++ b/plex-romaji-renamer.sh @@ -7,6 +7,11 @@ SCRIPT_FOLDER=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "$SCRIPT_FOLDER/config/.env" source "$SCRIPT_FOLDER/VERSION" source "$SCRIPT_FOLDER/functions.sh" +if ! grep -q -w "$version" "$SCRIPT_FOLDER/config/version_last_run.txt" +then + rm $SCRIPT_FOLDER/config/data/*.json +fi +printf "%s" "$version" > "$SCRIPT_FOLDER/config/version_last_run.txt" printf "%s - Plex-Romaji-Renamer v%s\n" "$(date +%H:%M:%S)" "$version" | tee -a "$LOG" locale=$(locale -a | grep -i "utf" | head -n 1) if [ -z "$locale" ] From 70f00a970fdbb6a1af7ee659c8012b5c9adeedee Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 18 Mar 2024 18:04:35 +0100 Subject: [PATCH 10/86] invert season and year --- functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index 04f6a60..2c61435 100644 --- a/functions.sh +++ b/functions.sh @@ -280,7 +280,7 @@ function get-animes-season-year () { then name_season=Fall fi - anime_season=$(printf "%s %s" "$name_season" "$year_season") + anime_season=$(printf "%s %s" "$year_season" "$name_season") fi } function get-airing-status () { @@ -872,4 +872,4 @@ function write-metadata () { anilist_id="" mal_id="" override_seasons_ignore="" -} \ No newline at end of file +} From abfd0b4236c3d128620411f5bd93d34886d84057 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 20 Mar 2024 21:35:58 +0100 Subject: [PATCH 11/86] Add seasons part and userlists --- animes-renamer.sh | 3 +- config/default.env | 6 + functions.sh | 289 +++++++++++++++++++++++++++++++++++++---- movies-renamer.sh | 4 +- plex-romaji-renamer.sh | 2 +- 5 files changed, 275 insertions(+), 29 deletions(-) diff --git a/animes-renamer.sh b/animes-renamer.sh index b2a2691..e3f45d9 100755 --- a/animes-renamer.sh +++ b/animes-renamer.sh @@ -30,8 +30,9 @@ fi :> "$MATCH_LOG" printf "%s - Starting animes script\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" -# Download animes mapping json data +# Download animes mapping json data & anilist userlist download-anime-id-mapping +get-anilist-userlist # export animes list from plex printf "%s - Creating animes list\n" "$(date +%H:%M:%S)" | tee -a "$LOG" diff --git a/config/default.env b/config/default.env index 7e5dca7..36ea670 100644 --- a/config/default.env +++ b/config/default.env @@ -75,5 +75,11 @@ REDUCE_TITLE_CAPS=Yes SEASON_YEAR=No # Disable anilist tags DISABLE_TAGS=No +# Add tags based on userlists from anilist (Completed, wathcing) +ANILIST_LISTS=Yes +# Anilist username +ANILIST_USERNAME=Arialz +# For Shows the level tags should be added ("show", "season" or "both") +ANILIST_LISTS_LEVEL=show # Mal Data cache time (in days min : 1) DATA_CACHE_TIME=5 diff --git a/functions.sh b/functions.sh index 2c61435..ae8d154 100644 --- a/functions.sh +++ b/functions.sh @@ -67,12 +67,15 @@ function get-anilist-infos () { wait_time=0 while [ $wait_time -lt 5 ]; do - if [[ "$season_loop" == 1 ]] - then - printf "%s\t\t - Downloading data for S%s anilist : %s\n" "$(date +%H:%M:%S)" "$season_number" "$anilist_id" | tee -a "$LOG" - elif [[ "$airing_loop" == 1 ]] + if [[ "$airing_loop" == 1 ]] then printf "%s\t\t\t - Downloading airing info for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" + elif [[ $cours_count_total -gt 1 ]] + then + printf "%s\t\t - Downloading data for S%s part%s Anilist : %s\n" "$(date +%H:%M:%S)" "$season_number" "$cours_count" "$anilist_id" | tee -a "$LOG" + elif [[ "$season_loop" == 1 ]] + then + printf "%s\t\t - Downloading data for S%s anilist : %s\n" "$(date +%H:%M:%S)" "$season_number" "$anilist_id" | tee -a "$LOG" else printf "%s\t\t - Downloading data for anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" fi @@ -89,7 +92,7 @@ function get-anilist-infos () { sleep 61 elif [[ $rate_limit -ge 3 ]] then - sleep 0.8 + sleep 0.6 if [[ "$airing_loop" == 1 ]] then printf "%s\t\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" @@ -120,7 +123,10 @@ function get-mal-infos () { else if [ ! -f "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json" ] then - if [[ "$season_loop" == 1 ]] + if [[ $cours_count_total -gt 1 ]] + then + printf "%s\t\t - Downloading data for S%s part%s MAL : %s\n" "$(date +%H:%M:%S)" "$season_number" "$cours_count" "$mal_id" | tee -a "$LOG" + elif [[ "$season_loop" == 1 ]] then printf "%s\t\t - Downloading data for S%s MAL : %s\n" "$(date +%H:%M:%S)" "$season_number" "$mal_id" | tee -a "$LOG" else @@ -138,6 +144,50 @@ function get-mal-infos () { fi fi } +function get-anilist-userlist { + if [[ $ANILIST_LISTS == "Yes" ]] + then + printf "%s\t - Creating Anilist userlist for : %s\n" "$(date +%H:%M:%S)" "$ANILIST_USERNAME" | tee -a "$LOG" + wait_time=0 + while [ $wait_time -lt 5 ]; + do + printf "%s\t\t - Downloading Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + curl -s 'https://graphql.anilist.co/' \ + -X POST \ + -H 'content-type: application/json' \ + --data '{ "query": "{ MediaListCollection(userName: \"'"$ANILIST_USERNAME"'\" type:ANIME) { lists { name entries { mediaId } }}}" }' > "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" + rate_limit=0 + rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") + ((wait_time++)) + if [[ -z $rate_limit ]] + then + printf "%s\t\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + sleep 61 + elif [[ $rate_limit -ge 3 ]] + then + sleep 0.6 + printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + break + elif [[ $rate_limit -lt 3 ]] + then + printf "%s\t\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" + sleep 30 + break + elif [[ $wait_time == 4 ]] + then + printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + fi + done + printf "%s\t\t - Sorting Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Completed" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-completed.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Watching" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-watching.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-dropped.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-paused.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-planning.tsv" + printf "%s\t - done\n" "$(date +%H:%M:%S)" "$ANILIST_USERNAME" | tee -a "$LOG" + fi +} function get-romaji-title () { title="null" title_tmp="null" @@ -523,6 +573,30 @@ function get-season-rating-1 () { fi fi } +function get-cour-rating-1 () { + if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] + then + if [[ $RATING_1_SOURCE == "ANILIST" ]] + then + get-score + score_1_cour=$anime_score + else + get-mal-score + score_1_cour=$anime_score + fi + score_1_cour=$(printf '%.*f\n' 1 "$score_1_cour") + if [[ "$score_1_cour" == 0.0 ]] + then + ((score_1_no_rating_cours++)) + fi + fi +} +function total-cour-rating-1 () { + if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] + then + total_1_cours_score=$(echo | awk -v v1="$score_1_cour" -v v2="$total_1_cours_score" '{print v1 + v2}') + fi +} function total-rating-1 () { if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] then @@ -595,6 +669,30 @@ function get-season-rating-2 () { fi fi } +function get-cour-rating-2 () { + if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] + then + if [[ $RATING_2_SOURCE == "ANILIST" ]] + then + get-score + score_2_cour=$anime_score + else + get-mal-score + score_2_cour=$anime_score + fi + score_2_cour=$(printf '%.*f\n' 1 "$score_2_cour") + if [[ "$score_2_cour" == 0.0 ]] + then + ((score_2_no_rating_cours++)) + fi + fi +} +function total-cour-rating-2 () { + if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] + then + total_2_cours_score=$(echo | awk -v v1="$score_2_cour" -v v2="$total_2_cours_score" '{print v1 + v2}') + fi +} function total-rating-2 () { if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] then @@ -668,21 +766,88 @@ function get-season-infos () { get-season-poster else season_loop=1 - anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) + anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | sort -n | paste -s -d, -) if [[ -n "$anilist_id" ]] then - get-anilist-infos - romaji_title=$(get-romaji-title) - english_title=$(get-english-title) - if [[ $MAIN_TITLE_ENG == "Yes" ]] + anilist_backup_id_season=$(printf "%s" "$anilist_ids" | head -n 1 ) + cours_count_total=$(echo "anilist_ids" | awk -F "," '{print NF}') + total_1_cours_score=0 + total_2_cours_score=0 + score_1_no_rating_cours=0 + score_2_no_rating_cours=0 + cours_count=0 + all_cours_anime_season="" + IFS=',' + for anilist_id in $anilist_ids + do + ((cours_count++)) + if [[ -n "$anilist_id" ]] + then + get-anilist-infos + get-cour-rating-1 + get-cour-rating-2 + if [[ $SEASON_YEAR == "Yes" ]] + then + get-animes-season-year + if [[ $cours_count -gt 1 ]] + then + all_cours_anime_season=$(printf "%s,%s" "$anime_season" "$all_cours_anime_season") + else + all_cours_anime_season=$anime_season + fi + fi + else + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cour_loop" "$plex_title" | tee -a "$LOG" + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cour_loop" "$plex_title" >> "$MATCH_LOG" + ((score_1_no_rating_cours++)) + ((score_2_no_rating_cours++)) + fi + total-cour-rating-1 + total-cour-rating-2 + done + anime_season=$all_cours_anime_season + if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] + then + if [[ "$total_1_cours_score" != 0 ]] + then + total_1_cours=$((cours_count - score_1_no_rating_cours)) + if [[ "$total_1_cours" != 0 ]] + then + score_1_season=$(echo | awk -v v1="$total_1_cours_score" -v v2="$total_1_cours" '{print v1 / v2}') + score_1_season=$(printf '%.*f\n' 1 "$score_1_season") + else + score_1_season=0 + ((score_1_no_rating_seasons++)) + fi + else + score_1_season=0 + ((score_1_no_rating_seasons++)) + fi + fi + if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] then - english_title=$romaji_title + if [[ "$total_2_cours_score" != 0 ]] + then + total_2_cours=$((cours_count - score_2_no_rating_cours)) + if [[ "$total_2_cours" != 0 ]] + then + score_2_season=$(echo | awk -v v1="$total_2_cours_score" -v v2="$total_2_cours" '{print v1 / v2}') + score_2_season=$(printf '%.*f\n' 1 "$score_2_season") + else + score_2_season=0 + ((score_2_no_rating_seasons++)) + fi + else + score_1_season=0 + ((score_1_no_rating_seasons++)) + fi fi - get-season-rating-1 - get-season-rating-2 + cours_count_total=0 + anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) + romaji_title=$(get-romaji-title) + english_title=$(get-english-title) if [[ $SEASON_YEAR == "Yes" ]] then - get-animes-season-year if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] then printf " %s:\n title: |-\n %s\n user_rating: %s\n label: %s,score\n" "$season_number" "$romaji_title" "$score_1_season" "$anime_season" >> "$METADATA" @@ -774,6 +939,24 @@ function get-season-infos () { fi anilist_id=$anilist_backup_id } +function other-lists-tags { + other_lists_tags="" + if [[ "$userlist_type" == "completed" ]] + then + other_lists_tags="watching,dropped,paused,planning" + elif [[ "$userlist_type" == "watching" ]] + then + other_lists_tags="completed,dropped,paused,planning" + elif [[ "$userlist_type" == "dropped" ]] + then + other_lists_tags="completed,watching,paused,planning" + elif [[ "$userlist_type" == "paused" ]] + then + other_lists_tags="completed,watching,dropped,planning" + else + other_lists_tags="completed,watching,dropped,paused" + fi +} function write-metadata () { get-anilist-infos if [[ $media_type == "animes" ]] @@ -829,20 +1012,76 @@ function write-metadata () { printf "%s\t\t - Writing airing status\n" "$(date +%H:%M:%S)" | tee -a "$LOG" if awk -F"\t" '{print "\""$1"\":"}' "$SCRIPT_FOLDER/config/data/ongoing.tsv" | grep -q -w "$tvdb_id" then - printf " label: Airing\n" >> "$METADATA" - printf " label.remove: Planned,Ended\n" >> "$METADATA" - printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + if [[ $ANILIST_LISTS == "Yes" ]] + then + if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] + then + for userlist_type in completed watching dropped paused planning + do + other-lists-tags + all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') + if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + then + printf " label: Airing,%s\n" >> "$METADATA" "$userlist_type" + printf " label.remove: Planned,Ended,%s\n" >> "$METADATA" "$other_lists_tags" + fi + done + fi + fi else get-airing-status if [[ $airing_status == Planned ]] then - printf " label: Planned\n" >> "$METADATA" - printf " label.remove: Airing,Ended\n" >> "$METADATA" - printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + if [[ $ANILIST_LISTS == "Yes" ]] + then + if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] + then + for userlist_type in completed watching dropped paused planning + do + other-lists-tags + all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') + if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + then + printf " label: Planned,%s\n" >> "$METADATA" "$userlist_type" + printf " label.remove: Airing,Ended,%s\n" >> "$METADATA" "$other_lists_tags" + fi + done + fi + fi else - printf " label: Ended\n" >> "$METADATA" - printf " label.remove: Planned,Airing\n" >> "$METADATA" - printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + if [[ $ANILIST_LISTS == "Yes" ]] + then + if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] + then + for userlist_type in completed watching dropped paused planning + do + other-lists-tags + all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') + if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + then + printf " label: Ended,%s\n" >> "$METADATA" "$userlist_type" + printf " label.remove: Planned,Airing,%s\n" >> "$METADATA" "$other_lists_tags" + fi + done + fi + fi + fi + fi + else + if [[ $ANILIST_LISTS == "Yes" ]] + then + if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] + then + for userlist_type in completed watching dropped paused planning + do + other-lists-tags + all_anilist_ids=$(jq --arg imdb_id "$imdb_id" '.[] | select( .imdb_id == $imdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') + if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + then + printf " label: %s\n" >> "$METADATA" "$userlist_type" + printf " label.remove: %s\n" >> "$METADATA" "$other_lists_tags" + fi + done fi fi fi @@ -872,4 +1111,4 @@ function write-metadata () { anilist_id="" mal_id="" override_seasons_ignore="" -} +} \ No newline at end of file diff --git a/movies-renamer.sh b/movies-renamer.sh index 957a33a..2a75e86 100755 --- a/movies-renamer.sh +++ b/movies-renamer.sh @@ -30,9 +30,9 @@ fi :> "$MATCH_LOG" printf "%s - Starting movies script\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" -# Download anime mapping json data +# Download animes mapping json data & anilist userlist download-anime-id-mapping - +get-anilist-userlist # export movies list from plex printf "%s - Creating animes list\n" "$(date +%H:%M:%S)" | tee -a "$LOG" diff --git a/plex-romaji-renamer.sh b/plex-romaji-renamer.sh index 9bd36a1..6333e0d 100755 --- a/plex-romaji-renamer.sh +++ b/plex-romaji-renamer.sh @@ -9,7 +9,7 @@ source "$SCRIPT_FOLDER/VERSION" source "$SCRIPT_FOLDER/functions.sh" if ! grep -q -w "$version" "$SCRIPT_FOLDER/config/version_last_run.txt" then - rm $SCRIPT_FOLDER/config/data/*.json + rm "$SCRIPT_FOLDER/config/data/*.json" fi printf "%s" "$version" > "$SCRIPT_FOLDER/config/version_last_run.txt" printf "%s - Plex-Romaji-Renamer v%s\n" "$(date +%H:%M:%S)" "$version" | tee -a "$LOG" From 7b30912a8e6419395e6bee200ae0c5d50f1a202b Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 20 Mar 2024 21:52:47 +0100 Subject: [PATCH 12/86] fix part detect --- functions.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index ae8d154..cb661e6 100644 --- a/functions.sh +++ b/functions.sh @@ -769,8 +769,7 @@ function get-season-infos () { anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | sort -n | paste -s -d, -) if [[ -n "$anilist_id" ]] then - anilist_backup_id_season=$(printf "%s" "$anilist_ids" | head -n 1 ) - cours_count_total=$(echo "anilist_ids" | awk -F "," '{print NF}') + cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') total_1_cours_score=0 total_2_cours_score=0 score_1_no_rating_cours=0 From 76d9b59fb9582a05131df8b8c6b25d19bc3dca8f Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 20 Mar 2024 22:13:44 +0100 Subject: [PATCH 13/86] fix season part log --- functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index cb661e6..7655a70 100644 --- a/functions.sh +++ b/functions.sh @@ -72,7 +72,7 @@ function get-anilist-infos () { printf "%s\t\t\t - Downloading airing info for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" elif [[ $cours_count_total -gt 1 ]] then - printf "%s\t\t - Downloading data for S%s part%s Anilist : %s\n" "$(date +%H:%M:%S)" "$season_number" "$cours_count" "$anilist_id" | tee -a "$LOG" + printf "%s\t\t - Downloading data for S%s part-%s Anilist : %s\n" "$(date +%H:%M:%S)" "$season_number" "$cours_count" "$anilist_id" | tee -a "$LOG" elif [[ "$season_loop" == 1 ]] then printf "%s\t\t - Downloading data for S%s anilist : %s\n" "$(date +%H:%M:%S)" "$season_number" "$anilist_id" | tee -a "$LOG" @@ -125,7 +125,7 @@ function get-mal-infos () { then if [[ $cours_count_total -gt 1 ]] then - printf "%s\t\t - Downloading data for S%s part%s MAL : %s\n" "$(date +%H:%M:%S)" "$season_number" "$cours_count" "$mal_id" | tee -a "$LOG" + printf "%s\t\t - Downloading data for S%s part-%s MAL : %s\n" "$(date +%H:%M:%S)" "$season_number" "$cours_count" "$mal_id" | tee -a "$LOG" elif [[ "$season_loop" == 1 ]] then printf "%s\t\t - Downloading data for S%s MAL : %s\n" "$(date +%H:%M:%S)" "$season_number" "$mal_id" | tee -a "$LOG" From 1386d457d1cd199c91332a6c5798a1f530ac8281 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 18:59:44 +0100 Subject: [PATCH 14/86] Add seasons userlists --- functions.sh | 75 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/functions.sh b/functions.sh index 7655a70..70cff6b 100644 --- a/functions.sh +++ b/functions.sh @@ -312,7 +312,7 @@ function get-studios() { fi } function get-animes-season-year () { - anime_season=$( (jq '.data.Media.season' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" && jq '.data.Media.seasonYear' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json") | paste -sd ' ' | tr '[:upper:]' '[:lower:]' | sed "s/\( \|^\)\(.\)/\1\u\2/g") + anime_season=$( (jq '.data.Media.seasonYear' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" && jq '.data.Media.season' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json") | paste -sd ' ' | tr '[:upper:]' '[:lower:]' | sed "s/\( \|^\)\(.\)/\1\u\2/g") if [ "$anime_season" == "Null Null" ] then year_season=$(jq '.data.Media.startDate.year' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json") @@ -741,6 +741,7 @@ function get-season-infos () { score_1_no_rating_seasons=0 score_2_no_rating_seasons=0 season_loop=0 + anime_season="" printf " seasons:\n" >> "$METADATA" IFS="," for season_number in $seasons_list @@ -765,16 +766,19 @@ function get-season-infos () { total-rating-2 get-season-poster else - season_loop=1 - anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | sort -n | paste -s -d, -) if [[ -n "$anilist_id" ]] then + season_loop=1 + anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | sort -n | paste -s -d, -) cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') total_1_cours_score=0 total_2_cours_score=0 score_1_no_rating_cours=0 score_2_no_rating_cours=0 cours_count=0 + cour_status="" + season_userlist_type="" + season_userlist_type_count="" all_cours_anime_season="" IFS=',' for anilist_id in $anilist_ids @@ -783,6 +787,12 @@ function get-season-infos () { if [[ -n "$anilist_id" ]] then get-anilist-infos + if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" + then + ((score_1_no_rating_cours++)) + ((score_2_no_rating_cours++)) + continue + fi get-cour-rating-1 get-cour-rating-2 if [[ $SEASON_YEAR == "Yes" ]] @@ -803,6 +813,19 @@ function get-season-infos () { fi total-cour-rating-1 total-cour-rating-2 + for userlist_type in completed watching dropped paused planning + do + if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + then + userlist_type_count=$(printf %s "$season_userlist_type" | awk -F "," '{print NF}') + if [[ $userlist_type_count -gt 1 ]] + then + season_userlist_type=$(printf "%s,%s" "$season_userlist_type" "$userlist_type") + else + season_userlist_type="$userlist_type" + fi + fi + done done anime_season=$all_cours_anime_season if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] @@ -845,22 +868,46 @@ function get-season-infos () { anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) romaji_title=$(get-romaji-title) english_title=$(get-english-title) - if [[ $SEASON_YEAR == "Yes" ]] + if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] then - if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] - then - printf " %s:\n title: |-\n %s\n user_rating: %s\n label: %s,score\n" "$season_number" "$romaji_title" "$score_1_season" "$anime_season" >> "$METADATA" - else - printf " %s:\n user_rating: %s\n label: %s,score\n" "$season_number" "$score_1_season" "$anime_season" >> "$METADATA" - fi + printf " %s:\n title: |-\n %s\n user_rating: %s\n label: score\n" "$season_number" "$romaji_title" "$score_1_season" >> "$METADATA" else - if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] + printf " %s:\n user_rating: %s\n label: score\n" "$season_number" "$score_1_season" >> "$METADATA" + fi + season_label_add="" + season_label_remove="" + if [[ $ANILIST_LISTS == "Yes" ]] + then + if [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] then - printf " %s:\n title: |-\n %s\n user_rating: %s\n label: score\n" "$season_number" "$romaji_title" "$score_1_season" >> "$METADATA" - else - printf " %s:\n user_rating: %s\n label: score\n" "$season_number" "$score_1_season" >> "$METADATA" + season_userlist_type_count=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') + if [[ -n $season_userlist_type_count ]] && [[ $season_userlist_type_count -gt 0 ]] + then + seasons_other_lists_tags="completed,watching,dropped,paused,planning" + IFS="," + for userlist_type in $season_userlist_type + do + seasons_other_lists_tags=$(printf "%s" "$seasons_other_lists_tags" | sed s/"$userlist_type"// | sed 's/^,//' | sed 's/,,/,/g') + done + season_label_add="$season_userlist_type" + season_label_remove="$seasons_other_lists_tags" + fi fi fi + if [[ -n "$anime_season" ]] + then + season_label_add=$(printf "%s,%s" "$season_label_add" "$anime_season") + fi + if [[ -n "$season_label_add" ]] + then + printf " label: score,%s\n" "$season_label_add" >> "$METADATA" + else + printf " label: score\n" >> "$METADATA" + fi + if [[ -n "$season_label_remove" ]] + then + printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" + fi total-rating-1 total-rating-2 get-season-poster From 80a09ea2fbcec783245fa5ad8f75927867000669 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 19:07:18 +0100 Subject: [PATCH 15/86] Fix double label score --- functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index 70cff6b..0a6db91 100644 --- a/functions.sh +++ b/functions.sh @@ -870,9 +870,9 @@ function get-season-infos () { english_title=$(get-english-title) if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] then - printf " %s:\n title: |-\n %s\n user_rating: %s\n label: score\n" "$season_number" "$romaji_title" "$score_1_season" >> "$METADATA" + printf " %s:\n title: |-\n %s\n user_rating: %s\n" "$season_number" "$romaji_title" "$score_1_season" >> "$METADATA" else - printf " %s:\n user_rating: %s\n label: score\n" "$season_number" "$score_1_season" >> "$METADATA" + printf " %s:\n user_rating: %s\n" "$season_number" "$score_1_season" >> "$METADATA" fi season_label_add="" season_label_remove="" From 0783c775d2a6868df84ef8de06770f27ec670361 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 19:40:31 +0100 Subject: [PATCH 16/86] Improve label --- config/default.env | 2 - functions.sh | 381 ++++++++++++++++++++------------------------- 2 files changed, 169 insertions(+), 214 deletions(-) diff --git a/config/default.env b/config/default.env index 36ea670..f4c9d30 100644 --- a/config/default.env +++ b/config/default.env @@ -67,8 +67,6 @@ POSTER_SEASON_DOWNLOAD=Yes POSTER_SOURCE=ANILIST # Ignore seasons title, rating and poster (Yes/No) IGNORE_SEASONS=No -# Ignore season 1 if it's the only season (Yes/No) -IGNORE_S1=Yes # Anilist have some full uppercase title, this settings will remove them "86 EIGHTY-SIX" > "86 Eighty-Six" (Yes/No) REDUCE_TITLE_CAPS=Yes #Add the anime season to the season label in plex (Fall 2022, Spring 2021, ...) diff --git a/functions.sh b/functions.sh index 0a6db91..7897563 100644 --- a/functions.sh +++ b/functions.sh @@ -750,171 +750,154 @@ function get-season-infos () { then printf " 0:\n label.remove: score\n" >> "$METADATA" else - if [[ $last_season -eq 1 && $IGNORE_S1 == "Yes" ]] + if [[ -n "$anilist_id" ]] then - anilist_id=$anilist_backup_id - get-season-rating-1 - get-season-rating-2 - if [[ $SEASON_YEAR == "Yes" ]] - then - get-animes-season-year - printf " 1:\n label: %s\n" "$anime_season" >> "$METADATA" - else - printf " 1:\n label.remove: score\n" >> "$METADATA" - fi - total-rating-1 - total-rating-2 - get-season-poster - else - if [[ -n "$anilist_id" ]] - then - season_loop=1 - anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | sort -n | paste -s -d, -) - cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') - total_1_cours_score=0 - total_2_cours_score=0 - score_1_no_rating_cours=0 - score_2_no_rating_cours=0 - cours_count=0 - cour_status="" - season_userlist_type="" - season_userlist_type_count="" - all_cours_anime_season="" - IFS=',' - for anilist_id in $anilist_ids - do - ((cours_count++)) - if [[ -n "$anilist_id" ]] + season_loop=1 + anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | sort -n | paste -s -d, -) + cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') + total_1_cours_score=0 + total_2_cours_score=0 + score_1_no_rating_cours=0 + score_2_no_rating_cours=0 + cours_count=0 + cour_status="" + season_userlist_type="" + season_userlist_type_count="" + all_cours_anime_season="" + IFS=',' + for anilist_id in $anilist_ids + do + ((cours_count++)) + if [[ -n "$anilist_id" ]] + then + get-anilist-infos + if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" then - get-anilist-infos - if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" - then - ((score_1_no_rating_cours++)) - ((score_2_no_rating_cours++)) - continue - fi - get-cour-rating-1 - get-cour-rating-2 - if [[ $SEASON_YEAR == "Yes" ]] - then - get-animes-season-year - if [[ $cours_count -gt 1 ]] - then - all_cours_anime_season=$(printf "%s,%s" "$anime_season" "$all_cours_anime_season") - else - all_cours_anime_season=$anime_season - fi - fi - else - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cour_loop" "$plex_title" | tee -a "$LOG" - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cour_loop" "$plex_title" >> "$MATCH_LOG" ((score_1_no_rating_cours++)) ((score_2_no_rating_cours++)) + continue fi - total-cour-rating-1 - total-cour-rating-2 - for userlist_type in completed watching dropped paused planning - do - if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" - then - userlist_type_count=$(printf %s "$season_userlist_type" | awk -F "," '{print NF}') - if [[ $userlist_type_count -gt 1 ]] - then - season_userlist_type=$(printf "%s,%s" "$season_userlist_type" "$userlist_type") - else - season_userlist_type="$userlist_type" - fi - fi - done - done - anime_season=$all_cours_anime_season - if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] - then - if [[ "$total_1_cours_score" != 0 ]] + get-cour-rating-1 + get-cour-rating-2 + if [[ $SEASON_YEAR == "Yes" ]] then - total_1_cours=$((cours_count - score_1_no_rating_cours)) - if [[ "$total_1_cours" != 0 ]] + get-animes-season-year + if [[ $cours_count -gt 1 ]] then - score_1_season=$(echo | awk -v v1="$total_1_cours_score" -v v2="$total_1_cours" '{print v1 / v2}') - score_1_season=$(printf '%.*f\n' 1 "$score_1_season") + all_cours_anime_season=$(printf "%s,%s" "$anime_season" "$all_cours_anime_season") else - score_1_season=0 - ((score_1_no_rating_seasons++)) + all_cours_anime_season=$anime_season fi - else - score_1_season=0 - ((score_1_no_rating_seasons++)) fi + else + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cour_loop" "$plex_title" | tee -a "$LOG" + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cour_loop" "$plex_title" >> "$MATCH_LOG" + ((score_1_no_rating_cours++)) + ((score_2_no_rating_cours++)) fi - if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] - then - if [[ "$total_2_cours_score" != 0 ]] + total-cour-rating-1 + total-cour-rating-2 + for userlist_type in completed watching dropped paused planning + do + if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then - total_2_cours=$((cours_count - score_2_no_rating_cours)) - if [[ "$total_2_cours" != 0 ]] + userlist_type_count=$(printf %s "$season_userlist_type" | awk -F "," '{print NF}') + if [[ $userlist_type_count -gt 1 ]] then - score_2_season=$(echo | awk -v v1="$total_2_cours_score" -v v2="$total_2_cours" '{print v1 / v2}') - score_2_season=$(printf '%.*f\n' 1 "$score_2_season") + season_userlist_type=$(printf "%s,%s" "$season_userlist_type" "$userlist_type") else - score_2_season=0 - ((score_2_no_rating_seasons++)) + season_userlist_type="$userlist_type" fi + fi + done + done + anime_season=$all_cours_anime_season + if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] + then + if [[ "$total_1_cours_score" != 0 ]] + then + total_1_cours=$((cours_count - score_1_no_rating_cours)) + if [[ "$total_1_cours" != 0 ]] + then + score_1_season=$(echo | awk -v v1="$total_1_cours_score" -v v2="$total_1_cours" '{print v1 / v2}') + score_1_season=$(printf '%.*f\n' 1 "$score_1_season") else score_1_season=0 ((score_1_no_rating_seasons++)) fi - fi - cours_count_total=0 - anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) - romaji_title=$(get-romaji-title) - english_title=$(get-english-title) - if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] - then - printf " %s:\n title: |-\n %s\n user_rating: %s\n" "$season_number" "$romaji_title" "$score_1_season" >> "$METADATA" else - printf " %s:\n user_rating: %s\n" "$season_number" "$score_1_season" >> "$METADATA" + score_1_season=0 + ((score_1_no_rating_seasons++)) fi - season_label_add="" - season_label_remove="" - if [[ $ANILIST_LISTS == "Yes" ]] + fi + if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] + then + if [[ "$total_2_cours_score" != 0 ]] then - if [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] + total_2_cours=$((cours_count - score_2_no_rating_cours)) + if [[ "$total_2_cours" != 0 ]] then - season_userlist_type_count=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') - if [[ -n $season_userlist_type_count ]] && [[ $season_userlist_type_count -gt 0 ]] - then - seasons_other_lists_tags="completed,watching,dropped,paused,planning" - IFS="," - for userlist_type in $season_userlist_type - do - seasons_other_lists_tags=$(printf "%s" "$seasons_other_lists_tags" | sed s/"$userlist_type"// | sed 's/^,//' | sed 's/,,/,/g') - done - season_label_add="$season_userlist_type" - season_label_remove="$seasons_other_lists_tags" - fi + score_2_season=$(echo | awk -v v1="$total_2_cours_score" -v v2="$total_2_cours" '{print v1 / v2}') + score_2_season=$(printf '%.*f\n' 1 "$score_2_season") + else + score_2_season=0 + ((score_2_no_rating_seasons++)) fi - fi - if [[ -n "$anime_season" ]] - then - season_label_add=$(printf "%s,%s" "$season_label_add" "$anime_season") - fi - if [[ -n "$season_label_add" ]] - then - printf " label: score,%s\n" "$season_label_add" >> "$METADATA" else - printf " label: score\n" >> "$METADATA" + score_1_season=0 + ((score_1_no_rating_seasons++)) fi - if [[ -n "$season_label_remove" ]] + fi + cours_count_total=0 + anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) + romaji_title=$(get-romaji-title) + english_title=$(get-english-title) + if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] + then + printf " %s:\n title: |-\n %s\n user_rating: %s\n" "$season_number" "$romaji_title" "$score_1_season" >> "$METADATA" + else + printf " %s:\n user_rating: %s\n" "$season_number" "$score_1_season" >> "$METADATA" + fi + season_label_add="" + season_label_remove="" + if [[ $ANILIST_LISTS == "Yes" ]] + then + if [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] then - printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" + season_userlist_type_count=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') + if [[ -n $season_userlist_type_count ]] && [[ $season_userlist_type_count -gt 0 ]] + then + seasons_userlist_type_remove="completed,watching,dropped,paused,planning" + IFS="," + for userlist_type in $season_userlist_type + do + seasons_userlist_type_remove=$(printf "%s" "$seasons_userlist_type_remove" | sed s/"$userlist_type"// | sed 's/^,//' | sed 's/,,/,/g') + done + season_label_add="$season_userlist_type" + season_label_remove="$seasons_userlist_type_remove" + fi fi - total-rating-1 - total-rating-2 - get-season-poster + fi + if [[ -n "$anime_season" ]] + then + season_label_add=$(printf "%s,%s" "$season_label_add" "$anime_season") + fi + if [[ -n "$season_label_add" ]] + then + printf " label: score,%s\n" "$season_label_add" >> "$METADATA" else - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" | tee -a "$LOG" - printf "%s - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" >> "$MATCH_LOG" + printf " label: score\n" >> "$METADATA" + fi + if [[ -n "$season_label_remove" ]] + then + printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" fi + total-rating-1 + total-rating-2 + get-season-poster + else + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" | tee -a "$LOG" + printf "%s - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" >> "$MATCH_LOG" fi fi done @@ -985,24 +968,6 @@ function get-season-infos () { fi anilist_id=$anilist_backup_id } -function other-lists-tags { - other_lists_tags="" - if [[ "$userlist_type" == "completed" ]] - then - other_lists_tags="watching,dropped,paused,planning" - elif [[ "$userlist_type" == "watching" ]] - then - other_lists_tags="completed,dropped,paused,planning" - elif [[ "$userlist_type" == "dropped" ]] - then - other_lists_tags="completed,watching,paused,planning" - elif [[ "$userlist_type" == "paused" ]] - then - other_lists_tags="completed,watching,dropped,planning" - else - other_lists_tags="completed,watching,dropped,paused" - fi -} function write-metadata () { get-anilist-infos if [[ $media_type == "animes" ]] @@ -1053,84 +1018,76 @@ function write-metadata () { anime_tags=$(get-tags) printf " genre.sync: Anime,%s\n" "$anime_tags" >> "$METADATA" fi + label_add="" + label_remove="" if [[ $media_type == "animes" ]] then printf "%s\t\t - Writing airing status\n" "$(date +%H:%M:%S)" | tee -a "$LOG" if awk -F"\t" '{print "\""$1"\":"}' "$SCRIPT_FOLDER/config/data/ongoing.tsv" | grep -q -w "$tvdb_id" then - if [[ $ANILIST_LISTS == "Yes" ]] - then - if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] - then - for userlist_type in completed watching dropped paused planning - do - other-lists-tags - all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') - if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" - then - printf " label: Airing,%s\n" >> "$METADATA" "$userlist_type" - printf " label.remove: Planned,Ended,%s\n" >> "$METADATA" "$other_lists_tags" - fi - done - fi - fi + label_add="Airing" + label_remove="Planned,Ended" + printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" else get-airing-status if [[ $airing_status == Planned ]] then - if [[ $ANILIST_LISTS == "Yes" ]] - then - if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] - then - for userlist_type in completed watching dropped paused planning - do - other-lists-tags - all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') - if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" - then - printf " label: Planned,%s\n" >> "$METADATA" "$userlist_type" - printf " label.remove: Airing,Ended,%s\n" >> "$METADATA" "$other_lists_tags" - fi - done - fi - fi + label_add="Planned" + label_remove="Airing,Ended" + printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" else - if [[ $ANILIST_LISTS == "Yes" ]] + label_add="Ended" + label_remove="Planned,Airing" + printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + fi + fi + fi + if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] + then + all_anilist_ids="" + userlist_type_remove="completed,watching,dropped,paused,planning" + for userlist_type in completed watching dropped paused planning + do + all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') + if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + then + userlist_type_count=$(printf %s "$season_userlist_type" | awk -F "," '{print NF}') + if [[ $userlist_type_count -gt 1 ]] then - if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] - then - for userlist_type in completed watching dropped paused planning - do - other-lists-tags - all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') - if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" - then - printf " label: Ended,%s\n" >> "$METADATA" "$userlist_type" - printf " label.remove: Planned,Airing,%s\n" >> "$METADATA" "$other_lists_tags" - fi - done - fi + userlist_type_add=$(printf "%s,%s" "$userlist_type_add" "$userlist_type") + else + userlist_type_add="$userlist_type" fi + userlist_type_remove=$(printf "%s" "$userlist_type_remove" | sed s/"$userlist_type"// | sed 's/^,//' | sed 's/,,/,/g') + fi + done + if [[ -n "$userlist_type_add" ]] + then + if [[ -n "$label_add" ]] + then + label_add=$(printf "%s,%s" "$label_add" "$userlist_type_add") + else + label_add="$userlist_type_add" fi fi - else - if [[ $ANILIST_LISTS == "Yes" ]] + if [[ -n "$userlist_type_remove" ]] then - if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] + if [[ -n "$label_remove" ]] then - for userlist_type in completed watching dropped paused planning - do - other-lists-tags - all_anilist_ids=$(jq --arg imdb_id "$imdb_id" '.[] | select( .imdb_id == $imdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') - if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" - then - printf " label: %s\n" >> "$METADATA" "$userlist_type" - printf " label.remove: %s\n" >> "$METADATA" "$other_lists_tags" - fi - done + label_remove=$(printf "%s,%s" "$label_add" "$userlist_type_remove") + else + label_remove="$userlist_type_remove" fi fi fi + if [[ -n "$label_add" ]] + then + printf " label: %s\n" "$label_add" >> "$METADATA" + fi + if [[ -n "$label_remove" ]] + then + printf " label.remove: %s\n" "$label_remove" >> "$METADATA" + fi get-studios if [[ -n "$studio" ]] then From 59bb40781dd395995fe2d58f2600755547627d3d Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 19:46:35 +0100 Subject: [PATCH 17/86] Add option to remove "Anime" tag --- config/default.env | 6 ++++-- functions.sh | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config/default.env b/config/default.env index f4c9d30..4c29eaf 100644 --- a/config/default.env +++ b/config/default.env @@ -57,6 +57,8 @@ SORT_TITLE_ENG=No ORIGINAL_TITLE_NATIVE=Yes # Rename season to the anilist title of that season (Yes/No) RENAME_SEASONS=Yes +# Add a default "Anime" tag to everything (Yes/No) +ADD_ANIME_TAG=Yes #Grab anilist tags higher or equal than percentage (0-100) ANILIST_TAGS_P=70 # Download poster (Yes/No) @@ -71,9 +73,9 @@ IGNORE_SEASONS=No REDUCE_TITLE_CAPS=Yes #Add the anime season to the season label in plex (Fall 2022, Spring 2021, ...) SEASON_YEAR=No -# Disable anilist tags +# Disable anilist tags (Yes/No) DISABLE_TAGS=No -# Add tags based on userlists from anilist (Completed, wathcing) +# Add tags based on userlists from anilist (Completed, wathcing) (Yes/No) ANILIST_LISTS=Yes # Anilist username ANILIST_USERNAME=Arialz diff --git a/functions.sh b/functions.sh index 7897563..05561d0 100644 --- a/functions.sh +++ b/functions.sh @@ -1016,7 +1016,12 @@ function write-metadata () { if [[ $DISABLE_TAGS != "Yes" ]] then anime_tags=$(get-tags) - printf " genre.sync: Anime,%s\n" "$anime_tags" >> "$METADATA" + if [[ "$ADD_ANIME_TAG" == "No" ]] + then + printf " genre.sync: %s\n" "$anime_tags" >> "$METADATA" + else + printf " genre.sync: Anime,%s\n" "$anime_tags" >> "$METADATA" + fi fi label_add="" label_remove="" From 8655d41a699f9626abfede6c0dd002512c67edb9 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 19:51:36 +0100 Subject: [PATCH 18/86] Fix label --- functions.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/functions.sh b/functions.sh index 05561d0..04759ae 100644 --- a/functions.sh +++ b/functions.sh @@ -761,8 +761,6 @@ function get-season-infos () { score_2_no_rating_cours=0 cours_count=0 cour_status="" - season_userlist_type="" - season_userlist_type_count="" all_cours_anime_season="" IFS=',' for anilist_id in $anilist_ids @@ -797,10 +795,12 @@ function get-season-infos () { fi total-cour-rating-1 total-cour-rating-2 + season_userlist_type="" for userlist_type in completed watching dropped paused planning do if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then + userlist_type_count="" userlist_type_count=$(printf %s "$season_userlist_type" | awk -F "," '{print NF}') if [[ $userlist_type_count -gt 1 ]] then @@ -1053,10 +1053,11 @@ function write-metadata () { userlist_type_remove="completed,watching,dropped,paused,planning" for userlist_type in completed watching dropped paused planning do + userlist_type_count="" all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then - userlist_type_count=$(printf %s "$season_userlist_type" | awk -F "," '{print NF}') + userlist_type_count=$(printf %s "$userlist_type_add" | awk -F "," '{print NF}') if [[ $userlist_type_count -gt 1 ]] then userlist_type_add=$(printf "%s,%s" "$userlist_type_add" "$userlist_type") From 2517770a63ce1bfb8e30834d024553fab84c4377 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 19:53:26 +0100 Subject: [PATCH 19/86] update default.env --- config/default.env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/default.env b/config/default.env index 4c29eaf..002a526 100644 --- a/config/default.env +++ b/config/default.env @@ -57,6 +57,8 @@ SORT_TITLE_ENG=No ORIGINAL_TITLE_NATIVE=Yes # Rename season to the anilist title of that season (Yes/No) RENAME_SEASONS=Yes +# Disable anilist tags (Yes/No) +DISABLE_TAGS=No # Add a default "Anime" tag to everything (Yes/No) ADD_ANIME_TAG=Yes #Grab anilist tags higher or equal than percentage (0-100) @@ -73,8 +75,6 @@ IGNORE_SEASONS=No REDUCE_TITLE_CAPS=Yes #Add the anime season to the season label in plex (Fall 2022, Spring 2021, ...) SEASON_YEAR=No -# Disable anilist tags (Yes/No) -DISABLE_TAGS=No # Add tags based on userlists from anilist (Completed, wathcing) (Yes/No) ANILIST_LISTS=Yes # Anilist username From ab8f0864115dd1d88f1eddba87665334b24c3a01 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 20:17:14 +0100 Subject: [PATCH 20/86] Fix label --- functions.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/functions.sh b/functions.sh index 04759ae..9f96eef 100644 --- a/functions.sh +++ b/functions.sh @@ -864,8 +864,8 @@ function get-season-infos () { then if [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] then - season_userlist_type_count=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') - if [[ -n $season_userlist_type_count ]] && [[ $season_userlist_type_count -gt 0 ]] + season_userlist_type_count=$(printf %s "$season_userlist_type" | awk -F "," '{print NF}') + if [[ -n $season_userlist_type ]] && [[ $season_userlist_type_count -gt 0 ]] then seasons_userlist_type_remove="completed,watching,dropped,paused,planning" IFS="," @@ -1050,10 +1050,11 @@ function write-metadata () { if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] then all_anilist_ids="" + userlist_type_add="" + userlist_type_remove="" userlist_type_remove="completed,watching,dropped,paused,planning" for userlist_type in completed watching dropped paused planning do - userlist_type_count="" all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then From 2f2e0a834848d13b2eab1f5a957373d16290fded Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 20:29:39 +0100 Subject: [PATCH 21/86] Fix label --- functions.sh | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/functions.sh b/functions.sh index 9f96eef..351839b 100644 --- a/functions.sh +++ b/functions.sh @@ -801,12 +801,12 @@ function get-season-infos () { if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then userlist_type_count="" - userlist_type_count=$(printf %s "$season_userlist_type" | awk -F "," '{print NF}') + userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') if [[ $userlist_type_count -gt 1 ]] then - season_userlist_type=$(printf "%s,%s" "$season_userlist_type" "$userlist_type") + season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") else - season_userlist_type="$userlist_type" + season_userlist_type_add="$userlist_type" fi fi done @@ -864,20 +864,36 @@ function get-season-infos () { then if [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] then - season_userlist_type_count=$(printf %s "$season_userlist_type" | awk -F "," '{print NF}') - if [[ -n $season_userlist_type ]] && [[ $season_userlist_type_count -gt 0 ]] + season_userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') + if [[ -n $season_userlist_type_add ]] && [[ $season_userlist_type_count -gt 0 ]] then seasons_userlist_type_remove="completed,watching,dropped,paused,planning" IFS="," - for userlist_type in $season_userlist_type + for userlist_type in $season_userlist_type_add do seasons_userlist_type_remove=$(printf "%s" "$seasons_userlist_type_remove" | sed s/"$userlist_type"// | sed 's/^,//' | sed 's/,,/,/g') done - season_label_add="$season_userlist_type" - season_label_remove="$seasons_userlist_type_remove" fi fi fi + if [[ -n "$seasons_userlist_type_remove" ]] + then + if [[ -n "$season_label_add" ]] + then + season_label_add=$(printf "%s,%s" "$eason_label_add" "$userlist_type_add") + else + season_label_add="$userlist_type_add" + fi + fi + if [[ -n "$seasons_userlist_type_remove" ]] + then + if [[ -n "$season_label_remove" ]] + then + season_label_remove=$(printf "%s,%s" "$eason_label_remove" "$seasons_userlist_type_remove") + else + season_label_remove="$seasons_userlist_type_remove" + fi + fi if [[ -n "$anime_season" ]] then season_label_add=$(printf "%s,%s" "$season_label_add" "$anime_season") @@ -1081,7 +1097,7 @@ function write-metadata () { then if [[ -n "$label_remove" ]] then - label_remove=$(printf "%s,%s" "$label_add" "$userlist_type_remove") + label_remove=$(printf "%s,%s" "$label_remove" "$userlist_type_remove") else label_remove="$userlist_type_remove" fi From f5e001d7462b0741eb92f7336c035402d31f577f Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 20:38:12 +0100 Subject: [PATCH 22/86] Fix label --- functions.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions.sh b/functions.sh index 351839b..1a10dc5 100644 --- a/functions.sh +++ b/functions.sh @@ -876,13 +876,13 @@ function get-season-infos () { fi fi fi - if [[ -n "$seasons_userlist_type_remove" ]] + if [[ -n "$season_userlist_type_add" ]] then if [[ -n "$season_label_add" ]] then - season_label_add=$(printf "%s,%s" "$eason_label_add" "$userlist_type_add") + season_label_add=$(printf "%s,%s" "$season_label_add" "$season_userlist_type_add") else - season_label_add="$userlist_type_add" + season_label_add="$season_userlist_type_add" fi fi if [[ -n "$seasons_userlist_type_remove" ]] From 4dc03600cfd211e8d8409923c83e0b11690b22e5 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 20:51:23 +0100 Subject: [PATCH 23/86] Fix label --- functions.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index 1a10dc5..5e6f9ec 100644 --- a/functions.sh +++ b/functions.sh @@ -795,12 +795,11 @@ function get-season-infos () { fi total-cour-rating-1 total-cour-rating-2 - season_userlist_type="" + season_userlist_type_add="" for userlist_type in completed watching dropped paused planning do if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then - userlist_type_count="" userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') if [[ $userlist_type_count -gt 1 ]] then From 94013486cff7173ce2641a58eb31c08ca1273b89 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 20:54:46 +0100 Subject: [PATCH 24/86] Fix userlist season label --- functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 5e6f9ec..d3522ea 100644 --- a/functions.sh +++ b/functions.sh @@ -762,6 +762,7 @@ function get-season-infos () { cours_count=0 cour_status="" all_cours_anime_season="" + season_userlist_type_add="" IFS=',' for anilist_id in $anilist_ids do @@ -795,7 +796,6 @@ function get-season-infos () { fi total-cour-rating-1 total-cour-rating-2 - season_userlist_type_add="" for userlist_type in completed watching dropped paused planning do if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" From cb6f8bfd2bc8f1454338462082d17add8acfbefd Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 21:09:32 +0100 Subject: [PATCH 25/86] Fix season userlist label --- functions.sh | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/functions.sh b/functions.sh index d3522ea..c1fabc2 100644 --- a/functions.sh +++ b/functions.sh @@ -776,6 +776,18 @@ function get-season-infos () { ((score_2_no_rating_cours++)) continue fi + for userlist_type in completed watching dropped paused planning + do + if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + then + if [[ "${#season_userlist_type_add}" -gt 0 ]] + then + season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") + else + season_userlist_type_add="$userlist_type" + fi + fi + done get-cour-rating-1 get-cour-rating-2 if [[ $SEASON_YEAR == "Yes" ]] @@ -796,19 +808,6 @@ function get-season-infos () { fi total-cour-rating-1 total-cour-rating-2 - for userlist_type in completed watching dropped paused planning - do - if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" - then - userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') - if [[ $userlist_type_count -gt 1 ]] - then - season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") - else - season_userlist_type_add="$userlist_type" - fi - fi - done done anime_season=$all_cours_anime_season if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] @@ -875,7 +874,7 @@ function get-season-infos () { fi fi fi - if [[ -n "$season_userlist_type_add" ]] + if [[ -n "$seasons_userlist_type_add" ]] then if [[ -n "$season_label_add" ]] then @@ -1073,8 +1072,7 @@ function write-metadata () { all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then - userlist_type_count=$(printf %s "$userlist_type_add" | awk -F "," '{print NF}') - if [[ $userlist_type_count -gt 1 ]] + if [[ "${#userlist_type_add}" -gt 0 ]] then userlist_type_add=$(printf "%s,%s" "$userlist_type_add" "$userlist_type") else From ff6d56a7cf1964e5fb8049547df94836606b3a0b Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 21:20:13 +0100 Subject: [PATCH 26/86] Fix userlist label --- functions.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/functions.sh b/functions.sh index c1fabc2..b74a655 100644 --- a/functions.sh +++ b/functions.sh @@ -777,17 +777,18 @@ function get-season-infos () { continue fi for userlist_type in completed watching dropped paused planning - do - if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" - then - if [[ "${#season_userlist_type_add}" -gt 0 ]] + do + if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then - season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") - else - season_userlist_type_add="$userlist_type" + userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') + if [[ $userlist_type_count -gt 1 ]] + then + season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") + else + season_userlist_type_add="$userlist_type" + fi fi - fi - done + done get-cour-rating-1 get-cour-rating-2 if [[ $SEASON_YEAR == "Yes" ]] @@ -1065,14 +1066,14 @@ function write-metadata () { then all_anilist_ids="" userlist_type_add="" - userlist_type_remove="" userlist_type_remove="completed,watching,dropped,paused,planning" for userlist_type in completed watching dropped paused planning do all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then - if [[ "${#userlist_type_add}" -gt 0 ]] + userlist_type_count=$(printf %s "$userlist_type_add" | awk -F "," '{print NF}') + if [[ $userlist_type_count -gt 1 ]] then userlist_type_add=$(printf "%s,%s" "$userlist_type_add" "$userlist_type") else From 6ef72aad2a703ee3de2952b047d7d2dddb1f7f33 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 21:48:15 +0100 Subject: [PATCH 27/86] Fix season userlist --- functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index b74a655..6f37101 100644 --- a/functions.sh +++ b/functions.sh @@ -863,8 +863,8 @@ function get-season-infos () { then if [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] then - season_userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') - if [[ -n $season_userlist_type_add ]] && [[ $season_userlist_type_count -gt 0 ]] + userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') + if [[ -n $season_userlist_type_add ]] && [[ $userlist_type_count -gt 0 ]] then seasons_userlist_type_remove="completed,watching,dropped,paused,planning" IFS="," From f01dce68d59a2849a02d0a3491fb9e64aadeb421 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 21 Mar 2024 21:57:54 +0100 Subject: [PATCH 28/86] Fix season userlist label --- functions.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index 6f37101..802e478 100644 --- a/functions.sh +++ b/functions.sh @@ -875,7 +875,7 @@ function get-season-infos () { fi fi fi - if [[ -n "$seasons_userlist_type_add" ]] + if [[ -n "$season_userlist_type_add" ]] then if [[ -n "$season_label_add" ]] then @@ -895,7 +895,12 @@ function get-season-infos () { fi if [[ -n "$anime_season" ]] then - season_label_add=$(printf "%s,%s" "$season_label_add" "$anime_season") + if [[ -n "$season_label_add" ]] + then + season_label_add=$(printf "%s,%s" "$season_label_add" "$anime_season") + else + season_label_add="$anime_season" + fi fi if [[ -n "$season_label_add" ]] then From 8ce6cc7bcf47be4d81ae75e51aefc715ecdf881d Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Fri, 22 Mar 2024 17:58:26 +0100 Subject: [PATCH 29/86] Fix type --- functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 802e478..e82f3e5 100644 --- a/functions.sh +++ b/functions.sh @@ -888,7 +888,7 @@ function get-season-infos () { then if [[ -n "$season_label_remove" ]] then - season_label_remove=$(printf "%s,%s" "$eason_label_remove" "$seasons_userlist_type_remove") + season_label_remove=$(printf "%s,%s" "$season_label_remove" "$seasons_userlist_type_remove") else season_label_remove="$seasons_userlist_type_remove" fi From 9dad320eb8097b902f88dd928f6de44850c4103f Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Fri, 22 Mar 2024 19:12:09 +0100 Subject: [PATCH 30/86] Fix trying to do season logic without anilist id --- functions.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index e82f3e5..96c8304 100644 --- a/functions.sh +++ b/functions.sh @@ -728,11 +728,12 @@ function get-season-infos () { first_season=$(echo "$seasons_list" | awk -F "," '{print $1}') last_season=$(echo "$seasons_list" | awk -F "," '{print $NF}') total_seasons=$(echo "$seasons_list" | awk -F "," '{print NF}') + valid_anilist_id=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json") if [[ "$first_season" -eq 0 ]] then total_seasons=$((total_seasons - 1)) fi - if [[ $season_check != -1 ]] + if [ -n "$valid_anilist_id" ] && [[ $season_check != -1 ]] then total_1_score=0 total_2_score=0 From e1af8365ec4ba3386507b25454d49b793f0164a8 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 10:58:20 +0100 Subject: [PATCH 31/86] Fix cour number in error --- functions.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions.sh b/functions.sh index 96c8304..934aee7 100644 --- a/functions.sh +++ b/functions.sh @@ -754,7 +754,7 @@ function get-season-infos () { if [[ -n "$anilist_id" ]] then season_loop=1 - anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | sort -n | paste -s -d, -) + anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') total_1_cours_score=0 total_2_cours_score=0 @@ -803,8 +803,8 @@ function get-season-infos () { fi fi else - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cour_loop" "$plex_title" | tee -a "$LOG" - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cour_loop" "$plex_title" >> "$MATCH_LOG" + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" | tee -a "$LOG" + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" >> "$MATCH_LOG" ((score_1_no_rating_cours++)) ((score_2_no_rating_cours++)) fi From 1ae4b4dde546e937816df656374d95cf3935bd0c Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 11:39:15 +0100 Subject: [PATCH 32/86] remove useless code --- functions.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index 934aee7..cdad1b0 100644 --- a/functions.sh +++ b/functions.sh @@ -83,9 +83,8 @@ function get-anilist-infos () { -X POST \ -H 'content-type: application/json' \ --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { relations { edges { relationType node { id type format title { romaji } status } } } title { romaji(stylised: false) english(stylised: false) native(stylised: false) } averageScore genres tags { name rank } studios { edges { node { name isAnimationStudio } } } startDate { year month } season seasonYear coverImage { extraLarge } status idMal} }" }' > "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" - rate_limit=0 rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") - ((wait_time++)) + ((wait_time++)) if [[ -z $rate_limit ]] then printf "%s\t\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" From d6c9760eb800b0b27223413d09c2cc5311a13c22 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 13:27:24 +0100 Subject: [PATCH 33/86] Fix userlist settings not working --- functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index cdad1b0..ea95608 100644 --- a/functions.sh +++ b/functions.sh @@ -861,7 +861,7 @@ function get-season-infos () { season_label_remove="" if [[ $ANILIST_LISTS == "Yes" ]] then - if [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] + if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') if [[ -n $season_userlist_type_add ]] && [[ $userlist_type_count -gt 0 ]] @@ -1067,7 +1067,7 @@ function write-metadata () { fi fi fi - if [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]] + if { [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then all_anilist_ids="" userlist_type_add="" From 77872782d694fd9402af9778091781c2feb5452e Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 13:31:35 +0100 Subject: [PATCH 34/86] Fix userlist for movies --- functions.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index ea95608..7ac84c2 100644 --- a/functions.sh +++ b/functions.sh @@ -1074,7 +1074,12 @@ function write-metadata () { userlist_type_remove="completed,watching,dropped,paused,planning" for userlist_type in completed watching dropped paused planning do - all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') + if [[ $media_type == "animes" ]] + then + all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') + else + all_anilist_ids=$(jq --arg imdb_id "$imdb_id" '.[] | select( .imdb_id == $imdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') + fi if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then userlist_type_count=$(printf %s "$userlist_type_add" | awk -F "," '{print NF}') From cf5f5c3703f1d57278b59139e102726024198a0c Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 13:35:45 +0100 Subject: [PATCH 35/86] Fix Anilist userlist --- functions.sh | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/functions.sh b/functions.sh index 7ac84c2..b67af51 100644 --- a/functions.sh +++ b/functions.sh @@ -859,38 +859,35 @@ function get-season-infos () { fi season_label_add="" season_label_remove="" - if [[ $ANILIST_LISTS == "Yes" ]] + if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then - if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] + userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') + if [[ -n $season_userlist_type_add ]] && [[ $userlist_type_count -gt 0 ]] then - userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') - if [[ -n $season_userlist_type_add ]] && [[ $userlist_type_count -gt 0 ]] - then - seasons_userlist_type_remove="completed,watching,dropped,paused,planning" - IFS="," - for userlist_type in $season_userlist_type_add - do - seasons_userlist_type_remove=$(printf "%s" "$seasons_userlist_type_remove" | sed s/"$userlist_type"// | sed 's/^,//' | sed 's/,,/,/g') - done - fi + seasons_userlist_type_remove="completed,watching,dropped,paused,planning" + IFS="," + for userlist_type in $season_userlist_type_add + do + seasons_userlist_type_remove=$(printf "%s" "$seasons_userlist_type_remove" | sed s/"$userlist_type"// | sed 's/^,//' | sed 's/,,/,/g') + done fi - fi - if [[ -n "$season_userlist_type_add" ]] - then - if [[ -n "$season_label_add" ]] + if [[ -n "$season_userlist_type_add" ]] then - season_label_add=$(printf "%s,%s" "$season_label_add" "$season_userlist_type_add") - else - season_label_add="$season_userlist_type_add" + if [[ -n "$season_label_add" ]] + then + season_label_add=$(printf "%s,%s" "$season_label_add" "$season_userlist_type_add") + else + season_label_add="$season_userlist_type_add" + fi fi - fi - if [[ -n "$seasons_userlist_type_remove" ]] - then - if [[ -n "$season_label_remove" ]] + if [[ -n "$seasons_userlist_type_remove" ]] then - season_label_remove=$(printf "%s,%s" "$season_label_remove" "$seasons_userlist_type_remove") - else - season_label_remove="$seasons_userlist_type_remove" + if [[ -n "$season_label_remove" ]] + then + season_label_remove=$(printf "%s,%s" "$season_label_remove" "$seasons_userlist_type_remove") + else + season_label_remove="$seasons_userlist_type_remove" + fi fi fi if [[ -n "$anime_season" ]] From 76d41e3c8d5678f88295e5835358506db3355a25 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 13:41:57 +0100 Subject: [PATCH 36/86] Fix movies userlists --- functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index b67af51..034b6cb 100644 --- a/functions.sh +++ b/functions.sh @@ -1075,7 +1075,7 @@ function write-metadata () { then all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') else - all_anilist_ids=$(jq --arg imdb_id "$imdb_id" '.[] | select( .imdb_id == $imdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') + all_anilist_ids="$anilist_id" fi if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then From 5d0818693924dd0e1c7abd7a3237d1cfdab47973 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 13:46:43 +0100 Subject: [PATCH 37/86] Fix download userlists --- functions.sh | 88 ++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/functions.sh b/functions.sh index 034b6cb..0a89bed 100644 --- a/functions.sh +++ b/functions.sh @@ -38,6 +38,50 @@ function download-anime-id-mapping () { sleep 30 done } +function get-anilist-userlist { + if [[ $ANILIST_LISTS == "Yes" ]] + then + printf "%s - Creating Anilist userlist for : %s\n" "$(date +%H:%M:%S)" "$ANILIST_USERNAME" | tee -a "$LOG" + wait_time=0 + while [ $wait_time -lt 5 ]; + do + printf "%s\t - Downloading Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + curl -s 'https://graphql.anilist.co/' \ + -X POST \ + -H 'content-type: application/json' \ + --data '{ "query": "{ MediaListCollection(userName: \"'"$ANILIST_USERNAME"'\" type:ANIME) { lists { name entries { mediaId } }}}" }' > "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" + rate_limit=0 + rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") + ((wait_time++)) + if [[ -z $rate_limit ]] + then + printf "%s\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + sleep 61 + elif [[ $rate_limit -ge 3 ]] + then + sleep 0.6 + printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + break + elif [[ $rate_limit -lt 3 ]] + then + printf "%s\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" + sleep 30 + break + elif [[ $wait_time == 4 ]] + then + printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + fi + done + printf "%s\t - Sorting Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Completed" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-completed.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Watching" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-watching.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-dropped.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-paused.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-planning.tsv" + printf "%s - done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + fi +} function get-anilist-id () { if [[ $media_type == "animes" ]] then @@ -143,50 +187,6 @@ function get-mal-infos () { fi fi } -function get-anilist-userlist { - if [[ $ANILIST_LISTS == "Yes" ]] - then - printf "%s\t - Creating Anilist userlist for : %s\n" "$(date +%H:%M:%S)" "$ANILIST_USERNAME" | tee -a "$LOG" - wait_time=0 - while [ $wait_time -lt 5 ]; - do - printf "%s\t\t - Downloading Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - curl -s 'https://graphql.anilist.co/' \ - -X POST \ - -H 'content-type: application/json' \ - --data '{ "query": "{ MediaListCollection(userName: \"'"$ANILIST_USERNAME"'\" type:ANIME) { lists { name entries { mediaId } }}}" }' > "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" - rate_limit=0 - rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") - ((wait_time++)) - if [[ -z $rate_limit ]] - then - printf "%s\t\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - sleep 61 - elif [[ $rate_limit -ge 3 ]] - then - sleep 0.6 - printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - break - elif [[ $rate_limit -lt 3 ]] - then - printf "%s\t\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" - sleep 30 - break - elif [[ $wait_time == 4 ]] - then - printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - exit 1 - fi - done - printf "%s\t\t - Sorting Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Completed" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-completed.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Watching" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-watching.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-dropped.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-paused.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-planning.tsv" - printf "%s\t - done\n" "$(date +%H:%M:%S)" "$ANILIST_USERNAME" | tee -a "$LOG" - fi -} function get-romaji-title () { title="null" title_tmp="null" From dd73e6174d1ffe8542c05e2a3d1d7a5d23600454 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 13:52:47 +0100 Subject: [PATCH 38/86] Fix script log --- animes-renamer.sh | 2 +- functions.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/animes-renamer.sh b/animes-renamer.sh index e3f45d9..92e5431 100755 --- a/animes-renamer.sh +++ b/animes-renamer.sh @@ -145,7 +145,7 @@ do fi fi done < "$SCRIPT_FOLDER/config/tmp/ongoing.tsv" -printf "%s\t - Done\n\n" "$(date +%H:%M:%S)" +printf "%s\t - Done\n" "$(date +%H:%M:%S)" printf "%s - Done\n\n" "$(date +%H:%M:%S)" # write PMM metadata file from ID/animes.tsv and jikan API diff --git a/functions.sh b/functions.sh index 0a89bed..031940a 100644 --- a/functions.sh +++ b/functions.sh @@ -79,7 +79,8 @@ function get-anilist-userlist { jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-dropped.tsv" jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-paused.tsv" jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-planning.tsv" - printf "%s - done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + printf "%s - done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" fi } function get-anilist-id () { From 27b6f1f2594f73ea676c348a7442a1716cae0007 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 14:55:14 +0100 Subject: [PATCH 39/86] Fix userlist --- functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 031940a..f81f907 100644 --- a/functions.sh +++ b/functions.sh @@ -862,10 +862,10 @@ function get-season-infos () { season_label_remove="" if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then + seasons_userlist_type_remove="completed,watching,dropped,paused,planning" userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') if [[ -n $season_userlist_type_add ]] && [[ $userlist_type_count -gt 0 ]] then - seasons_userlist_type_remove="completed,watching,dropped,paused,planning" IFS="," for userlist_type in $season_userlist_type_add do From 9c017f3523eb7208e7693a46197cf142c82c4c77 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 23 Mar 2024 14:56:36 +0100 Subject: [PATCH 40/86] Fix userlists --- functions.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/functions.sh b/functions.sh index f81f907..47c4d05 100644 --- a/functions.sh +++ b/functions.sh @@ -764,6 +764,7 @@ function get-season-infos () { cour_status="" all_cours_anime_season="" season_userlist_type_add="" + seasons_userlist_type_remove="" IFS=',' for anilist_id in $anilist_ids do From 8da3398a7d0ccf1dfcfc2a07457b359bb2548682 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Tue, 26 Mar 2024 18:07:48 +0100 Subject: [PATCH 41/86] Allow override with only 1 season in season loop --- functions.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 47c4d05..df13ef8 100644 --- a/functions.sh +++ b/functions.sh @@ -723,12 +723,18 @@ function check-rating-2-valid () { fi } function get-season-infos () { + override_id="" anilist_backup_id=$anilist_id season_check=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | .tvdb_season' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json") first_season=$(echo "$seasons_list" | awk -F "," '{print $1}') last_season=$(echo "$seasons_list" | awk -F "," '{print $NF}') total_seasons=$(echo "$seasons_list" | awk -F "," '{print NF}') valid_anilist_id=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json") + if awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/$OVERRIDE" | grep -q -w "$anilist_backup_id" && [[ $last_season -eq 1 ]] + then + valid_anilist_id=1 + override_id=$anilist_backup_id + fi if [[ "$first_season" -eq 0 ]] then total_seasons=$((total_seasons - 1)) @@ -755,6 +761,10 @@ function get-season-infos () { then season_loop=1 anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) + if [ -n "$override_id" ] + then + anilist_ids=$override_id + fi cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') total_1_cours_score=0 total_2_cours_score=0 @@ -1126,7 +1136,7 @@ function write-metadata () { get-poster if [[ $media_type == "animes" ]] then - if [[ $IGNORE_SEASONS == "Yes" ]] || [[ $override_seasons_ignore == "yes" ]] || [[ $override_seasons_ignore == "Yes" ]] + if [[ $IGNORE_SEASONS == "Yes" ]] || [[ $override_seasons_ignore == "yes" ]] then get-rating-1 get-rating-2 From c64a15085f655e60f8de9fecf9d12c46ff30a20c Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 27 Mar 2024 19:17:27 +0100 Subject: [PATCH 42/86] Add settings IGNORE_S1_ONLY_RATING --- config/default.env | 2 ++ functions.sh | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/config/default.env b/config/default.env index 002a526..9473cb9 100644 --- a/config/default.env +++ b/config/default.env @@ -75,6 +75,8 @@ IGNORE_SEASONS=No REDUCE_TITLE_CAPS=Yes #Add the anime season to the season label in plex (Fall 2022, Spring 2021, ...) SEASON_YEAR=No +# Ignore season 1 rating part if it's the only season (Yes/No) +IGNORE_S1_ONLY_RATING=Yes # Add tags based on userlists from anilist (Completed, wathcing) (Yes/No) ANILIST_LISTS=Yes # Anilist username diff --git a/functions.sh b/functions.sh index df13ef8..62659b4 100644 --- a/functions.sh +++ b/functions.sh @@ -865,9 +865,7 @@ function get-season-infos () { english_title=$(get-english-title) if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] then - printf " %s:\n title: |-\n %s\n user_rating: %s\n" "$season_number" "$romaji_title" "$score_1_season" >> "$METADATA" - else - printf " %s:\n user_rating: %s\n" "$season_number" "$score_1_season" >> "$METADATA" + printf " %s:\n title: |-\n %s\n" "$season_number" "$romaji_title" >> "$METADATA" fi season_label_add="" season_label_remove="" @@ -913,7 +911,17 @@ function get-season-infos () { fi if [[ -n "$season_label_add" ]] then - printf " label: score,%s\n" "$season_label_add" >> "$METADATA" + if [[ $last_season -eq 1 ]] + then + if [[ $IGNORE_S1_ONLY_RATING == "No" ]] + then + printf " label: score,%s\n" "$season_label_add" >> "$METADATA" + else + printf " label: %s\n" "$season_label_add" >> "$METADATA" + fi + else + printf " label: score,%s\n" "$season_label_add" >> "$METADATA" + fi else printf " label: score\n" >> "$METADATA" fi @@ -921,6 +929,15 @@ function get-season-infos () { then printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" fi + if [[ $last_season -eq 1 ]] + then + if [[ $IGNORE_S1_ONLY_RATING == "No" ]] + then + printf " %s:\n user_rating: %s\n" "$season_number" "$score_1_season" >> "$METADATA" + fi + else + printf " %s:\n user_rating: %s\n" "$season_number" "$score_1_season" >> "$METADATA" + fi total-rating-1 total-rating-2 get-season-poster From cebf2df43a719df98b9d50bed06ee69791c968f6 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 27 Mar 2024 19:30:08 +0100 Subject: [PATCH 43/86] Fix seasons metadata --- functions.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/functions.sh b/functions.sh index 62659b4..0c5a89e 100644 --- a/functions.sh +++ b/functions.sh @@ -863,9 +863,10 @@ function get-season-infos () { anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) romaji_title=$(get-romaji-title) english_title=$(get-english-title) + printf " %s:\n" "$season_number" >> "$METADATA" if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] then - printf " %s:\n title: |-\n %s\n" "$season_number" "$romaji_title" >> "$METADATA" + printf " title: |-\n %s\n" "$season_number" "$romaji_title" >> "$METADATA" fi season_label_add="" season_label_remove="" @@ -933,10 +934,10 @@ function get-season-infos () { then if [[ $IGNORE_S1_ONLY_RATING == "No" ]] then - printf " %s:\n user_rating: %s\n" "$season_number" "$score_1_season" >> "$METADATA" + printf "\n user_rating: %s\n" "$score_1_season" >> "$METADATA" fi else - printf " %s:\n user_rating: %s\n" "$season_number" "$score_1_season" >> "$METADATA" + printf "\n user_rating: %s\n" "$score_1_season" >> "$METADATA" fi total-rating-1 total-rating-2 From 252f5658c7c92cd4f042bd157e52019f8479bfd0 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 27 Mar 2024 19:40:59 +0100 Subject: [PATCH 44/86] Fix seasons metadata --- functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 0c5a89e..4e4d6ec 100644 --- a/functions.sh +++ b/functions.sh @@ -866,7 +866,7 @@ function get-season-infos () { printf " %s:\n" "$season_number" >> "$METADATA" if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]] then - printf " title: |-\n %s\n" "$season_number" "$romaji_title" >> "$METADATA" + printf " title: |-\n %s\n" "$romaji_title" >> "$METADATA" fi season_label_add="" season_label_remove="" From d5f88229a5d77fa2a2ec559c60e65b73e3ea94d4 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 27 Mar 2024 19:52:05 +0100 Subject: [PATCH 45/86] Fix seasons metadata --- functions.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/functions.sh b/functions.sh index 4e4d6ec..1bccfb1 100644 --- a/functions.sh +++ b/functions.sh @@ -924,20 +924,41 @@ function get-season-infos () { printf " label: score,%s\n" "$season_label_add" >> "$METADATA" fi else - printf " label: score\n" >> "$METADATA" + if [[ $last_season -eq 1 ]] + then + if [[ $IGNORE_S1_ONLY_RATING == "No" ]] + then + printf " label: score\n" >> "$METADATA" + fi + fi fi if [[ -n "$season_label_remove" ]] then + if [[ $last_season -eq 1 ]] + then + if [[ $IGNORE_S1_ONLY_RATING != "No" ]] + then + printf " label.remove: score,%s\n" "$season_label_remove" >> "$METADATA" + fi + fi printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" + else + if [[ $last_season -eq 1 ]] + then + if [[ $IGNORE_S1_ONLY_RATING != "No" ]] + then + printf " label.remove: score\n" >> "$METADATA" + fi + fi fi if [[ $last_season -eq 1 ]] then if [[ $IGNORE_S1_ONLY_RATING == "No" ]] then - printf "\n user_rating: %s\n" "$score_1_season" >> "$METADATA" + printf " user_rating: %s\n" "$score_1_season" >> "$METADATA" fi else - printf "\n user_rating: %s\n" "$score_1_season" >> "$METADATA" + printf " user_rating: %s\n" "$score_1_season" >> "$METADATA" fi total-rating-1 total-rating-2 From bd8d0d29a3c0e2540565d36089dbe269afa2a542 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 3 Apr 2024 19:00:58 +0200 Subject: [PATCH 46/86] Update anilist API limitrate --- functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index 1bccfb1..eff5f08 100644 --- a/functions.sh +++ b/functions.sh @@ -59,7 +59,7 @@ function get-anilist-userlist { sleep 61 elif [[ $rate_limit -ge 3 ]] then - sleep 0.6 + sleep 0.8 printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" break elif [[ $rate_limit -lt 3 ]] @@ -136,7 +136,7 @@ function get-anilist-infos () { sleep 61 elif [[ $rate_limit -ge 3 ]] then - sleep 0.6 + sleep 0.8 if [[ "$airing_loop" == 1 ]] then printf "%s\t\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" From f20b182ef4b56a62ea0d962d4f3cd10b7aa8a388 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 8 Apr 2024 19:03:03 +0200 Subject: [PATCH 47/86] Fix JQ error with override and keep aring list for 12 hours --- animes-renamer.sh | 115 ++++++++++++++++++++++++---------------------- functions.sh | 15 ++++-- 2 files changed, 70 insertions(+), 60 deletions(-) diff --git a/animes-renamer.sh b/animes-renamer.sh index 92e5431..bd649ca 100755 --- a/animes-renamer.sh +++ b/animes-renamer.sh @@ -82,70 +82,73 @@ printf "%s - Done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" # Create an ongoing list at $SCRIPT_FOLDER/config/data/ongoing.csv printf "%s - Creating Anilist airing list\n" "$(date +%H:%M:%S)" -:> "$SCRIPT_FOLDER/config/data/ongoing.tsv" -:> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" -ongoingpage=1 -while [ $ongoingpage -lt 9 ]; # get the airing list from jikan API max 9 pages (225 animes) -do - printf "%s\t - Downloading anilist airing list page : %s\n" "$(date +%H:%M:%S)" "$ongoingpage" | tee -a "$LOG" - wait_time=0 - while [ $wait_time -lt 5 ]; +find "$SCRIPT_FOLDER/config/data/ongoing.tsv" -type f -mmin +720 -exec rm {} \; +if [ ! -f "$SCRIPT_FOLDER/config/data/ongoing.tsv" ] +then + :> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" + ongoingpage=1 + while [ $ongoingpage -lt 9 ]; # get the airing list from jikan API max 9 pages (225 animes) do - curl -s 'https://graphql.anilist.co/' \ - -X POST \ - -H 'content-type: application/json' \ - --data '{ "query": "{ Page(page: '"$ongoingpage"', perPage: 50) { pageInfo { hasNextPage } media(type: ANIME, status_in: RELEASING, sort: POPULARITY_DESC) { id } } }" }' > "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" - rate_limit=0 - rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") - ((wait_time++)) - if [[ -z $rate_limit ]] - then - printf "%s\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - sleep 61 - elif [[ $rate_limit -ge 3 ]] - then - sleep 0.8 - printf "%s\t - done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - break - elif [[ $rate_limit -lt 3 ]] + printf "%s\t - Downloading anilist airing list page : %s\n" "$(date +%H:%M:%S)" "$ongoingpage" | tee -a "$LOG" + wait_time=0 + while [ $wait_time -lt 5 ]; + do + curl -s 'https://graphql.anilist.co/' \ + -X POST \ + -H 'content-type: application/json' \ + --data '{ "query": "{ Page(page: '"$ongoingpage"', perPage: 50) { pageInfo { hasNextPage } media(type: ANIME, status_in: RELEASING, sort: POPULARITY_DESC) { id } } }" }' > "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" + rate_limit=0 + rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") + ((wait_time++)) + if [[ -z $rate_limit ]] + then + printf "%s\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + sleep 61 + elif [[ $rate_limit -ge 3 ]] + then + sleep 1 + printf "%s\t - done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + break + elif [[ $rate_limit -lt 3 ]] + then + printf "%s\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" + sleep 30 + break + elif [[ $wait_time == 4 ]] + then + printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + fi + done + jq '.data.Page.media[].id' -r "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" >> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" # store the mal ID of the ongoing show + if grep -q -w ":false}" "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" # stop if page is empty then - printf "%s\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" - sleep 30 break - elif [[ $wait_time == 4 ]] - then - printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - exit 1 fi + ((ongoingpage++)) done - jq '.data.Page.media[].id' -r "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" >> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" # store the mal ID of the ongoing show - if grep -q -w ":false}" "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" # stop if page is empty - then - break - fi - ((ongoingpage++)) -done - printf "%s\t - Sorting anilist airing list \n" "$(date +%H:%M:%S)" | tee -a "$LOG" -sort -n "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" | uniq > "$SCRIPT_FOLDER/config/tmp/ongoing.tsv" -while read -r anilist_id -do - if awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/ID/animes.tsv" | grep -q -w "$anilist_id" - then - line=$(awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/ID/animes.tsv" | grep -w -n "$anilist_id" | cut -d : -f 1) - tvdb_id=$(sed -n "${line}p" "$SCRIPT_FOLDER/config/ID/animes.tsv" | awk -F"\t" '{print $1}') - printf "%s\n" "$tvdb_id" >> "$SCRIPT_FOLDER/config/data/ongoing.tsv" - else - tvdb_id=$(get-tvdb-id) # convert the mal id to tvdb id (to get the main anime) - if [[ "$tvdb_id" == 'null' ]] || [[ "${#tvdb_id}" == '0' ]] # Ignore anime with no mal to tvdb id conversion + printf "%s\t - Sorting anilist airing list \n" "$(date +%H:%M:%S)" | tee -a "$LOG" + sort -n "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" | uniq > "$SCRIPT_FOLDER/config/tmp/ongoing.tsv" + while read -r anilist_id + do + if awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/ID/animes.tsv" | grep -q -w "$anilist_id" then - printf "%s\t\t - Ongoing list missing TVDB ID for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" - continue - else + line=$(awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/ID/animes.tsv" | grep -w -n "$anilist_id" | cut -d : -f 1) + tvdb_id=$(sed -n "${line}p" "$SCRIPT_FOLDER/config/ID/animes.tsv" | awk -F"\t" '{print $1}') printf "%s\n" "$tvdb_id" >> "$SCRIPT_FOLDER/config/data/ongoing.tsv" + else + tvdb_id=$(get-tvdb-id) # convert the mal id to tvdb id (to get the main anime) + if [[ "$tvdb_id" == 'null' ]] || [[ "${#tvdb_id}" == '0' ]] # Ignore anime with no mal to tvdb id conversion + then + printf "%s\t\t - Ongoing list missing TVDB ID for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" + continue + else + printf "%s\n" "$tvdb_id" >> "$SCRIPT_FOLDER/config/data/ongoing.tsv" + fi fi - fi -done < "$SCRIPT_FOLDER/config/tmp/ongoing.tsv" -printf "%s\t - Done\n" "$(date +%H:%M:%S)" + done < "$SCRIPT_FOLDER/config/tmp/ongoing.tsv" + printf "%s\t - Done\n" "$(date +%H:%M:%S)" +fi printf "%s - Done\n\n" "$(date +%H:%M:%S)" # write PMM metadata file from ID/animes.tsv and jikan API diff --git a/functions.sh b/functions.sh index eff5f08..03bc0fb 100644 --- a/functions.sh +++ b/functions.sh @@ -59,7 +59,7 @@ function get-anilist-userlist { sleep 61 elif [[ $rate_limit -ge 3 ]] then - sleep 0.8 + sleep 1 printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" break elif [[ $rate_limit -lt 3 ]] @@ -136,7 +136,7 @@ function get-anilist-infos () { sleep 61 elif [[ $rate_limit -ge 3 ]] then - sleep 0.8 + sleep 1 if [[ "$airing_loop" == 1 ]] then printf "%s\t\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" @@ -763,7 +763,7 @@ function get-season-infos () { anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) if [ -n "$override_id" ] then - anilist_ids=$override_id + anilist_ids=$anilist_backup_id fi cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') total_1_cours_score=0 @@ -788,7 +788,9 @@ function get-season-infos () { ((score_2_no_rating_cours++)) continue fi - for userlist_type in completed watching dropped paused planning + if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] + then + for userlist_type in completed watching dropped paused planning do if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then @@ -801,6 +803,7 @@ function get-season-infos () { fi fi done + fi get-cour-rating-1 get-cour-rating-2 if [[ $SEASON_YEAR == "Yes" ]] @@ -861,6 +864,10 @@ function get-season-infos () { fi cours_count_total=0 anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) + if [ -n "$override_id" ] + then + anilist_id=$anilist_backup_id + fi romaji_title=$(get-romaji-title) english_title=$(get-english-title) printf " %s:\n" "$season_number" >> "$METADATA" From 8f0281aa6dd06648a0e24ec9592a1724eac2fb95 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 8 Apr 2024 20:01:02 +0200 Subject: [PATCH 48/86] Fix Missing MAL with only S0 --- functions.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/functions.sh b/functions.sh index 03bc0fb..38350de 100644 --- a/functions.sh +++ b/functions.sh @@ -612,11 +612,9 @@ function check-rating-1-valid () { then printf "%s\t\t - invalid rating for Anilist : %s skipping \n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" else - if [[ $mal_id == 'null' ]] || [[ $mal_id == 0 ]] || [[ -z $mal_id ]] + get-mal-id + if [[ $mal_id != 'null' ]] || [[ -n $mal_id ]] then - printf "%s\t\t - Missing MAL ID for Anilist : %s / %s\n" "$(date +%H:%M:%S)" "$anilist_id" "$plex_title" | tee -a "$LOG" - printf "%s - Missing MAL ID for Anilist : %s / %s\n" "$(date +%H:%M:%S)" "$anilist_id" "$plex_title" >> "$MATCH_LOG" - else printf "%s\t\t - invalid rating for MAL : %s skipping \n" "$(date +%H:%M:%S)" "$mal_id" | tee -a "$LOG" fi fi @@ -707,12 +705,10 @@ function check-rating-2-valid () { if [[ $RATING_2_SOURCE == "ANILIST" ]] then printf "%s\t\t - invalid rating for Anilist : %s skipping \n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" - else - if [[ $mal_id == 'null' ]] || [[ $mal_id == 0 ]] || [[ -z $mal_id ]] + else + get-mal-id + if [[ $mal_id == 'null' ]] || [[ -n $mal_id ]] then - printf "%s\t\t - Missing MAL ID for Anilist : %s / %s\n" "$(date +%H:%M:%S)" "$anilist_id" "$plex_title" | tee -a "$LOG" - printf "%s - Missing MAL ID for Anilist : %s / %s\n" "$(date +%H:%M:%S)" "$anilist_id" "$plex_title" >> "$MATCH_LOG" - else printf "%s\t\t - invalid rating for MAL : %s skipping \n" "$(date +%H:%M:%S)" "$mal_id" | tee -a "$LOG" fi fi From 6169783d907a4b4f220c11a68e223d5bb22444e4 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Tue, 9 Apr 2024 19:08:03 +0200 Subject: [PATCH 49/86] Fix mutli label.remove --- functions.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/functions.sh b/functions.sh index 38350de..6cf3bd9 100644 --- a/functions.sh +++ b/functions.sh @@ -917,11 +917,11 @@ function get-season-infos () { then if [[ $last_season -eq 1 ]] then - if [[ $IGNORE_S1_ONLY_RATING == "No" ]] + if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]] then - printf " label: score,%s\n" "$season_label_add" >> "$METADATA" - else printf " label: %s\n" "$season_label_add" >> "$METADATA" + else + printf " label: score,%s\n" "$season_label_add" >> "$METADATA" fi else printf " label: score,%s\n" "$season_label_add" >> "$METADATA" @@ -929,7 +929,7 @@ function get-season-infos () { else if [[ $last_season -eq 1 ]] then - if [[ $IGNORE_S1_ONLY_RATING == "No" ]] + if [[ $IGNORE_S1_ONLY_RATING != "Yes" ]] then printf " label: score\n" >> "$METADATA" fi @@ -939,16 +939,18 @@ function get-season-infos () { then if [[ $last_season -eq 1 ]] then - if [[ $IGNORE_S1_ONLY_RATING != "No" ]] + if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]] then - printf " label.remove: score,%s\n" "$season_label_remove" >> "$METADATA" + printf " label.remove: score,%s\n" "$season_label_remove" >> "$METADATA" + else + printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" fi fi printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" else if [[ $last_season -eq 1 ]] then - if [[ $IGNORE_S1_ONLY_RATING != "No" ]] + if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]] then printf " label.remove: score\n" >> "$METADATA" fi @@ -956,7 +958,7 @@ function get-season-infos () { fi if [[ $last_season -eq 1 ]] then - if [[ $IGNORE_S1_ONLY_RATING == "No" ]] + if [[ $IGNORE_S1_ONLY_RATING != "Yes" ]] then printf " user_rating: %s\n" "$score_1_season" >> "$METADATA" fi From 1f496c1d2bda041c82eb8096300a28ada42589d0 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Tue, 9 Apr 2024 19:08:26 +0200 Subject: [PATCH 50/86] Fix multi label remove --- functions.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 6cf3bd9..8eaf73b 100644 --- a/functions.sh +++ b/functions.sh @@ -945,8 +945,9 @@ function get-season-infos () { else printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" fi + else + printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" fi - printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" else if [[ $last_season -eq 1 ]] then From 5855316ad3cbcb200115e9d90cef9e55cc47d94d Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 10 Apr 2024 18:35:52 +0200 Subject: [PATCH 51/86] Fix JQ error --- functions.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/functions.sh b/functions.sh index 8eaf73b..0c4c064 100644 --- a/functions.sh +++ b/functions.sh @@ -757,9 +757,9 @@ function get-season-infos () { then season_loop=1 anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) - if [ -n "$override_id" ] + if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] then - anilist_ids=$anilist_backup_id + anilist_ids=$anilist_backup_id fi cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') total_1_cours_score=0 @@ -777,6 +777,7 @@ function get-season-infos () { ((cours_count++)) if [[ -n "$anilist_id" ]] then + echo "1" get-anilist-infos if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" then @@ -860,7 +861,7 @@ function get-season-infos () { fi cours_count_total=0 anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) - if [ -n "$override_id" ] + if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] then anilist_id=$anilist_backup_id fi From 48d929ee2616741f657e2e18ba0b2c8aade76285 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 10 Apr 2024 18:55:41 +0200 Subject: [PATCH 52/86] Fix ongoing error --- animes-renamer.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/animes-renamer.sh b/animes-renamer.sh index bd649ca..e919fdd 100755 --- a/animes-renamer.sh +++ b/animes-renamer.sh @@ -82,9 +82,10 @@ printf "%s - Done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" # Create an ongoing list at $SCRIPT_FOLDER/config/data/ongoing.csv printf "%s - Creating Anilist airing list\n" "$(date +%H:%M:%S)" -find "$SCRIPT_FOLDER/config/data/ongoing.tsv" -type f -mmin +720 -exec rm {} \; -if [ ! -f "$SCRIPT_FOLDER/config/data/ongoing.tsv" ] +if [ -f "$SCRIPT_FOLDER/config/data/ongoing.tsv" ] then + find "$SCRIPT_FOLDER/config/data/ongoing.tsv" -type f -mmin +720 -exec rm {} \; +else :> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" ongoingpage=1 while [ $ongoingpage -lt 9 ]; # get the airing list from jikan API max 9 pages (225 animes) From 90915b393fca827cdf9a73a9ab5b80b8038a9461 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sun, 14 Apr 2024 21:57:41 +0200 Subject: [PATCH 53/86] Fix airing status --- animes-renamer.sh | 118 +++++++++++++++++++++++----------------------- functions.sh | 1 - 2 files changed, 58 insertions(+), 61 deletions(-) diff --git a/animes-renamer.sh b/animes-renamer.sh index e919fdd..e09f6ea 100755 --- a/animes-renamer.sh +++ b/animes-renamer.sh @@ -82,74 +82,72 @@ printf "%s - Done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" # Create an ongoing list at $SCRIPT_FOLDER/config/data/ongoing.csv printf "%s - Creating Anilist airing list\n" "$(date +%H:%M:%S)" -if [ -f "$SCRIPT_FOLDER/config/data/ongoing.tsv" ] -then - find "$SCRIPT_FOLDER/config/data/ongoing.tsv" -type f -mmin +720 -exec rm {} \; -else - :> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" - ongoingpage=1 - while [ $ongoingpage -lt 9 ]; # get the airing list from jikan API max 9 pages (225 animes) +:> "$SCRIPT_FOLDER/config/data/ongoing.tsv" +:> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" +ongoingpage=1 +while [ $ongoingpage -lt 9 ]; # get the airing list from jikan API max 9 pages (225 animes) +do + printf "%s\t - Downloading anilist airing list page : %s\n" "$(date +%H:%M:%S)" "$ongoingpage" | tee -a "$LOG" + wait_time=0 + while [ $wait_time -lt 5 ]; do - printf "%s\t - Downloading anilist airing list page : %s\n" "$(date +%H:%M:%S)" "$ongoingpage" | tee -a "$LOG" - wait_time=0 - while [ $wait_time -lt 5 ]; - do - curl -s 'https://graphql.anilist.co/' \ - -X POST \ - -H 'content-type: application/json' \ - --data '{ "query": "{ Page(page: '"$ongoingpage"', perPage: 50) { pageInfo { hasNextPage } media(type: ANIME, status_in: RELEASING, sort: POPULARITY_DESC) { id } } }" }' > "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" - rate_limit=0 - rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") - ((wait_time++)) - if [[ -z $rate_limit ]] - then - printf "%s\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - sleep 61 - elif [[ $rate_limit -ge 3 ]] - then - sleep 1 - printf "%s\t - done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - break - elif [[ $rate_limit -lt 3 ]] - then - printf "%s\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" - sleep 30 - break - elif [[ $wait_time == 4 ]] - then - printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - exit 1 - fi - done - jq '.data.Page.media[].id' -r "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" >> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" # store the mal ID of the ongoing show - if grep -q -w ":false}" "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" # stop if page is empty + if [[ $wait_time == 4 ]] + then + printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + fi + curl -s 'https://graphql.anilist.co/' \ + -X POST \ + -H 'content-type: application/json' \ + --data '{ "query": "{ Page(page: '"$ongoingpage"', perPage: 50) { pageInfo { hasNextPage } media(type: ANIME, status_in: RELEASING, sort: POPULARITY_DESC) { id } } }" }' > "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" + rate_limit=0 + rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") + ((wait_time++)) + if [[ -z $rate_limit ]] then + printf "%s\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + sleep 61 + elif [[ $rate_limit -ge 3 ]] + then + sleep 1 + printf "%s\t - done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + break + elif [[ $rate_limit -lt 3 ]] + then + printf "%s\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" + sleep 30 break fi - ((ongoingpage++)) + ((wait_time++)) done - printf "%s\t - Sorting anilist airing list \n" "$(date +%H:%M:%S)" | tee -a "$LOG" - sort -n "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" | uniq > "$SCRIPT_FOLDER/config/tmp/ongoing.tsv" - while read -r anilist_id - do - if awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/ID/animes.tsv" | grep -q -w "$anilist_id" + jq '.data.Page.media[].id' -r "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" >> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" # store the mal ID of the ongoing show + if grep -q -w ":false}" "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" # stop if page is empty + then + break + fi + ((ongoingpage++)) +done + printf "%s\t - Sorting anilist airing list \n" "$(date +%H:%M:%S)" | tee -a "$LOG" +sort -n "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" | uniq > "$SCRIPT_FOLDER/config/tmp/ongoing.tsv" +while read -r anilist_id +do + if awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/ID/animes.tsv" | grep -q -w "$anilist_id" + then + line=$(awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/ID/animes.tsv" | grep -w -n "$anilist_id" | cut -d : -f 1) + tvdb_id=$(sed -n "${line}p" "$SCRIPT_FOLDER/config/ID/animes.tsv" | awk -F"\t" '{print $1}') + printf "%s\n" "$tvdb_id" >> "$SCRIPT_FOLDER/config/data/ongoing.tsv" + else + tvdb_id=$(get-tvdb-id) # convert the mal id to tvdb id (to get the main anime) + if [[ "$tvdb_id" == 'null' ]] || [[ "${#tvdb_id}" == '0' ]] # Ignore anime with no mal to tvdb id conversion then - line=$(awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/ID/animes.tsv" | grep -w -n "$anilist_id" | cut -d : -f 1) - tvdb_id=$(sed -n "${line}p" "$SCRIPT_FOLDER/config/ID/animes.tsv" | awk -F"\t" '{print $1}') - printf "%s\n" "$tvdb_id" >> "$SCRIPT_FOLDER/config/data/ongoing.tsv" + printf "%s\t\t - Ongoing list missing TVDB ID for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" + continue else - tvdb_id=$(get-tvdb-id) # convert the mal id to tvdb id (to get the main anime) - if [[ "$tvdb_id" == 'null' ]] || [[ "${#tvdb_id}" == '0' ]] # Ignore anime with no mal to tvdb id conversion - then - printf "%s\t\t - Ongoing list missing TVDB ID for Anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG" - continue - else - printf "%s\n" "$tvdb_id" >> "$SCRIPT_FOLDER/config/data/ongoing.tsv" - fi + printf "%s\n" "$tvdb_id" >> "$SCRIPT_FOLDER/config/data/ongoing.tsv" fi - done < "$SCRIPT_FOLDER/config/tmp/ongoing.tsv" - printf "%s\t - Done\n" "$(date +%H:%M:%S)" -fi + fi +done < "$SCRIPT_FOLDER/config/tmp/ongoing.tsv" +printf "%s\t - Done\n" "$(date +%H:%M:%S)" printf "%s - Done\n\n" "$(date +%H:%M:%S)" # write PMM metadata file from ID/animes.tsv and jikan API diff --git a/functions.sh b/functions.sh index 0c4c064..ad7f444 100644 --- a/functions.sh +++ b/functions.sh @@ -777,7 +777,6 @@ function get-season-infos () { ((cours_count++)) if [[ -n "$anilist_id" ]] then - echo "1" get-anilist-infos if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" then From 85f89783a7816d8cfd7327e3845c28504fdddde8 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 15 Apr 2024 18:34:50 +0200 Subject: [PATCH 54/86] Update readme --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 944366e..7269793 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Plex-Romaji-Renamer +# Romaji-Renamer A Bash script to import Anilist and MAL data to your Plex Media Server. This is done with a Plex-Meta-Manager (PMM) metadata file.
@@ -55,13 +55,13 @@ The seasonal-animes-download.sh can create a list of the new seasonal animes (Ne Designed for Plex TV agent / Plex Movie Agent, Hama is unsupported ## How it works: - - Plex-Romaji-Renamer will export your Animes and TVDB/IMDB IDs from Plex with python plexapi + - Romaji-Renamer will export your Animes and TVDB/IMDB IDs from Plex with python plexapi - Then it will then retrieve their MAL/Anilist IDs from my mapping list https://github.com/Arial-Z/Animes-ID - Use the Anilist API and Jikan API to get metadata from Anilist and MAL - Create and update a PMM metadata file to import everything in to your Plex when PMM runs. ### Docker container avalaible here -https://hub.docker.com/r/arialz/plex-romaji-renamer +https://hub.docker.com/r/arialz/romaji-renamer ### Step 1 - Prerequisites First you need a GNU/Linux OS to run bash script
@@ -78,7 +78,7 @@ First you need a GNU/Linux OS to run bash script
``` ### Step 2 - Download and extract the script -Git clone the **main** branch or get lastest release : https://github.com/Arial-Z/Plex-Romaji-Renamer/releases/latest +Git clone the **main** branch or get lastest release : https://github.com/Arial-Z/Romaji-Renamer/releases/latest ### Step 3 - Configure the script - Extract the script on a desired location.
@@ -179,7 +179,7 @@ Configuration finished. Run the script with bash:
``` -bash path/to/plex-romaji-renamer.sh +bash path/to/romaji-renamer.sh ``` You can also add it to CRON and make sure to run it before PMM (be careful it take a little time to run due to API limit rate) From c87d43ce34e551594f0fd2e0630bdbd3d4b53b99 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 15 Apr 2024 18:38:39 +0200 Subject: [PATCH 55/86] update docker compose --- docker-compose.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index de9dad0..a723ed6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,8 @@ --- -version: "2.1" services: - plex-romaji-renamer: - image: arialz/plex-romaji-renamer:dev - container_name: plex-romaji-renamer + romaji-renamer: + image: arialz/romaji-renamer:dev + container_name: romaji-renamer environment: - PUID=1000 - PGID=1000 From 3f24f457673a08505d52bcfc49ea9a3370e1af58 Mon Sep 17 00:00:00 2001 From: Arial-Z <100593180+Arial-Z@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:39:50 +0200 Subject: [PATCH 56/86] Update dev.yml --- .github/workflows/dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index db3abf7..bd9546d 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -42,4 +42,4 @@ jobs: "BRANCH_NAME=dev" platforms: linux/amd64,linux/arm64 push: true - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/plex-romaji-renamer:dev + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/romaji-renamer:dev From 8d0ddf58e0d554ec030e6146c951926010f34b1e Mon Sep 17 00:00:00 2001 From: Arial-Z <100593180+Arial-Z@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:40:01 +0200 Subject: [PATCH 57/86] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7a69ee9..0dfa958 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,4 +42,4 @@ jobs: "BRANCH_NAME=latest" platforms: linux/amd64,linux/arm64 push: true - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/plex-romaji-renamer:latest + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/romaji-renamer:latest From 45d56028ea1f641604b4f082cb59536d2aa54bf9 Mon Sep 17 00:00:00 2001 From: Arial-Z <100593180+Arial-Z@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:40:19 +0200 Subject: [PATCH 58/86] Update release.yml --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 383255c..0dddd80 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,4 +44,4 @@ jobs: file: ./Dockerfile platforms: linux/amd64,linux/arm64 push: true - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/plex-romaji-renamer:${{ steps.get_version.outputs.VERSION }} \ No newline at end of file + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/romaji-renamer:${{ steps.get_version.outputs.VERSION }} From c0e42b99f4019964c2e7c8faa165aec6262d1f23 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 15 Apr 2024 19:02:50 +0200 Subject: [PATCH 59/86] Fix anilist score --- functions.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions.sh b/functions.sh index ad7f444..1dfdf19 100644 --- a/functions.sh +++ b/functions.sh @@ -259,6 +259,8 @@ function get-score () { if [[ "$anime_score" == "null" ]] || [[ "$anime_score" == "" ]] then anime_score=0 + else + anime_score=$(printf %s "$anime_score" | awk '{print $1 / 10}') fi else anime_score=$(printf %s "$anime_score" | awk '{print $1 / 10}') From 136d19cb8cec0fd6d385207d798b470617318529 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 15 Apr 2024 19:14:23 +0200 Subject: [PATCH 60/86] Fix API --- animes-renamer.sh | 13 ++++++------- functions.sh | 41 ++++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/animes-renamer.sh b/animes-renamer.sh index e09f6ea..a5a55f3 100755 --- a/animes-renamer.sh +++ b/animes-renamer.sh @@ -91,11 +91,6 @@ do wait_time=0 while [ $wait_time -lt 5 ]; do - if [[ $wait_time == 4 ]] - then - printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - exit 1 - fi curl -s 'https://graphql.anilist.co/' \ -X POST \ -H 'content-type: application/json' \ @@ -103,7 +98,11 @@ do rate_limit=0 rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") ((wait_time++)) - if [[ -z $rate_limit ]] + if [[ $wait_time == 4 ]] + then + printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + elif [[ -z $rate_limit ]] then printf "%s\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" sleep 61 @@ -116,9 +115,9 @@ do then printf "%s\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" sleep 30 + printf "%s\t - done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" break fi - ((wait_time++)) done jq '.data.Page.media[].id' -r "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" >> "$SCRIPT_FOLDER/config/tmp/ongoing-tmp.tsv" # store the mal ID of the ongoing show if grep -q -w ":false}" "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" # stop if page is empty diff --git a/functions.sh b/functions.sh index 1dfdf19..8d44fc4 100644 --- a/functions.sh +++ b/functions.sh @@ -24,16 +24,15 @@ function download-anime-id-mapping () { curl -s "https://raw.githubusercontent.com/Arial-Z/Animes-ID/main/list-movies-id.json" > "$SCRIPT_FOLDER/config/tmp/list-movies-id.json" size=$(du -b "$SCRIPT_FOLDER/config/tmp/list-movies-id.json" | awk '{ print $1 }') fi - ((wait_time++)) - if [[ $size -gt 1000 ]] - then - printf "%s - Done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - break - fi + ((wait_time++)) if [[ $wait_time == 4 ]] then printf "%s - Error can't download animes mapping file stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" exit 1 + elif [[ $size -gt 1000 ]] + then + printf "%s - Done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + break fi sleep 30 done @@ -52,8 +51,12 @@ function get-anilist-userlist { --data '{ "query": "{ MediaListCollection(userName: \"'"$ANILIST_USERNAME"'\" type:ANIME) { lists { name entries { mediaId } }}}" }' > "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" rate_limit=0 rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") - ((wait_time++)) - if [[ -z $rate_limit ]] + ((wait_time++)) + if [[ $wait_time == 4 ]] + then + printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + elif [[ -z $rate_limit ]] then printf "%s\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" sleep 61 @@ -66,11 +69,8 @@ function get-anilist-userlist { then printf "%s\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" sleep 30 + printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" break - elif [[ $wait_time == 4 ]] - then - printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - exit 1 fi done printf "%s\t - Sorting Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" @@ -130,7 +130,11 @@ function get-anilist-infos () { --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { relations { edges { relationType node { id type format title { romaji } status } } } title { romaji(stylised: false) english(stylised: false) native(stylised: false) } averageScore genres tags { name rank } studios { edges { node { name isAnimationStudio } } } startDate { year month } season seasonYear coverImage { extraLarge } status idMal} }" }' > "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") ((wait_time++)) - if [[ -z $rate_limit ]] + if [[ $wait_time == 4 ]] + then + printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + elif [[ -z $rate_limit ]] then printf "%s\t\t - Cloudflare limit rate reached watiting 60s\n" "$(date +%H:%M:%S)" | tee -a "$LOG" sleep 61 @@ -148,11 +152,13 @@ function get-anilist-infos () { then printf "%s\t\t - Anilist API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" sleep 30 + if [[ "$airing_loop" == 1 ]] + then + printf "%s\t\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + else + printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + fi break - elif [[ $wait_time == 4 ]] - then - printf "%s - Error can't download anilist data stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - exit 1 fi done fi @@ -182,6 +188,7 @@ function get-mal-infos () { printf "%s - Jikan API limit reached watiting 30s" "$(date +%H:%M:%S)" | tee -a "$LOG" sleep 30 curl -s -o "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json" -w "%{http_code}" "https://api.jikan.moe/v4/anime/$mal_id" > "$SCRIPT_FOLDER/config/tmp/jikan-limit-rate.txt" + printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" fi sleep 1.1 printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" From 9776d6f32420687b93483739ec926f581c56685a Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Tue, 16 Apr 2024 18:42:51 +0200 Subject: [PATCH 61/86] Add Anime Awards --- config/default.env | 4 +++- functions.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/config/default.env b/config/default.env index 9473cb9..77f6c82 100644 --- a/config/default.env +++ b/config/default.env @@ -77,8 +77,10 @@ REDUCE_TITLE_CAPS=Yes SEASON_YEAR=No # Ignore season 1 rating part if it's the only season (Yes/No) IGNORE_S1_ONLY_RATING=Yes +# Add Anime Awards winner for seasons and shows +ANIME_AWARDS=Yes # Add tags based on userlists from anilist (Completed, wathcing) (Yes/No) -ANILIST_LISTS=Yes +ANILIST_LISTS=No # Anilist username ANILIST_USERNAME=Arialz # For Shows the level tags should be added ("show", "season" or "both") diff --git a/functions.sh b/functions.sh index 8d44fc4..a281ed6 100644 --- a/functions.sh +++ b/functions.sh @@ -30,6 +30,24 @@ function download-anime-id-mapping () { printf "%s - Error can't download animes mapping file stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" exit 1 elif [[ $size -gt 1000 ]] + then + printf "%s - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + break + fi + sleep 30 + done + wait_time=0 + while [ $wait_time -lt 5 ]; + do + printf "%s - Downloading animes awards data\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + curl -s "https://raw.githubusercontent.com/Arial-Z/Animes-ID/main/cr-award/cr-award.json" > "$SCRIPT_FOLDER/config/tmp/cr-award.json" + size=$(du -b "$SCRIPT_FOLDER/config/tmp/cr-award.json" | awk '{ print $1 }') + ((wait_time++)) + if [[ $wait_time == 4 ]] + then + printf "%s - Error can't download animes awards file stopping script\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + elif [[ $size -gt 1000 ]] then printf "%s - Done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" break @@ -342,6 +360,13 @@ function get-animes-season-year () { anime_season=$(printf "%s %s" "$year_season" "$name_season") fi } +function get-animes-award () { + if jq -e --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id )' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" > /dev/null + then + cr_awards_season=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) + cr_awards_anime=1 + fi +} function get-airing-status () { if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" then @@ -754,6 +779,7 @@ function get-season-infos () { score_2_no_rating_seasons=0 season_loop=0 anime_season="" + cr_awards_anime="" printf " seasons:\n" >> "$METADATA" IFS="," for season_number in $seasons_list @@ -780,6 +806,7 @@ function get-season-infos () { all_cours_anime_season="" season_userlist_type_add="" seasons_userlist_type_remove="" + cr_awards_season="" IFS=',' for anilist_id in $anilist_ids do @@ -811,6 +838,10 @@ function get-season-infos () { fi get-cour-rating-1 get-cour-rating-2 + if [[ $ANIME_AWARDS == "Yes" ]] + then + get-animes-award + fi if [[ $SEASON_YEAR == "Yes" ]] then get-animes-season-year @@ -882,6 +913,15 @@ function get-season-infos () { fi season_label_add="" season_label_remove="" + if [[ -n "$cr_awards_season" ]] + then + if [[ -n "$season_label_add" ]] + then + season_label_add=$(printf "%s,%s" "$season_label_add" "$cr_awards_season") + else + season_label_add="$cr_awards_season" + fi + fi if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then seasons_userlist_type_remove="completed,watching,dropped,paused,planning" @@ -1108,6 +1148,15 @@ function write-metadata () { fi label_add="" label_remove="" + if [[ "$cr_awards_anime" -eq 1 ]] + then + if [[ -n "$label_add" ]] + then + label_add=$(printf "%s,%s" "$label_add" "Anime Awards Winner") + else + label_add="Anime Awards Winner" + fi + fi if [[ $media_type == "animes" ]] then printf "%s\t\t - Writing airing status\n" "$(date +%H:%M:%S)" | tee -a "$LOG" From cddd397e71f5f3dd33939605f3c8eb4fe89892ac Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Tue, 16 Apr 2024 19:02:56 +0200 Subject: [PATCH 62/86] Do label last --- functions.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/functions.sh b/functions.sh index a281ed6..a32f379 100644 --- a/functions.sh +++ b/functions.sh @@ -1146,6 +1146,27 @@ function write-metadata () { printf " genre.sync: Anime,%s\n" "$anime_tags" >> "$METADATA" fi fi + get-studios + if [[ -n "$studio" ]] + then + printf " studio: %s\n" "$studio" >> "$METADATA" + fi + get-poster + if [[ $media_type == "animes" ]] + then + if [[ $IGNORE_SEASONS == "Yes" ]] || [[ $override_seasons_ignore == "yes" ]] + then + get-rating-1 + get-rating-2 + else + get-season-infos + check-rating-1-valid + check-rating-2-valid + fi + else + get-rating-1 + get-rating-2 + fi label_add="" label_remove="" if [[ "$cr_awards_anime" -eq 1 ]] @@ -1231,27 +1252,6 @@ function write-metadata () { then printf " label.remove: %s\n" "$label_remove" >> "$METADATA" fi - get-studios - if [[ -n "$studio" ]] - then - printf " studio: %s\n" "$studio" >> "$METADATA" - fi - get-poster - if [[ $media_type == "animes" ]] - then - if [[ $IGNORE_SEASONS == "Yes" ]] || [[ $override_seasons_ignore == "yes" ]] - then - get-rating-1 - get-rating-2 - else - get-season-infos - check-rating-1-valid - check-rating-2-valid - fi - else - get-rating-1 - get-rating-2 - fi tvdb_id="" imdb_id="" anilist_id="" From ff87dfd1aa2df623b8d2d4d7162423dba900b1c9 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Tue, 16 Apr 2024 19:17:41 +0200 Subject: [PATCH 63/86] Fix Anime Awards --- functions.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/functions.sh b/functions.sh index a32f379..618b4aa 100644 --- a/functions.sh +++ b/functions.sh @@ -364,7 +364,6 @@ function get-animes-award () { if jq -e --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id )' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" > /dev/null then cr_awards_season=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) - cr_awards_anime=1 fi } function get-airing-status () { @@ -915,6 +914,7 @@ function get-season-infos () { season_label_remove="" if [[ -n "$cr_awards_season" ]] then + cr_awards_anime=1 if [[ -n "$season_label_add" ]] then season_label_add=$(printf "%s,%s" "$season_label_add" "$cr_awards_season") @@ -1169,13 +1169,13 @@ function write-metadata () { fi label_add="" label_remove="" - if [[ "$cr_awards_anime" -eq 1 ]] + if [[ $cr_awards_anime -eq 1 ]] then if [[ -n "$label_add" ]] then - label_add=$(printf "%s,%s" "$label_add" "Anime Awards Winner") + label_add=$(printf "AA Winner,%s" "$label_add") else - label_add="Anime Awards Winner" + label_add="AA Winner" fi fi if [[ $media_type == "animes" ]] From f50d0099ec5a50ae527e2f02081252585de7075f Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Tue, 16 Apr 2024 20:00:32 +0200 Subject: [PATCH 64/86] Fix Anime Awards --- functions.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/functions.sh b/functions.sh index 618b4aa..8cae39f 100644 --- a/functions.sh +++ b/functions.sh @@ -1169,15 +1169,6 @@ function write-metadata () { fi label_add="" label_remove="" - if [[ $cr_awards_anime -eq 1 ]] - then - if [[ -n "$label_add" ]] - then - label_add=$(printf "AA Winner,%s" "$label_add") - else - label_add="AA Winner" - fi - fi if [[ $media_type == "animes" ]] then printf "%s\t\t - Writing airing status\n" "$(date +%H:%M:%S)" | tee -a "$LOG" @@ -1200,6 +1191,15 @@ function write-metadata () { fi fi fi + if [[ $cr_awards_anime -eq 1 ]] + then + if [[ -n "$label_add" ]] + then + label_add=$(printf "AA Winner,%s" "$label_add") + else + label_add="AA Winner" + fi + fi if { [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then all_anilist_ids="" From 4b98786fa7ba855f2c0711d23134354ce3c57d6f Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 17 Apr 2024 21:12:50 +0200 Subject: [PATCH 65/86] Add option to ignore non japanases VA --- config/default.env | 2 ++ functions.sh | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config/default.env b/config/default.env index 77f6c82..28335a7 100644 --- a/config/default.env +++ b/config/default.env @@ -79,6 +79,8 @@ SEASON_YEAR=No IGNORE_S1_ONLY_RATING=Yes # Add Anime Awards winner for seasons and shows ANIME_AWARDS=Yes +# Ignore non japanese voice actor awards (Yes/No) +ANIME_AWARDS_NO_FVA=Yes # Add tags based on userlists from anilist (Completed, wathcing) (Yes/No) ANILIST_LISTS=No # Anilist username diff --git a/functions.sh b/functions.sh index 8cae39f..68b9eb3 100644 --- a/functions.sh +++ b/functions.sh @@ -361,9 +361,17 @@ function get-animes-season-year () { fi } function get-animes-award () { - if jq -e --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id )' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" > /dev/null + if [[ $ANIME_AWARDS_NO_FVA == "Yes" ]] then - cr_awards_season=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) + if jq -e --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | select( .cr_award == "Best VA Performance (Japanese)" )' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" > /dev/null + then + cr_awards_season=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | select( .cr_award == "Best VA Performance (Japanese)" ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) + fi + else + if jq -e --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id )' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" > /dev/null + then + cr_awards_season=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) + fi fi } function get-airing-status () { From 435bd473f5b3a3ef3adfe353f4c339a42f7b4955 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 17 Apr 2024 22:24:03 +0200 Subject: [PATCH 66/86] Test ignore non japanase VA --- functions.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/functions.sh b/functions.sh index 68b9eb3..36474b5 100644 --- a/functions.sh +++ b/functions.sh @@ -361,16 +361,26 @@ function get-animes-season-year () { fi } function get-animes-award () { - if [[ $ANIME_AWARDS_NO_FVA == "Yes" ]] + if jq -e --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id )' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" > /dev/null then - if jq -e --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | select( .cr_award == "Best VA Performance (Japanese)" )' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" > /dev/null + cr_awards_season=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) + if [[ $ANIME_AWARDS_NO_FVA == "Yes" ]] then - cr_awards_season=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | select( .cr_award == "Best VA Performance (Japanese)" ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) - fi - else - if jq -e --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id )' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" > /dev/null - then - cr_awards_season=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) + awards_list="" + IFS="," + for awards in $cr_awards_season + do + if ! echo "$awards" | grep -q -w 'English\|Arabic\|Spanish\|Castilian\|French\|German\|Italian\|Portuguese\|Russian' + then + if [[ -n "$awards_list" ]] + then + awards_list=$(printf "%s,%s" "$awards_list" "$awards") + else + awards_list="$awards" + fi + cr_awards_season="$awards_list" + fi + done fi fi } From 93de8ab93ec22f253f5dc8fc8dcc7e53993515cd Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 17 Apr 2024 22:33:04 +0200 Subject: [PATCH 67/86] rename --- plex-romaji-renamer.sh => romaji-renamer.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plex-romaji-renamer.sh => romaji-renamer.sh (100%) mode change 100755 => 100644 diff --git a/plex-romaji-renamer.sh b/romaji-renamer.sh old mode 100755 new mode 100644 similarity index 100% rename from plex-romaji-renamer.sh rename to romaji-renamer.sh From 616b52d56c349d873ffc1d2dc0c85af72806a3a2 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sat, 20 Apr 2024 13:45:35 +0200 Subject: [PATCH 68/86] Simplify seasons award --- functions.sh | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/functions.sh b/functions.sh index 36474b5..ca514c0 100644 --- a/functions.sh +++ b/functions.sh @@ -361,26 +361,20 @@ function get-animes-season-year () { fi } function get-animes-award () { - if jq -e --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id )' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" > /dev/null + award_check="" + cr_awards="" + if [[ $ANIME_AWARDS_NO_FVA == "Yes" ]] then - cr_awards_season=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) - if [[ $ANIME_AWARDS_NO_FVA == "Yes" ]] + award_check=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | select(.cr_award | contains("English") or contains("Arabic") or contains("Spanish") or contains("Castilian") or contains("French")or contains("German") or contains("Italian") or contains("Portuguese") or contains("Russian") | not) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) > /dev/null + if [[ -n $award_check ]] then - awards_list="" - IFS="," - for awards in $cr_awards_season - do - if ! echo "$awards" | grep -q -w 'English\|Arabic\|Spanish\|Castilian\|French\|German\|Italian\|Portuguese\|Russian' - then - if [[ -n "$awards_list" ]] - then - awards_list=$(printf "%s,%s" "$awards_list" "$awards") - else - awards_list="$awards" - fi - cr_awards_season="$awards_list" - fi - done + cr_awards=$award_check + fi + else + award_check=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) > /dev/null + if [[ -n $award_check ]] + then + cr_awards=$award_check fi fi } @@ -796,7 +790,6 @@ function get-season-infos () { score_2_no_rating_seasons=0 season_loop=0 anime_season="" - cr_awards_anime="" printf " seasons:\n" >> "$METADATA" IFS="," for season_number in $seasons_list @@ -823,7 +816,6 @@ function get-season-infos () { all_cours_anime_season="" season_userlist_type_add="" seasons_userlist_type_remove="" - cr_awards_season="" IFS=',' for anilist_id in $anilist_ids do @@ -930,14 +922,13 @@ function get-season-infos () { fi season_label_add="" season_label_remove="" - if [[ -n "$cr_awards_season" ]] + if [[ -n "$cr_awards" ]] then - cr_awards_anime=1 if [[ -n "$season_label_add" ]] then - season_label_add=$(printf "%s,%s" "$season_label_add" "$cr_awards_season") + season_label_add=$(printf "%s,AA Winner" "$season_label_add") else - season_label_add="$cr_awards_season" + season_label_add="AA Winner" fi fi if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] @@ -1209,7 +1200,7 @@ function write-metadata () { fi fi fi - if [[ $cr_awards_anime -eq 1 ]] + if [[ -n $cr_awards ]] then if [[ -n "$label_add" ]] then @@ -1217,6 +1208,17 @@ function write-metadata () { else label_add="AA Winner" fi + else + get-animes-award + if [[ -n $cr_awards ]] + then + if [[ -n "$label_add" ]] + then + label_add=$(printf "AA Winner,%s" "$label_add") + else + label_add="AA Winner" + fi + fi fi if { [[ $ANILIST_LISTS_LEVEL == "show" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then From 67c45911e137785ed48feb5207a5589530f0960e Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sun, 21 Apr 2024 13:05:56 +0200 Subject: [PATCH 69/86] Fix awards --- functions.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index ca514c0..24357de 100644 --- a/functions.sh +++ b/functions.sh @@ -365,13 +365,13 @@ function get-animes-award () { cr_awards="" if [[ $ANIME_AWARDS_NO_FVA == "Yes" ]] then - award_check=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | select(.cr_award | contains("English") or contains("Arabic") or contains("Spanish") or contains("Castilian") or contains("French")or contains("German") or contains("Italian") or contains("Portuguese") or contains("Russian") | not) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) > /dev/null + award_check=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | select(.cr_award | contains("English") or contains("Arabic") or contains("Spanish") or contains("Castilian") or contains("French")or contains("German") or contains("Italian") or contains("Portuguese") or contains("Russian") | not) | "AA " + .year + " " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) > /dev/null if [[ -n $award_check ]] then cr_awards=$award_check fi else - award_check=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " - " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) > /dev/null + award_check=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | "AA " + .year + " " + .cr_award' -r "$SCRIPT_FOLDER/config/tmp/cr-award.json" | paste -s -d, -) > /dev/null if [[ -n $award_check ]] then cr_awards=$award_check @@ -790,6 +790,8 @@ function get-season-infos () { score_2_no_rating_seasons=0 season_loop=0 anime_season="" + award_check="" + cr_awards="" printf " seasons:\n" >> "$METADATA" IFS="," for season_number in $seasons_list @@ -1277,4 +1279,6 @@ function write-metadata () { anilist_id="" mal_id="" override_seasons_ignore="" + award_check="" + cr_awards="" } \ No newline at end of file From abd0b5bfe117b7d3fca889f3b9628a6825506c66 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Sun, 21 Apr 2024 17:33:20 +0200 Subject: [PATCH 70/86] Fix docker --- Dockerfile | 2 +- romaji-renamer.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index cde5ebf..8bc60ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,4 @@ RUN echo "**** install system packages ****" \ && rm -rf /requirements.txt /tmp/* /var/tmp/* /var/lib/apt/lists/* VOLUME /config VOLUME /pmm -ENTRYPOINT ["/tini", "-s", "bash", "plex-romaji-renamer.sh", "--"] \ No newline at end of file +ENTRYPOINT ["/tini", "-s", "bash", "romaji-renamer.sh", "--"] \ No newline at end of file diff --git a/romaji-renamer.sh b/romaji-renamer.sh index 6333e0d..7d9bdf5 100644 --- a/romaji-renamer.sh +++ b/romaji-renamer.sh @@ -12,7 +12,7 @@ then rm "$SCRIPT_FOLDER/config/data/*.json" fi printf "%s" "$version" > "$SCRIPT_FOLDER/config/version_last_run.txt" -printf "%s - Plex-Romaji-Renamer v%s\n" "$(date +%H:%M:%S)" "$version" | tee -a "$LOG" +printf "%s - Romaji-Renamer v%s\n" "$(date +%H:%M:%S)" "$version" | tee -a "$LOG" locale=$(locale -a | grep -i "utf" | head -n 1) if [ -z "$locale" ] then @@ -28,15 +28,15 @@ then fi if [ ! -f "$SCRIPT_FOLDER/config/default.env" ] then -curl -s "https://raw.githubusercontent.com/Arial-Z/Plex-Romaji-Renamer/dev/config/default.env" > "$SCRIPT_FOLDER/config/default.env" +curl -s "https://raw.githubusercontent.com/Arial-Z/Romaji-Renamer/dev/config/default.env" > "$SCRIPT_FOLDER/config/default.env" fi if [ ! -f "$SCRIPT_FOLDER/config/override-ID-animes.example.tsv" ] then -curl -s "https://raw.githubusercontent.com/Arial-Z/Plex-Romaji-Renamer/dev/config/override-ID-animes.example.tsv" > "$SCRIPT_FOLDER/config/override-ID-animes.example.tsv" +curl -s "https://raw.githubusercontent.com/Arial-Z/Romaji-Renamer/dev/config/override-ID-animes.example.tsv" > "$SCRIPT_FOLDER/config/override-ID-animes.example.tsv" fi if [ ! -f "$SCRIPT_FOLDER/config/override-ID-movies.example.tsv" ] then -curl -s "https://raw.githubusercontent.com/Arial-Z/Plex-Romaji-Renamer/dev/config/override-ID-movies.example.tsv" > "$SCRIPT_FOLDER/config/override-ID-movies.example.tsv" +curl -s "https://raw.githubusercontent.com/Arial-Z/Romaji-Renamer/dev/config/override-ID-movies.example.tsv" > "$SCRIPT_FOLDER/config/override-ID-movies.example.tsv" fi # sleep infinity if [ -f "$SCRIPT_FOLDER/config/.env" ] From bde9055212eb4c9a030b99183fdcd125e0f101f3 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 10 Jun 2024 20:02:07 +0200 Subject: [PATCH 71/86] Fix seasonal --- functions.sh | 4 ++-- seasonal-animes-download.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/functions.sh b/functions.sh index 24357de..0a75f95 100644 --- a/functions.sh +++ b/functions.sh @@ -1233,7 +1233,7 @@ function write-metadata () { then all_anilist_ids=$(jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, - | sed 's/,/\\|/g') else - all_anilist_ids="$anilist_id" + all_anilist_ids=$anilist_id fi if grep -q -w "$all_anilist_ids" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then @@ -1242,7 +1242,7 @@ function write-metadata () { then userlist_type_add=$(printf "%s,%s" "$userlist_type_add" "$userlist_type") else - userlist_type_add="$userlist_type" + userlist_type_add=$userlist_type fi userlist_type_remove=$(printf "%s" "$userlist_type_remove" | sed s/"$userlist_type"// | sed 's/^,//' | sed 's/,,/,/g') fi diff --git a/seasonal-animes-download.sh b/seasonal-animes-download.sh index 276a742..5ebe0e0 100755 --- a/seasonal-animes-download.sh +++ b/seasonal-animes-download.sh @@ -21,9 +21,9 @@ fi printf "%s - Starting script\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" download-anime-id-mapping printf "%s - checking current season\n" "$(date +%H:%M:%S)" | tee -a "$LOG" -curl -s -L -A "Mozilla/5.0 (X11; Linux x86_64)" "https://livechart.me/" -o "$SCRIPT_FOLDER/config/tmp/this-season.html" -season=$(awk -v IGNORECASE=1 -v RS=']*>/,"");print;exit}' "$SCRIPT_FOLDER/config/tmp/this-season.html" | awk '{print $1}'| tr '[:lower:]' '[:upper:]') -year=$(awk -v IGNORECASE=1 -v RS=']*>/,"");print;exit}' "$SCRIPT_FOLDER/config/tmp/this-season.html" | awk '{print $2}') +curl -s -L -A "Mozilla/5.0 (X11; Linux x86_64)" "https://anidb.net/anime/season/" -o "$SCRIPT_FOLDER/config/tmp/this-season.html" +season=$(awk -v IGNORECASE=1 -v RS=']*>/,"");print;exit}' "$SCRIPT_FOLDER/config/tmp/this-season.html" | awk '{print $4}'| tr '[:lower:]' '[:upper:]') +year=$(awk -v IGNORECASE=1 -v RS=']*>/,"");print;exit}' "$SCRIPT_FOLDER/config/tmp/this-season.html" | awk '{print $5}') printf "%s - Current season : %s %s\n\n" "$(date +%H:%M:%S)" "$season" "$year" | tee -a "$LOG" printf "%s - Creating seasonal list\n" "$(date +%H:%M:%S)" | tee -a "$LOG" printf "%s\t - Downloading anilist season list\n" "$(date +%H:%M:%S)" | tee -a "$LOG" From 26be049854d292e304c8d97793954b9ec4d0c6fb Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Mon, 10 Jun 2024 20:18:49 +0200 Subject: [PATCH 72/86] Add gawk to docker container --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8bc60ec..cc2563e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN echo "**** install system packages ****" \ && apt-get update \ && apt-get upgrade -y --no-install-recommends \ && apt-get install -y tzdata --no-install-recommends \ - && apt-get install -y gcc g++ libxml2-dev libxslt-dev libz-dev libjpeg62-turbo-dev zlib1g-dev wget curl jq \ + && apt-get install -y gcc g++ libxml2-dev libxslt-dev libz-dev libjpeg62-turbo-dev zlib1g-dev wget curl jq gawk \ && wget -O /tini https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-"$(dpkg --print-architecture | awk -F- '{ print $NF }')" \ && chmod +x /tini \ && pip3 install --no-cache-dir --upgrade --requirement /requirements.txt \ From e261dee96842f387e8f4208a19fdb91bda5c4c43 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 19 Jun 2024 17:51:31 +0200 Subject: [PATCH 73/86] Fix python changes --- .dockerignore | 1 + README.md | 17 ++++++++--------- animes-renamer.sh | 7 ++++++- movies-renamer.sh | 7 ++++++- plex_animes_export.py | 40 ++++++++++++++++++++-------------------- plex_movies_export.py | 2 +- 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/.dockerignore b/.dockerignore index 01d675c..f166ac5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,6 +12,7 @@ LICENSE .github Dockerfile docker-compose.yml +romaji-renamer-venv venv .env config/tmp diff --git a/README.md b/README.md index 7269793..115124c 100644 --- a/README.md +++ b/README.md @@ -68,21 +68,20 @@ First you need a GNU/Linux OS to run bash script
Requirements: Plex Media Server, Plex-Meta-Manager, Python and JQ
- Install and configure Plex-Meta-Manager: https://github.com/meisnate12/Plex-Meta-Manager
- Install JQ is a json parser see: https://stedolan.github.io/jq/ (Present by default on unRAID 6.10.0 and later.)
- - install python plexapi - ``` - pip install plexapi - ``` - - install python-dotenv - ``` - pip install python-dotenv - ``` ### Step 2 - Download and extract the script Git clone the **main** branch or get lastest release : https://github.com/Arial-Z/Romaji-Renamer/releases/latest -### Step 3 - Configure the script +### Step 3 - Install python modules and configure the script - Extract the script on a desired location.
- Navigate to its location.
+ - install python plexapi and python-dotenv with a virtual environment + ``` + cd into the script folder + python3 -m venv romaji-renamer-venv + source romaji-renamer-venv/bin/activate + pip install plexapi python-dotenv + ``` - Copy default.env to config/.env
- cd into the config folder and edit .env to fill out the variables.
```env diff --git a/animes-renamer.sh b/animes-renamer.sh index a5a55f3..898f7c0 100755 --- a/animes-renamer.sh +++ b/animes-renamer.sh @@ -37,7 +37,12 @@ get-anilist-userlist # export animes list from plex printf "%s - Creating animes list\n" "$(date +%H:%M:%S)" | tee -a "$LOG" printf "%s\t - Exporting Plex animes library\n" "$(date +%H:%M:%S)" | tee -a "$LOG" -python3 "$SCRIPT_FOLDER/plex_animes_export.py" +if [ -f "$SCRIPT_FOLDER/romaji-renamer-venv/bin/python3" ] +then + "$SCRIPT_FOLDER/romaji-renamer-venv/bin/python3" "$SCRIPT_FOLDER/plex_animes_export.py" +else + python3 "$SCRIPT_FOLDER/plex_animes_export.py" +fi printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" # create ID/animes.tsv diff --git a/movies-renamer.sh b/movies-renamer.sh index 2a75e86..352a01f 100755 --- a/movies-renamer.sh +++ b/movies-renamer.sh @@ -37,7 +37,12 @@ get-anilist-userlist # export movies list from plex printf "%s - Creating animes list\n" "$(date +%H:%M:%S)" | tee -a "$LOG" printf "%s\t - Exporting Plex animes library\n" "$(date +%H:%M:%S)" | tee -a "$LOG" -python3 "$SCRIPT_FOLDER/plex_movies_export.py" +if [ -f "$SCRIPT_FOLDER/romaji-renamer-venv/bin/python3" ] +then + "$SCRIPT_FOLDER/romaji-renamer-venv/bin/python3" "$SCRIPT_FOLDER/plex_movies_export.py" +else + python3 "$SCRIPT_FOLDER/plex_movies_export.py" +fi printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" # create ID/movies.tsv ( imdb_id | mal_id | anime_title | plex_title ) diff --git a/plex_animes_export.py b/plex_animes_export.py index 57f4b09..1e54949 100644 --- a/plex_animes_export.py +++ b/plex_animes_export.py @@ -17,23 +17,23 @@ plex = PlexServer(url, token, timeout=300) animes = plex.library.section(ANIME_LIBRARY_NAME) with open(Path(basedir, "config/tmp/plex_animes_export.tsv"), "w") as export_plex, open(Path(basedir, "config/tmp/plex_failed_animes.tsv"), "w") as export_fail: - for video in animes.search(): - title = str(video.title) - ids = str(video.guids) - tvdbid = re.search("(?<=tvdb://)(\d+)", ids) - if ( tvdbid ) : - tvdb = str(tvdbid.group(1)) - location = str(video.locations)[2:-2] - if (re.match("^.*(\\\\.*)$", location)) : - folder = str(PureWindowsPath(location).name) - else : - folder = str(PurePosixPath(location).name) - seasons = str(video.seasons()) - seasonslist = re.findall("\-(\d*)\>", seasons) - cleanseasonslist = ',' .join(seasonslist) - export=(tvdb + "\t" + title + "\t" + folder + "\t" + str(cleanseasonslist) + "\n") - export_plex.write(export) - else : - export=(title + " no id found" + ids + "\n") - export_fail.write(export) - print(export) \ No newline at end of file + for video in animes.search(): + title = str(video.title) + ids = str(video.guids) + tvdbid = re.search("(?<=tvdb://)(\\d+)", ids) + if ( tvdbid ) : + tvdb = str(tvdbid.group(1)) + location = str(video.locations)[2:-2] + if (re.match("^.*(\\\\.*)$", location)) : + folder = str(PureWindowsPath(location).name) + else : + folder = str(PurePosixPath(location).name) + seasons = str(video.seasons()) + seasonslist = re.findall("\\-(\\d*)\\>", seasons) + cleanseasonslist = ',' .join(seasonslist) + export=(tvdb + "\t" + title + "\t" + folder + "\t" + str(cleanseasonslist) + "\n") + export_plex.write(export) + else : + export=(title + " no id found" + ids + "\n") + export_fail.write(export) + print(export) \ No newline at end of file diff --git a/plex_movies_export.py b/plex_movies_export.py index afa6ace..0c8998d 100644 --- a/plex_movies_export.py +++ b/plex_movies_export.py @@ -19,7 +19,7 @@ for video in movies.search(): title = str(video.title) ids = str(video.guids) - imdbid = re.search("(?<=imdb://)(tt\d+)", ids) + imdbid = re.search("(?<=imdb://)(tt\\d+)", ids) if ( imdbid ) : imdb = str(imdbid.group(1)) location = str(video.locations)[2:-2] From 5b3ac933027ee06651d31baaf80b2ea03d2b71f3 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 19 Jun 2024 17:55:04 +0200 Subject: [PATCH 74/86] Fix log --- functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 0a75f95..93cf545 100644 --- a/functions.sh +++ b/functions.sh @@ -1,7 +1,7 @@ #!/bin/bash #General variables -LOG=$LOG_FOLDER/PRR_$(date +%Y.%m.%d).log +LOG=$LOG_FOLDER/RR_$(date +%Y.%m.%d).log MATCH_LOG=$LOG_FOLDER/${media_type}-missing-id.log # functions From 810f2c79efede4d27fd3508127739e3bc9c6159c Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 19 Jun 2024 19:00:33 +0200 Subject: [PATCH 75/86] update .env --- config/default.env | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/default.env b/config/default.env index 28335a7..105070d 100644 --- a/config/default.env +++ b/config/default.env @@ -57,6 +57,8 @@ SORT_TITLE_ENG=No ORIGINAL_TITLE_NATIVE=Yes # Rename season to the anilist title of that season (Yes/No) RENAME_SEASONS=Yes +# Anilist have some full uppercase title, this settings will remove them "86 EIGHTY-SIX" > "86 Eighty-Six" (Yes/No) +REDUCE_TITLE_CAPS=Yes # Disable anilist tags (Yes/No) DISABLE_TAGS=No # Add a default "Anime" tag to everything (Yes/No) @@ -71,11 +73,9 @@ POSTER_SEASON_DOWNLOAD=Yes POSTER_SOURCE=ANILIST # Ignore seasons title, rating and poster (Yes/No) IGNORE_SEASONS=No -# Anilist have some full uppercase title, this settings will remove them "86 EIGHTY-SIX" > "86 Eighty-Six" (Yes/No) -REDUCE_TITLE_CAPS=Yes #Add the anime season to the season label in plex (Fall 2022, Spring 2021, ...) SEASON_YEAR=No -# Ignore season 1 rating part if it's the only season (Yes/No) +# Ignore season rating for animmes with only 1 season (Yes/No) IGNORE_S1_ONLY_RATING=Yes # Add Anime Awards winner for seasons and shows ANIME_AWARDS=Yes @@ -88,4 +88,4 @@ ANILIST_USERNAME=Arialz # For Shows the level tags should be added ("show", "season" or "both") ANILIST_LISTS_LEVEL=show # Mal Data cache time (in days min : 1) -DATA_CACHE_TIME=5 +DATA_CACHE_TIME=5 \ No newline at end of file From 9f94acca2b98b0f681045213e57b026b1cc925c3 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Wed, 19 Jun 2024 20:28:01 +0200 Subject: [PATCH 76/86] Fix season missing id --- functions.sh | 186 +++++++++++++++++++++++++-------------------------- 1 file changed, 93 insertions(+), 93 deletions(-) diff --git a/functions.sh b/functions.sh index 93cf545..0d0a03d 100644 --- a/functions.sh +++ b/functions.sh @@ -800,121 +800,121 @@ function get-season-infos () { then printf " 0:\n label.remove: score\n" >> "$METADATA" else - if [[ -n "$anilist_id" ]] + season_loop=1 + anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) + if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] then - season_loop=1 - anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) - if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] + anilist_ids=$anilist_backup_id + fi + cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') + total_1_cours_score=0 + total_2_cours_score=0 + score_1_no_rating_cours=0 + score_2_no_rating_cours=0 + cours_count=0 + cour_status="" + all_cours_anime_season="" + season_userlist_type_add="" + seasons_userlist_type_remove="" + IFS=',' + for anilist_id in $anilist_ids + do + ((cours_count++)) + if [[ -n "$anilist_id" ]] then - anilist_ids=$anilist_backup_id - fi - cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') - total_1_cours_score=0 - total_2_cours_score=0 - score_1_no_rating_cours=0 - score_2_no_rating_cours=0 - cours_count=0 - cour_status="" - all_cours_anime_season="" - season_userlist_type_add="" - seasons_userlist_type_remove="" - IFS=',' - for anilist_id in $anilist_ids - do - ((cours_count++)) - if [[ -n "$anilist_id" ]] + get-anilist-infos + if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" then - get-anilist-infos - if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" - then - ((score_1_no_rating_cours++)) - ((score_2_no_rating_cours++)) - continue - fi - if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] - then - for userlist_type in completed watching dropped paused planning - do - if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + ((score_1_no_rating_cours++)) + ((score_2_no_rating_cours++)) + continue + fi + if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] + then + for userlist_type in completed watching dropped paused planning + do + if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + then + userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') + if [[ $userlist_type_count -gt 1 ]] then - userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') - if [[ $userlist_type_count -gt 1 ]] - then - season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") - else - season_userlist_type_add="$userlist_type" - fi + season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") + else + season_userlist_type_add="$userlist_type" fi - done - fi - get-cour-rating-1 - get-cour-rating-2 - if [[ $ANIME_AWARDS == "Yes" ]] - then - get-animes-award - fi - if [[ $SEASON_YEAR == "Yes" ]] - then - get-animes-season-year - if [[ $cours_count -gt 1 ]] - then - all_cours_anime_season=$(printf "%s,%s" "$anime_season" "$all_cours_anime_season") - else - all_cours_anime_season=$anime_season fi - fi - else - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" | tee -a "$LOG" - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" >> "$MATCH_LOG" - ((score_1_no_rating_cours++)) - ((score_2_no_rating_cours++)) + done fi - total-cour-rating-1 - total-cour-rating-2 - done - anime_season=$all_cours_anime_season - if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] - then - if [[ "$total_1_cours_score" != 0 ]] + get-cour-rating-1 + get-cour-rating-2 + if [[ $ANIME_AWARDS == "Yes" ]] + then + get-animes-award + fi + if [[ $SEASON_YEAR == "Yes" ]] then - total_1_cours=$((cours_count - score_1_no_rating_cours)) - if [[ "$total_1_cours" != 0 ]] + get-animes-season-year + if [[ $cours_count -gt 1 ]] then - score_1_season=$(echo | awk -v v1="$total_1_cours_score" -v v2="$total_1_cours" '{print v1 / v2}') - score_1_season=$(printf '%.*f\n' 1 "$score_1_season") + all_cours_anime_season=$(printf "%s,%s" "$anime_season" "$all_cours_anime_season") else - score_1_season=0 - ((score_1_no_rating_seasons++)) + all_cours_anime_season=$anime_season fi - else - score_1_season=0 - ((score_1_no_rating_seasons++)) fi + else + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" | tee -a "$LOG" + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" >> "$MATCH_LOG" + ((score_1_no_rating_cours++)) + ((score_2_no_rating_cours++)) fi - if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] + total-cour-rating-1 + total-cour-rating-2 + done + anime_season=$all_cours_anime_season + if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] + then + if [[ "$total_1_cours_score" != 0 ]] then - if [[ "$total_2_cours_score" != 0 ]] + total_1_cours=$((cours_count - score_1_no_rating_cours)) + if [[ "$total_1_cours" != 0 ]] then - total_2_cours=$((cours_count - score_2_no_rating_cours)) - if [[ "$total_2_cours" != 0 ]] - then - score_2_season=$(echo | awk -v v1="$total_2_cours_score" -v v2="$total_2_cours" '{print v1 / v2}') - score_2_season=$(printf '%.*f\n' 1 "$score_2_season") - else - score_2_season=0 - ((score_2_no_rating_seasons++)) - fi + score_1_season=$(echo | awk -v v1="$total_1_cours_score" -v v2="$total_1_cours" '{print v1 / v2}') + score_1_season=$(printf '%.*f\n' 1 "$score_1_season") else score_1_season=0 ((score_1_no_rating_seasons++)) fi + else + score_1_season=0 + ((score_1_no_rating_seasons++)) fi - cours_count_total=0 - anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) - if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] + fi + if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] + then + if [[ "$total_2_cours_score" != 0 ]] then - anilist_id=$anilist_backup_id + total_2_cours=$((cours_count - score_2_no_rating_cours)) + if [[ "$total_2_cours" != 0 ]] + then + score_2_season=$(echo | awk -v v1="$total_2_cours_score" -v v2="$total_2_cours" '{print v1 / v2}') + score_2_season=$(printf '%.*f\n' 1 "$score_2_season") + else + score_2_season=0 + ((score_2_no_rating_seasons++)) + fi + else + score_1_season=0 + ((score_1_no_rating_seasons++)) fi + fi + cours_count_total=0 + anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) + if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] + then + anilist_id=$anilist_backup_id + fi + if [[ -n "$anilist_id" ]] + then romaji_title=$(get-romaji-title) english_title=$(get-english-title) printf " %s:\n" "$season_number" >> "$METADATA" From a56fe55a4e4170bdfabfc672f2bf8864cad5dc8b Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 20 Jun 2024 21:24:40 +0200 Subject: [PATCH 77/86] Add caps userlists --- functions.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/functions.sh b/functions.sh index 0d0a03d..2257709 100644 --- a/functions.sh +++ b/functions.sh @@ -831,7 +831,7 @@ function get-season-infos () { fi if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then - for userlist_type in completed watching dropped paused planning + for userlist_type in Completed Watching Dropped Paused Planning do if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then @@ -935,7 +935,7 @@ function get-season-infos () { fi if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then - seasons_userlist_type_remove="completed,watching,dropped,paused,planning" + seasons_userlist_type_remove="Completed,Watching,Dropped,Paused,Planning" userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') if [[ -n $season_userlist_type_add ]] && [[ $userlist_type_count -gt 0 ]] then @@ -1226,8 +1226,8 @@ function write-metadata () { then all_anilist_ids="" userlist_type_add="" - userlist_type_remove="completed,watching,dropped,paused,planning" - for userlist_type in completed watching dropped paused planning + userlist_type_remove="Completed,Watching,Dropped,Paused,Planning" + for userlist_type in Completed Watching Dropped Paused Planning do if [[ $media_type == "animes" ]] then From d215763e3809df8ff4fc02b02c09711fa030f66b Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 20 Jun 2024 21:27:41 +0200 Subject: [PATCH 78/86] Change score label --- functions.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functions.sh b/functions.sh index 2257709..88e759a 100644 --- a/functions.sh +++ b/functions.sh @@ -981,17 +981,17 @@ function get-season-infos () { then printf " label: %s\n" "$season_label_add" >> "$METADATA" else - printf " label: score,%s\n" "$season_label_add" >> "$METADATA" + printf " label: Score,%s\n" "$season_label_add" >> "$METADATA" fi else - printf " label: score,%s\n" "$season_label_add" >> "$METADATA" + printf " label: Score,%s\n" "$season_label_add" >> "$METADATA" fi else if [[ $last_season -eq 1 ]] then if [[ $IGNORE_S1_ONLY_RATING != "Yes" ]] then - printf " label: score\n" >> "$METADATA" + printf " label: Score\n" >> "$METADATA" fi fi fi @@ -1001,7 +1001,7 @@ function get-season-infos () { then if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]] then - printf " label.remove: score,%s\n" "$season_label_remove" >> "$METADATA" + printf " label.remove: Score,%s\n" "$season_label_remove" >> "$METADATA" else printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" fi @@ -1013,7 +1013,7 @@ function get-season-infos () { then if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]] then - printf " label.remove: score\n" >> "$METADATA" + printf " label.remove: Score\n" >> "$METADATA" fi fi fi From d75c65871ed81a112fe1eb27947a1c40dc553023 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Thu, 20 Jun 2024 22:06:45 +0200 Subject: [PATCH 79/86] Fix char caps --- functions.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functions.sh b/functions.sh index 88e759a..1c7ebb4 100644 --- a/functions.sh +++ b/functions.sh @@ -92,11 +92,11 @@ function get-anilist-userlist { fi done printf "%s\t - Sorting Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Completed" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-completed.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Watching" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-watching.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-dropped.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-paused.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-planning.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Completed" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Completed.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Watching" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Watching.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Dropped.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Paused.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Planning.tsv" printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" printf "%s - done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" fi From 0c150a6b569fac9c53d3a1aa3526f2a040a547bc Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Fri, 21 Jun 2024 19:08:05 +0200 Subject: [PATCH 80/86] Fix override not working as expected --- functions.sh | 221 ++++++++++++++++++++++++++------------------------- 1 file changed, 112 insertions(+), 109 deletions(-) diff --git a/functions.sh b/functions.sh index 1c7ebb4..9dd9885 100644 --- a/functions.sh +++ b/functions.sh @@ -92,11 +92,11 @@ function get-anilist-userlist { fi done printf "%s\t - Sorting Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Completed" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Completed.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Watching" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Watching.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Dropped.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Paused.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Planning.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Completed" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-completed.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Watching" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-watching.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-dropped.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-paused.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-planning.tsv" printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" printf "%s - done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" fi @@ -800,121 +800,127 @@ function get-season-infos () { then printf " 0:\n label.remove: score\n" >> "$METADATA" else - season_loop=1 - anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) - if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] + if [[ -z "$anilist_id" ]] then - anilist_ids=$anilist_backup_id - fi - cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') - total_1_cours_score=0 - total_2_cours_score=0 - score_1_no_rating_cours=0 - score_2_no_rating_cours=0 - cours_count=0 - cour_status="" - all_cours_anime_season="" - season_userlist_type_add="" - seasons_userlist_type_remove="" - IFS=',' - for anilist_id in $anilist_ids - do - ((cours_count++)) - if [[ -n "$anilist_id" ]] + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" | tee -a "$LOG" + printf "%s - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" >> "$MATCH_LOG" + ((score_1_no_rating_seasons++)) + ((score_2_no_rating_seasons++)) + continue + else + season_loop=1 + anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) + if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] then - get-anilist-infos - if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" - then - ((score_1_no_rating_cours++)) - ((score_2_no_rating_cours++)) - continue - fi - if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] + anilist_ids=$anilist_backup_id + fi + cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') + total_1_cours_score=0 + total_2_cours_score=0 + score_1_no_rating_cours=0 + score_2_no_rating_cours=0 + cours_count=0 + cour_status="" + all_cours_anime_season="" + season_userlist_type_add="" + seasons_userlist_type_remove="" + IFS=',' + for anilist_id in $anilist_ids + do + ((cours_count++)) + if [[ -n "$anilist_id" ]] then - for userlist_type in Completed Watching Dropped Paused Planning - do - if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" - then - userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') - if [[ $userlist_type_count -gt 1 ]] + get-anilist-infos + if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" + then + ((score_1_no_rating_cours++)) + ((score_2_no_rating_cours++)) + continue + fi + if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] + then + for userlist_type in completed watching dropped paused planning + do + if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then - season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") - else - season_userlist_type_add="$userlist_type" + userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') + if [[ $userlist_type_count -gt 1 ]] + then + season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") + else + season_userlist_type_add="$userlist_type" + fi fi + done + fi + get-cour-rating-1 + get-cour-rating-2 + if [[ $ANIME_AWARDS == "Yes" ]] + then + get-animes-award + fi + if [[ $SEASON_YEAR == "Yes" ]] + then + get-animes-season-year + if [[ $cours_count -gt 1 ]] + then + all_cours_anime_season=$(printf "%s,%s" "$anime_season" "$all_cours_anime_season") + else + all_cours_anime_season=$anime_season fi - done - fi - get-cour-rating-1 - get-cour-rating-2 - if [[ $ANIME_AWARDS == "Yes" ]] - then - get-animes-award + fi + else + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" | tee -a "$LOG" + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" >> "$MATCH_LOG" + ((score_1_no_rating_cours++)) + ((score_2_no_rating_cours++)) fi - if [[ $SEASON_YEAR == "Yes" ]] + total-cour-rating-1 + total-cour-rating-2 + done + anime_season=$all_cours_anime_season + if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] + then + if [[ "$total_1_cours_score" != 0 ]] then - get-animes-season-year - if [[ $cours_count -gt 1 ]] + total_1_cours=$((cours_count - score_1_no_rating_cours)) + if [[ "$total_1_cours" != 0 ]] then - all_cours_anime_season=$(printf "%s,%s" "$anime_season" "$all_cours_anime_season") + score_1_season=$(echo | awk -v v1="$total_1_cours_score" -v v2="$total_1_cours" '{print v1 / v2}') + score_1_season=$(printf '%.*f\n' 1 "$score_1_season") else - all_cours_anime_season=$anime_season + score_1_season=0 + ((score_1_no_rating_seasons++)) fi + else + score_1_season=0 + ((score_1_no_rating_seasons++)) fi - else - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" | tee -a "$LOG" - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" >> "$MATCH_LOG" - ((score_1_no_rating_cours++)) - ((score_2_no_rating_cours++)) fi - total-cour-rating-1 - total-cour-rating-2 - done - anime_season=$all_cours_anime_season - if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] - then - if [[ "$total_1_cours_score" != 0 ]] + if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] then - total_1_cours=$((cours_count - score_1_no_rating_cours)) - if [[ "$total_1_cours" != 0 ]] + if [[ "$total_2_cours_score" != 0 ]] then - score_1_season=$(echo | awk -v v1="$total_1_cours_score" -v v2="$total_1_cours" '{print v1 / v2}') - score_1_season=$(printf '%.*f\n' 1 "$score_1_season") + total_2_cours=$((cours_count - score_2_no_rating_cours)) + if [[ "$total_2_cours" != 0 ]] + then + score_2_season=$(echo | awk -v v1="$total_2_cours_score" -v v2="$total_2_cours" '{print v1 / v2}') + score_2_season=$(printf '%.*f\n' 1 "$score_2_season") + else + score_2_season=0 + ((score_2_no_rating_seasons++)) + fi else score_1_season=0 ((score_1_no_rating_seasons++)) fi - else - score_1_season=0 - ((score_1_no_rating_seasons++)) fi - fi - if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] - then - if [[ "$total_2_cours_score" != 0 ]] + cours_count_total=0 + anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) + if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] then - total_2_cours=$((cours_count - score_2_no_rating_cours)) - if [[ "$total_2_cours" != 0 ]] - then - score_2_season=$(echo | awk -v v1="$total_2_cours_score" -v v2="$total_2_cours" '{print v1 / v2}') - score_2_season=$(printf '%.*f\n' 1 "$score_2_season") - else - score_2_season=0 - ((score_2_no_rating_seasons++)) - fi - else - score_1_season=0 - ((score_1_no_rating_seasons++)) + anilist_id=$anilist_backup_id fi - fi - cours_count_total=0 - anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) - if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] - then - anilist_id=$anilist_backup_id - fi - if [[ -n "$anilist_id" ]] - then romaji_title=$(get-romaji-title) english_title=$(get-english-title) printf " %s:\n" "$season_number" >> "$METADATA" @@ -935,7 +941,7 @@ function get-season-infos () { fi if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then - seasons_userlist_type_remove="Completed,Watching,Dropped,Paused,Planning" + seasons_userlist_type_remove="completed,watching,dropped,paused,planning" userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') if [[ -n $season_userlist_type_add ]] && [[ $userlist_type_count -gt 0 ]] then @@ -981,17 +987,17 @@ function get-season-infos () { then printf " label: %s\n" "$season_label_add" >> "$METADATA" else - printf " label: Score,%s\n" "$season_label_add" >> "$METADATA" + printf " label: score,%s\n" "$season_label_add" >> "$METADATA" fi else - printf " label: Score,%s\n" "$season_label_add" >> "$METADATA" + printf " label: score,%s\n" "$season_label_add" >> "$METADATA" fi else if [[ $last_season -eq 1 ]] then if [[ $IGNORE_S1_ONLY_RATING != "Yes" ]] then - printf " label: Score\n" >> "$METADATA" + printf " label: score\n" >> "$METADATA" fi fi fi @@ -1001,7 +1007,7 @@ function get-season-infos () { then if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]] then - printf " label.remove: Score,%s\n" "$season_label_remove" >> "$METADATA" + printf " label.remove: score,%s\n" "$season_label_remove" >> "$METADATA" else printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" fi @@ -1013,7 +1019,7 @@ function get-season-infos () { then if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]] then - printf " label.remove: Score\n" >> "$METADATA" + printf " label.remove: score\n" >> "$METADATA" fi fi fi @@ -1029,9 +1035,6 @@ function get-season-infos () { total-rating-1 total-rating-2 get-season-poster - else - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" | tee -a "$LOG" - printf "%s - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" >> "$MATCH_LOG" fi fi done @@ -1226,8 +1229,8 @@ function write-metadata () { then all_anilist_ids="" userlist_type_add="" - userlist_type_remove="Completed,Watching,Dropped,Paused,Planning" - for userlist_type in Completed Watching Dropped Paused Planning + userlist_type_remove="completed,watching,dropped,paused,planning" + for userlist_type in completed watching dropped paused planning do if [[ $media_type == "animes" ]] then From 7527abd0db457b1f5bd898919007e9259fca19d4 Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Fri, 21 Jun 2024 19:33:52 +0200 Subject: [PATCH 81/86] Fix label --- functions.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/functions.sh b/functions.sh index 9dd9885..08ee4cd 100644 --- a/functions.sh +++ b/functions.sh @@ -92,11 +92,11 @@ function get-anilist-userlist { fi done printf "%s\t - Sorting Anilist userlist\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Completed" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-completed.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Watching" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-watching.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-dropped.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-paused.tsv" - jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-planning.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Completed" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Completed.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Watching" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Watching.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Dropped" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Dropped.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Paused" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Paused.tsv" + jq '.data.MediaListCollection.lists | .[] | select( .name == "Planning" ) | .entries | .[].mediaId ' -r "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" | paste -s -d, - > "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-Planning.tsv" printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG" printf "%s - done\n\n" "$(date +%H:%M:%S)" | tee -a "$LOG" fi @@ -839,7 +839,7 @@ function get-season-infos () { fi if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then - for userlist_type in completed watching dropped paused planning + for userlist_type in Completed Watching Dropped Paused Planning do if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" then @@ -941,7 +941,7 @@ function get-season-infos () { fi if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] then - seasons_userlist_type_remove="completed,watching,dropped,paused,planning" + seasons_userlist_type_remove="Completed,Watching,Dropped,Paused,Planning" userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') if [[ -n $season_userlist_type_add ]] && [[ $userlist_type_count -gt 0 ]] then @@ -987,17 +987,17 @@ function get-season-infos () { then printf " label: %s\n" "$season_label_add" >> "$METADATA" else - printf " label: score,%s\n" "$season_label_add" >> "$METADATA" + printf " label: Score,%s\n" "$season_label_add" >> "$METADATA" fi else - printf " label: score,%s\n" "$season_label_add" >> "$METADATA" + printf " label: Score,%s\n" "$season_label_add" >> "$METADATA" fi else if [[ $last_season -eq 1 ]] then if [[ $IGNORE_S1_ONLY_RATING != "Yes" ]] then - printf " label: score\n" >> "$METADATA" + printf " label: Score\n" >> "$METADATA" fi fi fi @@ -1007,7 +1007,7 @@ function get-season-infos () { then if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]] then - printf " label.remove: score,%s\n" "$season_label_remove" >> "$METADATA" + printf " label.remove: Score,%s\n" "$season_label_remove" >> "$METADATA" else printf " label.remove: %s\n" "$season_label_remove" >> "$METADATA" fi @@ -1019,7 +1019,7 @@ function get-season-infos () { then if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]] then - printf " label.remove: score\n" >> "$METADATA" + printf " label.remove: Score\n" >> "$METADATA" fi fi fi @@ -1229,8 +1229,8 @@ function write-metadata () { then all_anilist_ids="" userlist_type_add="" - userlist_type_remove="completed,watching,dropped,paused,planning" - for userlist_type in completed watching dropped paused planning + userlist_type_remove="Completed,Watching,Dropped,Paused,Planning" + for userlist_type in Completed Watching Dropped Paused Planning do if [[ $media_type == "animes" ]] then From fead71eed45a47034848d3a1e4c2549efdd03b3a Mon Sep 17 00:00:00 2001 From: Arial-Z Date: Fri, 21 Jun 2024 19:58:25 +0200 Subject: [PATCH 82/86] Fix seasons missing id --- functions.sh | 197 +++++++++++++++++++++++++-------------------------- 1 file changed, 98 insertions(+), 99 deletions(-) diff --git a/functions.sh b/functions.sh index 08ee4cd..0c4d155 100644 --- a/functions.sh +++ b/functions.sh @@ -800,127 +800,126 @@ function get-season-infos () { then printf " 0:\n label.remove: score\n" >> "$METADATA" else - if [[ -z "$anilist_id" ]] + season_loop=1 + anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) + if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] then - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" | tee -a "$LOG" - printf "%s - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" >> "$MATCH_LOG" - ((score_1_no_rating_seasons++)) - ((score_2_no_rating_seasons++)) - continue - else - season_loop=1 - anilist_ids=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '[.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number )] | sort_by(.tvdb_epoffset) | .[].anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | paste -s -d, -) - if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] + anilist_ids=$anilist_backup_id + fi + cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') + total_1_cours_score=0 + total_2_cours_score=0 + score_1_no_rating_cours=0 + score_2_no_rating_cours=0 + cours_count=0 + cour_status="" + all_cours_anime_season="" + season_userlist_type_add="" + seasons_userlist_type_remove="" + IFS=',' + for anilist_id in $anilist_ids + do + ((cours_count++)) + if [[ -n "$anilist_id" ]] then - anilist_ids=$anilist_backup_id - fi - cours_count_total=$(printf %s "$anilist_ids" | awk -F "," '{print NF}') - total_1_cours_score=0 - total_2_cours_score=0 - score_1_no_rating_cours=0 - score_2_no_rating_cours=0 - cours_count=0 - cour_status="" - all_cours_anime_season="" - season_userlist_type_add="" - seasons_userlist_type_remove="" - IFS=',' - for anilist_id in $anilist_ids - do - ((cours_count++)) - if [[ -n "$anilist_id" ]] + get-anilist-infos + if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" then - get-anilist-infos - if jq '.data.Media.status' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | grep -q -w "NOT_YET_RELEASED" - then - ((score_1_no_rating_cours++)) - ((score_2_no_rating_cours++)) - continue - fi - if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] - then - for userlist_type in Completed Watching Dropped Paused Planning - do - if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + ((score_1_no_rating_cours++)) + ((score_2_no_rating_cours++)) + continue + fi + if { [[ $ANILIST_LISTS_LEVEL == "season" ]] || [[ $ANILIST_LISTS_LEVEL == "both" ]]; } && [[ $ANILIST_LISTS == "Yes" ]] + then + for userlist_type in Completed Watching Dropped Paused Planning + do + if grep -q -w "$anilist_id" "$SCRIPT_FOLDER/config/data/anilist-$ANILIST_USERNAME-$userlist_type.tsv" + then + userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') + if [[ $userlist_type_count -gt 1 ]] then - userlist_type_count=$(printf %s "$season_userlist_type_add" | awk -F "," '{print NF}') - if [[ $userlist_type_count -gt 1 ]] - then - season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") - else - season_userlist_type_add="$userlist_type" - fi + season_userlist_type_add=$(printf "%s,%s" "$season_userlist_type_add" "$userlist_type") + else + season_userlist_type_add="$userlist_type" fi - done - fi - get-cour-rating-1 - get-cour-rating-2 - if [[ $ANIME_AWARDS == "Yes" ]] - then - get-animes-award - fi - if [[ $SEASON_YEAR == "Yes" ]] - then - get-animes-season-year - if [[ $cours_count -gt 1 ]] - then - all_cours_anime_season=$(printf "%s,%s" "$anime_season" "$all_cours_anime_season") - else - all_cours_anime_season=$anime_season fi - fi - else - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" | tee -a "$LOG" - printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" >> "$MATCH_LOG" - ((score_1_no_rating_cours++)) - ((score_2_no_rating_cours++)) + done fi - total-cour-rating-1 - total-cour-rating-2 - done - anime_season=$all_cours_anime_season - if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] - then - if [[ "$total_1_cours_score" != 0 ]] + get-cour-rating-1 + get-cour-rating-2 + if [[ $ANIME_AWARDS == "Yes" ]] + then + get-animes-award + fi + if [[ $SEASON_YEAR == "Yes" ]] then - total_1_cours=$((cours_count - score_1_no_rating_cours)) - if [[ "$total_1_cours" != 0 ]] + get-animes-season-year + if [[ $cours_count -gt 1 ]] then - score_1_season=$(echo | awk -v v1="$total_1_cours_score" -v v2="$total_1_cours" '{print v1 / v2}') - score_1_season=$(printf '%.*f\n' 1 "$score_1_season") + all_cours_anime_season=$(printf "%s,%s" "$anime_season" "$all_cours_anime_season") else - score_1_season=0 - ((score_1_no_rating_seasons++)) + all_cours_anime_season=$anime_season fi - else - score_1_season=0 - ((score_1_no_rating_seasons++)) fi + else + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" | tee -a "$LOG" + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s cour : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$cours_count" "$plex_title" >> "$MATCH_LOG" + ((score_1_no_rating_cours++)) + ((score_2_no_rating_cours++)) fi - if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] + total-cour-rating-1 + total-cour-rating-2 + done + anime_season=$all_cours_anime_season + if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]] + then + if [[ "$total_1_cours_score" != 0 ]] then - if [[ "$total_2_cours_score" != 0 ]] + total_1_cours=$((cours_count - score_1_no_rating_cours)) + if [[ "$total_1_cours" != 0 ]] then - total_2_cours=$((cours_count - score_2_no_rating_cours)) - if [[ "$total_2_cours" != 0 ]] - then - score_2_season=$(echo | awk -v v1="$total_2_cours_score" -v v2="$total_2_cours" '{print v1 / v2}') - score_2_season=$(printf '%.*f\n' 1 "$score_2_season") - else - score_2_season=0 - ((score_2_no_rating_seasons++)) - fi + score_1_season=$(echo | awk -v v1="$total_1_cours_score" -v v2="$total_1_cours" '{print v1 / v2}') + score_1_season=$(printf '%.*f\n' 1 "$score_1_season") else score_1_season=0 ((score_1_no_rating_seasons++)) fi + else + score_1_season=0 + ((score_1_no_rating_seasons++)) fi - cours_count_total=0 - anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) - if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] + fi + if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]] + then + if [[ "$total_2_cours_score" != 0 ]] then - anilist_id=$anilist_backup_id + total_2_cours=$((cours_count - score_2_no_rating_cours)) + if [[ "$total_2_cours" != 0 ]] + then + score_2_season=$(echo | awk -v v1="$total_2_cours_score" -v v2="$total_2_cours" '{print v1 / v2}') + score_2_season=$(printf '%.*f\n' 1 "$score_2_season") + else + score_2_season=0 + ((score_2_no_rating_seasons++)) + fi + else + score_1_season=0 + ((score_1_no_rating_seasons++)) fi + fi + cours_count_total=0 + anilist_id=$(jq --arg tvdb_id "$tvdb_id" --arg season_number "$season_number" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == $season_number ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1) + if [ -n "$override_id" ] && [[ $season_number -eq 1 ]] + then + anilist_id=$anilist_backup_id + fi + if [[ -z "$anilist_id" ]] + then + printf "%s\t\t - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" | tee -a "$LOG" + printf "%s - Missing Anilist ID for tvdb : %s - Season : %s / %s\n" "$(date +%H:%M:%S)" "$tvdb_id" "$season_number" "$plex_title" >> "$MATCH_LOG" + ((score_1_no_rating_seasons++)) + ((score_2_no_rating_seasons++)) + else romaji_title=$(get-romaji-title) english_title=$(get-english-title) printf " %s:\n" "$season_number" >> "$METADATA" From f019ee38d8b45a10f2326510150f8c41f3805f95 Mon Sep 17 00:00:00 2001 From: Arialz Date: Mon, 18 Nov 2024 18:16:06 +0100 Subject: [PATCH 83/86] Add Check anilist API status --- functions.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/functions.sh b/functions.sh index 0c4d155..752afbe 100644 --- a/functions.sh +++ b/functions.sh @@ -147,6 +147,12 @@ function get-anilist-infos () { -H 'content-type: application/json' \ --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { relations { edges { relationType node { id type format title { romaji } status } } } title { romaji(stylised: false) english(stylised: false) native(stylised: false) } averageScore genres tags { name rank } studios { edges { node { name isAnimationStudio } } } startDate { year month } season seasonYear coverImage { extraLarge } status idMal} }" }' > "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") + if jq '.errors[].status' -r "$SCRIPT_FOLDER/data/anilist-$anilist_id.json" | grep -q -w "403" + then + rm "$SCRIPT_FOLDER/data/anilist-$anilist_id.json" + printf "%s - Error AniList API down, exiting\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + fi ((wait_time++)) if [[ $wait_time == 4 ]] then From 1d414453cbec68ce8565ccb60948c2116cb8a9c3 Mon Sep 17 00:00:00 2001 From: Arialz Date: Mon, 18 Nov 2024 18:26:31 +0100 Subject: [PATCH 84/86] revert API check --- functions.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/functions.sh b/functions.sh index 752afbe..0c4d155 100644 --- a/functions.sh +++ b/functions.sh @@ -147,12 +147,6 @@ function get-anilist-infos () { -H 'content-type: application/json' \ --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { relations { edges { relationType node { id type format title { romaji } status } } } title { romaji(stylised: false) english(stylised: false) native(stylised: false) } averageScore genres tags { name rank } studios { edges { node { name isAnimationStudio } } } startDate { year month } season seasonYear coverImage { extraLarge } status idMal} }" }' > "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") - if jq '.errors[].status' -r "$SCRIPT_FOLDER/data/anilist-$anilist_id.json" | grep -q -w "403" - then - rm "$SCRIPT_FOLDER/data/anilist-$anilist_id.json" - printf "%s - Error AniList API down, exiting\n" "$(date +%H:%M:%S)" | tee -a "$LOG" - exit 1 - fi ((wait_time++)) if [[ $wait_time == 4 ]] then From 1b5c1ac4ea5c45c8a58baa6bacfebd530f9bf29c Mon Sep 17 00:00:00 2001 From: Arialz Date: Mon, 18 Nov 2024 18:50:37 +0100 Subject: [PATCH 85/86] Stop script if Anilist API down --- animes-renamer.sh | 6 ++++++ functions.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/animes-renamer.sh b/animes-renamer.sh index 898f7c0..e117c3b 100755 --- a/animes-renamer.sh +++ b/animes-renamer.sh @@ -100,6 +100,12 @@ do -X POST \ -H 'content-type: application/json' \ --data '{ "query": "{ Page(page: '"$ongoingpage"', perPage: 50) { pageInfo { hasNextPage } media(type: ANIME, status_in: RELEASING, sort: POPULARITY_DESC) { id } } }" }' > "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" + if grep -q -w '"data": null' "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" + then + rm "$SCRIPT_FOLDER/config/tmp/ongoing-anilist.json" + printf "%s - Error AniList API down, exiting\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + fi rate_limit=0 rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") ((wait_time++)) diff --git a/functions.sh b/functions.sh index 0c4d155..a75e3f4 100644 --- a/functions.sh +++ b/functions.sh @@ -67,6 +67,12 @@ function get-anilist-userlist { -X POST \ -H 'content-type: application/json' \ --data '{ "query": "{ MediaListCollection(userName: \"'"$ANILIST_USERNAME"'\" type:ANIME) { lists { name entries { mediaId } }}}" }' > "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" + if grep -q -w '"data": null' "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" + then + rm "$SCRIPT_FOLDER/config/tmp/anilist-$ANILIST_USERNAME.json" + printf "%s - Error AniList API down, exiting\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + fi rate_limit=0 rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") ((wait_time++)) @@ -146,6 +152,12 @@ function get-anilist-infos () { -X POST \ -H 'content-type: application/json' \ --data '{ "query": "{ Media(type: ANIME, id: '"$anilist_id"') { relations { edges { relationType node { id type format title { romaji } status } } } title { romaji(stylised: false) english(stylised: false) native(stylised: false) } averageScore genres tags { name rank } studios { edges { node { name isAnimationStudio } } } startDate { year month } season seasonYear coverImage { extraLarge } status idMal} }" }' > "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" -D "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt" + if grep -q -w '"data": null' "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" + then + rm "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" + printf "%s - Error AniList API down, exiting\n" "$(date +%H:%M:%S)" | tee -a "$LOG" + exit 1 + fi rate_limit=$(grep -oP '(?<=x-ratelimit-remaining: )[0-9]+' "$SCRIPT_FOLDER/config/tmp/anilist-limit-rate.txt") ((wait_time++)) if [[ $wait_time == 4 ]] From 03114cccbf8558f547837e84f0b0abe652730b70 Mon Sep 17 00:00:00 2001 From: Arial-Z <100593180+Arial-Z@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:02:22 +0100 Subject: [PATCH 86/86] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 115124c..8ba2fe1 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ DATA_CACHE_TIME=5 - Within your (PMM) config.yml add the following metadata_path, it should look like this with the default filepath: ```yml Animes: - metadata_path: + metadata_files: - file: config/metadata-animes.yml ``` Configuration finished.