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