-
Notifications
You must be signed in to change notification settings - Fork 75
/
LegacyRenamer.cs
2337 lines (1903 loc) · 71.9 KB
/
LegacyRenamer.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NLog;
using Shoko.Commons.Extensions;
using Shoko.Models.Server;
using Shoko.Plugin.Abstractions;
using Shoko.Plugin.Abstractions.Attributes;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Server.Models;
using Shoko.Server.Repositories;
using Shoko.Server.Server;
using Shoko.Server.Utilities;
using EpisodeType = Shoko.Models.Enums.EpisodeType;
namespace Shoko.Server.Renamer;
[Renamer(RENAMER_ID, Description = "Legacy")]
public class LegacyRenamer : IRenamer
{
private const string RENAMER_ID = "Legacy";
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public string GetFilename(RenameEventArgs args)
{
if (args.Script == null)
{
throw new Exception("*Error: No script available for renamer");
}
if (args.Script.Type != RENAMER_ID && args.Script.Type != GroupAwareRenamer.RENAMER_ID)
{
return null;
}
return GetNewFileName(args, args.Script.Script);
}
public (IImportFolder destination, string subfolder) GetDestination(MoveEventArgs args)
{
if (args.Script == null)
{
throw new Exception("*Error: No script available for renamer");
}
return GetDestinationFolder(args);
}
private static readonly char[] validTests = "AGFEHXRTYDSCIZJWUMN".ToCharArray();
/* TESTS
A int Anime id
G int Group id
F int File version (ie 1, 2, 3 etc) Can use ! , > , >= , < , <=
E text Episode number
H text Episode Type (E=episode, S=special, T=trailer, C=credit, P=parody, O=other)
X text Total number of episodes
R text Rip source [Blu-ray, unknown, camcorder, TV, DTV, VHS, VCD, SVCD, LD, DVD, HKDVD, www]
T text Type [unknown, TV, OVA, Movie, Other, web]
Y int Year
D text Dub language (one of the audio tracks) [japanese, english, ...]
S text Sub language (one of the subtitle tracks) [japanese, english, ...]
C text Video Codec (one of the video tracks) [H264/AVC, DivX5/6, unknown, VP Other, WMV9 (also WMV3), XviD, ...]
J text Audio Codec (one of the audio tracks) [AC3, FLAC, MP3 CBR, MP3 VBR, Other, unknown, Vorbis (Ogg Vorbis) ...]
I text Tag has a value. Do not use %, i.e. I(eng) [eng, kan, rom, ...]
Z int Video Bith Depth [8,10]
W int Video Resolution Width [720, 1280, 1920, ...]
U int Video Resolution Height [576, 720, 1080, ...]
M null empty - test whether the file is manually linked
*/
/* TESTS - Alphabetical
A int Anime id
C text Video Codec (one of the video tracks) [H264/AVC, DivX5/6, unknown, VP Other, WMV9 (also WMV3), XviD, ...]
D text Dub language (one of the audio tracks) [japanese, english, ...]
E text Episode number
F int File version (ie 1, 2, 3 etc) Can use ! , > , >= , < , <=
G int Group id
H text Episode Type (E=episode, S=special, T=trailer, C=credit, P=parody, O=other)
I text Tag has a value. Do not use %, i.e. I(eng) [eng, kan, rom, ...]
J text Audio Codec (one of the audio tracks) [AC3, FLAC, MP3 CBR, MP3 VBR, Other, unknown, Vorbis (Ogg Vorbis) ...]
M null empty - test whether the file is manually linked
N null empty - test whether the file has any episodes linked to it
R text Rip source [Blu-ray, unknown, camcorder, TV, DTV, VHS, VCD, SVCD, LD, DVD, HKDVD, www]
S text Sub language (one of the subtitle tracks) [japanese, english, ...]
T text Type [unknown, TV, OVA, Movie, Other, web]
U int Video Resolution Height [576, 720, 1080, ...]
W int Video Resolution Width [720, 1280, 1920, ...]
X text Total number of episodes
Y int Year
Z int Video Bith Depth [8,10]
*/
/// <summary>
/// Test if the file belongs to the specified anime
/// </summary>
/// <param name="test"></param>
/// <param name="episodes"></param>
/// <returns></returns>
private static bool EvaluateTestA(string test, List<AniDB_Episode> episodes)
{
try
{
var notCondition = false;
if (test.Substring(0, 1).Equals("!"))
{
notCondition = true;
test = test.Substring(1, test.Length - 1);
}
if (!int.TryParse(test, out var animeID))
{
return false;
}
if (notCondition)
{
return animeID != episodes[0].AnimeID;
}
return animeID == episodes[0].AnimeID;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
/// <summary>
/// Test if the file belongs to the specified group
/// </summary>
/// <param name="test"></param>
/// <param name="aniFile"></param>
/// <returns></returns>
private static bool EvaluateTestG(string test, SVR_AniDB_File aniFile)
{
try
{
var notCondition = false;
if (test.Substring(0, 1).Equals("!"))
{
notCondition = true;
test = test.Substring(1, test.Length - 1);
}
var groupID = 0;
//Leave groupID at 0 if "unknown".
if (!test.Equals("unknown", StringComparison.OrdinalIgnoreCase))
{
if (!int.TryParse(test, out groupID))
{
return false;
}
}
if (notCondition)
{
return groupID != aniFile.GroupID;
}
return groupID == aniFile.GroupID;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
/// <summary>
/// Test if the file is manually linked
/// No test parameter is required
/// </summary>
/// <param name="test"></param>
/// <param name="aniFile"></param>
/// <param name="episodes"></param>
/// <returns></returns>
private static bool EvaluateTestM(string test, SVR_AniDB_File aniFile, List<AniDB_Episode> episodes)
{
try
{
var notCondition = !string.IsNullOrEmpty(test) && test.Substring(0, 1).Equals("!");
// for a file to be manually linked it must NOT have an anifile, but does need episodes attached
var manuallyLinked = false;
if (aniFile == null)
{
manuallyLinked = true;
if (episodes == null || episodes.Count == 0)
{
manuallyLinked = false;
}
}
if (notCondition)
{
return !manuallyLinked;
}
return manuallyLinked;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
/// <summary>
/// Test if the file has any episodes linked
/// No test parameter is required
/// </summary>
/// <param name="test"></param>
/// <param name="aniFile"></param>
/// <param name="episodes"></param>
/// <returns></returns>
private static bool EvaluateTestN(string test, SVR_AniDB_File aniFile, List<AniDB_Episode> episodes)
{
try
{
var notCondition = !string.IsNullOrEmpty(test) && test.Substring(0, 1).Equals("!");
var epsLinked = aniFile == null && episodes != null && episodes.Count > 0;
if (notCondition)
{
return !epsLinked;
}
return epsLinked;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
/// <summary>
/// Test if this file has the specified Dub (audio) language
/// </summary>
/// <param name="test"></param>
/// <param name="aniFile"></param>
/// <returns></returns>
private static bool EvaluateTestD(string test, SVR_AniDB_File aniFile)
{
try
{
var notCondition = false;
if (test.Substring(0, 1).Equals("!"))
{
notCondition = true;
test = test.Substring(1, test.Length - 1);
}
if (aniFile == null)
{
return false;
}
return notCondition
? aniFile.Languages.All(lan =>
!lan.LanguageName.Trim().Equals(test.Trim(), StringComparison.InvariantCultureIgnoreCase))
: aniFile.Languages.Any(lan =>
lan.LanguageName.Trim().Equals(test.Trim(), StringComparison.InvariantCultureIgnoreCase));
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
/// <summary>
/// Test is this files has the specified Sub (subtitle) language
/// </summary>
/// <param name="test"></param>
/// <param name="aniFile"></param>
/// <returns></returns>
private static bool EvaluateTestS(string test, SVR_AniDB_File aniFile)
{
try
{
var notCondition = false;
if (test.Substring(0, 1).Equals("!"))
{
notCondition = true;
test = test.Substring(1, test.Length - 1);
}
if (aniFile == null)
{
return false;
}
if (
test.Trim()
.Equals(Constants.FileRenameReserved.None, StringComparison.InvariantCultureIgnoreCase) &&
aniFile.Subtitles.Count == 0)
{
return !notCondition;
}
return notCondition
? aniFile.Subtitles.All(lan =>
!lan.LanguageName.Trim().Equals(test.Trim(), StringComparison.InvariantCultureIgnoreCase))
: aniFile.Subtitles.Any(lan =>
lan.LanguageName.Trim().Equals(test.Trim(), StringComparison.InvariantCultureIgnoreCase));
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
/// <summary>
/// Test is this files is a specific version
/// </summary>
/// <param name="test"></param>
/// <param name="aniFile"></param>
/// <returns></returns>
private static bool EvaluateTestF(string test, SVR_AniDB_File aniFile)
{
try
{
ProcessNumericalOperators(ref test, out var notCondition, out var greaterThan, out var greaterThanEqual,
out var lessThan, out var lessThanEqual);
if (aniFile == null)
{
return false;
}
if (!int.TryParse(test, out var version))
{
return false;
}
var hasFileVersionOperator = greaterThan | greaterThanEqual | lessThan | lessThanEqual;
if (!hasFileVersionOperator)
{
if (!notCondition)
{
return aniFile.FileVersion == version;
}
return aniFile.FileVersion != version;
}
if (greaterThan)
{
return aniFile.FileVersion > version;
}
if (greaterThanEqual)
{
return aniFile.FileVersion >= version;
}
if (lessThan)
{
return aniFile.FileVersion < version;
}
return aniFile.FileVersion <= version;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
/// <summary>
/// Test is this file is a specific bit depth
/// </summary>
/// <param name="test"></param>
/// <param name="vid"></param>
/// <returns></returns>
private static bool EvaluateTestZ(string test, SVR_VideoLocal vid)
{
try
{
ProcessNumericalOperators(ref test, out var notCondition, out var greaterThan, out var greaterThanEqual,
out var lessThan, out var lessThanEqual);
if (!int.TryParse(test, out var testBitDepth))
{
return false;
}
if (vid.Media?.VideoStream == null)
{
return false;
}
var hasFileVersionOperator = greaterThan | greaterThanEqual | lessThan | lessThanEqual;
if (!hasFileVersionOperator)
{
if (!notCondition)
{
return testBitDepth == vid.Media?.VideoStream?.BitDepth;
}
return testBitDepth != vid.Media?.VideoStream?.BitDepth;
}
if (greaterThan)
{
return vid.Media?.VideoStream?.BitDepth > testBitDepth;
}
if (greaterThanEqual)
{
return vid.Media?.VideoStream?.BitDepth >= testBitDepth;
}
if (lessThan)
{
return vid.Media?.VideoStream?.BitDepth < testBitDepth;
}
return vid.Media?.VideoStream?.BitDepth <= testBitDepth;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
private static bool EvaluateTestW(string test, SVR_VideoLocal vid)
{
try
{
ProcessNumericalOperators(ref test, out var notCondition, out var greaterThan, out var greaterThanEqual,
out var lessThan, out var lessThanEqual);
if (vid == null)
{
return false;
}
if (!int.TryParse(test, out var testWidth))
{
return false;
}
var width = Utils.GetVideoWidth(vid.VideoResolution);
var hasFileVersionOperator = greaterThan | greaterThanEqual | lessThan | lessThanEqual;
if (!hasFileVersionOperator)
{
if (!notCondition)
{
return testWidth == width;
}
return testWidth != width;
}
if (greaterThan)
{
return width > testWidth;
}
if (greaterThanEqual)
{
return width >= testWidth;
}
if (lessThan)
{
return width < testWidth;
}
return width <= testWidth;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
private static bool EvaluateTestU(string test, SVR_VideoLocal vid)
{
try
{
ProcessNumericalOperators(ref test, out var notCondition, out var greaterThan, out var greaterThanEqual,
out var lessThan, out var lessThanEqual);
if (vid == null)
{
return false;
}
if (!int.TryParse(test, out var testHeight))
{
return false;
}
var height = Utils.GetVideoHeight(vid.VideoResolution);
var hasFileVersionOperator = greaterThan | greaterThanEqual | lessThan | lessThanEqual;
if (!hasFileVersionOperator)
{
if (!notCondition)
{
return testHeight == height;
}
return testHeight != height;
}
if (greaterThan)
{
return height > testHeight;
}
if (greaterThanEqual)
{
return height >= testHeight;
}
if (lessThan)
{
return height < testHeight;
}
return height <= testHeight;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
private static bool EvaluateTestR(string test, SVR_AniDB_File aniFile)
{
try
{
var notCondition = false;
if (test.Substring(0, 1).Equals("!"))
{
notCondition = true;
test = test.Substring(1, test.Length - 1);
}
if (aniFile == null)
{
return false;
}
var hasSource = !string.IsNullOrEmpty(aniFile.File_Source);
if (
test.Trim()
.Equals(Constants.FileRenameReserved.Unknown, StringComparison.InvariantCultureIgnoreCase) &&
!hasSource)
{
return !notCondition;
}
if (test.Trim().Equals(aniFile.File_Source, StringComparison.InvariantCultureIgnoreCase))
{
return !notCondition;
}
return notCondition;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
private static bool EvaluateTestT(string test, SVR_AniDB_Anime anime)
{
try
{
var notCondition = false;
if (test.Substring(0, 1).Equals("!"))
{
notCondition = true;
test = test.Substring(1, test.Length - 1);
}
var hasType = !string.IsNullOrEmpty(anime.GetAnimeTypeRAW());
if (
test.Trim()
.Equals(Constants.FileRenameReserved.Unknown, StringComparison.InvariantCultureIgnoreCase) &&
!hasType)
{
return !notCondition;
}
if (test.Trim().Equals(anime.GetAnimeTypeRAW(), StringComparison.InvariantCultureIgnoreCase))
{
return !notCondition;
}
return notCondition;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
private static bool EvaluateTestY(string test, SVR_AniDB_Anime anime)
{
try
{
ProcessNumericalOperators(ref test, out var notCondition, out var greaterThan, out var greaterThanEqual,
out var lessThan, out var lessThanEqual);
if (!int.TryParse(test, out var testYear))
{
return false;
}
var hasFileVersionOperator = greaterThan | greaterThanEqual | lessThan | lessThanEqual;
if (!hasFileVersionOperator)
{
if (!notCondition)
{
return anime.BeginYear == testYear;
}
return anime.BeginYear != testYear;
}
if (greaterThan)
{
return anime.BeginYear > testYear;
}
if (greaterThanEqual)
{
return anime.BeginYear >= testYear;
}
if (lessThan)
{
return anime.BeginYear < testYear;
}
return anime.BeginYear <= testYear;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
private static bool EvaluateTestE(string test, List<AniDB_Episode> episodes)
{
try
{
ProcessNumericalOperators(ref test, out var notCondition, out var greaterThan, out var greaterThanEqual,
out var lessThan, out var lessThanEqual);
if (!int.TryParse(test, out var testEpNumber))
{
return false;
}
var hasFileVersionOperator = greaterThan | greaterThanEqual | lessThan | lessThanEqual;
if (!hasFileVersionOperator)
{
if (!notCondition)
{
return episodes[0].EpisodeNumber == testEpNumber;
}
return episodes[0].EpisodeNumber != testEpNumber;
}
if (greaterThan)
{
return episodes[0].EpisodeNumber > testEpNumber;
}
if (greaterThanEqual)
{
return episodes[0].EpisodeNumber >= testEpNumber;
}
if (lessThan)
{
return episodes[0].EpisodeNumber < testEpNumber;
}
return episodes[0].EpisodeNumber <= testEpNumber;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
private static bool EvaluateTestH(string test, List<AniDB_Episode> episodes)
{
try
{
var notCondition = false;
if (test.Substring(0, 1).Equals("!"))
{
notCondition = true;
test = test.Substring(1, test.Length - 1);
}
var epType = string.Empty;
switch (episodes[0].GetEpisodeTypeEnum())
{
case EpisodeType.Episode:
epType = "E";
break;
case EpisodeType.Credits:
epType = "C";
break;
case EpisodeType.Other:
epType = "O";
break;
case EpisodeType.Parody:
epType = "P";
break;
case EpisodeType.Special:
epType = "S";
break;
case EpisodeType.Trailer:
epType = "T";
break;
}
if (test.Trim().Equals(epType, StringComparison.InvariantCultureIgnoreCase))
{
return !notCondition;
}
return notCondition;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
/// <summary>
/// Takes the the test parameters and checks for numerical operators
/// Removes the operators from the test string passed
/// </summary>
/// <param name="test"></param>
/// <param name="notCondition"></param>
/// <param name="greaterThan"></param>
/// <param name="greaterThanEqual"></param>
/// <param name="lessThan"></param>
/// <param name="lessThanEqual"></param>
private static void ProcessNumericalOperators(ref string test, out bool notCondition, out bool greaterThan,
out bool greaterThanEqual, out bool lessThan, out bool lessThanEqual)
{
notCondition = false;
if (test.Substring(0, 1).Equals("!"))
{
notCondition = true;
test = test.Substring(1, test.Length - 1);
}
greaterThan = false;
greaterThanEqual = false;
if (test.Substring(0, 1).Equals(">"))
{
greaterThan = true;
test = test.Substring(1, test.Length - 1);
if (test.Substring(0, 1).Equals("="))
{
greaterThan = false;
greaterThanEqual = true;
test = test.Substring(1, test.Length - 1);
}
}
lessThan = false;
lessThanEqual = false;
if (!test.Substring(0, 1).Equals("<"))
{
return;
}
lessThan = true;
test = test.Substring(1, test.Length - 1);
if (!test.Substring(0, 1).Equals("="))
{
return;
}
lessThan = false;
lessThanEqual = true;
test = test.Substring(1, test.Length - 1);
}
private static bool EvaluateTestX(string test, SVR_AniDB_Anime anime)
{
try
{
ProcessNumericalOperators(ref test, out var notCondition, out var greaterThan, out var greaterThanEqual,
out var lessThan, out var lessThanEqual);
if (!int.TryParse(test, out var epCount))
{
return false;
}
var hasFileVersionOperator = greaterThan | greaterThanEqual | lessThan | lessThanEqual;
if (!hasFileVersionOperator)
{
if (!notCondition)
{
return anime.EpisodeCountNormal == epCount;
}
return anime.EpisodeCountNormal != epCount;
}
if (greaterThan)
{
return anime.EpisodeCountNormal > epCount;
}
if (greaterThanEqual)
{
return anime.EpisodeCountNormal >= epCount;
}
if (lessThan)
{
return anime.EpisodeCountNormal < epCount;
}
return anime.EpisodeCountNormal <= epCount;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return false;
}
}
/// <summary>
/// Test whether the specified tag has a value
/// </summary>
/// <param name="test"></param>
/// <param name="vid"></param>
/// <param name="aniFile"></param>
/// <param name="episodes"></param>
/// <param name="anime"></param>
/// <returns></returns>
private static bool EvaluateTestI(string test, SVR_VideoLocal vid, SVR_AniDB_File aniFile,
List<AniDB_Episode> episodes,
SVR_AniDB_Anime anime)
{
try
{
var notCondition = false;
if (test.Substring(0, 1).Equals("!"))
{
notCondition = true;
test = test.Substring(1, test.Length - 1);
}
if (anime == null)
{
return false;
}
#region Test if Anime ID exists
// Test if Anime ID exists
var tagAnimeID = Constants.FileRenameTag.AnimeID.Substring(1,
Constants.FileRenameTag.AnimeID.Length - 1); // remove % at the front
if (test.Trim().Equals(tagAnimeID, StringComparison.InvariantCultureIgnoreCase))
{
// manually linked files won't have an anime id
if (aniFile != null)
{
if (notCondition)
{
return false;
}
return true;
}
if (notCondition)
{
return true;
}
return false;
}
#endregion
#region Test if Group ID exists
// Test if Group ID exists
var tagGroupID = Constants.FileRenameTag.GroupID.Substring(1,
Constants.FileRenameTag.GroupID.Length - 1); // remove % at the front
if (test.Trim().Equals(tagGroupID, StringComparison.InvariantCultureIgnoreCase))
{
// manually linked files won't have an group id
if (aniFile != null)
{
if (notCondition)
{
return false;
}
return true;
}
if (notCondition)
{
return false;
}
return true;
}
#endregion
#region Test if Original File Name exists
// Test if Original File Nameexists
var tagOriginalFileName = Constants.FileRenameTag.OriginalFileName.Substring(1,
Constants.FileRenameTag.OriginalFileName.Length - 1); // remove % at the front
if (test.Trim().Equals(tagOriginalFileName, StringComparison.InvariantCultureIgnoreCase))
{
// manually linked files won't have an Original File Name
if (aniFile != null)
{
if (string.IsNullOrEmpty(aniFile.FileName))
{
return notCondition;
}
return !notCondition;
}
return notCondition;
}
#endregion
#region Test if Episode Number exists
// Test if Episode Number exists
var tagEpisodeNumber = Constants.FileRenameTag.EpisodeNumber.Substring(1,
Constants.FileRenameTag.EpisodeNumber.Length - 1); // remove % at the front
if (test.Trim().Equals(tagEpisodeNumber, StringComparison.InvariantCultureIgnoreCase))
{
// manually linked files won't have an Episode Number
if (aniFile != null)
{
return !notCondition;
}
return notCondition;
}
#endregion
#region Test file version
// Test if Group Short Name exists - yes it always does