From 17ef5eae0f565ca845c2159acc7b21d70b574a73 Mon Sep 17 00:00:00 2001 From: Glax Date: Sat, 30 Mar 2024 21:53:11 +0100 Subject: [PATCH 1/7] Fix MangaDex request for new Chapter. --- Tranga/MangaConnectors/MangaDex.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/MangaConnectors/MangaDex.cs b/Tranga/MangaConnectors/MangaDex.cs index 08c4bac..aef00df 100644 --- a/Tranga/MangaConnectors/MangaDex.cs +++ b/Tranga/MangaConnectors/MangaDex.cs @@ -252,7 +252,7 @@ public class MangaDex : MangaConnector Log($"Retrieving chapter-info {chapter} {chapterParentManga}"); //Request URLs for Chapter-Images RequestResult requestResult = - downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", RequestType.MangaDexImage); + downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false", RequestType.MangaDexImage); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) { progressToken?.Cancel(); From 94582496ef181603bf8f42d52269fb6cc6365fac Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 1 Apr 2024 20:00:02 +0200 Subject: [PATCH 2/7] Mangadex do not try downloading externally linked chapters, or chapters that have no pages. https://github.com/C9Glax/tranga/issues/153 --- Tranga/MangaConnectors/MangaDex.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tranga/MangaConnectors/MangaDex.cs b/Tranga/MangaConnectors/MangaDex.cs index aef00df..84b8891 100644 --- a/Tranga/MangaConnectors/MangaDex.cs +++ b/Tranga/MangaConnectors/MangaDex.cs @@ -216,6 +216,7 @@ public class MangaDex : MangaConnector { JsonObject chapter = (JsonObject)jsonNode!; JsonObject attributes = chapter["attributes"]!.AsObject(); + string chapterId = chapter["id"]!.GetValue(); string? title = attributes.ContainsKey("title") && attributes["title"] is not null @@ -230,6 +231,14 @@ public class MangaDex : MangaConnector ? attributes["chapter"]!.GetValue() : "null"; + + if (attributes.ContainsKey("pages") && attributes["pages"] is not null && + attributes["pages"]!.GetValue() < 1) + { + Log($"Skipping {chapterId} Vol.{volume} Ch.{chapterNum} {title} because it has no pages or is externally linked."); + continue; + } + if(chapterNum is not "null") chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId)); } From 6a8697fc3a8490f9f6de402a27105eb3bb7024b0 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 1 Apr 2024 20:12:25 +0200 Subject: [PATCH 3/7] Manga4Life fix bug that made it impossible for Manga to be loaded if they did not have a "Load more Chapters" button. https://github.com/C9Glax/tranga/issues/149 Created a check if the button exists before trying to click it. --- Tranga/MangaConnectors/ChromiumDownloadClient.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tranga/MangaConnectors/ChromiumDownloadClient.cs b/Tranga/MangaConnectors/ChromiumDownloadClient.cs index 961d878..5ae80ad 100644 --- a/Tranga/MangaConnectors/ChromiumDownloadClient.cs +++ b/Tranga/MangaConnectors/ChromiumDownloadClient.cs @@ -2,6 +2,7 @@ using System.Text; using HtmlAgilityPack; using PuppeteerSharp; +using PuppeteerSharp.Input; namespace Tranga.MangaConnectors; @@ -81,7 +82,7 @@ internal class ChromiumDownloadClient : DownloadClient { if (content.Contains("text/html")) { - if(clickButton is not null) + if (clickButton is not null && page.QuerySelectorAsync(clickButton).Result is not null) page.ClickAsync(clickButton).Wait(); string htmlString = page.GetContentAsync().Result; stream = new MemoryStream(Encoding.Default.GetBytes(htmlString)); From 537ad3a5f88a57e87927fdc9280dced62393675b Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 1 Apr 2024 20:35:47 +0200 Subject: [PATCH 4/7] https://github.com/C9Glax/tranga/issues/142 Cleanup old temporary Folders and files --- Tranga/Jobs/JobBoss.cs | 2 +- Tranga/MangaConnectors/MangaConnector.cs | 6 ++++-- Tranga/Tranga.cs | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index f603313..99670b4 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -164,7 +164,7 @@ public class JobBoss : GlobalBase } HashSet coverFileNames = cachedPublications.Select(manga => manga.coverFileNameInCache!).ToHashSet(); - foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) + foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) //Cleanup Unused Covers { if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga))) File.Delete(fileName); diff --git a/Tranga/MangaConnectors/MangaConnector.cs b/Tranga/MangaConnectors/MangaConnector.cs index bd80aed..302a064 100644 --- a/Tranga/MangaConnectors/MangaConnector.cs +++ b/Tranga/MangaConnectors/MangaConnector.cs @@ -237,7 +237,7 @@ public abstract class MangaConnector : GlobalBase return HttpStatusCode.Created; //Create a temporary folder to store images - string tempFolder = Directory.CreateTempSubdirectory().FullName; + string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName; int chapter = 0; //Download all Images to temporary Folder @@ -260,8 +260,10 @@ public abstract class MangaConnector : GlobalBase progressToken?.Increment(); } - if(comicInfoPath is not null) + if(comicInfoPath is not null){ File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml")); + File.Delete(comicInfoPath); //Delete tmp-file + } Log($"Creating archive {saveArchiveFilePath}"); //ZIP-it and ship-it diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index e146f6f..9dcc387 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -26,6 +26,8 @@ public partial class Tranga : GlobalBase new Bato(this), new MangaLife(this) }; + foreach(DirectoryInfo dir in new DirectoryInfo(Path.GetTempPath()).GetDirectories("trangatemp"))//Cleanup old temp folders + dir.Delete(); jobBoss = new(this, this._connectors); StartJobBoss(); this._server = new Server(this); From b27114eaad24bc3cb13f650b8953c19c78574c11 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 15 Apr 2024 14:50:03 +0200 Subject: [PATCH 5/7] April Fools Mode https://github.com/C9Glax/tranga/issues/155 --- Tranga/Server.cs | 13 +++++++++++++ Tranga/Tranga.cs | 15 ++++++++++++++- Tranga/TrangaSettings.cs | 9 ++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Tranga/Server.cs b/Tranga/Server.cs index cf2d15a..75b159f 100644 --- a/Tranga/Server.cs +++ b/Tranga/Server.cs @@ -206,6 +206,9 @@ public class Server : GlobalBase case "Settings/customRequestLimit": SendResponse(HttpStatusCode.OK, response, settings.requestLimits); break; + case "Settings/AprilFoolsMode": + SendResponse(HttpStatusCode.OK, response, settings.aprilFoolsMode); + break; case "NotificationConnectors": SendResponse(HttpStatusCode.OK, response, notificationConnectors); break; @@ -405,6 +408,16 @@ public class Server : GlobalBase settings.UpdateDownloadLocation(downloadLocation, moveFiles); SendResponse(HttpStatusCode.Accepted, response); break; + case "Settings/AprilFoolsMode": + if (!requestVariables.TryGetValue("enabled", out string? aprilFoolsModeEnabledStr) || + bool.TryParse(aprilFoolsModeEnabledStr, out bool aprilFoolsModeEnabled)) + { + SendResponse(HttpStatusCode.BadRequest, response); + break; + } + settings.UpdateAprilFoolsMode(aprilFoolsModeEnabled); + SendResponse(HttpStatusCode.Accepted, response); + break; /*case "Settings/UpdateWorkingDirectory": if (!requestVariables.TryGetValue("workingDirectory", out string? workingDirectory)) { diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index 9dcc387..f5a0f91 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -73,10 +73,23 @@ public partial class Tranga : GlobalBase { while (keepRunning) { - jobBoss.CheckJobs(); + if(!settings.aprilFoolsMode & !IsAprilFirst()) + jobBoss.CheckJobs(); + else + Log("April Fools Mode in Effect"); Thread.Sleep(100); } }); t.Start(); } + + private bool IsAprilFirst() + { + //UTC 01 Apr +-12hrs + DateTime start = new DateTime(DateTime.Now.Year, 03, 31, 12, 0, 0, DateTimeKind.Utc); + DateTime end = new DateTime(DateTime.Now.Year, 04, 02, 12, 0, 0, DateTimeKind.Utc); + if (DateTime.UtcNow > start && DateTime.UtcNow < end) + return true; + return false; + } } \ No newline at end of file diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs index 4fae2fb..0bb8399 100644 --- a/Tranga/TrangaSettings.cs +++ b/Tranga/TrangaSettings.cs @@ -20,7 +20,8 @@ public class TrangaSettings [JsonIgnore] public string jobsFolderPath => Path.Join(workingDirectory, "jobs"); [JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache"); [JsonIgnore] internal static readonly string DefaultUserAgent = $"Tranga ({Enum.GetName(Environment.OSVersion.Platform)}; {(Environment.Is64BitOperatingSystem ? "x64" : "")}) / 1.0"; - public ushort? version { get; set; } = 1; + public ushort? version { get; } = 1; + public bool aprilFoolsMode { get; private set; } = true; [JsonIgnore]internal static readonly Dictionary DefaultRequestLimits = new () { {RequestType.MangaInfo, 250}, @@ -102,6 +103,12 @@ public class TrangaSettings })!; } + public void UpdateAprilFoolsMode(bool enabled) + { + this.aprilFoolsMode = enabled; + ExportSettings(); + } + public void UpdateDownloadLocation(string newPath, bool moveFiles = true) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) From 82bdb248b92d972ef28a8204ced7506bfe19404f Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 15 Apr 2024 14:50:44 +0200 Subject: [PATCH 6/7] userAgent private set in settings --- Tranga/TrangaSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs index 0bb8399..7d674bd 100644 --- a/Tranga/TrangaSettings.cs +++ b/Tranga/TrangaSettings.cs @@ -13,7 +13,7 @@ public class TrangaSettings public string downloadLocation { get; private set; } public string workingDirectory { get; private set; } public int apiPortNumber { get; init; } - public string userAgent { get; set; } = DefaultUserAgent; + public string userAgent { get; private set; } = DefaultUserAgent; [JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json"); [JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json"); [JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json"); From c25a4f69eca0d90fe3facecec37740bcc3502641 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 15 Apr 2024 14:51:01 +0200 Subject: [PATCH 7/7] Cleanup --- Tranga/Server.cs | 2 +- Tranga/TrangaSettings.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Tranga/Server.cs b/Tranga/Server.cs index 75b159f..9b99c7a 100644 --- a/Tranga/Server.cs +++ b/Tranga/Server.cs @@ -400,7 +400,7 @@ public class Server : GlobalBase case "Settings/UpdateDownloadLocation": if (!requestVariables.TryGetValue("downloadLocation", out string? downloadLocation) || !requestVariables.TryGetValue("moveFiles", out string? moveFilesStr) || - !Boolean.TryParse(moveFilesStr, out bool moveFiles)) + !bool.TryParse(moveFilesStr, out bool moveFiles)) { SendResponse(HttpStatusCode.BadRequest, response); break; diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs index 7d674bd..596ab36 100644 --- a/Tranga/TrangaSettings.cs +++ b/Tranga/TrangaSettings.cs @@ -1,5 +1,4 @@ -using System.Net.Http.Headers; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; using Newtonsoft.Json; using Tranga.LibraryConnectors; using Tranga.MangaConnectors;