From c69f1f65691a3c53ac5791d4061e7ea1b33cb52c Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 22 Apr 2024 04:45:49 +0200 Subject: [PATCH 1/4] Addresses #170 Manganato authors and genres include "\r\n" --- Tranga/MangaConnectors/Manganato.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tranga/MangaConnectors/Manganato.cs b/Tranga/MangaConnectors/Manganato.cs index cbbf0f0..f6ff4c1 100644 --- a/Tranga/MangaConnectors/Manganato.cs +++ b/Tranga/MangaConnectors/Manganato.cs @@ -98,6 +98,8 @@ public class Manganato : MangaConnector break; case "authors": authors = value.Split('-'); + for (int i = 0; i < authors.Length; i++) + authors[i] = authors[i].Replace("\r\n", ""); break; case "status": switch (value.ToLower()) @@ -108,6 +110,8 @@ public class Manganato : MangaConnector break; case "genres": string[] genres = value.Split(" - "); + for (int i = 0; i < genres.Length; i++) + genres[i] = genres[i].Replace("\r\n", ""); tags = genres.ToHashSet(); break; } From 5f820c53f53513125df305530798dc9d822a8238 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 22 Apr 2024 22:03:09 +0200 Subject: [PATCH 2/4] Update websiteUrl on metadata-refresh https://github.com/C9Glax/tranga-website/issues/60 --- Tranga/Manga.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index a29f2b6..89f2596 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -84,6 +84,7 @@ public struct Manga this.tags = tags.Union(newManga.tags).ToArray(); this.status = newManga.status; this.releaseStatus = newManga.releaseStatus; + this.websiteUrl = newManga.websiteUrl; this.year = newManga.year; } @@ -98,6 +99,7 @@ public struct Manga this.sortName == compareManga.sortName && this.latestChapterAvailable.Equals(compareManga.latestChapterAvailable) && this.authors.All(a => compareManga.authors.Contains(a)) && + this.websiteUrl.Equals(compareManga.websiteUrl) && this.tags.All(t => compareManga.tags.Contains(t)); } From 06fe98323a4e2ef0e4727a49f34073f95ba3d2c4 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 22 Apr 2024 22:09:43 +0200 Subject: [PATCH 3/4] Fix crashing when comparing old Manga (missing websiteUrl) --- Tranga/Manga.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 89f2596..32ea54b 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -44,12 +44,12 @@ public struct Manga public float latestChapterDownloaded { get; set; } public float latestChapterAvailable { get; set; } - public string websiteUrl { get; private 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 publicationId, ReleaseStatusByte releaseStatus, string? websiteUrl, 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 = null, string? folderName = null, float? ignoreChaptersBelow = 0) { this.sortName = sortName; this.authors = authors; @@ -71,6 +71,7 @@ public struct Manga this.latestChapterDownloaded = 0; this.latestChapterAvailable = 0; this.releaseStatus = releaseStatus; + this.status = Enum.GetName(releaseStatus) ?? ""; this.websiteUrl = websiteUrl; } @@ -99,7 +100,7 @@ public struct Manga this.sortName == compareManga.sortName && this.latestChapterAvailable.Equals(compareManga.latestChapterAvailable) && this.authors.All(a => compareManga.authors.Contains(a)) && - this.websiteUrl.Equals(compareManga.websiteUrl) && + (this.websiteUrl??"").Equals(compareManga.websiteUrl) && this.tags.All(t => compareManga.tags.Contains(t)); } From 79e61a62c7e132ace15cb68f8300afaf6146b583 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 22 Apr 2024 22:29:22 +0200 Subject: [PATCH 4/4] Export Jobfiles after execution, update metadata in jobfiles --- Tranga/Jobs/JobBoss.cs | 6 ++++-- Tranga/Jobs/UpdateMetadata.cs | 2 +- Tranga/Manga.cs | 25 ++++++++++++++----------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 99670b4..4380497 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -171,7 +171,7 @@ public class JobBoss : GlobalBase } } - private void UpdateJobFile(Job job) + internal void UpdateJobFile(Job job) { string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); @@ -245,7 +245,9 @@ public class JobBoss : GlobalBase Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}"); }else if (queueHead.progressToken.state is ProgressToken.State.Standby) { - Job[] subJobs = jobQueue.Peek().ExecuteReturnSubTasks(this).ToArray(); + Job eJob = jobQueue.Peek(); + Job[] subJobs = eJob.ExecuteReturnSubTasks(this).ToArray(); + UpdateJobFile(eJob); AddJobs(subJobs); AddJobsToQueue(subJobs); }else if (queueHead.progressToken.state is ProgressToken.State.Running && DateTime.Now.Subtract(queueHead.progressToken.lastUpdate) > TimeSpan.FromMinutes(5)) diff --git a/Tranga/Jobs/UpdateMetadata.cs b/Tranga/Jobs/UpdateMetadata.cs index e9107ce..5471685 100644 --- a/Tranga/Jobs/UpdateMetadata.cs +++ b/Tranga/Jobs/UpdateMetadata.cs @@ -33,7 +33,7 @@ public class UpdateMetadata : Job return Array.Empty(); } - this.manga.UpdateMetadata(updatedManga); + this.manga = manga.WithMetadata(updatedManga); this.manga.SaveSeriesInfoJson(settings.downloadLocation, true); this.progressToken.Complete(); } diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 32ea54b..388d02d 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -75,18 +75,21 @@ public struct Manga this.websiteUrl = websiteUrl; } - public void UpdateMetadata(Manga newManga) + public Manga WithMetadata(Manga newManga) { - this.sortName = newManga.sortName; - this.description = newManga.description; - this.coverUrl = newManga.coverUrl; - this.authors = authors.Union(newManga.authors).ToList(); - this.altTitles = altTitles.UnionBy(newManga.altTitles, kv => kv.Key).ToDictionary(x => x.Key, x => x.Value); - this.tags = tags.Union(newManga.tags).ToArray(); - this.status = newManga.status; - this.releaseStatus = newManga.releaseStatus; - this.websiteUrl = newManga.websiteUrl; - this.year = newManga.year; + return this with + { + sortName = newManga.sortName, + description = newManga.description, + coverUrl = newManga.coverUrl, + authors = authors.Union(newManga.authors).ToList(), + altTitles = altTitles.UnionBy(newManga.altTitles, kv => kv.Key).ToDictionary(x => x.Key, x => x.Value), + tags = tags.Union(newManga.tags).ToArray(), + status = newManga.status, + releaseStatus = newManga.releaseStatus, + websiteUrl = newManga.websiteUrl, + year = newManga.year + }; } public override bool Equals(object? obj)