Compare commits
4 Commits
bb77e5348f
...
2c84688925
Author | SHA1 | Date | |
---|---|---|---|
2c84688925 | |||
a58f113d14 | |||
fcb1848a93 | |||
337111d833 |
@ -63,114 +63,39 @@ public static class Tranga_Cli
|
|||||||
settings.komga = new Komga(tmpUrl, tmpUser, tmpPass);
|
settings.komga = new Komga(tmpUrl, tmpUser, tmpPass);
|
||||||
}
|
}
|
||||||
|
|
||||||
//For now only TaskManager mode
|
|
||||||
/*
|
|
||||||
Console.Write("Mode (D: Interactive only, T: TaskManager):");
|
|
||||||
ConsoleKeyInfo mode = Console.ReadKey();
|
|
||||||
while (mode.Key != ConsoleKey.D && mode.Key != ConsoleKey.T)
|
|
||||||
mode = Console.ReadKey();
|
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
if(mode.Key == ConsoleKey.D)
|
|
||||||
DownloadNow(settings);
|
|
||||||
else if (mode.Key == ConsoleKey.T)
|
|
||||||
TaskMode(settings);*/
|
|
||||||
TaskMode(settings);
|
TaskMode(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TaskMode(TaskManager.SettingsData settings)
|
private static void TaskMode(TaskManager.SettingsData settings)
|
||||||
{
|
{
|
||||||
TaskManager taskManager = new TaskManager(settings);
|
TaskManager taskManager = new (settings);
|
||||||
ConsoleKey selection = ConsoleKey.NoName;
|
ConsoleKey selection = PrintMenu(taskManager, settings.downloadLocation);
|
||||||
int menu = 0;
|
while (selection != ConsoleKey.Q)
|
||||||
while (selection != ConsoleKey.Escape && selection != ConsoleKey.Q)
|
|
||||||
{
|
{
|
||||||
switch (menu)
|
switch (selection)
|
||||||
{
|
{
|
||||||
case 1:
|
case ConsoleKey.L:
|
||||||
PrintTasks(taskManager.GetAllTasks());
|
PrintTasks(taskManager.GetAllTasks());
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
menu = 0;
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case ConsoleKey.C:
|
||||||
TrangaTask.Task task = SelectTask();
|
CreateTask(taskManager, settings);
|
||||||
|
|
||||||
Connector? connector = null;
|
|
||||||
if(task != TrangaTask.Task.UpdateKomgaLibrary)
|
|
||||||
connector = SelectConnector(settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray());
|
|
||||||
|
|
||||||
Publication? publication = null;
|
|
||||||
if(task != TrangaTask.Task.UpdatePublications && task != TrangaTask.Task.UpdateKomgaLibrary)
|
|
||||||
publication = SelectPublication(connector!);
|
|
||||||
|
|
||||||
TimeSpan reoccurrence = SelectReoccurrence();
|
|
||||||
TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en");
|
|
||||||
Console.WriteLine(newTask);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
menu = 0;
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case ConsoleKey.D:
|
||||||
RemoveTask(taskManager);
|
RemoveTask (taskManager);
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
menu = 0;
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case ConsoleKey.E:
|
||||||
ExecuteTaskNow(taskManager);
|
ExecuteTaskNow(taskManager);
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
menu = 0;
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case ConsoleKey.S:
|
||||||
Console.WriteLine("Search-Query (Name):");
|
SearchTasks(taskManager);
|
||||||
string? query = Console.ReadLine();
|
|
||||||
while (query is null || query.Length < 1)
|
|
||||||
query = Console.ReadLine();
|
|
||||||
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
|
|
||||||
qTask.ToString().ToLower().Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray());
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
menu = 0;
|
|
||||||
break;
|
break;
|
||||||
case 6:
|
case ConsoleKey.R:
|
||||||
PrintTasks(taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running).ToArray());
|
PrintTasks(taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running).ToArray());
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
menu = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
selection = Menu(taskManager, settings.downloadLocation);
|
|
||||||
switch (selection)
|
|
||||||
{
|
|
||||||
case ConsoleKey.L:
|
|
||||||
menu = 1;
|
|
||||||
break;
|
|
||||||
case ConsoleKey.C:
|
|
||||||
menu = 2;
|
|
||||||
break;
|
|
||||||
case ConsoleKey.D:
|
|
||||||
menu = 3;
|
|
||||||
break;
|
|
||||||
case ConsoleKey.E:
|
|
||||||
menu = 4;
|
|
||||||
break;
|
|
||||||
case ConsoleKey.U:
|
|
||||||
menu = 0;
|
|
||||||
break;
|
|
||||||
case ConsoleKey.S:
|
|
||||||
menu = 5;
|
|
||||||
break;
|
|
||||||
case ConsoleKey.R:
|
|
||||||
menu = 6;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
menu = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Console.WriteLine("Press any key.");
|
||||||
|
Console.ReadKey();
|
||||||
|
selection = PrintMenu(taskManager, settings.downloadLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taskManager.GetAllTasks().Any(task => task.state == TrangaTask.ExecutionState.Running))
|
if (taskManager.GetAllTasks().Any(task => task.state == TrangaTask.ExecutionState.Running))
|
||||||
@ -185,7 +110,7 @@ public static class Tranga_Cli
|
|||||||
taskManager.Shutdown(false);
|
taskManager.Shutdown(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConsoleKey Menu(TaskManager taskManager, string folderPath)
|
private static ConsoleKey PrintMenu(TaskManager taskManager, string folderPath)
|
||||||
{
|
{
|
||||||
int taskCount = taskManager.GetAllTasks().Length;
|
int taskCount = taskManager.GetAllTasks().Length;
|
||||||
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running);
|
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running);
|
||||||
@ -218,6 +143,34 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine($"{tIndex++:000}: {trangaTask}");
|
Console.WriteLine($"{tIndex++:000}: {trangaTask}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CreateTask(TaskManager taskManager, TaskManager.SettingsData settings)
|
||||||
|
{
|
||||||
|
TrangaTask.Task? tmpTask = SelectTaskType();
|
||||||
|
if (tmpTask is null)
|
||||||
|
return;
|
||||||
|
TrangaTask.Task task = (TrangaTask.Task)tmpTask!;
|
||||||
|
|
||||||
|
Connector? connector = null;
|
||||||
|
if (task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||||
|
{
|
||||||
|
connector = SelectConnector(settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray());
|
||||||
|
if (connector is null)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Publication? publication = null;
|
||||||
|
if (task != TrangaTask.Task.UpdatePublications && task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||||
|
{
|
||||||
|
publication = SelectPublication(connector!);
|
||||||
|
if (publication is null)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeSpan reoccurrence = SelectReoccurrence();
|
||||||
|
TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en");
|
||||||
|
Console.WriteLine(newTask);
|
||||||
|
}
|
||||||
|
|
||||||
private static void ExecuteTaskNow(TaskManager taskManager)
|
private static void ExecuteTaskNow(TaskManager taskManager)
|
||||||
{
|
{
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||||
@ -229,14 +182,29 @@ public static class Tranga_Cli
|
|||||||
}
|
}
|
||||||
PrintTasks(tasks);
|
PrintTasks(tasks);
|
||||||
|
|
||||||
|
Console.WriteLine("Enter q to abort");
|
||||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
string? selectedTask = Console.ReadLine();
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
while(selectedTask is null || selectedTask.Length < 1)
|
||||||
selectedTask = Console.ReadLine();
|
selectedTask = Console.ReadLine();
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
|
||||||
|
|
||||||
taskManager.ExecuteTaskNow(tasks[selectedTaskIndex]);
|
if (selectedTask.Length == 1 && selectedTask.ToLower() == "q")
|
||||||
|
{
|
||||||
|
Console.WriteLine("aborted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||||
|
taskManager.ExecuteTaskNow(tasks[selectedTaskIndex]);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RemoveTask(TaskManager taskManager)
|
private static void RemoveTask(TaskManager taskManager)
|
||||||
@ -250,17 +218,31 @@ public static class Tranga_Cli
|
|||||||
}
|
}
|
||||||
PrintTasks(tasks);
|
PrintTasks(tasks);
|
||||||
|
|
||||||
|
Console.WriteLine("Enter q to abort");
|
||||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
string? selectedTask = Console.ReadLine();
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
while(selectedTask is null || selectedTask.Length < 1)
|
||||||
selectedTask = Console.ReadLine();
|
selectedTask = Console.ReadLine();
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
|
||||||
|
|
||||||
taskManager.RemoveTask(tasks[selectedTaskIndex].task, tasks[selectedTaskIndex].connectorName, tasks[selectedTaskIndex].publication);
|
if (selectedTask.Length == 1 && selectedTask.ToLower() == "q")
|
||||||
|
{
|
||||||
|
Console.WriteLine("aborted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||||
|
taskManager.RemoveTask(tasks[selectedTaskIndex].task, tasks[selectedTaskIndex].connectorName, tasks[selectedTaskIndex].publication);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TrangaTask.Task SelectTask()
|
private static TrangaTask.Task? SelectTaskType()
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
string[] taskNames = Enum.GetNames<TrangaTask.Task>();
|
string[] taskNames = Enum.GetNames<TrangaTask.Task>();
|
||||||
@ -269,15 +251,32 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine("Available Tasks:");
|
Console.WriteLine("Available Tasks:");
|
||||||
foreach (string taskName in taskNames)
|
foreach (string taskName in taskNames)
|
||||||
Console.WriteLine($"{tIndex++}: {taskName}");
|
Console.WriteLine($"{tIndex++}: {taskName}");
|
||||||
|
|
||||||
|
Console.WriteLine("Enter q to abort");
|
||||||
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):");
|
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):");
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
string? selectedTask = Console.ReadLine();
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
while(selectedTask is null || selectedTask.Length < 1)
|
||||||
selectedTask = Console.ReadLine();
|
selectedTask = Console.ReadLine();
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
|
||||||
|
|
||||||
string selectedTaskName = taskNames[selectedTaskIndex];
|
if (selectedTask.Length == 1 && selectedTask.ToLower() == "q")
|
||||||
return Enum.Parse<TrangaTask.Task>(selectedTaskName);
|
{
|
||||||
|
Console.WriteLine("aborted.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||||
|
string selectedTaskName = taskNames[selectedTaskIndex];
|
||||||
|
return Enum.Parse<TrangaTask.Task>(selectedTaskName);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TimeSpan SelectReoccurrence()
|
private static TimeSpan SelectReoccurrence()
|
||||||
@ -286,28 +285,7 @@ public static class Tranga_Cli
|
|||||||
return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US"));
|
return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DownloadNow(TaskManager.SettingsData settings)
|
private static Connector? SelectConnector(string folderPath, Connector[] connectors)
|
||||||
{
|
|
||||||
Connector connector = SelectConnector(settings.downloadLocation, new Connector[]{new MangaDex(settings.downloadLocation)});
|
|
||||||
|
|
||||||
Publication publication = SelectPublication(connector);
|
|
||||||
|
|
||||||
Chapter[] downloadChapters = SelectChapters(connector, publication);
|
|
||||||
|
|
||||||
if (downloadChapters.Length > 0)
|
|
||||||
{
|
|
||||||
connector.DownloadCover(publication);
|
|
||||||
connector.SaveSeriesInfo(publication);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Chapter chapter in downloadChapters)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Downloading {publication.sortName} V{chapter.volumeNumber}C{chapter.chapterNumber}");
|
|
||||||
connector.DownloadChapter(publication, chapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Connector SelectConnector(string folderPath, Connector[] connectors)
|
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
|
||||||
@ -315,17 +293,34 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine("Connectors:");
|
Console.WriteLine("Connectors:");
|
||||||
foreach (Connector connector in connectors)
|
foreach (Connector connector in connectors)
|
||||||
Console.WriteLine($"{cIndex++}: {connector.name}");
|
Console.WriteLine($"{cIndex++}: {connector.name}");
|
||||||
|
|
||||||
|
Console.WriteLine("Enter q to abort");
|
||||||
Console.WriteLine($"Select Connector (0-{connectors.Length - 1}):");
|
Console.WriteLine($"Select Connector (0-{connectors.Length - 1}):");
|
||||||
|
|
||||||
string? selectedConnector = Console.ReadLine();
|
string? selectedConnector = Console.ReadLine();
|
||||||
while(selectedConnector is null || selectedConnector.Length < 1)
|
while(selectedConnector is null || selectedConnector.Length < 1)
|
||||||
selectedConnector = Console.ReadLine();
|
selectedConnector = Console.ReadLine();
|
||||||
int selectedConnectorIndex = Convert.ToInt32(selectedConnector);
|
|
||||||
|
|
||||||
return connectors[selectedConnectorIndex];
|
if (selectedConnector.Length == 1 && selectedConnector.ToLower() == "q")
|
||||||
|
{
|
||||||
|
Console.WriteLine("aborted.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int selectedConnectorIndex = Convert.ToInt32(selectedConnector);
|
||||||
|
return connectors[selectedConnectorIndex];
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Publication SelectPublication(Connector connector)
|
private static Publication? SelectPublication(Connector connector)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine($"Connector: {connector.name}");
|
Console.WriteLine($"Connector: {connector.name}");
|
||||||
@ -338,52 +333,39 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine("Publications:");
|
Console.WriteLine("Publications:");
|
||||||
foreach(Publication publication in publications)
|
foreach(Publication publication in publications)
|
||||||
Console.WriteLine($"{pIndex++}: {publication.sortName}");
|
Console.WriteLine($"{pIndex++}: {publication.sortName}");
|
||||||
|
|
||||||
|
Console.WriteLine("Enter q to abort");
|
||||||
Console.WriteLine($"Select publication to Download (0-{publications.Length - 1}):");
|
Console.WriteLine($"Select publication to Download (0-{publications.Length - 1}):");
|
||||||
|
|
||||||
string? selected = Console.ReadLine();
|
string? selectedPublication = Console.ReadLine();
|
||||||
while(selected is null || selected.Length < 1)
|
while(selectedPublication is null || selectedPublication.Length < 1)
|
||||||
selected = Console.ReadLine();
|
selectedPublication = Console.ReadLine();
|
||||||
return publications[Convert.ToInt32(selected)];
|
|
||||||
|
if (selectedPublication.Length == 1 && selectedPublication.ToLower() == "q")
|
||||||
|
{
|
||||||
|
Console.WriteLine("aborted.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int selectedPublicationIndex = Convert.ToInt32(selectedPublication);
|
||||||
|
return publications[selectedPublicationIndex];
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Chapter[] SelectChapters(Connector connector, Publication publication)
|
private static void SearchTasks(TaskManager taskManager)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
string? query = Console.ReadLine();
|
||||||
Console.WriteLine($"Connector: {connector.name} Publication: {publication.sortName}");
|
while (query is null || query.Length < 1)
|
||||||
Chapter[] chapters = connector.GetChapters(publication, "en");
|
query = Console.ReadLine();
|
||||||
|
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
|
||||||
int cIndex = 0;
|
qTask.ToString().ToLower().Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray());
|
||||||
Console.WriteLine("Chapters:");
|
|
||||||
foreach (Chapter ch in chapters)
|
|
||||||
{
|
|
||||||
string name = cIndex.ToString();
|
|
||||||
if (ch.name is not null && ch.name.Length > 0)
|
|
||||||
name = ch.name;
|
|
||||||
else if (ch.chapterNumber is not null && ch.chapterNumber.Length > 0)
|
|
||||||
name = ch.chapterNumber;
|
|
||||||
Console.WriteLine($"{cIndex++}: {name}");
|
|
||||||
}
|
|
||||||
Console.WriteLine($"Select Chapters to download (0-{chapters.Length - 1}) [range x-y or 'a' for all]: ");
|
|
||||||
string? selected = Console.ReadLine();
|
|
||||||
while(selected is null || selected.Length < 1)
|
|
||||||
selected = Console.ReadLine();
|
|
||||||
|
|
||||||
int start = 0;
|
|
||||||
int end;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return chapters.Skip(start).Take((end + 1)-start).ToArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user