From c1de2da183a9f045083e4b0773ced47cc16013b8 Mon Sep 17 00:00:00 2001 From: Charles Lopes Date: Sat, 3 Sep 2022 21:10:49 +0100 Subject: [PATCH 1/6] Fix XML deserialization of empty elements to integers --- API.Tests/Services/ArchiveServiceTests.cs | 19 ++++++++++++++++++ .../ArchiveService/ComicInfos/ComicInfo2.zip | Bin 0 -> 2670 bytes API/Data/Metadata/ComicInfo.cs | 10 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 API.Tests/Services/Test Data/ArchiveService/ComicInfos/ComicInfo2.zip diff --git a/API.Tests/Services/ArchiveServiceTests.cs b/API.Tests/Services/ArchiveServiceTests.cs index be0662a537..ffe6fd6fe0 100644 --- a/API.Tests/Services/ArchiveServiceTests.cs +++ b/API.Tests/Services/ArchiveServiceTests.cs @@ -291,9 +291,28 @@ public void CanParseComicInfo() Web = "https://www.comixology.com/BTOOOM/digital-comic/450184" }; + // XXX: This is not doing anything useful Assert.NotStrictEqual(expected, actual); + // XXX: This also works + Assert.NotStrictEqual(null, actual); } + [Fact] + public void CanParseComicInfo2() + { + var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos"); + var archive = Path.Join(testDirectory, "ComicInfo2.zip"); + var comicInfo = _archiveService.GetComicInfo(archive); + + Assert.NotNull(comicInfo); + Assert.Equal("Hellboy", comicInfo.Series); + Assert.Equal("The Right Hand of Doom", comicInfo.Title); + Assert.Equal("", comicInfo.Number); + Assert.Equal(0, comicInfo.Count); + Assert.Equal("4", comicInfo.Volume); + } + + #endregion #region FindCoverImageFilename diff --git a/API.Tests/Services/Test Data/ArchiveService/ComicInfos/ComicInfo2.zip b/API.Tests/Services/Test Data/ArchiveService/ComicInfos/ComicInfo2.zip new file mode 100644 index 0000000000000000000000000000000000000000..b327b62d16dbedaf9d4b4a3fda17c50f5f440240 GIT binary patch literal 2670 zcmZ{mc{~%08^Gr(_bt-o3?oN!%$13;xrrp#cpJ?Xb2f5KA~w;S%W@^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*na9k$y|X&p0@iTP?6$Uy?0ihLZ;I%0`dV03PUpnEl3#TSd8djvZVB zlr6~u1{!1%V6d=uC+1T+iut`X$sIO&y&fWEoy_28~~dJUu&`C;3sr z0e)AMc^;3@7my|j;S>WxU#_(qZ_kAsnx*DSFndhJU7IK5@kv+ZHToA^`pdmVS?z3pf|0SLL- zDXH--Jtr6^)lLV`rk8~;BI>|OHEsb|A`Y9dF*pn4CUg8=F~hsYBzY4y@Its)ewI5y zUc%O29#mB1eVD9QYIpPHygHwHnVsO$hFt`O&)y}+D?9n{RAwDEouFzQlBx0hOEW=L z%MS=vJAZM0$T*WH=0quXo05R28luM#sCPIPp!aw{Mm32S-^aV;wd$dKSo}rhtU{##n=@z@*_L5eHl+%-eL@4)zPrkMG3tbQnDLm57 z_H0$E;%5O`_jMk=6l)HZ--^p~HFu`0`MBnsqeI2o?Q2}`Rt5A0t)5FkB<_axhxvVg z$XHEE@-0WxkSV3wM%mC=O`mlMzJS8kd2*7tS@0;Fx}ZL0zp!cbZVi>Ov(F!r9m+QM zC74Ae^hp9K%BB?dnUun<`pAUo6)T!q+@ST9vy5!c7h*wGy<+xQvHIF{Stsh?)8*(< zUB^nqs_P|!j4dss74N2QtbN=ExH)ohALsdh7$|puhX4TAfu?8t6a5bq^8E)2{~HM1 T9Qh9YGt6}$=MFrd;6K^lH=X)| literal 0 HcmV?d00001 diff --git a/API/Data/Metadata/ComicInfo.cs b/API/Data/Metadata/ComicInfo.cs index eb9cdb344a..37d5b2c9c7 100644 --- a/API/Data/Metadata/ComicInfo.cs +++ b/API/Data/Metadata/ComicInfo.cs @@ -23,6 +23,8 @@ public class ComicInfo /// /// The total number of items in the series. /// + // This should really be -1 according to anansi-project spec + [System.ComponentModel.DefaultValueAttribute(0)] public int Count { get; set; } = 0; public string Volume { get; set; } = string.Empty; public string Notes { get; set; } = string.Empty; @@ -37,8 +39,14 @@ public class ComicInfo /// This is the link to where the data was scraped from /// public string Web { get; set; } = string.Empty; + // This should really be -1 according to anansi-project spec + [System.ComponentModel.DefaultValueAttribute(0)] public int Day { get; set; } = 0; + // This should really be -1 according to anansi-project spec + [System.ComponentModel.DefaultValueAttribute(0)] public int Month { get; set; } = 0; + // This should really be -1 according to anansi-project spec + [System.ComponentModel.DefaultValueAttribute(0)] public int Year { get; set; } = 0; @@ -54,6 +62,8 @@ public class ComicInfo public string StoryArc { get; set; } = string.Empty; public string SeriesGroup { get; set; } = string.Empty; public string AlternateNumber { get; set; } = string.Empty; + // This should really be -1 according to anansi-project spec + [System.ComponentModel.DefaultValueAttribute(0)] public int AlternateCount { get; set; } = 0; public string AlternateSeries { get; set; } = string.Empty; From 7e12f5548611e8c8c2c0279ea5d0a0bffd9b5196 Mon Sep 17 00:00:00 2001 From: Charles Lopes Date: Sat, 3 Sep 2022 21:12:33 +0100 Subject: [PATCH 2/6] Fix assumption that environment uses US time format --- API/Services/Tasks/Scanner/ProcessSeries.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API/Services/Tasks/Scanner/ProcessSeries.cs b/API/Services/Tasks/Scanner/ProcessSeries.cs index e8db2a97aa..6db859b3b7 100644 --- a/API/Services/Tasks/Scanner/ProcessSeries.cs +++ b/API/Services/Tasks/Scanner/ProcessSeries.cs @@ -647,7 +647,7 @@ void AddTag(Tag tag, bool added) { var day = Math.Max(comicInfo.Day, 1); var month = Math.Max(comicInfo.Month, 1); - chapter.ReleaseDate = DateTime.Parse($"{month}/{day}/{comicInfo.Year}"); + chapter.ReleaseDate = new DateTime(comicInfo.Year, month, day); } var people = GetTagValues(comicInfo.Colorist); From d7159b09bb0e5c2cf63d13cc64e856560939e461 Mon Sep 17 00:00:00 2001 From: Charles Lopes Date: Sat, 3 Sep 2022 21:56:20 +0100 Subject: [PATCH 3/6] Use series name as SeriesSort in epub --- API/Services/BookService.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/API/Services/BookService.cs b/API/Services/BookService.cs index dfbfc33d2b..39bf64b95b 100644 --- a/API/Services/BookService.cs +++ b/API/Services/BookService.cs @@ -447,6 +447,10 @@ public ComicInfo GetComicInfo(string filePath) case "calibre:title_sort": info.TitleSort = metadataItem.Content; break; + case "calibre:series": + info.Series = metadataItem.Content; + info.SeriesSort = metadataItem.Content; + break; } } @@ -609,15 +613,10 @@ public ParserInfo ParseInfo(string filePath) FullFilePath = filePath, IsSpecial = false, Series = series.Trim(), + SeriesSort = series.Trim(), Volumes = seriesIndex }; - // Don't set titleSort if the book belongs to a group - if (!string.IsNullOrEmpty(titleSort) && string.IsNullOrEmpty(seriesIndex) && (groupPosition.Equals("series") || groupPosition.Equals("set"))) - { - info.SeriesSort = titleSort; - } - return info; } } From 8ed0d4b9a8f7d62ced57a889be0283893612c2b9 Mon Sep 17 00:00:00 2001 From: Charles Lopes Date: Tue, 13 Sep 2022 18:34:40 +0100 Subject: [PATCH 4/6] Address some PR comments --- API.Tests/Services/ArchiveServiceTests.cs | 6 +++++- API/Data/Metadata/ComicInfo.cs | 5 ----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/API.Tests/Services/ArchiveServiceTests.cs b/API.Tests/Services/ArchiveServiceTests.cs index ffe6fd6fe0..eb8dc420ce 100644 --- a/API.Tests/Services/ArchiveServiceTests.cs +++ b/API.Tests/Services/ArchiveServiceTests.cs @@ -297,8 +297,12 @@ public void CanParseComicInfo() Assert.NotStrictEqual(null, actual); } + #endregion + + #region CanParseComicInfo_DefaultNumberIsBlank + [Fact] - public void CanParseComicInfo2() + public void CanParseComicInfo_DefaultNumberIsBlank() { var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos"); var archive = Path.Join(testDirectory, "ComicInfo2.zip"); diff --git a/API/Data/Metadata/ComicInfo.cs b/API/Data/Metadata/ComicInfo.cs index 37d5b2c9c7..20061f0634 100644 --- a/API/Data/Metadata/ComicInfo.cs +++ b/API/Data/Metadata/ComicInfo.cs @@ -23,7 +23,6 @@ public class ComicInfo /// /// The total number of items in the series. /// - // This should really be -1 according to anansi-project spec [System.ComponentModel.DefaultValueAttribute(0)] public int Count { get; set; } = 0; public string Volume { get; set; } = string.Empty; @@ -39,13 +38,10 @@ public class ComicInfo /// This is the link to where the data was scraped from /// public string Web { get; set; } = string.Empty; - // This should really be -1 according to anansi-project spec [System.ComponentModel.DefaultValueAttribute(0)] public int Day { get; set; } = 0; - // This should really be -1 according to anansi-project spec [System.ComponentModel.DefaultValueAttribute(0)] public int Month { get; set; } = 0; - // This should really be -1 according to anansi-project spec [System.ComponentModel.DefaultValueAttribute(0)] public int Year { get; set; } = 0; @@ -62,7 +58,6 @@ public class ComicInfo public string StoryArc { get; set; } = string.Empty; public string SeriesGroup { get; set; } = string.Empty; public string AlternateNumber { get; set; } = string.Empty; - // This should really be -1 according to anansi-project spec [System.ComponentModel.DefaultValueAttribute(0)] public int AlternateCount { get; set; } = 0; public string AlternateSeries { get; set; } = string.Empty; From 0e29cfa151105ad4103b6f0eb339daee4b169757 Mon Sep 17 00:00:00 2001 From: Charles Lopes Date: Tue, 13 Sep 2022 18:42:58 +0100 Subject: [PATCH 5/6] Add partial Equals(0 implementation to ComicInfo --- API.Tests/Services/ArchiveServiceTests.cs | 30 ++++++++++++++--------- API/Data/Metadata/ComicInfo.cs | 14 +++++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/API.Tests/Services/ArchiveServiceTests.cs b/API.Tests/Services/ArchiveServiceTests.cs index eb8dc420ce..c86b960c46 100644 --- a/API.Tests/Services/ArchiveServiceTests.cs +++ b/API.Tests/Services/ArchiveServiceTests.cs @@ -291,10 +291,7 @@ public void CanParseComicInfo() Web = "https://www.comixology.com/BTOOOM/digital-comic/450184" }; - // XXX: This is not doing anything useful - Assert.NotStrictEqual(expected, actual); - // XXX: This also works - Assert.NotStrictEqual(null, actual); + Assert.StrictEqual(expected, actual); } #endregion @@ -306,14 +303,25 @@ public void CanParseComicInfo_DefaultNumberIsBlank() { var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos"); var archive = Path.Join(testDirectory, "ComicInfo2.zip"); - var comicInfo = _archiveService.GetComicInfo(archive); + var actual = _archiveService.GetComicInfo(archive); + var expected = new ComicInfo() + { + Publisher = "Dark Horse Comics", + Genre = "Supernatural/Occult, Horror, Action/Adventure", + Summary = "When strangeness threatens to engulf the world, a strange man will come to save it. Sent to investigate a mystery with supernatural overtones, Hellboy discovers the secrets of his own origins, and his link to the Nazi occultists who promised Hitler a final solution in the form of a demonic avatar.", + PageCount = 147, + LanguageISO = "en", + Notes = "Scraped metadata from Comixology [CMXDB450184]", + Series = "Hellboy", + Title = "The Right Hand of Doom", + Number = "", + Count = 0, + Volume = "4", + Web = "https://comicvine.gamespot.com/hellboy-the-right-hand-of-doom-1-volume-4/4000-194124/" - Assert.NotNull(comicInfo); - Assert.Equal("Hellboy", comicInfo.Series); - Assert.Equal("The Right Hand of Doom", comicInfo.Title); - Assert.Equal("", comicInfo.Number); - Assert.Equal(0, comicInfo.Count); - Assert.Equal("4", comicInfo.Volume); + }; + + Assert.StrictEqual(expected, actual); } diff --git a/API/Data/Metadata/ComicInfo.cs b/API/Data/Metadata/ComicInfo.cs index 20061f0634..bed7e5e535 100644 --- a/API/Data/Metadata/ComicInfo.cs +++ b/API/Data/Metadata/ComicInfo.cs @@ -125,4 +125,18 @@ public static void CleanComicInfo(ComicInfo info) } + // TODO: Example of Equals() implementation. This currently only + // covers enough fields to cover the unit tests + public override bool Equals(object obj) + { + return obj is ComicInfo info && + this.Count == info.Count && + this.Genre == info.Genre && + this.Number == info.Number && + this.PageCount == info.PageCount && + this.Series == info.Series && + this.Summary.Trim() == info.Summary.Trim() && + this.Title == info.Title && + this.Volume == info.Volume; + } } From 0b7db5eaf02a596b168a8cd594365953c40037a5 Mon Sep 17 00:00:00 2001 From: Charles Lopes Date: Tue, 13 Sep 2022 19:15:41 +0100 Subject: [PATCH 6/6] Update ComicInfo unittest. Revert previous version --- API.Tests/Services/ArchiveServiceTests.cs | 55 +++++++++-------------- API/Data/Metadata/ComicInfo.cs | 14 ------ 2 files changed, 20 insertions(+), 49 deletions(-) diff --git a/API.Tests/Services/ArchiveServiceTests.cs b/API.Tests/Services/ArchiveServiceTests.cs index c86b960c46..35e26757a2 100644 --- a/API.Tests/Services/ArchiveServiceTests.cs +++ b/API.Tests/Services/ArchiveServiceTests.cs @@ -276,22 +276,18 @@ public void CanParseComicInfo() { var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos"); var archive = Path.Join(testDirectory, "ComicInfo.zip"); - var actual = _archiveService.GetComicInfo(archive); - var expected = new ComicInfo() - { - Publisher = "Yen Press", - Genre = "Manga, Movies & TV", - Summary = - "By all counts, Ryouta Sakamoto is a loser when he's not holed up in his room, bombing things into oblivion in his favorite online action RPG. But his very own uneventful life is blown to pieces when he's abducted and taken to an uninhabited island, where he soon learns the hard way that he's being pitted against others just like him in a explosives-riddled death match! How could this be happening? Who's putting them up to this? And why!? The name, not to mention the objective, of this very real survival game is eerily familiar to Ryouta, who has mastered its virtual counterpart-BTOOOM! Can Ryouta still come out on top when he's playing for his life!?", - PageCount = 194, - LanguageISO = "en", - Notes = "Scraped metadata from Comixology [CMXDB450184]", - Series = "BTOOOM!", - Title = "v01", - Web = "https://www.comixology.com/BTOOOM/digital-comic/450184" - }; - - Assert.StrictEqual(expected, actual); + var comicInfo = _archiveService.GetComicInfo(archive); + + Assert.NotNull(comicInfo); + Assert.Equal(comicInfo.Publisher, "Yen Press"); + Assert.Equal(comicInfo.Genre, "Manga, Movies & TV"); + Assert.Equal(comicInfo.Summary, "By all counts, Ryouta Sakamoto is a loser when he's not holed up in his room, bombing things into oblivion in his favorite online action RPG. But his very own uneventful life is blown to pieces when he's abducted and taken to an uninhabited island, where he soon learns the hard way that he's being pitted against others just like him in a explosives-riddled death match! How could this be happening? Who's putting them up to this? And why!? The name, not to mention the objective, of this very real survival game is eerily familiar to Ryouta, who has mastered its virtual counterpart-BTOOOM! Can Ryouta still come out on top when he's playing for his life!?"); + Assert.Equal(comicInfo.PageCount, 194); + Assert.Equal(comicInfo.LanguageISO, "en"); + Assert.Equal(comicInfo.Notes, "Scraped metadata from Comixology [CMXDB450184]"); + Assert.Equal(comicInfo.Series, "BTOOOM!"); + Assert.Equal(comicInfo.Title, "v01"); + Assert.Equal(comicInfo.Web, "https://www.comixology.com/BTOOOM/digital-comic/450184"); } #endregion @@ -303,25 +299,14 @@ public void CanParseComicInfo_DefaultNumberIsBlank() { var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/ComicInfos"); var archive = Path.Join(testDirectory, "ComicInfo2.zip"); - var actual = _archiveService.GetComicInfo(archive); - var expected = new ComicInfo() - { - Publisher = "Dark Horse Comics", - Genre = "Supernatural/Occult, Horror, Action/Adventure", - Summary = "When strangeness threatens to engulf the world, a strange man will come to save it. Sent to investigate a mystery with supernatural overtones, Hellboy discovers the secrets of his own origins, and his link to the Nazi occultists who promised Hitler a final solution in the form of a demonic avatar.", - PageCount = 147, - LanguageISO = "en", - Notes = "Scraped metadata from Comixology [CMXDB450184]", - Series = "Hellboy", - Title = "The Right Hand of Doom", - Number = "", - Count = 0, - Volume = "4", - Web = "https://comicvine.gamespot.com/hellboy-the-right-hand-of-doom-1-volume-4/4000-194124/" - - }; - - Assert.StrictEqual(expected, actual); + var comicInfo = _archiveService.GetComicInfo(archive); + + Assert.NotNull(comicInfo); + Assert.Equal("Hellboy", comicInfo.Series); + Assert.Equal("The Right Hand of Doom", comicInfo.Title); + Assert.Equal("", comicInfo.Number); + Assert.Equal(0, comicInfo.Count); + Assert.Equal("4", comicInfo.Volume); } diff --git a/API/Data/Metadata/ComicInfo.cs b/API/Data/Metadata/ComicInfo.cs index bed7e5e535..20061f0634 100644 --- a/API/Data/Metadata/ComicInfo.cs +++ b/API/Data/Metadata/ComicInfo.cs @@ -125,18 +125,4 @@ public static void CleanComicInfo(ComicInfo info) } - // TODO: Example of Equals() implementation. This currently only - // covers enough fields to cover the unit tests - public override bool Equals(object obj) - { - return obj is ComicInfo info && - this.Count == info.Count && - this.Genre == info.Genre && - this.Number == info.Number && - this.PageCount == info.PageCount && - this.Series == info.Series && - this.Summary.Trim() == info.Summary.Trim() && - this.Title == info.Title && - this.Volume == info.Volume; - } }