From 6adbda23594054b63167766a607d36475bfeb6eb Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 1 Nov 2023 13:59:21 +0100 Subject: [PATCH] #77 Added field releaseStatus to Manga --- Tranga/Manga.cs | 12 +++++++++++- Tranga/MangaConnectors/Bato.cs | 11 ++++++++++- Tranga/MangaConnectors/MangaDex.cs | 11 ++++++++++- Tranga/MangaConnectors/MangaKatana.cs | 8 +++++++- Tranga/MangaConnectors/MangaLife.cs | 12 ++++++++++-- Tranga/MangaConnectors/Manganato.cs | 8 +++++++- Tranga/MangaConnectors/Mangasee.cs | 11 ++++++++++- Tranga/MangaConnectors/Mangaworld.cs | 12 +++++++++++- 8 files changed, 76 insertions(+), 9 deletions(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 7745a8a..93e38c7 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -28,6 +28,15 @@ public struct Manga public string? originalLanguage { get; } // ReSharper disable twice MemberCanBePrivate.Global public string status { get; } + public ReleaseStatusByte releaseStatus { get; } + public enum ReleaseStatusByte : byte + { + Continuing = 0, + Completed = 1, + OnHiatus = 2, + Cancelled = 3, + Unreleased = 4 + }; public string folderName { get; private set; } public string publicationId { get; } public string internalId { get; } @@ -38,7 +47,7 @@ public struct Manga private static readonly Regex LegalCharacters = new (@"[A-Z]*[a-z]*[0-9]* *\.*-*,*'*\'*\)*\(*~*!*"); [JsonConstructor] - public Manga(string sortName, List authors, string? description, Dictionary altTitles, string[] tags, string? coverUrl, string? coverFileNameInCache, Dictionary? links, int? year, string? originalLanguage, string status, string publicationId, string? folderName = null, float? ignoreChaptersBelow = 0) + public Manga(string sortName, List authors, string? description, Dictionary altTitles, string[] tags, string? coverUrl, string? coverFileNameInCache, Dictionary? links, int? year, string? originalLanguage, string status, string publicationId, ReleaseStatusByte releaseStatus = 0, string? folderName = null, float? ignoreChaptersBelow = 0) { this.sortName = sortName; this.authors = authors; @@ -60,6 +69,7 @@ public struct Manga this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f; this.latestChapterDownloaded = 0; this.latestChapterAvailable = 0; + this.releaseStatus = releaseStatus; } public override string ToString() diff --git a/Tranga/MangaConnectors/Bato.cs b/Tranga/MangaConnectors/Bato.cs index 97d85ef..9b6dfa4 100644 --- a/Tranga/MangaConnectors/Bato.cs +++ b/Tranga/MangaConnectors/Bato.cs @@ -102,9 +102,18 @@ public class Bato : MangaConnector string status = document.DocumentNode.SelectSingleNode("//span[text()='Original Publication:']/..") .ChildNodes[2].InnerText; + Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased; + switch (status.ToLower()) + { + case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; + case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break; + case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break; + case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "pending": releaseStatus = Manga.ReleaseStatusByte.Unreleased; break; + } Manga manga = new (sortName, authors, description, altTitles, tags, posterUrl, coverFileNameInCache, new Dictionary(), - year, originalLanguage, status, publicationId); + year, originalLanguage, status, publicationId, releaseStatus); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/MangaDex.cs b/Tranga/MangaConnectors/MangaDex.cs index f7f05e5..290dc6c 100644 --- a/Tranga/MangaConnectors/MangaDex.cs +++ b/Tranga/MangaConnectors/MangaDex.cs @@ -170,6 +170,14 @@ public class MangaDex : MangaConnector if(!attributes.ContainsKey("status")) return null; string status = attributes["status"]!.GetValue(); + Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased; + switch (status.ToLower()) + { + case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; + case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break; + case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break; + case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + } Manga pub = new( title, @@ -183,7 +191,8 @@ public class MangaDex : MangaConnector year, originalLanguage, status, - publicationId + publicationId, + releaseStatus ); cachedPublications.Add(pub); return pub; diff --git a/Tranga/MangaConnectors/MangaKatana.cs b/Tranga/MangaConnectors/MangaKatana.cs index fa650cc..43f9dcc 100644 --- a/Tranga/MangaConnectors/MangaKatana.cs +++ b/Tranga/MangaConnectors/MangaKatana.cs @@ -87,6 +87,7 @@ public class MangaKatana : MangaConnector HashSet tags = new(); string[] authors = Array.Empty(); string originalLanguage = ""; + Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased; HtmlNode infoNode = document.DocumentNode.SelectSingleNode("//*[@id='single_book']"); string sortName = infoNode.Descendants("h1").First(n => n.HasClass("heading")).InnerText; @@ -110,6 +111,11 @@ public class MangaKatana : MangaConnector break; case "status": status = value; + switch (status.ToLower()) + { + case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; + case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break; + } break; case "genres": tags = row.SelectNodes("div").Last().Descendants("a").Select(a => a.InnerText).ToHashSet(); @@ -136,7 +142,7 @@ public class MangaKatana : MangaConnector } Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, - year, originalLanguage, status, publicationId); + year, originalLanguage, status, publicationId, releaseStatus); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/MangaLife.cs b/Tranga/MangaConnectors/MangaLife.cs index b7f2be5..f93cdcc 100644 --- a/Tranga/MangaConnectors/MangaLife.cs +++ b/Tranga/MangaConnectors/MangaLife.cs @@ -72,6 +72,7 @@ public class MangaLife : MangaConnector string originalLanguage = "", status = ""; Dictionary altTitles = new(), links = new(); HashSet tags = new(); + Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased; HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//img"); string posterUrl = posterNode.GetAttributeValue("src", ""); @@ -104,6 +105,14 @@ public class MangaLife : MangaConnector foreach (HtmlNode statusNode in statusNodes) if (statusNode.InnerText.Contains("publish", StringComparison.CurrentCultureIgnoreCase)) status = statusNode.InnerText.Split(' ')[0]; + switch (status.ToLower()) + { + case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break; + case "discontinued": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "complete": releaseStatus = Manga.ReleaseStatusByte.Completed; break; + case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; + } HtmlNode descriptionNode = document.DocumentNode .SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Description:']/..") @@ -111,8 +120,7 @@ public class MangaLife : MangaConnector string description = descriptionNode.InnerText; Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, - coverFileNameInCache, links, - year, originalLanguage, status, publicationId); + coverFileNameInCache, links, year, originalLanguage, status, publicationId, releaseStatus); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/Manganato.cs b/Tranga/MangaConnectors/Manganato.cs index 28258d4..816e81a 100644 --- a/Tranga/MangaConnectors/Manganato.cs +++ b/Tranga/MangaConnectors/Manganato.cs @@ -74,6 +74,7 @@ public class Manganato : MangaConnector HashSet tags = new(); string[] authors = Array.Empty(); string originalLanguage = ""; + Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased; HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("story-info-right")); @@ -99,6 +100,11 @@ public class Manganato : MangaConnector break; case "status": status = value; + switch (status.ToLower()) + { + case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; + case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break; + } break; case "genres": string[] genres = value.Split(" - "); @@ -122,7 +128,7 @@ public class Manganato : MangaConnector int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000; Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, - year, originalLanguage, status, publicationId); + year, originalLanguage, status, publicationId, releaseStatus); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/Mangasee.cs b/Tranga/MangaConnectors/Mangasee.cs index 773fa82..d3d5759 100644 --- a/Tranga/MangaConnectors/Mangasee.cs +++ b/Tranga/MangaConnectors/Mangasee.cs @@ -127,6 +127,7 @@ public class Mangasee : MangaConnector string originalLanguage = "", status = ""; Dictionary altTitles = new(), links = new(); HashSet tags = new(); + Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased; HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//img"); string posterUrl = posterNode.GetAttributeValue("src", ""); @@ -159,6 +160,14 @@ public class Mangasee : MangaConnector foreach (HtmlNode statusNode in statusNodes) if (statusNode.InnerText.Contains("publish", StringComparison.CurrentCultureIgnoreCase)) status = statusNode.InnerText.Split(' ')[0]; + switch (status.ToLower()) + { + case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break; + case "discontinued": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "complete": releaseStatus = Manga.ReleaseStatusByte.Completed; break; + case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; + } HtmlNode descriptionNode = document.DocumentNode .SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Description:']/..") @@ -167,7 +176,7 @@ public class Mangasee : MangaConnector Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, - year, originalLanguage, status, publicationId); + year, originalLanguage, status, publicationId, releaseStatus); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/Mangaworld.cs b/Tranga/MangaConnectors/Mangaworld.cs index 1939423..422008e 100644 --- a/Tranga/MangaConnectors/Mangaworld.cs +++ b/Tranga/MangaConnectors/Mangaworld.cs @@ -72,6 +72,7 @@ public class Mangaworld: MangaConnector Dictionary altTitles = new(); Dictionary? links = null; string originalLanguage = ""; + Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased; HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("info")); @@ -94,6 +95,15 @@ public class Mangaworld: MangaConnector string[] authors = new[] { authorsNode.SelectNodes("a").First().InnerText }; string status = metadata.SelectSingleNode("//span[text()='Stato: ']/..").SelectNodes("a").First().InnerText; + // ReSharper disable 5 times StringLiteralTypo + switch (status.ToLower()) + { + case "cancellato": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "in pausa": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break; + case "droppato": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break; + case "finito": releaseStatus = Manga.ReleaseStatusByte.Completed; break; + case "in corso": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; + } string posterUrl = document.DocumentNode.SelectSingleNode("//img[@class='rounded']").GetAttributeValue("src", ""); @@ -105,7 +115,7 @@ public class Mangaworld: MangaConnector int year = Convert.ToInt32(yearString); Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, - year, originalLanguage, status, publicationId); + year, originalLanguage, status, publicationId, releaseStatus); cachedPublications.Add(manga); return manga; }