From 394829ee367236c1d7bd255e858c4800e52ca376 Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 31 Aug 2023 12:14:03 +0200 Subject: [PATCH] Revert "Download Covers only when Downloading Chapters" This reverts commit e663163d Covers might be important --- Tranga/Manga.cs | 4 ++-- Tranga/MangaConnectors/MangaDex.cs | 6 ++++-- Tranga/MangaConnectors/MangaKatana.cs | 7 +++---- Tranga/MangaConnectors/Manganato.cs | 7 +++---- Tranga/MangaConnectors/Mangasee.cs | 6 ++---- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 2f1ba06..247be53 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -36,14 +36,14 @@ 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, 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, string? folderName = null, float? ignoreChaptersBelow = 0) { this.sortName = sortName; this.authors = authors; this.description = description; this.altTitles = altTitles; this.tags = tags; - this.coverFileNameInCache = null; + this.coverFileNameInCache = coverFileNameInCache; this.coverUrl = coverUrl; this.links = links ?? new Dictionary(); this.year = year; diff --git a/Tranga/MangaConnectors/MangaDex.cs b/Tranga/MangaConnectors/MangaDex.cs index c413ff5..a484c20 100644 --- a/Tranga/MangaConnectors/MangaDex.cs +++ b/Tranga/MangaConnectors/MangaDex.cs @@ -102,6 +102,9 @@ public class MangaDex : MangaConnector authorIds.Add(node!["id"]!.GetValue()); } string? coverUrl = GetCoverUrl(publicationId, posterId); + string? coverCacheName = null; + if (coverUrl is not null) + coverCacheName = SaveCoverImageToCache(coverUrl, (byte)RequestType.AtHomeServer); List authors = GetAuthors(authorIds); @@ -132,6 +135,7 @@ public class MangaDex : MangaConnector altTitlesDict, tags.ToArray(), coverUrl, + coverCacheName, linksDict, year, originalLanguage, @@ -227,8 +231,6 @@ public class MangaDex : MangaConnector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - if (chapterParentManga.coverUrl is not null) - chapterParentManga.coverFileNameInCache = SaveCoverImageToCache(chapterParentManga.coverUrl, (byte)RequestType.AtHomeServer); //Download Chapter-Images return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), (byte)RequestType.AtHomeServer, comicInfoPath, progressToken:progressToken); } diff --git a/Tranga/MangaConnectors/MangaKatana.cs b/Tranga/MangaConnectors/MangaKatana.cs index e88f776..7803aa0 100644 --- a/Tranga/MangaConnectors/MangaKatana.cs +++ b/Tranga/MangaConnectors/MangaKatana.cs @@ -119,6 +119,8 @@ public class MangaKatana : MangaConnector string posterUrl = document.DocumentNode.SelectSingleNode("//*[@id='single_book']/div[1]/div").Descendants("img").First() .GetAttributes().First(a => a.Name == "src").Value; + string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1); + string description = document.DocumentNode.SelectSingleNode("//*[@id='single_book']/div[3]/p").InnerText; while (description.StartsWith('\n')) description = description.Substring(1); @@ -132,7 +134,7 @@ public class MangaKatana : MangaConnector year = Convert.ToInt32(yearString); } - return new Manga(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, links, + return new Manga(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, status, publicationId); } @@ -199,9 +201,6 @@ public class MangaKatana : MangaConnector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - if (chapterParentManga.coverUrl is not null) - chapterParentManga.coverFileNameInCache = SaveCoverImageToCache(chapterParentManga.coverUrl, 1); - return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken); } diff --git a/Tranga/MangaConnectors/Manganato.cs b/Tranga/MangaConnectors/Manganato.cs index 9711fd8..b22b17f 100644 --- a/Tranga/MangaConnectors/Manganato.cs +++ b/Tranga/MangaConnectors/Manganato.cs @@ -111,6 +111,8 @@ public class Manganato : MangaConnector string posterUrl = document.DocumentNode.Descendants("span").First(s => s.HasClass("info-image")).Descendants("img").First() .GetAttributes().First(a => a.Name == "src").Value; + string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1); + string description = document.DocumentNode.Descendants("div").First(d => d.HasClass("panel-story-info-description")) .InnerText.Replace("Description :", ""); while (description.StartsWith('\n')) @@ -120,7 +122,7 @@ public class Manganato : MangaConnector .First(s => s.HasClass("chapter-time")).InnerText; int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000; - return new Manga(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, links, + return new Manga(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, status, publicationId); } @@ -185,9 +187,6 @@ public class Manganato : MangaConnector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - if (chapterParentManga.coverUrl is not null) - chapterParentManga.coverFileNameInCache = SaveCoverImageToCache(chapterParentManga.coverUrl, 1); - return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, "https://chapmanganato.com/", progressToken:progressToken); } diff --git a/Tranga/MangaConnectors/Mangasee.cs b/Tranga/MangaConnectors/Mangasee.cs index 3e67760..0932436 100644 --- a/Tranga/MangaConnectors/Mangasee.cs +++ b/Tranga/MangaConnectors/Mangasee.cs @@ -133,6 +133,7 @@ public class Mangasee : MangaConnector HtmlNode posterNode = document.DocumentNode.Descendants("img").First(img => img.HasClass("img-fluid") && img.HasClass("bottom-5")); string posterUrl = posterNode.GetAttributeValue("src", ""); + string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1); HtmlNode attributes = document.DocumentNode.Descendants("div") .First(div => div.HasClass("col-md-9") && div.HasClass("col-sm-8") && div.HasClass("top-5")) @@ -170,7 +171,7 @@ public class Mangasee : MangaConnector foreach(string at in a) altTitles.Add((i++).ToString(), at); - return new Manga(sortName, authors, description, altTitles, tags.ToArray(), posterUrl, links, + return new Manga(sortName, authors, description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, status, publicationId); } @@ -270,9 +271,6 @@ public class Mangasee : MangaConnector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - if (chapterParentManga.coverUrl is not null) - chapterParentManga.coverFileNameInCache = SaveCoverImageToCache(chapterParentManga.coverUrl, 1); - return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, progressToken:progressToken); } return response.Status;