Better downloadChapter selection
This commit is contained in:
parent
d42393c83a
commit
02fe849046
@ -119,36 +119,7 @@ app.MapPost("/Tasks/CreateDownloadChaptersTask", (string connectorName, string i
|
|||||||
if (publication is null)
|
if (publication is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Chapter[] availableChapters = connector.GetChapters((Publication)publication, language??"en");;
|
IEnumerable<Chapter> toDownload = connector.SearchChapters((Publication)publication, chapters, language ?? "en");
|
||||||
IEnumerable<Chapter> toDownload;
|
|
||||||
|
|
||||||
if (chapters.Contains("vol", StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
{
|
|
||||||
if (chapters.Contains('-'))
|
|
||||||
{
|
|
||||||
string selectString = chapters.Split(' ').First(str => str.Contains('-'));
|
|
||||||
int start = Convert.ToInt32(selectString.Split('-')[0]);
|
|
||||||
int end = Convert.ToInt32(selectString.Split('-')[1]);
|
|
||||||
toDownload = availableChapters.Where(chapter =>
|
|
||||||
Convert.ToInt32(chapter.volumeNumber) >= start && Convert.ToInt32(chapter.volumeNumber) <= end);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string selectString = chapters.Split(' ').First(str => !str.Contains("vol", StringComparison.InvariantCultureIgnoreCase));
|
|
||||||
toDownload = availableChapters.Where(chapter => chapter.volumeNumber.Equals(selectString));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (chapters.Contains('-'))
|
|
||||||
{
|
|
||||||
int start = Convert.ToInt32(chapters.Split('-')[0]);
|
|
||||||
int end = Convert.ToInt32(chapters.Split('-')[1]) + 1;
|
|
||||||
toDownload = availableChapters[start..end];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
toDownload = new[] { availableChapters[Convert.ToInt32(chapters)] };
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(Chapter chapter in toDownload)
|
foreach(Chapter chapter in toDownload)
|
||||||
taskManager.AddTask(new DownloadChapterTask(TrangaTask.Task.DownloadChapter, connectorName,
|
taskManager.AddTask(new DownloadChapterTask(TrangaTask.Task.DownloadChapter, connectorName,
|
||||||
(Publication)publication, chapter, "en"));
|
(Publication)publication, chapter, "en"));
|
||||||
|
@ -499,22 +499,7 @@ public static class Tranga_Cli
|
|||||||
while(selectedChapters is null || selectedChapters.Length < 1)
|
while(selectedChapters is null || selectedChapters.Length < 1)
|
||||||
selectedChapters = Console.ReadLine();
|
selectedChapters = Console.ReadLine();
|
||||||
|
|
||||||
if (selectedChapters.Length == 1 && selectedChapters.ToLower() == "q")
|
return connector.SearchChapters(publication, selectedChapters);
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("aborted.");
|
|
||||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
|
||||||
return Array.Empty<Chapter>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedChapters.Contains('-'))
|
|
||||||
{
|
|
||||||
int start = Convert.ToInt32(selectedChapters.Split('-')[0]);
|
|
||||||
int end = Convert.ToInt32(selectedChapters.Split('-')[1]) + 1;
|
|
||||||
return availableChapters[start..end];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return new Chapter[] { availableChapters[Convert.ToInt32(selectedChapters)] };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Connector? SelectConnector(Connector[] connectors, Logger logger)
|
private static Connector? SelectConnector(Connector[] connectors, Logger logger)
|
||||||
|
@ -54,6 +54,72 @@ public abstract class Connector
|
|||||||
/// <returns>Array of Chapters matching Publication and Language</returns>
|
/// <returns>Array of Chapters matching Publication and Language</returns>
|
||||||
public abstract Chapter[] GetChapters(Publication publication, string language = "");
|
public abstract Chapter[] GetChapters(Publication publication, string language = "");
|
||||||
|
|
||||||
|
public Chapter[] SearchChapters(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);
|
||||||
|
if (volumeRegex.IsMatch(searchTerm) && chapterRegex.IsMatch(searchTerm))
|
||||||
|
{
|
||||||
|
string volume = singleResultRegex.Match(volumeRegex.Match(searchTerm).Value).Value;
|
||||||
|
string chapter = singleResultRegex.Match(chapterRegex.Match(searchTerm).Value).Value;
|
||||||
|
return availableChapters.Where(aCh => aCh.volumeNumber is not null && aCh.chapterNumber is not null &&
|
||||||
|
aCh.volumeNumber.Equals(volume, StringComparison.InvariantCultureIgnoreCase) &&
|
||||||
|
aCh.chapterNumber.Equals(chapter, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
else if (volumeRegex.IsMatch(searchTerm))
|
||||||
|
{
|
||||||
|
string volume = volumeRegex.Match(searchTerm).Value;
|
||||||
|
if (rangeResultRegex.IsMatch(volume))
|
||||||
|
{
|
||||||
|
string range = rangeResultRegex.Match(volume).Value;
|
||||||
|
int start = Convert.ToInt32(range.Split('-')[0]);
|
||||||
|
int end = Convert.ToInt32(range.Split('-')[1]);
|
||||||
|
return availableChapters.Where(aCh => aCh.volumeNumber is not null &&
|
||||||
|
Convert.ToInt32(aCh.volumeNumber) >= start &&
|
||||||
|
Convert.ToInt32(aCh.volumeNumber) <= end).ToArray();
|
||||||
|
}
|
||||||
|
else if(singleResultRegex.IsMatch(volume))
|
||||||
|
return availableChapters.Where(aCh =>
|
||||||
|
aCh.volumeNumber is not null &&
|
||||||
|
aCh.volumeNumber.Equals(volume, StringComparison.InvariantCultureIgnoreCase)).ToArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (chapterRegex.IsMatch(searchTerm))
|
||||||
|
{
|
||||||
|
string chapter = volumeRegex.Match(searchTerm).Value;
|
||||||
|
if (rangeResultRegex.IsMatch(chapter))
|
||||||
|
{
|
||||||
|
string range = rangeResultRegex.Match(chapter).Value;
|
||||||
|
int start = Convert.ToInt32(range.Split('-')[0]);
|
||||||
|
int end = Convert.ToInt32(range.Split('-')[1]);
|
||||||
|
return availableChapters.Where(aCh => aCh.chapterNumber is not null &&
|
||||||
|
Convert.ToInt32(aCh.chapterNumber) >= start &&
|
||||||
|
Convert.ToInt32(aCh.chapterNumber) <= end).ToArray();
|
||||||
|
}
|
||||||
|
else if(singleResultRegex.IsMatch(chapter))
|
||||||
|
return availableChapters.Where(aCh =>
|
||||||
|
aCh.chapterNumber is not null &&
|
||||||
|
aCh.chapterNumber.Equals(chapter, StringComparison.InvariantCultureIgnoreCase)).ToArray();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (rangeResultRegex.IsMatch(searchTerm))
|
||||||
|
{
|
||||||
|
int start = Convert.ToInt32(searchTerm.Split('-')[0]);
|
||||||
|
int end = Convert.ToInt32(searchTerm.Split('-')[1]);
|
||||||
|
return availableChapters[start..(end + 1)];
|
||||||
|
}
|
||||||
|
else if(singleResultRegex.IsMatch(searchTerm))
|
||||||
|
return new [] { availableChapters[Convert.ToInt32(searchTerm)] };
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the Chapter (+Images) from the website.
|
/// Retrieves the Chapter (+Images) from the website.
|
||||||
/// Should later call DownloadChapterImages to retrieve the individual Images of the Chapter and create .cbz archive.
|
/// Should later call DownloadChapterImages to retrieve the individual Images of the Chapter and create .cbz archive.
|
||||||
|
Loading…
Reference in New Issue
Block a user