From d78897eb745efe3f771e692409333fd2bddf02b1 Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 27 Oct 2023 14:07:15 +0200 Subject: [PATCH] #74 untested --- Tranga/GlobalBase.cs | 2 +- Tranga/Jobs/DownloadChapter.cs | 1 + Tranga/Manga.cs | 12 +++++++++++- Tranga/MangaConnectors/MangaConnector.cs | 7 +++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Tranga/GlobalBase.cs b/Tranga/GlobalBase.cs index 52f7540..147327d 100644 --- a/Tranga/GlobalBase.cs +++ b/Tranga/GlobalBase.cs @@ -14,7 +14,7 @@ public abstract class GlobalBase protected HashSet notificationConnectors { get; init; } protected HashSet libraryConnectors { get; init; } protected List cachedPublications { get; init; } - protected static readonly NumberFormatInfo numberFormatDecimalPoint = new (){ NumberDecimalSeparator = "." }; + public static readonly NumberFormatInfo numberFormatDecimalPoint = new (){ NumberDecimalSeparator = "." }; protected static readonly Regex baseUrlRex = new(@"https?:\/\/[0-9A-z\.-]*"); protected GlobalBase(GlobalBase clone) diff --git a/Tranga/Jobs/DownloadChapter.cs b/Tranga/Jobs/DownloadChapter.cs index d01fd49..b13503c 100644 --- a/Tranga/Jobs/DownloadChapter.cs +++ b/Tranga/Jobs/DownloadChapter.cs @@ -33,6 +33,7 @@ public class DownloadChapter : Job { mangaConnector.CopyCoverFromCacheToDownloadLocation(chapter.parentManga); HttpStatusCode success = mangaConnector.DownloadChapter(chapter, this.progressToken); + chapter.parentManga.UpdateLatestDownloadedChapter(chapter); if (success == HttpStatusCode.OK) { UpdateLibraries(); diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 9bde5c6..4424bc9 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -26,12 +26,14 @@ public struct Manga // ReSharper disable once MemberCanBePrivate.Global public int? year { get; } public string? originalLanguage { get; } - // ReSharper disable once MemberCanBePrivate.Global + // ReSharper disable twice MemberCanBePrivate.Global public string status { get; } public string folderName { get; private set; } public string publicationId { get; } public string internalId { get; } public float ignoreChaptersBelow { get; set; } + public float latestChapterDownloaded { get; set; } + public float latestChapterAvailable { get; set; } private static readonly Regex LegalCharacters = new (@"[A-Z]*[a-z]*[0-9]* *\.*-*,*'*\'*\)*\(*~*!*"); @@ -56,6 +58,8 @@ public struct Manga string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter)); this.internalId = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{onlyLowerLetters}{this.year}")); this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f; + this.latestChapterDownloaded = 0; + this.latestChapterAvailable = 0; } public override string ToString() @@ -82,6 +86,12 @@ public struct Manga Directory.Move(oldPath, newPath); } + public void UpdateLatestDownloadedChapter(Chapter chapter)//TODO check files if chapters are all downloaded + { + float chapterNumber = Convert.ToSingle(chapter.chapterNumber, GlobalBase.numberFormatDecimalPoint); + latestChapterDownloaded = latestChapterDownloaded < chapterNumber ? chapterNumber : latestChapterDownloaded; + } + public void SaveSeriesInfoJson(string downloadDirectory) { string publicationFolder = CreatePublicationFolder(downloadDirectory); diff --git a/Tranga/MangaConnectors/MangaConnector.cs b/Tranga/MangaConnectors/MangaConnector.cs index cd42d3e..a2a8a48 100644 --- a/Tranga/MangaConnectors/MangaConnector.cs +++ b/Tranga/MangaConnectors/MangaConnector.cs @@ -56,12 +56,15 @@ public abstract class MangaConnector : GlobalBase public Chapter[] GetNewChapters(Manga manga, string language = "en") { Log($"Getting new Chapters for {manga}"); - Chapter[] newChapters = this.GetChapters(manga, language); + Chapter[] allChapters = this.GetChapters(manga, language); Log($"Checking for duplicates {manga}"); - List newChaptersList = newChapters.Where(nChapter => float.TryParse(nChapter.chapterNumber, numberFormatDecimalPoint, out float chapterNumber) + List newChaptersList = allChapters.Where(nChapter => float.TryParse(nChapter.chapterNumber, numberFormatDecimalPoint, out float chapterNumber) && chapterNumber > manga.ignoreChaptersBelow && !nChapter.CheckChapterIsDownloaded(settings.downloadLocation)).ToList(); Log($"{newChaptersList.Count} new chapters. {manga}"); + Chapter latestChapterAvailable = + allChapters.MaxBy(chapter => Convert.ToSingle(chapter.chapterNumber, numberFormatDecimalPoint)); + manga.latestChapterAvailable = Convert.ToSingle(latestChapterAvailable.chapterNumber, numberFormatDecimalPoint); return newChaptersList.ToArray(); }