From 5bdbd9e2e4fe94ab455c46c9be471b2c2070a3ad Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 22 Apr 2024 02:25:39 +0200 Subject: [PATCH] Hack to resolve #60 Website-URL. Field will have same name, just acquisition will be better. --- Tranga/Manga.cs | 38 +++++++++------------------ Tranga/MangaConnectors/Bato.cs | 6 ++--- Tranga/MangaConnectors/MangaDex.cs | 6 ++--- Tranga/MangaConnectors/MangaKatana.cs | 12 ++++----- Tranga/MangaConnectors/MangaLife.cs | 6 ++--- Tranga/MangaConnectors/Manganato.cs | 10 +++---- Tranga/MangaConnectors/Mangasee.cs | 6 ++--- Tranga/MangaConnectors/Mangaworld.cs | 6 ++--- 8 files changed, 36 insertions(+), 54 deletions(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 0267286..a29f2b6 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -43,11 +43,13 @@ public struct Manga public float ignoreChaptersBelow { get; set; } public float latestChapterDownloaded { get; set; } public float latestChapterAvailable { get; set; } + + public string websiteUrl { get; private set; } private static readonly Regex LegalCharacters = new (@"[A-Za-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, ReleaseStatusByte releaseStatus = 0, string? websiteUrl = null, 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 publicationId, ReleaseStatusByte releaseStatus, string? websiteUrl, string? folderName = null, float? ignoreChaptersBelow = 0) { this.sortName = sortName; this.authors = authors; @@ -59,7 +61,6 @@ public struct Manga this.links = links ?? new Dictionary(); this.year = year; this.originalLanguage = originalLanguage; - this.status = status; this.publicationId = publicationId; this.folderName = folderName ?? string.Concat(LegalCharacters.Matches(sortName)); while (this.folderName.EndsWith('.')) @@ -70,6 +71,7 @@ public struct Manga this.latestChapterDownloaded = 0; this.latestChapterAvailable = 0; this.releaseStatus = releaseStatus; + this.websiteUrl = websiteUrl; } public void UpdateMetadata(Manga newManga) @@ -171,38 +173,22 @@ public struct Manga [JsonRequired]public string year { get; } [JsonRequired]public string status { get; } [JsonRequired]public string description_text { get; } - [JsonIgnore] public static string[] continuing = new[] - { - "ongoing", - "hiatus", - "in corso", - "in pausa" - }; - [JsonIgnore] public static string[] ended = new[] - { - "completed", - "cancelled", - "discontinued", - "finito", - "cancellato", - "droppato" - }; - public Metadata(Manga manga) : this(manga.sortName, manga.year.ToString() ?? string.Empty, manga.status, manga.description ?? "") + public Metadata(Manga manga) : this(manga.sortName, manga.year.ToString() ?? string.Empty, manga.releaseStatus, manga.description ?? "") { } - public Metadata(string name, string year, string status, string description_text) + public Metadata(string name, string year, ReleaseStatusByte status, string description_text) { this.name = name; this.year = year; - if(continuing.Contains(status.ToLower())) - this.status = "Continuing"; - else if(ended.Contains(status.ToLower())) - this.status = "Ended"; - else - this.status = status; + this.status = status switch + { + ReleaseStatusByte.Continuing => "Continuing", + ReleaseStatusByte.Completed => "Ended", + _ => Enum.GetName(status) ?? "Ended" + }; this.description_text = description_text; //kill it with fire, but otherwise Komga will not parse diff --git a/Tranga/MangaConnectors/Bato.cs b/Tranga/MangaConnectors/Bato.cs index 96d97c0..edc6dc9 100644 --- a/Tranga/MangaConnectors/Bato.cs +++ b/Tranga/MangaConnectors/Bato.cs @@ -49,7 +49,7 @@ public class Bato : MangaConnector Log($"Failed to retrieve site"); return null; } - return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1]); + return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1], url); } private Manga[] ParsePublicationsFromHtml(HtmlDocument document) @@ -72,7 +72,7 @@ public class Bato : MangaConnector return ret.ToArray(); } - private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId) + private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl) { HtmlNode infoNode = document.DocumentNode.SelectSingleNode("/html/body/div/main/div[1]/div[2]"); @@ -115,7 +115,7 @@ public class Bato : MangaConnector } Manga manga = new (sortName, authors, description, altTitles, tags, posterUrl, coverFileNameInCache, new Dictionary(), - year, originalLanguage, status, publicationId, releaseStatus); + year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/MangaDex.cs b/Tranga/MangaConnectors/MangaDex.cs index d5af20c..550e34f 100644 --- a/Tranga/MangaConnectors/MangaDex.cs +++ b/Tranga/MangaConnectors/MangaDex.cs @@ -116,7 +116,7 @@ public class MangaDex : MangaConnector Dictionary linksDict = new(); if (attributes.TryGetPropertyValue("links", out JsonNode? linksNode)) - foreach (KeyValuePair linkKv in linksNode!.AsObject()) + foreach (KeyValuePair linkKv in linksNode!.AsObject()) linksDict.TryAdd(linkKv.Key, linkKv.Value.GetValue()); string? originalLanguage = @@ -183,9 +183,9 @@ public class MangaDex : MangaConnector linksDict, year, originalLanguage, - Enum.GetName(status) ?? "", publicationId, - status + status, + websiteUrl: $"https://mangadex.org/title/{publicationId}" ); cachedPublications.Add(pub); return pub; diff --git a/Tranga/MangaConnectors/MangaKatana.cs b/Tranga/MangaConnectors/MangaKatana.cs index a62315b..de59030 100644 --- a/Tranga/MangaConnectors/MangaKatana.cs +++ b/Tranga/MangaConnectors/MangaKatana.cs @@ -28,7 +28,7 @@ public class MangaKatana : MangaConnector && requestResult.redirectedToUrl is not null && requestResult.redirectedToUrl.Contains("mangakatana.com/manga")) { - return new [] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.redirectedToUrl.Split('/')[^1]) }; + return new [] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.redirectedToUrl.Split('/')[^1], requestResult.redirectedToUrl) }; } Manga[] publications = ParsePublicationsFromHtml(requestResult.result); @@ -47,7 +47,7 @@ public class MangaKatana : MangaConnector downloadClient.MakeRequest(url, RequestType.MangaInfo); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return null; - return ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1]); + return ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1], url); } private Manga[] ParsePublicationsFromHtml(Stream html) @@ -77,13 +77,12 @@ public class MangaKatana : MangaConnector return ret.ToArray(); } - private Manga ParseSinglePublicationFromHtml(Stream html, string publicationId) + private Manga ParseSinglePublicationFromHtml(Stream html, string publicationId, string websiteUrl) { StreamReader reader = new(html); string htmlString = reader.ReadToEnd(); HtmlDocument document = new(); document.LoadHtml(htmlString); - string status = ""; Dictionary altTitles = new(); Dictionary? links = null; HashSet tags = new(); @@ -112,8 +111,7 @@ public class MangaKatana : MangaConnector authors = value.Split(','); break; case "status": - status = value; - switch (status.ToLower()) + switch (value.ToLower()) { case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break; @@ -144,7 +142,7 @@ public class MangaKatana : MangaConnector } Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, - year, originalLanguage, status, publicationId, releaseStatus); + year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/MangaLife.cs b/Tranga/MangaConnectors/MangaLife.cs index fd92377..3f87953 100644 --- a/Tranga/MangaConnectors/MangaLife.cs +++ b/Tranga/MangaConnectors/MangaLife.cs @@ -41,7 +41,7 @@ public class MangaLife : MangaConnector RequestResult requestResult = this.downloadClient.MakeRequest(url, RequestType.MangaInfo); if(requestResult.htmlDocument is not null) - return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId); + return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url); return null; } @@ -69,7 +69,7 @@ public class MangaLife : MangaConnector } - private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId) + private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl) { string originalLanguage = "", status = ""; Dictionary altTitles = new(), links = new(); @@ -122,7 +122,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, releaseStatus); + coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/Manganato.cs b/Tranga/MangaConnectors/Manganato.cs index d7bbd79..cbbf0f0 100644 --- a/Tranga/MangaConnectors/Manganato.cs +++ b/Tranga/MangaConnectors/Manganato.cs @@ -65,12 +65,11 @@ public class Manganato : MangaConnector if (requestResult.htmlDocument is null) return null; - return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1]); + return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1], url); } - private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId) + private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl) { - string status = ""; Dictionary altTitles = new(); Dictionary? links = null; HashSet tags = new(); @@ -101,8 +100,7 @@ public class Manganato : MangaConnector authors = value.Split('-'); break; case "status": - status = value; - switch (status.ToLower()) + switch (value.ToLower()) { case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break; case "completed": releaseStatus = Manga.ReleaseStatusByte.Completed; break; @@ -130,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, releaseStatus); + year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/Mangasee.cs b/Tranga/MangaConnectors/Mangasee.cs index c354d1c..f99e108 100644 --- a/Tranga/MangaConnectors/Mangasee.cs +++ b/Tranga/MangaConnectors/Mangasee.cs @@ -120,11 +120,11 @@ public class Mangasee : MangaConnector RequestResult requestResult = this.downloadClient.MakeRequest(url, RequestType.MangaInfo); if((int)requestResult.statusCode < 300 && (int)requestResult.statusCode >= 200 && requestResult.htmlDocument is not null) - return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId); + return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url); return null; } - private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId) + private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl) { string originalLanguage = "", status = ""; Dictionary altTitles = new(), links = new(); @@ -178,7 +178,7 @@ public class Mangasee : MangaConnector Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, - year, originalLanguage, status, publicationId, releaseStatus); + year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); cachedPublications.Add(manga); return manga; } diff --git a/Tranga/MangaConnectors/Mangaworld.cs b/Tranga/MangaConnectors/Mangaworld.cs index a457999..0f2e80d 100644 --- a/Tranga/MangaConnectors/Mangaworld.cs +++ b/Tranga/MangaConnectors/Mangaworld.cs @@ -68,10 +68,10 @@ public class Mangaworld: MangaConnector Regex idRex = new (@"https:\/\/www\.mangaworld\.[a-z]{0,63}\/manga\/([0-9]+\/[0-9A-z\-]+).*"); string id = idRex.Match(url).Groups[1].Value; - return ParseSinglePublicationFromHtml(requestResult.htmlDocument, id); + return ParseSinglePublicationFromHtml(requestResult.htmlDocument, id, url); } - private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId) + private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl) { Dictionary altTitles = new(); Dictionary? links = null; @@ -119,7 +119,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, releaseStatus); + year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); cachedPublications.Add(manga); return manga; }