Rename Connector.SearchChapters -> SelectChapters

Added "a(ll)"-option to SelectChapters
This commit is contained in:
glax 2023-06-27 23:02:55 +02:00
parent 2833b7f22a
commit b3e1d39d0f
3 changed files with 6 additions and 3 deletions

View File

@ -182,7 +182,7 @@ public class RequestHandler
if (publication2 is null)
return;
IEnumerable<Chapter> toDownload = connector2.SearchChapters((Publication)publication2, chapters, language2 ?? "en");
IEnumerable<Chapter> toDownload = connector2.SelectChapters((Publication)publication2, chapters, language2 ?? "en");
foreach(Chapter chapter in toDownload)
_taskManager.AddTask(new DownloadChapterTask(connectorName2, (Publication)publication2, chapter, "en"));
break;

View File

@ -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)

View File

@ -48,13 +48,14 @@ public abstract class Connector
/// <returns>Array of Chapters matching Publication and Language</returns>
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<Chapter>();