diff --git a/Tranga-CLI/Program.cs b/Tranga-CLI/Program.cs index 476d9e7..84865f3 100644 --- a/Tranga-CLI/Program.cs +++ b/Tranga-CLI/Program.cs @@ -7,9 +7,54 @@ public class Program public static void Main(string[] args) { MangaDex mangaDexConnector = new MangaDex("D:"); - Publication[] publications = mangaDexConnector.GetPublications("test"); - Chapter[] chapters = mangaDexConnector.GetChapters(publications[1]); - mangaDexConnector.DownloadChapter(publications[1], chapters[0]); + Console.WriteLine("Search query (leave empty for all):"); + string? query = Console.ReadLine(); + Publication[] publications = mangaDexConnector.GetPublications(query ?? ""); + + int pIndex = 0; + foreach(Publication publication in publications) + Console.WriteLine($"{pIndex++}: {publication.sortName}"); + Console.WriteLine($"Select publication to Download (0-{publications.Length - 1}):"); + + string? selected = Console.ReadLine(); + while(selected is null || selected.Length < 1) + selected = Console.ReadLine(); + Publication selectedPub = publications[Convert.ToInt32(selected)]; + + Chapter[] chapters = mangaDexConnector.GetChapters(selectedPub); + + int cIndex = 0; + foreach (Chapter ch in chapters) + { + string name = ch.name is not null && ch.name.Length > 0 ? ch.name : cIndex.ToString(); + Console.WriteLine($"{cIndex++}: {name}"); + } + Console.WriteLine($"Select Chapters to download (0-{chapters.Length - 1}) [range x-y or 'a' for all]: "); + selected = Console.ReadLine(); + while(selected is null || selected.Length < 1) + selected = Console.ReadLine(); + + int start = 0; + int end = 0; + if (selected == "a") + end = chapters.Length - 1; + else if (selected.Contains('-')) + { + string[] split = selected.Split('-'); + start = Convert.ToInt32(split[0]); + end = Convert.ToInt32(split[1]); + } + else + { + start = Convert.ToInt32(selected); + end = Convert.ToInt32(selected); + } + + for (int i = start; i < end + 1; i++) + { + Console.WriteLine($"Downloading {selectedPub.sortName} Chapter {i}"); + mangaDexConnector.DownloadChapter(selectedPub, chapters[start]); + } } } \ No newline at end of file