From 8af2b12fc0106eb901400010179715c52c3ab3db Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 16:26:29 +0200 Subject: [PATCH 01/11] Moved class to appropriate namespaces --- API/Program.cs | 2 ++ Tranga/{ => LibraryManagers}/LibraryManager.cs | 2 +- Tranga/Migrate.cs | 1 + Tranga/{ => NotificationManagers}/NotificationManager.cs | 3 +-- Tranga/TrangaTasks/DownloadChapterTask.cs | 2 ++ Tranga/{ => TrangaTasks}/TrangaTask.cs | 3 +-- 6 files changed, 8 insertions(+), 5 deletions(-) rename Tranga/{ => LibraryManagers}/LibraryManager.cs (99%) rename Tranga/{ => NotificationManagers}/NotificationManager.cs (97%) rename Tranga/{ => TrangaTasks}/TrangaTask.cs (99%) diff --git a/API/Program.cs b/API/Program.cs index 1bca2dc..1ea36d6 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -1,6 +1,8 @@ using System.Runtime.InteropServices; using Logging; using Tranga; +using Tranga.NotificationManagers; +using Tranga.LibraryManagers; namespace API; diff --git a/Tranga/LibraryManager.cs b/Tranga/LibraryManagers/LibraryManager.cs similarity index 99% rename from Tranga/LibraryManager.cs rename to Tranga/LibraryManagers/LibraryManager.cs index b0dcb70..c2ead5f 100644 --- a/Tranga/LibraryManager.cs +++ b/Tranga/LibraryManagers/LibraryManager.cs @@ -5,7 +5,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Tranga.LibraryManagers; -namespace Tranga; +namespace Tranga.LibraryManagers; public abstract class LibraryManager { diff --git a/Tranga/Migrate.cs b/Tranga/Migrate.cs index 61b34ee..4db6f5c 100644 --- a/Tranga/Migrate.cs +++ b/Tranga/Migrate.cs @@ -1,5 +1,6 @@ using Logging; using Newtonsoft.Json; +using Tranga.TrangaTasks; namespace Tranga; diff --git a/Tranga/NotificationManager.cs b/Tranga/NotificationManagers/NotificationManager.cs similarity index 97% rename from Tranga/NotificationManager.cs rename to Tranga/NotificationManagers/NotificationManager.cs index 1c6da52..7c65063 100644 --- a/Tranga/NotificationManager.cs +++ b/Tranga/NotificationManagers/NotificationManager.cs @@ -1,9 +1,8 @@ using Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Tranga.NotificationManagers; -namespace Tranga; +namespace Tranga.NotificationManagers; public abstract class NotificationManager { diff --git a/Tranga/TrangaTasks/DownloadChapterTask.cs b/Tranga/TrangaTasks/DownloadChapterTask.cs index fa396dd..8a76f69 100644 --- a/Tranga/TrangaTasks/DownloadChapterTask.cs +++ b/Tranga/TrangaTasks/DownloadChapterTask.cs @@ -1,5 +1,7 @@ using System.Net; using Logging; +using Tranga.NotificationManagers; +using Tranga.LibraryManagers; namespace Tranga.TrangaTasks; diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTasks/TrangaTask.cs similarity index 99% rename from Tranga/TrangaTask.cs rename to Tranga/TrangaTasks/TrangaTask.cs index 6dbf0d1..4c2b4eb 100644 --- a/Tranga/TrangaTask.cs +++ b/Tranga/TrangaTasks/TrangaTask.cs @@ -3,10 +3,9 @@ using System.Text.Json.Serialization; using Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Tranga.TrangaTasks; using JsonConverter = Newtonsoft.Json.JsonConverter; -namespace Tranga; +namespace Tranga.TrangaTasks; /// /// Stores information on Task, when implementing new Tasks also update the serializer From 579e400a5d6106d9f1ff97ad857fbeeec79f53f2 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:01:54 +0200 Subject: [PATCH 02/11] Moved class to appropriate namespaces --- API/RequestHandler.cs | 1 + Tranga-CLI/Tranga_Cli.cs | 1 + Tranga/{ => Connectors}/Connector.cs | 2 +- Tranga/TrangaTasks/DownloadChapterTask.cs | 1 + Tranga/TrangaTasks/MonitorPublicationTask.cs | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) rename Tranga/{ => Connectors}/Connector.cs (99%) diff --git a/API/RequestHandler.cs b/API/RequestHandler.cs index 5958a2d..2a5ac72 100644 --- a/API/RequestHandler.cs +++ b/API/RequestHandler.cs @@ -2,6 +2,7 @@ using System.Net; using System.Text.RegularExpressions; using Tranga; +using Tranga.Connectors; using Tranga.TrangaTasks; namespace API; diff --git a/Tranga-CLI/Tranga_Cli.cs b/Tranga-CLI/Tranga_Cli.cs index f0d2b07..fb1da45 100644 --- a/Tranga-CLI/Tranga_Cli.cs +++ b/Tranga-CLI/Tranga_Cli.cs @@ -1,6 +1,7 @@ using System.Globalization; using Logging; using Tranga; +using Tranga.Connectors; using Tranga.LibraryManagers; using Tranga.NotificationManagers; using Tranga.TrangaTasks; diff --git a/Tranga/Connector.cs b/Tranga/Connectors/Connector.cs similarity index 99% rename from Tranga/Connector.cs rename to Tranga/Connectors/Connector.cs index 1b9b157..e5f85d8 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connectors/Connector.cs @@ -7,7 +7,7 @@ using Logging; using Tranga.TrangaTasks; using static System.IO.UnixFileMode; -namespace Tranga; +namespace Tranga.Connectors; /// /// Base-Class for all Connectors diff --git a/Tranga/TrangaTasks/DownloadChapterTask.cs b/Tranga/TrangaTasks/DownloadChapterTask.cs index 8a76f69..939f5d3 100644 --- a/Tranga/TrangaTasks/DownloadChapterTask.cs +++ b/Tranga/TrangaTasks/DownloadChapterTask.cs @@ -1,5 +1,6 @@ using System.Net; using Logging; +using Tranga.Connectors; using Tranga.NotificationManagers; using Tranga.LibraryManagers; diff --git a/Tranga/TrangaTasks/MonitorPublicationTask.cs b/Tranga/TrangaTasks/MonitorPublicationTask.cs index 2b93f7c..ac72ab2 100644 --- a/Tranga/TrangaTasks/MonitorPublicationTask.cs +++ b/Tranga/TrangaTasks/MonitorPublicationTask.cs @@ -1,5 +1,6 @@ using System.Net; using Logging; +using Tranga.Connectors; namespace Tranga.TrangaTasks; From b4bef25a226b8d407424bcd8790f22b19150ed7f Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:04:43 +0200 Subject: [PATCH 03/11] Moved downloadclient to separate file --- Tranga/Connectors/Connector.cs | 108 +-------------------------------- Tranga/DownloadClient.cs | 108 +++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 106 deletions(-) create mode 100644 Tranga/DownloadClient.cs diff --git a/Tranga/Connectors/Connector.cs b/Tranga/Connectors/Connector.cs index e5f85d8..6f1d1a7 100644 --- a/Tranga/Connectors/Connector.cs +++ b/Tranga/Connectors/Connector.cs @@ -16,8 +16,8 @@ namespace Tranga.Connectors; public abstract class Connector { protected TrangaSettings settings { get; } - protected DownloadClient downloadClient { get; init; } = null!; - + internal DownloadClient downloadClient { get; init; } = null!; + protected readonly Logger? logger; @@ -272,108 +272,4 @@ public abstract class Connector logger?.WriteLine(this.GetType().ToString(), $"Saving image to {saveImagePath}"); return filename; } - - protected class DownloadClient - { - private static readonly HttpClient Client = new() - { - Timeout = TimeSpan.FromSeconds(60) - }; - - private readonly Dictionary _lastExecutedRateLimit; - private readonly Dictionary _rateLimit; - // ReSharper disable once InconsistentNaming - private readonly Logger? logger; - - /// - /// Creates a httpClient - /// - /// Rate limits for requests. byte is RequestType, int maximum requests per minute for RequestType - /// - public DownloadClient(Dictionary rateLimitRequestsPerMinute, Logger? logger) - { - this.logger = logger; - _lastExecutedRateLimit = new(); - _rateLimit = new(); - foreach(KeyValuePair limit in rateLimitRequestsPerMinute) - _rateLimit.Add(limit.Key, TimeSpan.FromMinutes(1).Divide(limit.Value)); - } - - /// - /// Request Webpage - /// - /// - /// For RateLimits: Same Endpoints use same type - /// Used in http request header - /// RequestResult with StatusCode and Stream of received data - public RequestResult MakeRequest(string url, byte requestType, string? referrer = null) - { - if (_rateLimit.TryGetValue(requestType, out TimeSpan value)) - _lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value)); - else - { - logger?.WriteLine(this.GetType().ToString(), "RequestType not configured for rate-limit."); - return new RequestResult(HttpStatusCode.NotAcceptable, Stream.Null); - } - - TimeSpan rateLimitTimeout = _rateLimit[requestType] - .Subtract(DateTime.Now.Subtract(_lastExecutedRateLimit[requestType])); - - if(rateLimitTimeout > TimeSpan.Zero) - Thread.Sleep(rateLimitTimeout); - - HttpResponseMessage? response = null; - while (response is null) - { - try - { - HttpRequestMessage requestMessage = new(HttpMethod.Get, url); - if(referrer is not null) - requestMessage.Headers.Referrer = new Uri(referrer); - _lastExecutedRateLimit[requestType] = DateTime.Now; - response = Client.Send(requestMessage); - } - catch (HttpRequestException e) - { - logger?.WriteLine(this.GetType().ToString(), e.Message); - logger?.WriteLine(this.GetType().ToString(), $"Waiting {_rateLimit[requestType] * 2}... Retrying."); - Thread.Sleep(_rateLimit[requestType] * 2); - } - } - if (!response.IsSuccessStatusCode) - { - logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}"); - return new RequestResult(response.StatusCode, Stream.Null); - } - - // Request has been redirected to another page. For example, it redirects directly to the results when there is only 1 result - if(response.RequestMessage is not null && response.RequestMessage.RequestUri is not null) - { - return new RequestResult(response.StatusCode, response.Content.ReadAsStream(), true, response.RequestMessage.RequestUri.AbsoluteUri); - } - - return new RequestResult(response.StatusCode, response.Content.ReadAsStream()); - } - - public struct RequestResult - { - public HttpStatusCode statusCode { get; } - public Stream result { get; } - public bool HasBeenRedirected { get; } - public string? RedirectedToUrl { get; } - - public RequestResult(HttpStatusCode statusCode, Stream result) - { - this.statusCode = statusCode; - this.result = result; - } - - public RequestResult(HttpStatusCode statusCode, Stream result, bool hasBeenRedirected, string redirectedTo) - : this(statusCode, result) - { - this.HasBeenRedirected = hasBeenRedirected; - RedirectedToUrl = redirectedTo; - } - } - } } \ No newline at end of file diff --git a/Tranga/DownloadClient.cs b/Tranga/DownloadClient.cs new file mode 100644 index 0000000..585b15a --- /dev/null +++ b/Tranga/DownloadClient.cs @@ -0,0 +1,108 @@ +using System.Net; +using Logging; + +namespace Tranga; + +internal class DownloadClient + { + private static readonly HttpClient Client = new() + { + Timeout = TimeSpan.FromSeconds(60) + }; + + private readonly Dictionary _lastExecutedRateLimit; + private readonly Dictionary _rateLimit; + // ReSharper disable once InconsistentNaming + private readonly Logger? logger; + + /// + /// Creates a httpClient + /// + /// Rate limits for requests. byte is RequestType, int maximum requests per minute for RequestType + /// + public DownloadClient(Dictionary rateLimitRequestsPerMinute, Logger? logger) + { + this.logger = logger; + _lastExecutedRateLimit = new(); + _rateLimit = new(); + foreach(KeyValuePair limit in rateLimitRequestsPerMinute) + _rateLimit.Add(limit.Key, TimeSpan.FromMinutes(1).Divide(limit.Value)); + } + + /// + /// Request Webpage + /// + /// + /// For RateLimits: Same Endpoints use same type + /// Used in http request header + /// RequestResult with StatusCode and Stream of received data + public RequestResult MakeRequest(string url, byte requestType, string? referrer = null) + { + if (_rateLimit.TryGetValue(requestType, out TimeSpan value)) + _lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value)); + else + { + logger?.WriteLine(this.GetType().ToString(), "RequestType not configured for rate-limit."); + return new RequestResult(HttpStatusCode.NotAcceptable, Stream.Null); + } + + TimeSpan rateLimitTimeout = _rateLimit[requestType] + .Subtract(DateTime.Now.Subtract(_lastExecutedRateLimit[requestType])); + + if(rateLimitTimeout > TimeSpan.Zero) + Thread.Sleep(rateLimitTimeout); + + HttpResponseMessage? response = null; + while (response is null) + { + try + { + HttpRequestMessage requestMessage = new(HttpMethod.Get, url); + if(referrer is not null) + requestMessage.Headers.Referrer = new Uri(referrer); + _lastExecutedRateLimit[requestType] = DateTime.Now; + response = Client.Send(requestMessage); + } + catch (HttpRequestException e) + { + logger?.WriteLine(this.GetType().ToString(), e.Message); + logger?.WriteLine(this.GetType().ToString(), $"Waiting {_rateLimit[requestType] * 2}... Retrying."); + Thread.Sleep(_rateLimit[requestType] * 2); + } + } + if (!response.IsSuccessStatusCode) + { + logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}"); + return new RequestResult(response.StatusCode, Stream.Null); + } + + // Request has been redirected to another page. For example, it redirects directly to the results when there is only 1 result + if(response.RequestMessage is not null && response.RequestMessage.RequestUri is not null) + { + return new RequestResult(response.StatusCode, response.Content.ReadAsStream(), true, response.RequestMessage.RequestUri.AbsoluteUri); + } + + return new RequestResult(response.StatusCode, response.Content.ReadAsStream()); + } + + public struct RequestResult + { + public HttpStatusCode statusCode { get; } + public Stream result { get; } + public bool HasBeenRedirected { get; } + public string? RedirectedToUrl { get; } + + public RequestResult(HttpStatusCode statusCode, Stream result) + { + this.statusCode = statusCode; + this.result = result; + } + + public RequestResult(HttpStatusCode statusCode, Stream result, bool hasBeenRedirected, string redirectedTo) + : this(statusCode, result) + { + this.HasBeenRedirected = hasBeenRedirected; + RedirectedToUrl = redirectedTo; + } + } + } \ No newline at end of file From 000539d6a6e9ae9853437efc9c0c1674f774a785 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:08:43 +0200 Subject: [PATCH 04/11] Moved logger to Trangasettings --- API/Program.cs | 18 ++++---- API/RequestHandler.cs | 10 ++-- Tranga-CLI/Tranga_Cli.cs | 14 +++--- Tranga/Connectors/Connector.cs | 25 ++++------ Tranga/Connectors/MangaDex.cs | 25 +++++----- Tranga/Connectors/MangaKatana.cs | 13 +++--- Tranga/Connectors/Manganato.cs | 13 +++--- Tranga/Connectors/Mangasee.cs | 27 ++++++----- Tranga/TaskManager.cs | 48 ++++++++++---------- Tranga/TrangaSettings.cs | 16 ++++--- Tranga/TrangaTasks/DownloadChapterTask.cs | 3 +- Tranga/TrangaTasks/MonitorPublicationTask.cs | 3 +- Tranga/TrangaTasks/TrangaTask.cs | 12 ++--- 13 files changed, 107 insertions(+), 120 deletions(-) diff --git a/API/Program.cs b/API/Program.cs index 1ea36d6..fc41b84 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -29,22 +29,22 @@ public class Program if (File.Exists(settingsFilePath)) settings = TrangaSettings.LoadSettings(settingsFilePath, logger); else - settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, new HashSet(), new HashSet()); + settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, new HashSet(), new HashSet(), logger); Directory.CreateDirectory(settings.workingDirectory); Directory.CreateDirectory(settings.downloadLocation); Directory.CreateDirectory(settings.coverImageCache); - logger.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}"); - logger.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}"); - logger.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}"); - logger.WriteLine("Tranga",$"Logfile-Path: {logFilePath}"); - logger.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}"); + settings.logger?.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}"); + settings.logger?.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}"); + settings.logger?.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}"); + settings.logger?.WriteLine("Tranga",$"Logfile-Path: {logFilePath}"); + settings.logger?.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}"); - logger.WriteLine("Tranga", "Loading Taskmanager."); - TaskManager taskManager = new (settings, logger); + settings.logger?.WriteLine("Tranga", "Loading Taskmanager."); + TaskManager taskManager = new (settings); - Server server = new (6531, taskManager, logger); + Server server = new (6531, taskManager); foreach(NotificationManager nm in taskManager.settings.notificationManagers) nm.SendNotification("Tranga-API", "Started Tranga-API"); } diff --git a/API/RequestHandler.cs b/API/RequestHandler.cs index 2a5ac72..4572ee1 100644 --- a/API/RequestHandler.cs +++ b/API/RequestHandler.cs @@ -247,17 +247,17 @@ public class RequestHandler variables.TryGetValue("lunaseaWebhook", out string? lunaseaWebhook); if (downloadLocation is not null && downloadLocation.Length > 0) - _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, _parent.logger, downloadLocation); + _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, downloadLocation); if (komgaUrl is not null && komgaAuth is not null && komgaUrl.Length > 5 && komgaAuth.Length > 0) - _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Komga, _parent.logger, komgaUrl, komgaAuth); + _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Komga, komgaUrl, komgaAuth); if (kavitaUrl is not null && kavitaPassword is not null && kavitaUsername is not null && kavitaUrl.Length > 5 && kavitaUsername.Length > 0 && kavitaPassword.Length > 0) - _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, _parent.logger, kavitaUrl, kavitaUsername, + _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, kavitaUrl, kavitaUsername, kavitaPassword); if (gotifyUrl is not null && gotifyAppToken is not null && gotifyUrl.Length > 5 && gotifyAppToken.Length > 0) - _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, _parent.logger, gotifyUrl, gotifyAppToken); + _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, gotifyUrl, gotifyAppToken); if(lunaseaWebhook is not null && lunaseaWebhook.Length > 5) - _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.LunaSea, _parent.logger, lunaseaWebhook); + _taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.LunaSea, lunaseaWebhook); break; } } diff --git a/Tranga-CLI/Tranga_Cli.cs b/Tranga-CLI/Tranga_Cli.cs index fb1da45..a131b5e 100644 --- a/Tranga-CLI/Tranga_Cli.cs +++ b/Tranga-CLI/Tranga_Cli.cs @@ -32,16 +32,16 @@ public static class Tranga_Cli Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, Console.Out.Encoding, logFilePath); logger.WriteLine("Tranga_CLI", "Loading Taskmanager."); - TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath, logger) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, new HashSet(), new HashSet()); + TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath, logger) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, new HashSet(), new HashSet(), logger); - logger.WriteLine("Tranga_CLI", "User Input"); + settings.logger?.WriteLine("Tranga_CLI", "User Input"); Console.WriteLine($"Output folder path [{settings.downloadLocation}]:"); string? tmpPath = Console.ReadLine(); while(tmpPath is null) tmpPath = Console.ReadLine(); if (tmpPath.Length > 0) - settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, logger, tmpPath); + settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, tmpPath); Console.WriteLine($"Komga BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Komga))?.baseUrl}]:"); string? tmpUrlKomga = Console.ReadLine(); @@ -74,7 +74,7 @@ public static class Tranga_Cli } } while (key != ConsoleKey.Enter); - settings.UpdateSettings(TrangaSettings.UpdateField.Komga, logger, tmpUrlKomga, tmpKomgaUser, tmpKomgaPass); + settings.UpdateSettings(TrangaSettings.UpdateField.Komga, tmpUrlKomga, tmpKomgaUser, tmpKomgaPass); } Console.WriteLine($"Kavita BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Kavita))?.baseUrl}]:"); @@ -108,7 +108,7 @@ public static class Tranga_Cli } } while (key != ConsoleKey.Enter); - settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, logger, tmpUrlKavita, tmpKavitaUser, tmpKavitaPass); + settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, tmpUrlKavita, tmpKavitaUser, tmpKavitaPass); } Console.WriteLine($"Gotify BaseURL [{((Gotify?)settings.notificationManagers.FirstOrDefault(lm => lm.GetType() == typeof(Gotify)))?.endpoint}]:"); @@ -122,7 +122,7 @@ public static class Tranga_Cli while (tmpGotifyAppToken is null || tmpGotifyAppToken.Length < 1) tmpGotifyAppToken = Console.ReadLine(); - settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, logger, tmpGotifyUrl, tmpGotifyAppToken); + settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, tmpGotifyUrl, tmpGotifyAppToken); } logger.WriteLine("Tranga_CLI", "Loaded."); @@ -133,7 +133,7 @@ public static class Tranga_Cli private static void TaskMode(TrangaSettings settings, Logger logger) { - TaskManager taskManager = new (settings, logger); + TaskManager taskManager = new (settings); ConsoleKey selection = ConsoleKey.EraseEndOfFile; PrintMenu(taskManager, taskManager.settings.downloadLocation); while (selection != ConsoleKey.Q) diff --git a/Tranga/Connectors/Connector.cs b/Tranga/Connectors/Connector.cs index 6f1d1a7..f048133 100644 --- a/Tranga/Connectors/Connector.cs +++ b/Tranga/Connectors/Connector.cs @@ -3,7 +3,6 @@ using System.IO.Compression; using System.Net; using System.Runtime.InteropServices; using System.Text.RegularExpressions; -using Logging; using Tranga.TrangaTasks; using static System.IO.UnixFileMode; @@ -18,13 +17,9 @@ public abstract class Connector protected TrangaSettings settings { get; } internal DownloadClient downloadClient { get; init; } = null!; - protected readonly Logger? logger; - - - protected Connector(TrangaSettings settings, Logger? logger = null) + protected Connector(TrangaSettings settings) { this.settings = settings; - this.logger = logger; if (!Directory.Exists(settings.coverImageCache)) Directory.CreateDirectory(settings.coverImageCache); } @@ -68,11 +63,11 @@ public abstract class Connector Chapter[] newChapters = this.GetChapters(publication, language); collection.Add(publication); NumberFormatInfo decimalPoint = new (){ NumberDecimalSeparator = "." }; - logger?.WriteLine(this.GetType().ToString(), "Checking for duplicates"); + settings.logger?.WriteLine(this.GetType().ToString(), "Checking for duplicates"); List newChaptersList = newChapters.Where(nChapter => float.Parse(nChapter.chapterNumber, decimalPoint) > publication.ignoreChaptersBelow && !nChapter.CheckChapterIsDownloaded(settings.downloadLocation)).ToList(); - logger?.WriteLine(this.GetType().ToString(), $"{newChaptersList.Count} new chapters."); + settings.logger?.WriteLine(this.GetType().ToString(), $"{newChaptersList.Count} new chapters."); return newChaptersList; } @@ -167,19 +162,19 @@ public abstract class Connector /// TrangaSettings public void CopyCoverFromCacheToDownloadLocation(Publication publication, TrangaSettings settings) { - logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {publication.sortName} -> {publication.internalId}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {publication.sortName} -> {publication.internalId}"); //Check if Publication already has a Folder and cover string publicationFolder = publication.CreatePublicationFolder(settings.downloadLocation); DirectoryInfo dirInfo = new (publicationFolder); if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase))) { - logger?.WriteLine(this.GetType().ToString(), $"Cover exists {publication.sortName}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Cover exists {publication.sortName}"); return; } string fileInCache = Path.Join(settings.coverImageCache, publication.coverFileNameInCache); string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" ); - logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {fileInCache} -> {newFilePath}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {fileInCache} -> {newFilePath}"); File.Copy(fileInCache, newFilePath, true); if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) File.SetUnixFileMode(newFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite); @@ -217,7 +212,7 @@ public abstract class Connector { if (cancellationToken?.IsCancellationRequested ?? false) return HttpStatusCode.RequestTimeout; - logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}"); + settings.logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}"); //Check if Publication Directory already exists string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!; if (!Directory.Exists(directoryPath)) @@ -235,7 +230,7 @@ public abstract class Connector { string[] split = imageUrl.Split('.'); string extension = split[^1]; - logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {parentTask.publication.sortName} {parentTask.publication.internalId} Vol.{parentTask.chapter.volumeNumber} Ch.{parentTask.chapter.chapterNumber} {parentTask.progress:P2}"); + settings.logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {parentTask.publication.sortName} {parentTask.publication.internalId} Vol.{parentTask.chapter.volumeNumber} Ch.{parentTask.chapter.chapterNumber} {parentTask.progress:P2}"); HttpStatusCode status = DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer); if ((int)status < 200 || (int)status >= 300) return status; @@ -247,7 +242,7 @@ public abstract class Connector if(comicInfoPath is not null) File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml")); - logger?.WriteLine("Connector", $"Creating archive {saveArchiveFilePath}"); + settings.logger?.WriteLine("Connector", $"Creating archive {saveArchiveFilePath}"); //ZIP-it and ship-it ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath); if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) @@ -269,7 +264,7 @@ public abstract class Connector using MemoryStream ms = new(); coverResult.result.CopyTo(ms); File.WriteAllBytes(saveImagePath, ms.ToArray()); - logger?.WriteLine(this.GetType().ToString(), $"Saving image to {saveImagePath}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Saving image to {saveImagePath}"); return filename; } } \ No newline at end of file diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index 58c4abf..4ff9d2c 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -2,7 +2,6 @@ using System.Net; using System.Text.Json; using System.Text.Json.Nodes; -using Logging; using Tranga.TrangaTasks; namespace Tranga.Connectors; @@ -19,7 +18,7 @@ public class MangaDex : Connector Author, } - public MangaDex(TrangaSettings settings, Logger? logger = null) : base(settings, logger) + public MangaDex(TrangaSettings settings) : base(settings) { name = "MangaDex"; this.downloadClient = new DownloadClient(new Dictionary() @@ -29,12 +28,12 @@ public class MangaDex : Connector {(byte)RequestType.AtHomeServer, 40}, {(byte)RequestType.CoverUrl, 250}, {(byte)RequestType.Author, 250} - }, logger); + }, settings.logger); } protected override Publication[] GetPublicationsInternal(string publicationTitle = "") { - logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); const int limit = 100; //How many values we want returned at once int offset = 0; //"Page" int total = int.MaxValue; //How many total results are there, is updated on first request @@ -60,7 +59,7 @@ public class MangaDex : Connector //Loop each Manga and extract information from JSON foreach (JsonNode? mangeNode in mangaInResult) { - logger?.WriteLine(this.GetType().ToString(), $"Getting publication data. {++loadedPublicationData}/{total}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Getting publication data. {++loadedPublicationData}/{total}"); JsonObject manga = (JsonObject)mangeNode!; JsonObject attributes = manga["attributes"]!.AsObject(); @@ -147,13 +146,13 @@ public class MangaDex : Connector } } - logger?.WriteLine(this.GetType().ToString(), $"Done getting publications (title={publicationTitle})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Done getting publications (title={publicationTitle})"); return publications.ToArray(); } public override Chapter[] GetChapters(Publication publication, string language = "") { - logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})"); const int limit = 100; //How many values we want returned at once int offset = 0; //"Page" int total = int.MaxValue; //How many total results are there, is updated on first request @@ -204,7 +203,7 @@ public class MangaDex : Connector { NumberDecimalSeparator = "." }; - logger?.WriteLine(this.GetType().ToString(), $"Done getting {chapters.Count} Chapters for {publication.internalId}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Done getting {chapters.Count} Chapters for {publication.internalId}"); return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray(); } @@ -212,7 +211,7 @@ public class MangaDex : Connector { if (cancellationToken?.IsCancellationRequested ?? false) return HttpStatusCode.RequestTimeout; - logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); //Request URLs for Chapter-Images DownloadClient.RequestResult requestResult = downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", (byte)RequestType.AtHomeServer); @@ -239,10 +238,10 @@ public class MangaDex : Connector private string? GetCoverUrl(string publicationId, string? posterId) { - logger?.WriteLine(this.GetType().ToString(), $"Getting CoverUrl for {publicationId}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Getting CoverUrl for {publicationId}"); if (posterId is null) { - logger?.WriteLine(this.GetType().ToString(), $"No posterId, aborting"); + settings.logger?.WriteLine(this.GetType().ToString(), $"No posterId, aborting"); return null; } @@ -258,7 +257,7 @@ public class MangaDex : Connector string fileName = result["data"]!["attributes"]!["fileName"]!.GetValue(); string coverUrl = $"https://uploads.mangadex.org/covers/{publicationId}/{fileName}"; - logger?.WriteLine(this.GetType().ToString(), $"Got Cover-Url for {publicationId} -> {coverUrl}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Got Cover-Url for {publicationId} -> {coverUrl}"); return coverUrl; } @@ -277,7 +276,7 @@ public class MangaDex : Connector string authorName = result["data"]!["attributes"]!["name"]!.GetValue(); ret.Add(authorName); - logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {authorName}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {authorName}"); } return ret; } diff --git a/Tranga/Connectors/MangaKatana.cs b/Tranga/Connectors/MangaKatana.cs index 12f1e8c..ffb6a84 100644 --- a/Tranga/Connectors/MangaKatana.cs +++ b/Tranga/Connectors/MangaKatana.cs @@ -2,7 +2,6 @@ using System.Net; using System.Text.RegularExpressions; using HtmlAgilityPack; -using Logging; using Tranga.TrangaTasks; namespace Tranga.Connectors; @@ -11,18 +10,18 @@ public class MangaKatana : Connector { public override string name { get; } - public MangaKatana(TrangaSettings settings, Logger? logger = null) : base(settings, logger) + public MangaKatana(TrangaSettings settings) : base(settings) { this.name = "MangaKatana"; this.downloadClient = new DownloadClient(new Dictionary() { {(byte)1, 60} - }, logger); + }, settings.logger); } protected override Publication[] GetPublicationsInternal(string publicationTitle = "") { - logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '_'); string requestUrl = $"https://mangakatana.com/?search={sanitizedTitle}&search_by=book_name"; DownloadClient.RequestResult requestResult = @@ -136,7 +135,7 @@ public class MangaKatana : Connector public override Chapter[] GetChapters(Publication publication, string language = "") { - logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})"); string requestUrl = $"https://mangakatana.com/manga/{publication.publicationId}"; // Leaving this in for verification if the page exists DownloadClient.RequestResult requestResult = @@ -150,7 +149,7 @@ public class MangaKatana : Connector NumberDecimalSeparator = "." }; List chapters = ParseChaptersFromHtml(publication, requestUrl); - logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}"); return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray(); } @@ -183,7 +182,7 @@ public class MangaKatana : Connector { if (cancellationToken?.IsCancellationRequested ?? false) return HttpStatusCode.RequestTimeout; - logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); string requestUrl = chapter.url; // Leaving this in to check if the page exists DownloadClient.RequestResult requestResult = diff --git a/Tranga/Connectors/Manganato.cs b/Tranga/Connectors/Manganato.cs index f01db65..cc050bb 100644 --- a/Tranga/Connectors/Manganato.cs +++ b/Tranga/Connectors/Manganato.cs @@ -2,7 +2,6 @@ using System.Net; using System.Text.RegularExpressions; using HtmlAgilityPack; -using Logging; using Tranga.TrangaTasks; namespace Tranga.Connectors; @@ -11,18 +10,18 @@ public class Manganato : Connector { public override string name { get; } - public Manganato(TrangaSettings settings, Logger? logger = null) : base(settings, logger) + public Manganato(TrangaSettings settings) : base(settings) { this.name = "Manganato"; this.downloadClient = new DownloadClient(new Dictionary() { {(byte)1, 60} - }, logger); + }, settings.logger); } protected override Publication[] GetPublicationsInternal(string publicationTitle = "") { - logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*")).ToLower(); string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}"; DownloadClient.RequestResult requestResult = @@ -127,7 +126,7 @@ public class Manganato : Connector public override Chapter[] GetChapters(Publication publication, string language = "") { - logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})"); string requestUrl = $"https://chapmanganato.com/{publication.publicationId}"; DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(requestUrl, (byte)1); @@ -140,7 +139,7 @@ public class Manganato : Connector NumberDecimalSeparator = "." }; List chapters = ParseChaptersFromHtml(publication, requestResult.result); - logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}"); return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray(); } @@ -173,7 +172,7 @@ public class Manganato : Connector { if (cancellationToken?.IsCancellationRequested ?? false) return HttpStatusCode.RequestTimeout; - logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); string requestUrl = chapter.url; DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(requestUrl, (byte)1); diff --git a/Tranga/Connectors/Mangasee.cs b/Tranga/Connectors/Mangasee.cs index df282e0..3bc6cb9 100644 --- a/Tranga/Connectors/Mangasee.cs +++ b/Tranga/Connectors/Mangasee.cs @@ -3,7 +3,6 @@ using System.Net; using System.Text.RegularExpressions; using System.Xml.Linq; using HtmlAgilityPack; -using Logging; using Newtonsoft.Json; using PuppeteerSharp; using Tranga.TrangaTasks; @@ -16,13 +15,13 @@ public class Mangasee : Connector private IBrowser? _browser = null; private const string ChromiumVersion = "1154303"; - public Mangasee(TrangaSettings settings, Logger? logger = null) : base(settings, logger) + public Mangasee(TrangaSettings settings) : base(settings) { this.name = "Mangasee"; this.downloadClient = new DownloadClient(new Dictionary() { { (byte)1, 60 } - }, logger); + }, settings.logger); Task d = new Task(DownloadBrowser); d.Start(); @@ -35,31 +34,31 @@ public class Mangasee : Connector browserFetcher.Remove(rev); if (!browserFetcher.LocalRevisions().Contains(ChromiumVersion)) { - logger?.WriteLine(this.GetType().ToString(), "Downloading headless browser"); + settings.logger?.WriteLine(this.GetType().ToString(), "Downloading headless browser"); DateTime last = DateTime.Now.Subtract(TimeSpan.FromSeconds(5)); browserFetcher.DownloadProgressChanged += (sender, args) => { double currentBytes = Convert.ToDouble(args.BytesReceived) / Convert.ToDouble(args.TotalBytesToReceive); if (args.TotalBytesToReceive == args.BytesReceived) { - logger?.WriteLine(this.GetType().ToString(), "Browser downloaded."); + settings.logger?.WriteLine(this.GetType().ToString(), "Browser downloaded."); } else if (DateTime.Now > last.AddSeconds(5)) { - logger?.WriteLine(this.GetType().ToString(), $"Browser download progress: {currentBytes:P2}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Browser download progress: {currentBytes:P2}"); last = DateTime.Now; } }; if (!browserFetcher.CanDownloadAsync(ChromiumVersion).Result) { - logger?.WriteLine(this.GetType().ToString(), $"Can't download browser version {ChromiumVersion}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Can't download browser version {ChromiumVersion}"); return; } await browserFetcher.DownloadAsync(ChromiumVersion); } - logger?.WriteLine(this.GetType().ToString(), "Starting browser."); + settings.logger?.WriteLine(this.GetType().ToString(), "Starting browser."); this._browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true, @@ -74,7 +73,7 @@ public class Mangasee : Connector protected override Publication[] GetPublicationsInternal(string publicationTitle = "") { - logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); string requestUrl = $"https://mangasee123.com/_search.php"; DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(requestUrl, (byte)1); @@ -99,7 +98,7 @@ public class Mangasee : Connector queryFiltered = queryFiltered.Where(item => item.Value >= publicationTitle.Split(' ').Length - 1) .ToDictionary(item => item.Key, item => item.Value); - logger?.WriteLine(this.GetType().ToString(), $"Got {queryFiltered.Count} Publications (title={publicationTitle})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Got {queryFiltered.Count} Publications (title={publicationTitle})"); HashSet ret = new(); List orderedFiltered = @@ -112,7 +111,7 @@ public class Mangasee : Connector downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", (byte)1); if ((int)requestResult.statusCode >= 200 || (int)requestResult.statusCode < 300) { - logger?.WriteLine(this.GetType().ToString(), $"Retrieving Publication info: {orderedItem.s} {index++}/{orderedFiltered.Count}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Retrieving Publication info: {orderedItem.s} {index++}/{orderedFiltered.Count}"); ret.Add(ParseSinglePublicationFromHtml(requestResult.result, orderedItem.s, orderedItem.i, orderedItem.a)); } } @@ -230,7 +229,7 @@ public class Mangasee : Connector { NumberDecimalSeparator = "." }; - logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}"); return ret.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray(); } @@ -240,13 +239,13 @@ public class Mangasee : Connector return HttpStatusCode.RequestTimeout; while (this._browser is null && !(cancellationToken?.IsCancellationRequested??false)) { - logger?.WriteLine(this.GetType().ToString(), "Waiting for headless browser to download..."); + settings.logger?.WriteLine(this.GetType().ToString(), "Waiting for headless browser to download..."); Thread.Sleep(1000); } if (cancellationToken?.IsCancellationRequested??false) return HttpStatusCode.RequestTimeout; - logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); IPage page = _browser!.NewPageAsync().Result; IResponse response = page.GoToAsync(chapter.url).Result; if (response.Ok) diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index 383ab2d..f3f4076 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -17,23 +17,21 @@ public class TaskManager private bool _continueRunning = true; private readonly Connector[] _connectors; public TrangaSettings settings { get; } - private Logger? logger { get; } - public TaskManager(TrangaSettings settings, Logger? logger = null) + public TaskManager(TrangaSettings settings) { - this.logger = logger; - logger?.WriteLine("Tranga", value: "\n"+ - @"-----------------------------------------------------------------"+"\n"+ - @" |¯¯¯¯¯¯|°|¯¯¯¯¯¯\ /¯¯¯¯¯¯| |¯¯¯\|¯¯¯| /¯¯¯¯¯¯\' /¯¯¯¯¯¯| "+"\n"+ - @" | | | x <|' / ! | | '| | (/¯¯¯\° / ! | "+ "\n"+ - @" ¯|__|¯ |__|\\__\\ /___/¯|_'| |___|\\__| \\_____/' /___/¯|_'| "+ "\n"+ - @"-----------------------------------------------------------------"); + settings.logger?.WriteLine("Tranga", value: "\n"+ + @"-----------------------------------------------------------------"+"\n"+ + @" |¯¯¯¯¯¯|°|¯¯¯¯¯¯\ /¯¯¯¯¯¯| |¯¯¯\|¯¯¯| /¯¯¯¯¯¯\' /¯¯¯¯¯¯| "+"\n"+ + @" | | | x <|' / ! | | '| | (/¯¯¯\° / ! | "+ "\n"+ + @" ¯|__|¯ |__|\\__\\ /___/¯|_'| |___|\\__| \\_____/' /___/¯|_'| "+ "\n"+ + @"-----------------------------------------------------------------"); this._connectors = new Connector[] { - new MangaDex(settings, logger), - new Manganato(settings, logger), - new Mangasee(settings, logger), - new MangaKatana(settings, logger) + new MangaDex(settings), + new Manganato(settings), + new Mangasee(settings), + new MangaKatana(settings) }; this.settings = settings; @@ -50,7 +48,7 @@ public class TaskManager /// private void TaskCheckerThread() { - logger?.WriteLine(this.GetType().ToString(), "Starting TaskCheckerThread."); + settings.logger?.WriteLine(this.GetType().ToString(), "Starting TaskCheckerThread."); int waitingTasksCount = _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting); while (_continueRunning) { @@ -137,7 +135,7 @@ public class TaskManager CancellationTokenSource cToken = new (); Task t = new(() => { - task.Execute(this, this.logger, cToken.Token); + task.Execute(this, cToken.Token); }, cToken.Token); _runningTasks.Add(task, cToken); t.Start(); @@ -149,7 +147,7 @@ public class TaskManager { case TrangaTask.Task.UpdateLibraries: //Only one UpdateKomgaLibrary Task - logger?.WriteLine(this.GetType().ToString(), $"Replacing old {newTask.task}-Task."); + settings.logger?.WriteLine(this.GetType().ToString(), $"Replacing old {newTask.task}-Task."); if (GetTasksMatching(newTask).FirstOrDefault() is { } exists) _allTasks.Remove(exists); _allTasks.Add(newTask); @@ -158,19 +156,19 @@ public class TaskManager default: if (!GetTasksMatching(newTask).Any()) { - logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {newTask}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {newTask}"); _allTasks.Add(newTask); ExportDataAndSettings(); } else - logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask}"); break; } } public void DeleteTask(TrangaTask removeTask) { - logger?.WriteLine(this.GetType().ToString(), $"Removing Task {removeTask}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Removing Task {removeTask}"); if(_allTasks.Contains(removeTask)) _allTasks.Remove(removeTask); removeTask.parentTask?.RemoveChildTask(removeTask); @@ -321,7 +319,7 @@ public class TaskManager /// If force is true, tasks are aborted. public void Shutdown(bool force = false) { - logger?.WriteLine(this.GetType().ToString(), $"Shutting down (forced={force})"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Shutting down (forced={force})"); _continueRunning = false; ExportDataAndSettings(); @@ -331,17 +329,17 @@ public class TaskManager //Wait for tasks to finish while(_allTasks.Any(task => task.state is TrangaTask.ExecutionState.Running or TrangaTask.ExecutionState.Enqueued)) Thread.Sleep(10); - logger?.WriteLine(this.GetType().ToString(), "Tasks finished. Bye!"); + settings.logger?.WriteLine(this.GetType().ToString(), "Tasks finished. Bye!"); Environment.Exit(0); } private void ImportData() { - logger?.WriteLine(this.GetType().ToString(), "Importing Data"); + settings.logger?.WriteLine(this.GetType().ToString(), "Importing Data"); string buffer; if (File.Exists(settings.tasksFilePath)) { - logger?.WriteLine(this.GetType().ToString(), $"Importing tasks from {settings.tasksFilePath}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Importing tasks from {settings.tasksFilePath}"); buffer = File.ReadAllText(settings.tasksFilePath); this._allTasks = JsonConvert.DeserializeObject>(buffer, new JsonSerializerSettings() { Converters = { new TrangaTask.TrangaTaskJsonConverter() } })!; } @@ -362,10 +360,10 @@ public class TaskManager /// private void ExportDataAndSettings() { - logger?.WriteLine(this.GetType().ToString(), $"Exporting settings to {settings.settingsFilePath}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Exporting settings to {settings.settingsFilePath}"); settings.ExportSettings(); - logger?.WriteLine(this.GetType().ToString(), $"Exporting tasks to {settings.tasksFilePath}"); + settings.logger?.WriteLine(this.GetType().ToString(), $"Exporting tasks to {settings.tasksFilePath}"); while(IsFileInUse(settings.tasksFilePath)) Thread.Sleep(50); File.WriteAllText(settings.tasksFilePath, JsonConvert.SerializeObject(this._allTasks)); diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs index d272477..d142ed2 100644 --- a/Tranga/TrangaSettings.cs +++ b/Tranga/TrangaSettings.cs @@ -16,9 +16,10 @@ public class TrangaSettings public HashSet libraryManagers { get; } public HashSet notificationManagers { get; } public ushort? version { get; set; } + [JsonIgnore] public Logger? logger { get; init; } public TrangaSettings(string downloadLocation, string workingDirectory, HashSet? libraryManagers, - HashSet? notificationManagers) + HashSet? notificationManagers, Logger? logger) { if (downloadLocation.Length < 1 || workingDirectory.Length < 1) throw new ArgumentException("Download-location and working-directory paths can not be empty!"); @@ -26,13 +27,14 @@ public class TrangaSettings this.downloadLocation = downloadLocation; this.libraryManagers = libraryManagers??new(); this.notificationManagers = notificationManagers??new(); + this.logger = logger; } public static TrangaSettings LoadSettings(string importFilePath, Logger? logger) { if (!File.Exists(importFilePath)) return new TrangaSettings(Path.Join(Directory.GetCurrentDirectory(), "Downloads"), - Directory.GetCurrentDirectory(), new HashSet(), new HashSet()); + Directory.GetCurrentDirectory(), new HashSet(), new HashSet(), logger); string toRead = File.ReadAllText(importFilePath); TrangaSettings settings = JsonConvert.DeserializeObject(toRead, @@ -71,7 +73,7 @@ public class TrangaSettings File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this)); } - public void UpdateSettings(UpdateField field, Logger? logger = null, params string[] values) + public void UpdateSettings(UpdateField field, params string[] values) { switch (field) { @@ -84,19 +86,19 @@ public class TrangaSettings if (values.Length != 2) return; libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Komga)); - libraryManagers.Add(new Komga(values[0], values[1], logger)); + libraryManagers.Add(new Komga(values[0], values[1], this.logger)); break; case UpdateField.Kavita: if (values.Length != 3) return; libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Kavita)); - libraryManagers.Add(new Kavita(values[0], values[1], values[2], logger)); + libraryManagers.Add(new Kavita(values[0], values[1], values[2], this.logger)); break; case UpdateField.Gotify: if (values.Length != 2) return; notificationManagers.RemoveWhere(nm => nm.GetType() == typeof(Gotify)); - Gotify newGotify = new(values[0], values[1], logger); + Gotify newGotify = new(values[0], values[1], this.logger); notificationManagers.Add(newGotify); newGotify.SendNotification("Success!", "Gotify was added to Tranga!"); break; @@ -104,7 +106,7 @@ public class TrangaSettings if(values.Length != 1) return; notificationManagers.RemoveWhere(nm => nm.GetType() == typeof(LunaSea)); - LunaSea newLunaSea = new(values[0], logger); + LunaSea newLunaSea = new(values[0], this.logger); notificationManagers.Add(newLunaSea); newLunaSea.SendNotification("Success!", "LunaSea was added to Tranga!"); break; diff --git a/Tranga/TrangaTasks/DownloadChapterTask.cs b/Tranga/TrangaTasks/DownloadChapterTask.cs index 939f5d3..1546621 100644 --- a/Tranga/TrangaTasks/DownloadChapterTask.cs +++ b/Tranga/TrangaTasks/DownloadChapterTask.cs @@ -1,5 +1,4 @@ using System.Net; -using Logging; using Tranga.Connectors; using Tranga.NotificationManagers; using Tranga.LibraryManagers; @@ -23,7 +22,7 @@ public class DownloadChapterTask : TrangaTask this.language = language; } - protected override HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null) + protected override HttpStatusCode ExecuteTask(TaskManager taskManager, CancellationToken? cancellationToken = null) { if (cancellationToken?.IsCancellationRequested ?? false) return HttpStatusCode.RequestTimeout; diff --git a/Tranga/TrangaTasks/MonitorPublicationTask.cs b/Tranga/TrangaTasks/MonitorPublicationTask.cs index ac72ab2..5173ee6 100644 --- a/Tranga/TrangaTasks/MonitorPublicationTask.cs +++ b/Tranga/TrangaTasks/MonitorPublicationTask.cs @@ -1,5 +1,4 @@ using System.Net; -using Logging; using Tranga.Connectors; namespace Tranga.TrangaTasks; @@ -16,7 +15,7 @@ public class MonitorPublicationTask : TrangaTask this.language = language; } - protected override HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null) + protected override HttpStatusCode ExecuteTask(TaskManager taskManager, CancellationToken? cancellationToken = null) { if (cancellationToken?.IsCancellationRequested ?? false) return HttpStatusCode.RequestTimeout; diff --git a/Tranga/TrangaTasks/TrangaTask.cs b/Tranga/TrangaTasks/TrangaTask.cs index 4c2b4eb..d867faa 100644 --- a/Tranga/TrangaTasks/TrangaTask.cs +++ b/Tranga/TrangaTasks/TrangaTask.cs @@ -51,9 +51,8 @@ public abstract class TrangaTask /// BL for concrete Tasks /// /// - /// /// - protected abstract HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null); + protected abstract HttpStatusCode ExecuteTask(TaskManager taskManager, CancellationToken? cancellationToken = null); public abstract TrangaTask Clone(); @@ -63,18 +62,17 @@ public abstract class TrangaTask /// Execute the task /// /// Should be the parent taskManager - /// /// - public void Execute(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null) + public void Execute(TaskManager taskManager, CancellationToken? cancellationToken = null) { - logger?.WriteLine(this.GetType().ToString(), $"Executing Task {this}"); + taskManager.settings.logger?.WriteLine(this.GetType().ToString(), $"Executing Task {this}"); this.state = ExecutionState.Running; this.executionStarted = DateTime.Now; this.lastChange = DateTime.Now; if(parentTask is not null && parentTask.childTasks.All(ct => ct.state is ExecutionState.Waiting or ExecutionState.Failed)) parentTask.executionStarted = DateTime.Now; - HttpStatusCode statusCode = ExecuteTask(taskManager, logger, cancellationToken); + HttpStatusCode statusCode = ExecuteTask(taskManager, cancellationToken); if ((int)statusCode >= 200 && (int)statusCode < 300) { @@ -90,7 +88,7 @@ public abstract class TrangaTask if (this is DownloadChapterTask) taskManager.DeleteTask(this); - logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}"); + taskManager.settings.logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}"); } public void AddChildTask(TrangaTask childTask) From 437349bd27836914d2ae2641be151dafa54b60b3 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:09:10 +0200 Subject: [PATCH 05/11] TrangaSettings changed set directive --- Tranga/TrangaSettings.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs index d142ed2..fdeddfe 100644 --- a/Tranga/TrangaSettings.cs +++ b/Tranga/TrangaSettings.cs @@ -1,5 +1,4 @@ -using System.Text.RegularExpressions; -using Logging; +using Logging; using Newtonsoft.Json; using Tranga.LibraryManagers; using Tranga.NotificationManagers; @@ -8,8 +7,8 @@ namespace Tranga; public class TrangaSettings { - public string downloadLocation { get; set; } - public string workingDirectory { get; set; } + public string downloadLocation { get; private set; } + public string workingDirectory { get; init; } [JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json"); [JsonIgnore] public string tasksFilePath => Path.Join(workingDirectory, "tasks.json"); [JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache"); From abf587377c445174218aa361abea6f3c4d219f97 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:09:30 +0200 Subject: [PATCH 06/11] API: Changed uninstantiated class Program to static --- API/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API/Program.cs b/API/Program.cs index fc41b84..da4f4bf 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -6,7 +6,7 @@ using Tranga.LibraryManagers; namespace API; -public class Program +public static class Program { public static void Main(string[] args) { From b610ec734e1bf8c64fac51d5ee1a59a512ed8100 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:09:39 +0200 Subject: [PATCH 07/11] Chapter readonly struct --- Tranga/Chapter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index 3dcd0ce..cf1e2bc 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -7,7 +7,7 @@ namespace Tranga; /// Has to be Part of a publication /// Includes the Chapter-Name, -VolumeNumber, -ChapterNumber, the location of the chapter on the internet and the saveName of the local file. /// -public struct Chapter +public readonly struct Chapter { public Publication parentPublication { get; } public string? name { get; } From d83aa1ef5b8197baee4042ff1f27dbf140f19054 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:11:11 +0200 Subject: [PATCH 08/11] deprecated --- Tranga/TrangaTasks/UpdateLibrariesTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/TrangaTasks/UpdateLibrariesTask.cs b/Tranga/TrangaTasks/UpdateLibrariesTask.cs index 17824a4..1039a9c 100644 --- a/Tranga/TrangaTasks/UpdateLibrariesTask.cs +++ b/Tranga/TrangaTasks/UpdateLibrariesTask.cs @@ -12,7 +12,7 @@ public class UpdateLibrariesTask : TrangaTask { } - protected override HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null) + protected override HttpStatusCode ExecuteTask(TaskManager taskManager, CancellationToken? cancellationToken = null) { return HttpStatusCode.BadRequest; } From 1afa3df3160ccdcb8761652ac45695cf131a1cde Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:25:04 +0200 Subject: [PATCH 09/11] Cleanup build warnings, ReShaper, Dictionary --- Tranga.sln.DotSettings | 3 ++ Tranga/Chapter.cs | 2 ++ Tranga/Connectors/Connector.cs | 3 +- Tranga/Connectors/MangaKatana.cs | 26 +++++++++-------- Tranga/Connectors/Manganato.cs | 15 +++++----- Tranga/Connectors/Mangasee.cs | 30 ++++++++++++-------- Tranga/DownloadClient.cs | 8 +++--- Tranga/LibraryManagers/Kavita.cs | 5 ++-- Tranga/LibraryManagers/Komga.cs | 3 +- Tranga/LibraryManagers/LibraryManager.cs | 3 +- Tranga/Migrate.cs | 3 +- Tranga/NotificationManagers/Gotify.cs | 3 ++ Tranga/NotificationManagers/LunaSea.cs | 6 +++- Tranga/Publication.cs | 9 ++++-- Tranga/TaskManager.cs | 7 ++--- Tranga/TrangaTasks/DownloadChapterTask.cs | 5 ++-- Tranga/TrangaTasks/MonitorPublicationTask.cs | 3 +- Tranga/TrangaTasks/TrangaTask.cs | 7 +++-- Tranga/TrangaTasks/UpdateLibrariesTask.cs | 1 - 19 files changed, 84 insertions(+), 58 deletions(-) diff --git a/Tranga.sln.DotSettings b/Tranga.sln.DotSettings index 37bbfaf..7f9a86f 100644 --- a/Tranga.sln.DotSettings +++ b/Tranga.sln.DotSettings @@ -1,6 +1,9 @@  + True + True True True + True True True True diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index cf1e2bc..0559f40 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -9,11 +9,13 @@ namespace Tranga; /// public readonly struct Chapter { + // ReSharper disable once MemberCanBePrivate.Global public Publication parentPublication { get; } public string? name { get; } public string? volumeNumber { get; } public string chapterNumber { get; } public string url { get; } + // ReSharper disable once MemberCanBePrivate.Global public string fileName { get; } private static readonly Regex LegalCharacters = new (@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*"); diff --git a/Tranga/Connectors/Connector.cs b/Tranga/Connectors/Connector.cs index f048133..9233409 100644 --- a/Tranga/Connectors/Connector.cs +++ b/Tranga/Connectors/Connector.cs @@ -159,8 +159,7 @@ public abstract class Connector /// Copies the already downloaded cover from cache to downloadLocation /// /// Publication to retrieve Cover for - /// TrangaSettings - public void CopyCoverFromCacheToDownloadLocation(Publication publication, TrangaSettings settings) + public void CopyCoverFromCacheToDownloadLocation(Publication publication) { settings.logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {publication.sortName} -> {publication.internalId}"); //Check if Publication already has a Folder and cover diff --git a/Tranga/Connectors/MangaKatana.cs b/Tranga/Connectors/MangaKatana.cs index ffb6a84..93a0441 100644 --- a/Tranga/Connectors/MangaKatana.cs +++ b/Tranga/Connectors/MangaKatana.cs @@ -15,7 +15,7 @@ public class MangaKatana : Connector this.name = "MangaKatana"; this.downloadClient = new DownloadClient(new Dictionary() { - {(byte)1, 60} + {1, 60} }, settings.logger); } @@ -25,16 +25,17 @@ public class MangaKatana : Connector string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '_'); string requestUrl = $"https://mangakatana.com/?search={sanitizedTitle}&search_by=book_name"; DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest(requestUrl, (byte)1); + downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return Array.Empty(); + // ReSharper disable once MergeIntoPattern // If a single result is found, the user will be redirected to the results directly instead of a result page - if(requestResult.HasBeenRedirected - && requestResult.RedirectedToUrl is not null - && requestResult.RedirectedToUrl.Contains("mangakatana.com/manga")) + if(requestResult.hasBeenRedirected + && requestResult.redirectedToUrl is not null + && requestResult.redirectedToUrl.Contains("mangakatana.com/manga")) { - return new Publication[] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.RedirectedToUrl.Split('/')[^1]) }; + return new [] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.redirectedToUrl.Split('/')[^1]) }; } return ParsePublicationsFromHtml(requestResult.result); @@ -58,7 +59,7 @@ public class MangaKatana : Connector foreach (string url in urls) { DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest(url, (byte)1); + downloadClient.MakeRequest(url, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return Array.Empty(); @@ -107,7 +108,6 @@ public class MangaKatana : Connector case "genres": tags = row.SelectNodes("div").Last().Descendants("a").Select(a => a.InnerText).ToHashSet(); break; - default: break; } } @@ -139,7 +139,7 @@ public class MangaKatana : Connector string requestUrl = $"https://mangakatana.com/manga/{publication.publicationId}"; // Leaving this in for verification if the page exists DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest(requestUrl, (byte)1); + downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return Array.Empty(); @@ -168,7 +168,7 @@ public class MangaKatana : Connector string fullString = chapterInfo.Descendants("a").First().InnerText; string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null; - string? chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Split(" ")[0].Replace('-', '.'); + string chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Split(" ")[0].Replace('-', '.'); string chapterName = string.Concat(fullString.Split(':')[1..]); string url = chapterInfo.Descendants("a").First() .GetAttributeValue("href", ""); @@ -186,7 +186,7 @@ public class MangaKatana : Connector string requestUrl = chapter.url; // Leaving this in to check if the page exists DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest(requestUrl, (byte)1); + downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return requestResult.statusCode; @@ -195,7 +195,7 @@ public class MangaKatana : Connector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), (byte)1, parentTask, comicInfoPath, "https://mangakatana.com/", cancellationToken); + return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, parentTask, comicInfoPath, "https://mangakatana.com/", cancellationToken); } private string[] ParseImageUrlsFromHtml(string mangaUrl) @@ -208,6 +208,8 @@ public class MangaKatana : Connector .Replace("\r", "") .Replace("\n", "") .Replace("\t", ""); + + // ReSharper disable once StringLiteralTypo string regexPat = @"(var thzq=\[')(.*)(,];function)"; var group = Regex.Matches(js, regexPat).First().Groups[2].Value.Replace("'", ""); var urls = group.Split(','); diff --git a/Tranga/Connectors/Manganato.cs b/Tranga/Connectors/Manganato.cs index cc050bb..19baee7 100644 --- a/Tranga/Connectors/Manganato.cs +++ b/Tranga/Connectors/Manganato.cs @@ -15,7 +15,7 @@ public class Manganato : Connector this.name = "Manganato"; this.downloadClient = new DownloadClient(new Dictionary() { - {(byte)1, 60} + {1, 60} }, settings.logger); } @@ -25,7 +25,7 @@ public class Manganato : Connector string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*")).ToLower(); string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}"; DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest(requestUrl, (byte)1); + downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return Array.Empty(); @@ -50,7 +50,7 @@ public class Manganato : Connector foreach (string url in urls) { DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest(url, (byte)1); + downloadClient.MakeRequest(url, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return Array.Empty(); @@ -102,7 +102,6 @@ public class Manganato : Connector string[] genres = value.Split(" - "); tags = genres.ToHashSet(); break; - default: break; } } @@ -129,7 +128,7 @@ public class Manganato : Connector settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})"); string requestUrl = $"https://chapmanganato.com/{publication.publicationId}"; DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest(requestUrl, (byte)1); + downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return Array.Empty(); @@ -158,7 +157,7 @@ public class Manganato : Connector string fullString = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")).InnerText; string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null; - string? chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Replace('-','.'); + string chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Replace('-','.'); string chapterName = string.Concat(fullString.Split(':')[1..]); string url = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")) .GetAttributeValue("href", ""); @@ -175,7 +174,7 @@ public class Manganato : Connector settings.logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); string requestUrl = chapter.url; DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest(requestUrl, (byte)1); + downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return requestResult.statusCode; @@ -184,7 +183,7 @@ public class Manganato : Connector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), (byte)1, parentTask, comicInfoPath, "https://chapmanganato.com/", cancellationToken); + return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, parentTask, comicInfoPath, "https://chapmanganato.com/", cancellationToken); } private string[] ParseImageUrlsFromHtml(Stream html) diff --git a/Tranga/Connectors/Mangasee.cs b/Tranga/Connectors/Mangasee.cs index 3bc6cb9..c82dd7b 100644 --- a/Tranga/Connectors/Mangasee.cs +++ b/Tranga/Connectors/Mangasee.cs @@ -12,7 +12,7 @@ namespace Tranga.Connectors; public class Mangasee : Connector { public override string name { get; } - private IBrowser? _browser = null; + private IBrowser? _browser; private const string ChromiumVersion = "1154303"; public Mangasee(TrangaSettings settings) : base(settings) @@ -20,7 +20,7 @@ public class Mangasee : Connector this.name = "Mangasee"; this.downloadClient = new DownloadClient(new Dictionary() { - { (byte)1, 60 } + { 1, 60 } }, settings.logger); Task d = new Task(DownloadBrowser); @@ -36,7 +36,7 @@ public class Mangasee : Connector { settings.logger?.WriteLine(this.GetType().ToString(), "Downloading headless browser"); DateTime last = DateTime.Now.Subtract(TimeSpan.FromSeconds(5)); - browserFetcher.DownloadProgressChanged += (sender, args) => + browserFetcher.DownloadProgressChanged += (_, args) => { double currentBytes = Convert.ToDouble(args.BytesReceived) / Convert.ToDouble(args.TotalBytesToReceive); if (args.TotalBytesToReceive == args.BytesReceived) @@ -76,7 +76,7 @@ public class Mangasee : Connector settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); string requestUrl = $"https://mangasee123.com/_search.php"; DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest(requestUrl, (byte)1); + downloadClient.MakeRequest(requestUrl, 1); if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) return Array.Empty(); @@ -108,7 +108,7 @@ public class Mangasee : Connector foreach (SearchResultItem orderedItem in orderedFiltered) { DownloadClient.RequestResult requestResult = - downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", (byte)1); + downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", 1); if ((int)requestResult.statusCode >= 200 || (int)requestResult.statusCode < 300) { settings.logger?.WriteLine(this.GetType().ToString(), $"Retrieving Publication info: {orderedItem.s} {index++}/{orderedFiltered.Count}"); @@ -177,11 +177,17 @@ public class Mangasee : Connector // ReSharper disable once ClassNeverInstantiated.Local Will be instantiated during deserialization private class SearchResultItem { -#pragma warning disable CS8618 //Will always be set - public string i { get; set; } - public string s { get; set; } - public string[] a { get; set; } -#pragma warning restore CS8618 + public string i { get; init; } + public string s { get; init; } + public string[] a { get; init; } + + [JsonConstructor] + public SearchResultItem(string i, string s, string[] a) + { + this.i = i; + this.s = s; + this.a = a; + } public int GetMatches(string title) { @@ -215,7 +221,7 @@ public class Mangasee : Connector List ret = new(); foreach (XElement chapter in chapterItems) { - string? volumeNumber = "1"; + string volumeNumber = "1"; string chapterName = chapter.Descendants("title").First().Value; string chapterNumber = Regex.Matches(chapterName, "[0-9]+")[^1].ToString(); @@ -262,7 +268,7 @@ public class Mangasee : Connector string comicInfoPath = Path.GetTempFileName(); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); - return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), (byte)1, parentTask, comicInfoPath, cancellationToken:cancellationToken); + return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), 1, parentTask, comicInfoPath, cancellationToken:cancellationToken); } return response.Status; } diff --git a/Tranga/DownloadClient.cs b/Tranga/DownloadClient.cs index 585b15a..2951598 100644 --- a/Tranga/DownloadClient.cs +++ b/Tranga/DownloadClient.cs @@ -89,8 +89,8 @@ internal class DownloadClient { public HttpStatusCode statusCode { get; } public Stream result { get; } - public bool HasBeenRedirected { get; } - public string? RedirectedToUrl { get; } + public bool hasBeenRedirected { get; } + public string? redirectedToUrl { get; } public RequestResult(HttpStatusCode statusCode, Stream result) { @@ -101,8 +101,8 @@ internal class DownloadClient public RequestResult(HttpStatusCode statusCode, Stream result, bool hasBeenRedirected, string redirectedTo) : this(statusCode, result) { - this.HasBeenRedirected = hasBeenRedirected; - RedirectedToUrl = redirectedTo; + this.hasBeenRedirected = hasBeenRedirected; + redirectedToUrl = redirectedTo; } } } \ No newline at end of file diff --git a/Tranga/LibraryManagers/Kavita.cs b/Tranga/LibraryManagers/Kavita.cs index 9abc66d..04cbe67 100644 --- a/Tranga/LibraryManagers/Kavita.cs +++ b/Tranga/LibraryManagers/Kavita.cs @@ -36,7 +36,7 @@ public class Kavita : LibraryManager HttpResponseMessage response = client.Send(requestMessage); JsonObject? result = JsonSerializer.Deserialize(response.Content.ReadAsStream()); if (result is not null) - return result!["token"]!.GetValue(); + return result["token"]!.GetValue(); else return ""; } @@ -73,7 +73,7 @@ public class Kavita : LibraryManager { var jObject = (JsonObject?)jsonNode; int libraryId = jObject!["id"]!.GetValue(); - string libraryName = jObject!["name"]!.GetValue(); + string libraryName = jObject["name"]!.GetValue(); ret.Add(new KavitaLibrary(libraryId, libraryName)); } @@ -83,6 +83,7 @@ public class Kavita : LibraryManager private struct KavitaLibrary { public int id { get; } + // ReSharper disable once UnusedAutoPropertyAccessor.Local public string name { get; } public KavitaLibrary(int id, string name) diff --git a/Tranga/LibraryManagers/Komga.cs b/Tranga/LibraryManagers/Komga.cs index bacc2c6..545ec91 100644 --- a/Tranga/LibraryManagers/Komga.cs +++ b/Tranga/LibraryManagers/Komga.cs @@ -54,7 +54,7 @@ public class Komga : LibraryManager { var jObject = (JsonObject?)jsonNode; string libraryId = jObject!["id"]!.GetValue(); - string libraryName = jObject!["name"]!.GetValue(); + string libraryName = jObject["name"]!.GetValue(); ret.Add(new KomgaLibrary(libraryId, libraryName)); } @@ -64,6 +64,7 @@ public class Komga : LibraryManager private struct KomgaLibrary { public string id { get; } + // ReSharper disable once UnusedAutoPropertyAccessor.Local public string name { get; } public KomgaLibrary(string id, string name) diff --git a/Tranga/LibraryManagers/LibraryManager.cs b/Tranga/LibraryManagers/LibraryManager.cs index c2ead5f..88e7b98 100644 --- a/Tranga/LibraryManagers/LibraryManager.cs +++ b/Tranga/LibraryManagers/LibraryManager.cs @@ -3,7 +3,6 @@ using System.Net.Http.Headers; using Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Tranga.LibraryManagers; namespace Tranga.LibraryManagers; @@ -15,8 +14,10 @@ public abstract class LibraryManager Kavita = 1 } + // ReSharper disable once UnusedAutoPropertyAccessor.Global public LibraryType libraryType { get; } public string baseUrl { get; } + // ReSharper disable once MemberCanBeProtected.Global public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems protected Logger? logger; diff --git a/Tranga/Migrate.cs b/Tranga/Migrate.cs index 4db6f5c..02b4988 100644 --- a/Tranga/Migrate.cs +++ b/Tranga/Migrate.cs @@ -1,5 +1,4 @@ -using Logging; -using Newtonsoft.Json; +using Newtonsoft.Json; using Tranga.TrangaTasks; namespace Tranga; diff --git a/Tranga/NotificationManagers/Gotify.cs b/Tranga/NotificationManagers/Gotify.cs index 8dce233..a823665 100644 --- a/Tranga/NotificationManagers/Gotify.cs +++ b/Tranga/NotificationManagers/Gotify.cs @@ -7,9 +7,11 @@ namespace Tranga.NotificationManagers; public class Gotify : NotificationManager { public string endpoint { get; } + // ReSharper disable once MemberCanBePrivate.Global public string appToken { get; } private readonly HttpClient _client = new(); + [JsonConstructor] public Gotify(string endpoint, string appToken, Logger? logger = null) : base(NotificationManagerType.Gotify, logger) { this.endpoint = endpoint; @@ -33,6 +35,7 @@ public class Gotify : NotificationManager private class MessageData { + // ReSharper disable four times UnusedAutoPropertyAccessor.Local public string message { get; } public long priority { get; } public string title { get; } diff --git a/Tranga/NotificationManagers/LunaSea.cs b/Tranga/NotificationManagers/LunaSea.cs index 363bddf..aef14c5 100644 --- a/Tranga/NotificationManagers/LunaSea.cs +++ b/Tranga/NotificationManagers/LunaSea.cs @@ -6,8 +6,11 @@ namespace Tranga.NotificationManagers; public class LunaSea : NotificationManager { - public string id { get; } + // ReSharper disable once MemberCanBePrivate.Global + public string id { get; init; } private readonly HttpClient _client = new(); + + [JsonConstructor] public LunaSea(string id, Logger? logger = null) : base(NotificationManagerType.LunaSea, logger) { this.id = id; @@ -29,6 +32,7 @@ public class LunaSea : NotificationManager private class MessageData { + // ReSharper disable twice UnusedAutoPropertyAccessor.Local public string title { get; } public string body { get; } diff --git a/Tranga/Publication.cs b/Tranga/Publication.cs index c72e605..330e7c0 100644 --- a/Tranga/Publication.cs +++ b/Tranga/Publication.cs @@ -13,15 +13,20 @@ public struct Publication { public string sortName { get; } public List authors { get; } + // ReSharper disable once UnusedAutoPropertyAccessor.Global public Dictionary altTitles { get; } - // ReSharper disable trice MemberCanBePrivate.Global, trust + // ReSharper disable once MemberCanBePrivate.Global public string? description { get; } public string[] tags { get; } + // ReSharper disable once UnusedAutoPropertyAccessor.Global public string? posterUrl { get; } public string? coverFileNameInCache { get; } + // ReSharper disable once UnusedAutoPropertyAccessor.Global public Dictionary links { get; } + // ReSharper disable once MemberCanBePrivate.Global public int? year { get; } public string? originalLanguage { get; } + // ReSharper disable once MemberCanBePrivate.Global public string status { get; } public string folderName { get; } public string publicationId { get; } @@ -74,7 +79,7 @@ public struct Publication } /// Serialized JSON String for series.json - public string GetSeriesInfoJson() + private string GetSeriesInfoJson() { SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? "")); return System.Text.Json.JsonSerializer.Serialize(si); diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index f3f4076..11c12d5 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -1,5 +1,4 @@ -using Logging; -using Newtonsoft.Json; +using Newtonsoft.Json; using Tranga.Connectors; using Tranga.TrangaTasks; @@ -182,6 +181,7 @@ public class TaskManager ExportDataAndSettings(); } + // ReSharper disable once MemberCanBePrivate.Global public IEnumerable GetTasksMatching(TrangaTask mTask) { switch (mTask.task) @@ -336,11 +336,10 @@ public class TaskManager private void ImportData() { settings.logger?.WriteLine(this.GetType().ToString(), "Importing Data"); - string buffer; if (File.Exists(settings.tasksFilePath)) { settings.logger?.WriteLine(this.GetType().ToString(), $"Importing tasks from {settings.tasksFilePath}"); - buffer = File.ReadAllText(settings.tasksFilePath); + string buffer = File.ReadAllText(settings.tasksFilePath); this._allTasks = JsonConvert.DeserializeObject>(buffer, new JsonSerializerSettings() { Converters = { new TrangaTask.TrangaTaskJsonConverter() } })!; } diff --git a/Tranga/TrangaTasks/DownloadChapterTask.cs b/Tranga/TrangaTasks/DownloadChapterTask.cs index 1546621..a70e350 100644 --- a/Tranga/TrangaTasks/DownloadChapterTask.cs +++ b/Tranga/TrangaTasks/DownloadChapterTask.cs @@ -9,10 +9,11 @@ public class DownloadChapterTask : TrangaTask { public string connectorName { get; } public Publication publication { get; } + // ReSharper disable once MemberCanBePrivate.Global public string language { get; } public Chapter chapter { get; } - private double _dctProgress = 0; + private double _dctProgress; public DownloadChapterTask(string connectorName, Publication publication, Chapter chapter, string language = "en", MonitorPublicationTask? parentTask = null) : base(Task.DownloadChapter, TimeSpan.Zero, parentTask) { @@ -27,7 +28,7 @@ public class DownloadChapterTask : TrangaTask if (cancellationToken?.IsCancellationRequested ?? false) return HttpStatusCode.RequestTimeout; Connector connector = taskManager.GetConnector(this.connectorName); - connector.CopyCoverFromCacheToDownloadLocation(this.publication, taskManager.settings); + connector.CopyCoverFromCacheToDownloadLocation(this.publication); HttpStatusCode downloadSuccess = connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken); if ((int)downloadSuccess >= 200 && (int)downloadSuccess < 300) { diff --git a/Tranga/TrangaTasks/MonitorPublicationTask.cs b/Tranga/TrangaTasks/MonitorPublicationTask.cs index 5173ee6..5319759 100644 --- a/Tranga/TrangaTasks/MonitorPublicationTask.cs +++ b/Tranga/TrangaTasks/MonitorPublicationTask.cs @@ -7,6 +7,7 @@ public class MonitorPublicationTask : TrangaTask { public string connectorName { get; } public Publication publication { get; } + // ReSharper disable once MemberCanBePrivate.Global public string language { get; } public MonitorPublicationTask(string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(Task.MonitorPublication, reoccurrence) { @@ -25,7 +26,7 @@ public class MonitorPublicationTask : TrangaTask publication.CreatePublicationFolder(taskManager.settings.downloadLocation); List newChapters = connector.GetNewChaptersList(publication, language, ref taskManager.collection); - connector.CopyCoverFromCacheToDownloadLocation(publication, taskManager.settings); + connector.CopyCoverFromCacheToDownloadLocation(publication); publication.SaveSeriesInfoJson(taskManager.settings.downloadLocation); diff --git a/Tranga/TrangaTasks/TrangaTask.cs b/Tranga/TrangaTasks/TrangaTask.cs index d867faa..b3e4e60 100644 --- a/Tranga/TrangaTasks/TrangaTask.cs +++ b/Tranga/TrangaTasks/TrangaTask.cs @@ -1,6 +1,5 @@ using System.Net; using System.Text.Json.Serialization; -using Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using JsonConverter = Newtonsoft.Json.JsonConverter; @@ -15,8 +14,7 @@ namespace Tranga.TrangaTasks; [JsonDerivedType(typeof(DownloadChapterTask), 4)] public abstract class TrangaTask { - // ReSharper disable once CommentTypo ...Tell me why! - // ReSharper disable once MemberCanBePrivate.Global I want it thaaat way + // ReSharper disable once MemberCanBeProtected.Global public TimeSpan reoccurrence { get; } public DateTime lastExecuted { get; set; } [Newtonsoft.Json.JsonIgnore] public ExecutionState state { get; set; } @@ -26,9 +24,12 @@ public abstract class TrangaTask public string? parentTaskId { get; set; } [Newtonsoft.Json.JsonIgnore] internal HashSet childTasks { get; } public double progress => GetProgress(); + // ReSharper disable once MemberCanBePrivate.Global [Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; } [Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; internal set; } + // ReSharper disable once MemberCanBePrivate.Global [Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => lastChange.Add(GetRemainingTime()); + // ReSharper disable once MemberCanBePrivate.Global public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now); [Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence); diff --git a/Tranga/TrangaTasks/UpdateLibrariesTask.cs b/Tranga/TrangaTasks/UpdateLibrariesTask.cs index 1039a9c..e7ecb02 100644 --- a/Tranga/TrangaTasks/UpdateLibrariesTask.cs +++ b/Tranga/TrangaTasks/UpdateLibrariesTask.cs @@ -1,5 +1,4 @@ using System.Net; -using Logging; namespace Tranga.TrangaTasks; From 98ec0b837fc77417c24603cd4be0f87303eeaaf4 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:27:47 +0200 Subject: [PATCH 10/11] Remove Enter input from settings, instead update all settings on click of "Update" Button. resolves #38 --- Website/interaction.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Website/interaction.js b/Website/interaction.js index 18d6283..be6d15f 100644 --- a/Website/interaction.js +++ b/Website/interaction.js @@ -70,13 +70,6 @@ createDownloadChapterTaskButton.addEventListener("click", () => { OpenDownloadChapterTaskPopup(); }); publicationTaskStart.addEventListener("click", () => StartTaskClick()); -settingApiUri.addEventListener("keypress", (event) => { - if(event.key === "Enter"){ - apiUri = settingApiUri.value; - setTimeout(() => GetSettingsClick(), 100); - document.cookie = `apiUri=${apiUri};`; - } -}); searchPublicationQuery.addEventListener("keypress", (event) => { if(event.key === "Enter"){ NewSearch(); @@ -352,6 +345,11 @@ function UpdateLibrarySettings(){ if(settingLunaseaWebhook.value != ""){ UpdateLunaSea(settingLunaseaWebhook.value); } + + if(settingApiUri.value != ""){ + apiUri = settingApiUri.value; + document.cookie = `apiUri=${apiUri};`; + } setTimeout(() => GetSettingsClick(), 200); } From ad4027779f36a2cfa44ac1bb37f2cfc9b2f7cffc Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 30 Jul 2023 17:29:30 +0200 Subject: [PATCH 11/11] Remove Deprecated CreateUpdateLibraryTask --- API/RequestHandler.cs | 7 ------- Website/apiConnector.js | 5 ----- Website/interaction.js | 2 -- 3 files changed, 14 deletions(-) diff --git a/API/RequestHandler.cs b/API/RequestHandler.cs index 4572ee1..118e3f2 100644 --- a/API/RequestHandler.cs +++ b/API/RequestHandler.cs @@ -23,7 +23,6 @@ public class RequestHandler new(HttpMethod.Get, "/Tasks/Types", Array.Empty()), new(HttpMethod.Post, "/Tasks/CreateMonitorTask", new[] { "connectorName", "internalId", "reoccurrenceTime", "language?", "ignoreChaptersBelow?" }), - //DEPRECATED new(HttpMethod.Post, "/Tasks/CreateUpdateLibraryTask", new[] { "reoccurrenceTime" }), new(HttpMethod.Post, "/Tasks/CreateDownloadChaptersTask", new[] { "connectorName", "internalId", "chapters", "language?" }), new(HttpMethod.Get, "/Tasks", new[] { "taskType", "connectorName?", "publicationId?" }), @@ -168,12 +167,6 @@ public class RequestHandler pPublication1.ignoreChaptersBelow = float.Parse(minChapter,new NumberFormatInfo() { NumberDecimalSeparator = "." }); _taskManager.AddTask(new MonitorPublicationTask(connectorName1, pPublication1, TimeSpan.Parse(reoccurrenceTime1), language1 ?? "en")); break; - case "/Tasks/CreateUpdateLibraryTask": // DEPRECATED - /*variables.TryGetValue("reoccurrenceTime", out string? reoccurrenceTime2); - if (reoccurrenceTime2 is null) - return; - _taskManager.AddTask(new UpdateLibrariesTask(TimeSpan.Parse(reoccurrenceTime2)));*/ - break; case "/Tasks/CreateDownloadChaptersTask": variables.TryGetValue("connectorName", out string? connectorName2); variables.TryGetValue("internalId", out string? internalId2); diff --git a/Website/apiConnector.js b/Website/apiConnector.js index c999389..560d3a5 100644 --- a/Website/apiConnector.js +++ b/Website/apiConnector.js @@ -106,11 +106,6 @@ function CreateMonitorTask(connectorName, internalId, reoccurrence, language){ PostData(uri); } -function CreateUpdateLibraryTask(reoccurrence){ - var uri = apiUri + `/Tasks/CreateUpdateLibraryTask?reoccurrenceTime=${reoccurrence}`; - PostData(uri); -} - function CreateDownloadChaptersTask(connectorName, internalId, chapters, language){ var uri = apiUri + `/Tasks/CreateDownloadChaptersTask?connectorName=${connectorName}&internalId=${internalId}&chapters=${chapters}&language=${language}`; PostData(uri); diff --git a/Website/interaction.js b/Website/interaction.js index be6d15f..e6695db 100644 --- a/Website/interaction.js +++ b/Website/interaction.js @@ -330,12 +330,10 @@ function UpdateLibrarySettings(){ var auth = utf8_to_b64(`${settingKomgaUser.value}:${settingKomgaPass.value}`); console.log(auth); UpdateKomga(settingKomgaUrl.value, auth); - CreateUpdateLibraryTask(libraryUpdateTime.value); } if(settingKavitaUrl.value != "" && settingKavitaUser.value != "" && settingKavitaPass.value != ""){ UpdateKavita(settingKavitaUrl.value, settingKavitaUser.value, settingKavitaPass.value); - CreateUpdateLibraryTask(libraryUpdateTime.value); } if(settingGotifyUrl.value != "" && settingGotifyAppToken.value != ""){