From b3e1d39d0f28fac6561330eb98f7570d686a9236 Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 27 Jun 2023 23:02:55 +0200 Subject: [PATCH] Rename Connector.SearchChapters -> SelectChapters Added "a(ll)"-option to SelectChapters --- API/RequestHandler.cs | 2 +- Tranga-CLI/Tranga_Cli.cs | 2 +- Tranga/Connector.cs | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/API/RequestHandler.cs b/API/RequestHandler.cs index 0e54d31..27d5cad 100644 --- a/API/RequestHandler.cs +++ b/API/RequestHandler.cs @@ -182,7 +182,7 @@ public class RequestHandler if (publication2 is null) return; - IEnumerable toDownload = connector2.SearchChapters((Publication)publication2, chapters, language2 ?? "en"); + IEnumerable toDownload = connector2.SelectChapters((Publication)publication2, chapters, language2 ?? "en"); foreach(Chapter chapter in toDownload) _taskManager.AddTask(new DownloadChapterTask(connectorName2, (Publication)publication2, chapter, "en")); break; diff --git a/Tranga-CLI/Tranga_Cli.cs b/Tranga-CLI/Tranga_Cli.cs index 060cb8a..d2a279e 100644 --- a/Tranga-CLI/Tranga_Cli.cs +++ b/Tranga-CLI/Tranga_Cli.cs @@ -514,7 +514,7 @@ public static class Tranga_Cli while(selectedChapters is null || selectedChapters.Length < 1) selectedChapters = Console.ReadLine(); - return connector.SearchChapters(publication, selectedChapters); + return connector.SelectChapters(publication, selectedChapters); } private static Connector? SelectConnector(Connector[] connectors, Logger logger) diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index 8f54bc1..e3de71b 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -48,13 +48,14 @@ public abstract class Connector /// Array of Chapters matching Publication and Language public abstract Chapter[] GetChapters(Publication publication, string language = ""); - public Chapter[] SearchChapters(Publication publication, string searchTerm, string? language = null) + public Chapter[] SelectChapters(Publication publication, string searchTerm, string? language = null) { Chapter[] availableChapters = this.GetChapters(publication, language??"en"); Regex volumeRegex = new ("((v(ol)*(olume)*)+ *([0-9]+(-[0-9]+)?){1})", RegexOptions.IgnoreCase); Regex chapterRegex = new ("((c(h)*(hapter)*)+ *([0-9]+(-[0-9]+)?){1})", RegexOptions.IgnoreCase); Regex singleResultRegex = new("([0-9]+)", RegexOptions.IgnoreCase); Regex rangeResultRegex = new("([0-9]+(-[0-9]+))", RegexOptions.IgnoreCase); + Regex allRegex = new("a(ll)?", RegexOptions.IgnoreCase); if (volumeRegex.IsMatch(searchTerm) && chapterRegex.IsMatch(searchTerm)) { string volume = singleResultRegex.Match(volumeRegex.Match(searchTerm).Value).Value; @@ -115,6 +116,8 @@ public abstract class Connector } else if(singleResultRegex.IsMatch(searchTerm)) return new [] { availableChapters[Convert.ToInt32(searchTerm)] }; + else if (allRegex.IsMatch(searchTerm)) + return availableChapters; } return Array.Empty();