From 9a640aed2735e3a9c28dff4ab724550861f649cb Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 22 May 2023 21:38:44 +0200 Subject: [PATCH] Rewrote CoverDownload check if exists. --- Tranga/Connectors/MangaDex.cs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index f037a7d..f949c40 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -270,29 +270,26 @@ public class MangaDex : Connector if(!Directory.Exists(publicationFolder)) Directory.CreateDirectory(publicationFolder); DirectoryInfo dirInfo = new (publicationFolder); - foreach(FileInfo fileInfo in dirInfo.EnumerateFiles()) - if (fileInfo.Name.Contains("cover.")) - { - logger?.WriteLine(this.GetType().ToString(), $"Cover exists {publication.sortName}"); - return; - } - - if (publication.posterUrl is null) + if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover."))) { - logger?.WriteLine(this.GetType().ToString(), $"No posterurl in publication"); + logger?.WriteLine(this.GetType().ToString(), $"Cover exists {publication.sortName}"); return; } - string coverUrl = publication.posterUrl; + if (publication.posterUrl is null || !(bool)publication.posterUrl?.Contains("http")) + { + logger?.WriteLine(this.GetType().ToString(), $"No Poster-URL in publication"); + return; + } //Get file-extension (jpg, png) - string[] split = coverUrl.Split('.'); + string[] split = publication.posterUrl.Split('.'); string extension = split[^1]; string outFolderPath = Path.Join(downloadLocation, publication.folderName); Directory.CreateDirectory(outFolderPath); //Download cover-Image - DownloadImage(coverUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this.downloadClient, (byte)RequestType.AtHomeServer); + DownloadImage(publication.posterUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this.downloadClient, (byte)RequestType.AtHomeServer); } } \ No newline at end of file