-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.sh
1298 lines (1296 loc) · 45.1 KB
/
functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#General variables
LOG=$LOG_FOLDER/RR_$(date +%Y.%m.%d).log
MATCH_LOG=$LOG_FOLDER/${media_type}-missing-id.log
# functions
function create-override () {
if [ ! -f "$SCRIPT_FOLDER/config/$OVERRIDE" ]
then
cp "$SCRIPT_FOLDER/config/override-ID-${media_type}.example.tsv" "$SCRIPT_FOLDER/config/$OVERRIDE"
fi
}
function download-anime-id-mapping () {
wait_time=0
while [ $wait_time -lt 5 ];
do
printf "%s - Downloading animes mapping\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
if [[ $media_type == "animes" ]]
then
curl -s "https://raw.githubusercontent.com/Arial-Z/Animes-ID/main/list-animes-id.json" > "$SCRIPT_FOLDER/config/tmp/list-animes-id.json"
size=$(du -b "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | awk '{ print $1 }')
else
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 [[ $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" "$(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
fi
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"
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++))
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
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
printf "%s\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
break
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\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 () {
if [[ $media_type == "animes" ]]
then
jq --arg tvdb_id "$tvdb_id" '.[] | select( .tvdb_id == $tvdb_id ) | select( .tvdb_season == "1" or .tvdb_season == "-1" ) | select( .tvdb_epoffset == "0" ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1
else
jq --arg imdb_id "$imdb_id" '.[] | select( .imdb_id == $imdb_id ) | .anilist_id' -r "$SCRIPT_FOLDER/config/tmp/list-movies-id.json" | head -n 1
fi
}
function get-mal-id () {
mal_id=$(jq '.data.Media.idMal' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
if [[ $mal_id == 'null' ]] || [[ -z $mal_id ]]
then
if [[ $media_type == "animes" ]]
then
mal_id=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | .mal_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json" | head -n 1)
else
mal_id=$(jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | .mal_id' -r "$SCRIPT_FOLDER/config/tmp/list-movies-id.json" | head -n 1)
fi
fi
}
function get-tvdb-id () {
jq --arg anilist_id "$anilist_id" '.[] | select( .anilist_id == $anilist_id ) | .tvdb_id' -r "$SCRIPT_FOLDER/config/tmp/list-animes-id.json"
}
function get-anilist-infos () {
if [ ! -f "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" ]
then
wait_time=0
while [ $wait_time -lt 5 ];
do
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
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} }" }' > "$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 ]]
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
elif [[ $rate_limit -ge 3 ]]
then
sleep 1
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
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
fi
done
fi
}
function get-mal-infos () {
mal_id=""
get-mal-id
if [[ $mal_id == 'null' ]] || [[ -z $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
if [ ! -f "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json" ]
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"
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
printf "%s\t\t - Downloading data for MAL : %s\n" "$(date +%H:%M:%S)" "$mal_id" | tee -a "$LOG"
fi
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"
if grep -q -w "429" "$SCRIPT_FOLDER/config/tmp/jikan-limit-rate.txt"
then
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"
fi
fi
}
function get-romaji-title () {
title="null"
title_tmp="null"
if awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/$OVERRIDE" | grep -q -w "$anilist_id"
then
line=$(awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/$OVERRIDE" | grep -w -n "$anilist_id" | cut -d : -f 1)
title_tmp=$(sed -n "${line}p" "$SCRIPT_FOLDER/config/$OVERRIDE" | awk -F"\t" '{print $3}')
if [[ -z "$title_tmp" ]]
then
title=$(jq '.data.Media.title.romaji' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
less-caps-title
echo "$title"
else
title="$title_tmp"
less-caps-title
echo "$title"
fi
else
title=$(jq '.data.Media.title.romaji' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
less-caps-title
echo "$title"
fi
}
function get-english-title () {
title="null"
title_tmp="null"
if awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/$OVERRIDE" | grep -q -w "$anilist_id"
then
line=$(awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/$OVERRIDE" | grep -w -n "$anilist_id" | cut -d : -f 1)
title_tmp=$(sed -n "${line}p" "$SCRIPT_FOLDER/config/$OVERRIDE" | awk -F"\t" '{print $3}')
if [[ -z "$title_tmp" ]]
then
title=$(jq '.data.Media.title.english' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
less-caps-title
echo "$title"
else
title="$title_tmp"
less-caps-title
echo "$title"
fi
else
title=$(jq '.data.Media.title.english' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
less-caps-title
echo "$title"
fi
}
function get-native-title () {
title=$(jq '.data.Media.title.native' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
echo "$title"
}
function less-caps-title () {
if [[ $REDUCE_TITLE_CAPS == "Yes" ]]
then
upper_check=$(echo "$title" | sed -e "s/[^ a-zA-Z]//g" -e 's/ //g')
if [[ "$upper_check" =~ ^[A-Z]+$ ]]
then
title=$(echo "$title" | tr '[:upper:]' '[:lower:]' | sed "s/\( \|^\)\(.\)/\1\u\2/g")
fi
fi
}
function get-score () {
anime_score=0
anime_score=$(jq '.data.Media.averageScore' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
if [[ "$anime_score" == "null" ]] || [[ "$anime_score" == "" ]]
then
rm "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json"
get-anilist-infos
anime_score=$(jq '.data.Media.averageScore' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
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}')
fi
}
function get-mal-score () {
mal_id=""
get-mal-id
if [[ $mal_id == 'null' ]] || [[ -z $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
anime_score=0
get-mal-infos
anime_score=$(jq '.data.score' -r "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json")
if [[ "$anime_score" == "null" ]] || [[ "$anime_score" == "" ]]
then
rm "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json"
get-mal-infos
anime_score=$(jq '.data.score' -r "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json")
if [[ "$anime_score" == "null" ]] || [[ "$anime_score" == "" ]]
then
anime_score=0
fi
fi
fi
}
function get-tags () {
(jq '.data.Media.genres | .[]' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" && jq --argjson anilist_tags_p "$ANILIST_TAGS_P" '.data.Media.tags | .[] | select( .rank >= $anilist_tags_p ) | .name' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json") | awk '{print $0}' | paste -sd ','
}
function get-studios() {
if awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/$OVERRIDE" | grep -q -w "$anilist_id"
then
line=$(awk -F"\t" '{print $2}' "$SCRIPT_FOLDER/config/$OVERRIDE" | grep -w -n "$anilist_id" | cut -d : -f 1)
studio=$(sed -n "${line}p" "$SCRIPT_FOLDER/config/$OVERRIDE" | awk -F"\t" '{print $4}')
if [[ -z "$studio" ]]
then
studio=$(jq '.data.Media.studios.edges[].node | select( .isAnimationStudio == true ) | .name' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | head -n 1)
if [[ -z "$studio" ]]
then
studio=$(jq '.data.Media.studios.edges[].node | .name' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | head -n 1)
fi
fi
else
studio=$(jq '.data.Media.studios.edges[].node | select( .isAnimationStudio == true ) | .name' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | head -n 1)
if [[ -z "$studio" ]]
then
studio=$(jq '.data.Media.studios.edges[].node | .name' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json" | head -n 1)
fi
fi
}
function get-animes-season-year () {
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")
month_season=$(jq '.data.Media.startDate.month' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
if [[ $month_season -le 3 ]]
then
name_season=Winter
elif [[ $month_season -ge 4 && $month_season -le 6 ]]
then
name_season=Spring
elif [[ $month_season -ge 7 && $month_season -le 9 ]]
then
name_season=Summer
elif [[ $month_season -ge 10 ]]
then
name_season=Fall
fi
anime_season=$(printf "%s %s" "$year_season" "$name_season")
fi
}
function get-animes-award () {
award_check=""
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
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
if [[ -n $award_check ]]
then
cr_awards=$award_check
fi
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
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
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")
if [ -z "$sequel_data" ]
then
airing_status="Ended"
anilist_id=$anilist_backup_id
break
else
sequel_check=$(printf "%s" "$sequel_data" | jq 'select ( .format == "TV" or .format == "ONA" or .format == "MOVIE" )')
if echo "$sequel_check" | grep -q -w "NOT_YET_RELEASED"
then
airing_status="Planned"
anilist_id=$anilist_backup_id
break
else
anilist_id=$(printf "%s" "$sequel_data" | jq '.id')
sequel_multi_check=$(printf %s "$anilist_id" | wc -l)
if [[ $sequel_multi_check -gt 0 ]]
then
printf "%s" "$anilist_id" > "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.txt"
anilist_id=$( printf "%s" "$anilist_id" | head -n 1)
((last_sequel_found++))
else
((last_sequel_found++))
fi
fi
fi
else
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"
anilist_id=$anilist_backup_id
break
else
sequel_check=$(printf "%s" "$sequel_data" | jq 'select ( .format == "TV" or .format == "ONA" or .format == "MOVIE" )')
if echo "$sequel_check" | grep -q -w "NOT_YET_RELEASED"
then
airing_status="Planned"
anilist_id=$anilist_backup_id
break
else
anilist_id=$(printf "%s" "$sequel_data" | jq '.id')
sequel_multi_check=$(printf %s "$anilist_id" | wc -l)
if [[ $sequel_multi_check -gt 0 ]]
then
printf "%s\n" "$anilist_id" > "$SCRIPT_FOLDER/config/tmp/airing_sequel_tmp.txt"
anilist_id=$( printf "%s" "$anilist_id" | head -n 1)
((last_sequel_found++))
else
((last_sequel_found++))
fi
fi
fi
fi
done
airing_loop=0
anilist_id=$anilist_backup_id
if [[ $last_sequel_found -ge 50 ]]
then
airing_status="Ended"
fi
fi
}
function get-poster () {
if [[ $POSTER_DOWNLOAD == "Yes" ]]
then
if [ ! -f "$ASSET_FOLDER/$asset_name/poster.jpg" ]
then
if [ ! -d "$ASSET_FOLDER/$asset_name" ]
then
mkdir "$ASSET_FOLDER/$asset_name"
fi
if [[ $POSTER_SOURCE == "MAL" ]]
then
get-mal-infos
printf "%s\t\t - Downloading poster for MAL : %s\n" "$(date +%H:%M:%S)" "$mal_id" | tee -a "$LOG"
poster_url=$(jq '.data.images.jpg.large_image_url' -r "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json")
curl -s "$poster_url" -o "$ASSET_FOLDER/$asset_name/poster.jpg"
sleep 1.5
printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
else
printf "%s\t\t - Downloading poster for anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG"
poster_url=$(jq '.data.Media.coverImage.extraLarge' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
curl -s "$poster_url" -o "$ASSET_FOLDER/$asset_name/poster.jpg"
sleep 0.5
printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
fi
else
postersize=$(du -b "$ASSET_FOLDER/$asset_name/poster.jpg" | awk '{ print $1 }')
if [[ $postersize -lt 10000 ]]
then
rm "$ASSET_FOLDER/$asset_name/poster.jpg"
if [ ! -d "$ASSET_FOLDER/$asset_name" ]
then
mkdir "$ASSET_FOLDER/$asset_name"
fi
if [[ $POSTER_SOURCE == "MAL" ]]
then
get-mal-infos
printf "%s\t\t - Downloading poster for MAL : %s\n" "$(date +%H:%M:%S)" "$mal_id" | tee -a "$LOG"
poster_url=$(jq '.data.images.jpg.large_image_url' -r "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json")
curl -s "$poster_url" -o "$ASSET_FOLDER/$asset_name/poster.jpg"
sleep 1.5
printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
else
printf "%s\t\t - Downloading poster for anilist : %s\n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG"
poster_url=$(jq '.data.Media.coverImage.extraLarge' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
curl -s "$poster_url" -o "$ASSET_FOLDER/$asset_name/poster.jpg"
sleep 0.5
printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
fi
fi
fi
fi
}
function get-season-poster () {
if [[ $POSTER_SEASON_DOWNLOAD == "Yes" ]]
then
if [[ $season_number -lt 10 ]]
then
assets_filepath="$ASSET_FOLDER/$asset_name/Season0$season_number.jpg"
else
assets_filepath="$ASSET_FOLDER/$asset_name/Season$season_number.jpg"
fi
if [ ! -f "$assets_filepath" ]
then
if [ ! -d "$ASSET_FOLDER/$asset_name" ]
then
mkdir "$ASSET_FOLDER/$asset_name"
fi
if [[ $POSTER_SOURCE == "MAL" ]]
then
get-mal-infos
printf "%s\t\t - Downloading poster for S%s MAL : %s\n" "$(date +%H:%M:%S)" "$season_number" "$mal_id" | tee -a "$LOG"
poster_url=$(jq '.data.images.jpg.large_image_url' -r "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json")
curl -s "$poster_url" -o "$assets_filepath"
sleep 1.5
printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
else
printf "%s\t\t - Downloading poster for S%s anilist : %s\n" "$(date +%H:%M:%S)" "$season_number" "$anilist_id" | tee -a "$LOG"
poster_url=$(jq '.data.Media.coverImage.extraLarge' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
curl -s "$poster_url" -o "$assets_filepath"
sleep 0.5
printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
fi
else
postersize=$(du -b "$assets_filepath" | awk '{ print $1 }')
if [[ $postersize -lt 10000 ]]
then
rm "$assets_filepath"
if [ ! -d "$ASSET_FOLDER/$asset_name" ]
then
mkdir "$ASSET_FOLDER/$asset_name"
fi
if [[ $POSTER_SOURCE == "MAL" ]]
then
get-mal-infos
printf "%s\t\t - Downloading poster S%s MAL : %s\n" "$(date +%H:%M:%S)" "$season_number" "$mal_id" | tee -a "$LOG"
poster_url=$(jq '.data.images.jpg.large_image_url' -r "$SCRIPT_FOLDER/config/data/MAL-$mal_id.json")
curl -s "$poster_url" -o "$assets_filepath"
sleep 1.5
printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
else
printf "%s\t\t - Downloading poster S%s anilist : %s\n" "$(date +%H:%M:%S)" "$season_number" "$anilist_id" | tee -a "$LOG"
poster_url=$(jq '.data.Media.coverImage.extraLarge' -r "$SCRIPT_FOLDER/config/data/anilist-$anilist_id.json")
curl -s "$poster_url" -o "$assets_filepath"
sleep 0.5
printf "%s\t\t - Done\n" "$(date +%H:%M:%S)" | tee -a "$LOG"
fi
fi
fi
fi
}
function get-rating-1 () {
if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]]
then
if [[ $RATING_1_SOURCE == "ANILIST" ]]
then
get-score
score_1=$anime_score
else
get-mal-score
score_1=$anime_score
fi
fi
if [[ "$score_1" == 0 ]]
then
if [[ $RATING_1_SOURCE == "ANILIST" ]]
then
printf "%s\t\t - invalid rating for Anilist : %s skipping \n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG"
else
printf "%s\t\t - invalid rating for MAL : %s skipping \n" "$(date +%H:%M:%S)" "$mal_id" | tee -a "$LOG"
fi
else
score_1=$(printf '%.*f\n' 1 "$score_1")
printf " %s_rating: %s\n" "$RATING_1_TYPE" "$score_1" >> "$METADATA"
fi
}
function get-season-rating-1 () {
if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]]
then
if [[ $RATING_1_SOURCE == "ANILIST" ]]
then
get-score
score_1_season=$anime_score
else
get-mal-score
score_1_season=$anime_score
fi
score_1_season=$(printf '%.*f\n' 1 "$score_1_season")
if [[ "$score_1_season" == 0.0 ]]
then
((score_1_no_rating_seasons++))
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
total_1_score=$(echo | awk -v v1="$score_1_season" -v v2="$total_1_score" '{print v1 + v2}')
fi
}
function check-rating-1-valid () {
if [[ $RATING_1_SOURCE == "ANILIST" || $RATING_1_SOURCE == "MAL" ]]
then
if [[ "$score_1" == 0 ]]
then
if [[ $RATING_1_SOURCE == "ANILIST" ]]
then
printf "%s\t\t - invalid rating for Anilist : %s skipping \n" "$(date +%H:%M:%S)" "$anilist_id" | tee -a "$LOG"
else
get-mal-id
if [[ $mal_id != 'null' ]] || [[ -n $mal_id ]]
then
printf "%s\t\t - invalid rating for MAL : %s skipping \n" "$(date +%H:%M:%S)" "$mal_id" | tee -a "$LOG"
fi
fi
else
score_1=$(printf '%.*f\n' 1 "$score_1")
printf " %s_rating: %s\n" "$RATING_1_TYPE" "$score_1" >> "$METADATA"
fi
fi
}
function get-rating-2 () {
if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]]
then
if [[ $RATING_2_SOURCE == "ANILIST" ]]
then
get-score
score_2=$anime_score
else
get-mal-score
score_2=$anime_score
fi
fi
if [[ "$score_2" == 0 ]]
then
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
printf "%s\t\t - invalid rating for MAL : %s skipping \n" "$(date +%H:%M:%S)" "$mal_id" | tee -a "$LOG"
fi
else
score_2=$(printf '%.*f\n' 1 "$score_2")
printf " %s_rating: %s\n" "$RATING_2_TYPE" "$score_2" >> "$METADATA"
fi
}
function get-season-rating-2 () {
if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]]
then
if [[ $RATING_2_SOURCE == "ANILIST" ]]
then
get-score
score_2_season=$anime_score
else
get-mal-score
score_2_season=$anime_score
fi
score_2_season=$(printf '%.*f\n' 1 "$score_2_season")
if [[ "$score_2_season" == 0.0 ]]
then
((score_2_no_rating_seasons++))
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
total_2_score=$(echo | awk -v v1="$score_2_season" -v v2="$total_2_score" '{print v1 + v2}')
fi
}
function check-rating-2-valid () {
if [[ $RATING_2_SOURCE == "ANILIST" || $RATING_2_SOURCE == "MAL" ]]
then
if [[ "$score_2" == 0 ]]
then
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
get-mal-id
if [[ $mal_id == 'null' ]] || [[ -n $mal_id ]]
then
printf "%s\t\t - invalid rating for MAL : %s skipping \n" "$(date +%H:%M:%S)" "$mal_id" | tee -a "$LOG"
fi
fi
else
score_2=$(printf '%.*f\n' 1 "$score_2")
printf " %s_rating: %s\n" "$RATING_2_TYPE" "$score_2" >> "$METADATA"
fi
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))
fi
if [ -n "$valid_anilist_id" ] && [[ $season_check != -1 ]]
then
total_1_score=0
total_2_score=0
score_1_season=0
score_2_season=0
score_1_no_rating_seasons=0
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
do
if [[ $season_number -eq 0 ]]
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 ]]
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" ]]
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"
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
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++))
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
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
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"
if [[ $ALLOW_RENAMING == "Yes" && $RENAME_SEASONS == "Yes" ]]
then
printf " title: |-\n %s\n" "$romaji_title" >> "$METADATA"
fi
season_label_add=""
season_label_remove=""
if [[ -n "$cr_awards" ]]
then
if [[ -n "$season_label_add" ]]
then
season_label_add=$(printf "%s,AA Winner" "$season_label_add")
else
season_label_add="AA Winner"
fi
fi
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
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
if [[ -n "$season_userlist_type_add" ]]
then
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
if [[ -n "$seasons_userlist_type_remove" ]]
then
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" ]]
then
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
if [[ $last_season -eq 1 ]]
then
if [[ $IGNORE_S1_ONLY_RATING == "Yes" ]]
then
printf " label: %s\n" "$season_label_add" >> "$METADATA"
else