Compare commits
No commits in common. "21e56a949fd08e31de6f83f21cefde5b8ae4f43e" and "86bb49508a17878e9f293396a26ad2011c27c428" have entirely different histories.
21e56a949f
...
86bb49508a
@ -1,20 +0,0 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
|
|
||||||
WORKDIR /app
|
|
||||||
EXPOSE 80
|
|
||||||
EXPOSE 443
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
|
||||||
WORKDIR /src
|
|
||||||
COPY ["Tranga-API/Tranga-API.csproj", "Tranga-API/"]
|
|
||||||
RUN dotnet restore "Tranga-API/Tranga-API.csproj"
|
|
||||||
COPY . .
|
|
||||||
WORKDIR "/src/Tranga-API"
|
|
||||||
RUN dotnet build "Tranga-API.csproj" -c Release -o /app/build
|
|
||||||
|
|
||||||
FROM build AS publish
|
|
||||||
RUN dotnet publish "Tranga-API.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
|
||||||
|
|
||||||
FROM base AS final
|
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=publish /app/publish .
|
|
||||||
ENTRYPOINT ["dotnet", "Tranga-API.dll"]
|
|
@ -1,51 +0,0 @@
|
|||||||
using System.Text.Json;
|
|
||||||
using Tranga;
|
|
||||||
using Tranga.Connectors;
|
|
||||||
|
|
||||||
TaskManager taskManager = new TaskManager(Directory.GetCurrentDirectory());
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
|
||||||
var app = builder.Build();
|
|
||||||
|
|
||||||
app.MapGet("/GetConnectors", () => JsonSerializer.Serialize(taskManager.GetAvailableConnectors().Values.ToArray()));
|
|
||||||
|
|
||||||
app.MapGet("/GetPublications", (string connectorName, string? title) =>
|
|
||||||
{
|
|
||||||
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(c => c.Key == connectorName).Value;
|
|
||||||
if (connector is null)
|
|
||||||
JsonSerializer.Serialize($"Connector {connectorName} is not a known connector.");
|
|
||||||
|
|
||||||
Publication[] publications;
|
|
||||||
if (title is not null)
|
|
||||||
publications = connector.GetPublications(title);
|
|
||||||
else
|
|
||||||
publications = connector.GetPublications();
|
|
||||||
|
|
||||||
return JsonSerializer.Serialize(publications);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/ListTasks", () => JsonSerializer.Serialize(taskManager.GetAllTasks()));
|
|
||||||
|
|
||||||
app.MapGet("/CreateTask",
|
|
||||||
(TrangaTask.Task task, string connectorName, string? publicationName, TimeSpan reoccurrence, string language) =>
|
|
||||||
{
|
|
||||||
Publication? publication =
|
|
||||||
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
|
|
||||||
if (publication is null)
|
|
||||||
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
|
|
||||||
|
|
||||||
taskManager.AddTask(task, connectorName, publication, reoccurrence, language);
|
|
||||||
JsonSerializer.Serialize("Success");
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/RemoveTask", (TrangaTask.Task task, string connector, string? publicationName) =>
|
|
||||||
{
|
|
||||||
Publication? publication =
|
|
||||||
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
|
|
||||||
if (publication is null)
|
|
||||||
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
|
|
||||||
|
|
||||||
taskManager.RemoveTask(task, connector, publication);
|
|
||||||
JsonSerializer.Serialize("Success");
|
|
||||||
});
|
|
||||||
|
|
||||||
app.Run();
|
|
@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"iisSettings": {
|
|
||||||
"windowsAuthentication": false,
|
|
||||||
"anonymousAuthentication": true,
|
|
||||||
"iisExpress": {
|
|
||||||
"applicationUrl": "http://localhost:14826",
|
|
||||||
"sslPort": 44333
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
|
||||||
"http": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"applicationUrl": "http://localhost:5119",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"https": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"applicationUrl": "https://localhost:7070;http://localhost:5119",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"IIS Express": {
|
|
||||||
"commandName": "IISExpress",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<RootNamespace>Tranga_API</RootNamespace>
|
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="..\.dockerignore">
|
|
||||||
<Link>.dockerignore</Link>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
[{"reoccurrence":"00:00:00","lastExecuted":"2023-05-19T17:34:40.5349215+02:00","connectorName":"MangaDex","task":0,"publication":{"sortName":null,"description":null,"tags":null,"posterUrl":null,"year":null,"originalLanguage":null,"status":null,"folderName":null,"downloadUrl":null},"language":"en"}]
|
|
@ -7,198 +7,70 @@ public static class Tranga_Cli
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Output folder path [standard D:]:");
|
Console.WriteLine("Output folder path (D:):");
|
||||||
string? folderPath = Console.ReadLine();
|
string? folderPath = Console.ReadLine();
|
||||||
while(folderPath is null )
|
while(folderPath is null )
|
||||||
folderPath = Console.ReadLine();
|
folderPath = Console.ReadLine();
|
||||||
if (folderPath.Length < 1)
|
if (folderPath.Length < 1)
|
||||||
folderPath = "D:";
|
folderPath = "D:";
|
||||||
|
|
||||||
Console.Write("Mode (D: downloadNow, T: tasks):");
|
DownloadNow(folderPath);
|
||||||
ConsoleKeyInfo mode = Console.ReadKey();
|
|
||||||
while (mode.Key != ConsoleKey.D && mode.Key != ConsoleKey.T)
|
|
||||||
mode = Console.ReadKey();
|
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
if(mode.Key == ConsoleKey.D)
|
|
||||||
DownloadNow(folderPath);
|
|
||||||
else if (mode.Key == ConsoleKey.T)
|
|
||||||
TaskMode(folderPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void TaskMode(string folderPath)
|
|
||||||
{
|
|
||||||
TaskManager taskManager = new TaskManager(folderPath);
|
|
||||||
ConsoleKey selection = ConsoleKey.NoName;
|
|
||||||
int menu = 0;
|
|
||||||
while (selection != ConsoleKey.Escape && selection != ConsoleKey.Q)
|
|
||||||
{
|
|
||||||
switch (menu)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
PrintTasks(taskManager);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
menu = 0;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
Connector connector = SelectConnector(folderPath, taskManager.GetAvailableConnectors().Values.ToArray());
|
|
||||||
TrangaTask.Task task = SelectTask();
|
|
||||||
Publication? publication = null;
|
|
||||||
if(task != TrangaTask.Task.UpdatePublications)
|
|
||||||
publication = SelectPublication(connector);
|
|
||||||
TimeSpan reoccurrence = SelectReoccurence();
|
|
||||||
taskManager.AddTask(task, connector.name, publication, reoccurrence, "en");
|
|
||||||
Console.WriteLine($"{task} - {connector.name} - {publication?.sortName}");
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
menu = 0;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
RemoveTask(taskManager);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
menu = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
selection = Menu(folderPath);
|
|
||||||
switch (selection)
|
|
||||||
{
|
|
||||||
case ConsoleKey.L:
|
|
||||||
menu = 1;
|
|
||||||
break;
|
|
||||||
case ConsoleKey.C:
|
|
||||||
menu = 2;
|
|
||||||
break;
|
|
||||||
case ConsoleKey.D:
|
|
||||||
menu = 3;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
menu = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
taskManager.Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ConsoleKey Menu(string folderPath)
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine($"Download Folder: {folderPath}");
|
|
||||||
Console.WriteLine("Select Option:");
|
|
||||||
Console.WriteLine("L: List tasks");
|
|
||||||
Console.WriteLine("C: Create Task");
|
|
||||||
Console.WriteLine("D: Delete Task");
|
|
||||||
Console.WriteLine("Q: Exit with saving");
|
|
||||||
ConsoleKey selection = Console.ReadKey().Key;
|
|
||||||
Console.WriteLine();
|
|
||||||
return selection;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int PrintTasks(TaskManager taskManager)
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
|
||||||
int tIndex = 0;
|
|
||||||
Console.WriteLine("Tasks:");
|
|
||||||
foreach(TrangaTask trangaTask in tasks)
|
|
||||||
Console.WriteLine($"{tIndex++}: {trangaTask.task} - {trangaTask.publication?.sortName} - {trangaTask.connectorName}");
|
|
||||||
return tasks.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RemoveTask(TaskManager taskManager)
|
|
||||||
{
|
|
||||||
int length = PrintTasks(taskManager);
|
|
||||||
|
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
|
||||||
Console.WriteLine($"Select Task (0-{length - 1}):");
|
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
|
||||||
selectedTask = Console.ReadLine();
|
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
|
||||||
|
|
||||||
taskManager.RemoveTask(tasks[selectedTaskIndex].task, tasks[selectedTaskIndex].connectorName, tasks[selectedTaskIndex].publication);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TrangaTask.Task SelectTask()
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
string[] taskNames = Enum.GetNames<TrangaTask.Task>();
|
|
||||||
|
|
||||||
int tIndex = 0;
|
|
||||||
Console.WriteLine("Available Tasks:");
|
|
||||||
foreach (string taskName in taskNames)
|
|
||||||
Console.WriteLine($"{tIndex++}: {taskName}");
|
|
||||||
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):");
|
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
|
||||||
selectedTask = Console.ReadLine();
|
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
|
||||||
|
|
||||||
string selectedTaskName = taskNames[selectedTaskIndex];
|
|
||||||
return Enum.Parse<TrangaTask.Task>(selectedTaskName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TimeSpan SelectReoccurence()
|
|
||||||
{
|
|
||||||
return TimeSpan.FromSeconds(30); //TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DownloadNow(string folderPath)
|
private static void DownloadNow(string folderPath)
|
||||||
{
|
{
|
||||||
Connector connector = SelectConnector(folderPath);
|
Connector connector = SelectConnector(folderPath);
|
||||||
|
|
||||||
Publication publication = SelectPublication(connector);
|
Console.WriteLine("Search query (leave empty for all):");
|
||||||
|
string? query = Console.ReadLine();
|
||||||
|
|
||||||
|
Publication[] publications = connector.GetPublications(query ?? "");
|
||||||
|
Publication selectedPub = SelectPublication(publications);
|
||||||
|
|
||||||
Chapter[] downloadChapters = SelectChapters(connector, publication);
|
Chapter[] allChapteres = connector.GetChapters(selectedPub, "en");
|
||||||
|
Chapter[] downloadChapters = SelectChapters(allChapteres);
|
||||||
|
|
||||||
if (downloadChapters.Length > 0)
|
if (downloadChapters.Length > 0)
|
||||||
{
|
{
|
||||||
connector.DownloadCover(publication);
|
connector.DownloadCover(selectedPub);
|
||||||
connector.SaveSeriesInfo(publication);
|
File.WriteAllText(Path.Join(folderPath, selectedPub.folderName, "series.json"),selectedPub.GetSeriesInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Chapter chapter in downloadChapters)
|
foreach (Chapter chapter in downloadChapters)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Downloading {publication.sortName} V{chapter.volumeNumber}C{chapter.chapterNumber}");
|
Console.WriteLine($"Downloading {selectedPub.sortName} V{chapter.volumeNumber}C{chapter.chapterNumber}");
|
||||||
connector.DownloadChapter(publication, chapter);
|
connector.DownloadChapter(selectedPub, chapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Connector SelectConnector(string folderPath, Connector[]? availableConnectors = null)
|
private static Connector SelectConnector(string folderPath)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.WriteLine("Select Connector:");
|
||||||
Connector[] connectors = availableConnectors ?? new Connector[] { new MangaDex(folderPath) };
|
Console.WriteLine("0: MangaDex");
|
||||||
|
|
||||||
int cIndex = 0;
|
|
||||||
Console.WriteLine("Connectors:");
|
|
||||||
foreach (Connector connector in connectors)
|
|
||||||
Console.WriteLine($"{cIndex++}: {connector.name}");
|
|
||||||
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);
|
int selectedConnectorIndex = Convert.ToInt32(selectedConnector);
|
||||||
|
|
||||||
return connectors[selectedConnectorIndex];
|
Connector connector;
|
||||||
|
switch (selectedConnectorIndex)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
connector = new MangaDex(folderPath);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
connector = new MangaDex(folderPath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return connector;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Publication SelectPublication(Connector connector)
|
private static Publication SelectPublication(Publication[] publications)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine($"Connector: {connector.name}");
|
|
||||||
Console.WriteLine("Publication search query (leave empty for all):");
|
|
||||||
string? query = Console.ReadLine();
|
|
||||||
|
|
||||||
Publication[] publications = connector.GetPublications(query ?? "");
|
|
||||||
|
|
||||||
int pIndex = 0;
|
int pIndex = 0;
|
||||||
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($"Select publication to Download (0-{publications.Length - 1}):");
|
Console.WriteLine($"Select publication to Download (0-{publications.Length - 1}):");
|
||||||
@ -209,14 +81,9 @@ public static class Tranga_Cli
|
|||||||
return publications[Convert.ToInt32(selected)];
|
return publications[Convert.ToInt32(selected)];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Chapter[] SelectChapters(Connector connector, Publication publication)
|
private static Chapter[] SelectChapters(Chapter[] chapters)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine($"Connector: {connector.name} Publication: {publication.sortName}");
|
|
||||||
Chapter[] chapters = connector.GetChapters(publication, "en");
|
|
||||||
|
|
||||||
int cIndex = 0;
|
int cIndex = 0;
|
||||||
Console.WriteLine("Chapters:");
|
|
||||||
foreach (Chapter ch in chapters)
|
foreach (Chapter ch in chapters)
|
||||||
{
|
{
|
||||||
string name = cIndex.ToString();
|
string name = cIndex.ToString();
|
||||||
|
@ -4,8 +4,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.c
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tranga-CLI.csproj", "{4899E3B2-B259-479A-B43E-042D043E9501}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tranga-CLI.csproj", "{4899E3B2-B259-479A-B43E-042D043E9501}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{6284C936-4E90-486B-BC46-0AFAD85AD8EE}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -20,9 +18,5 @@ Global
|
|||||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.Build.0 = Release|Any CPU
|
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -42,13 +42,6 @@ public abstract class Connector
|
|||||||
ZipFile.CreateFromDirectory(tempFolder, fullPath);
|
ZipFile.CreateFromDirectory(tempFolder, fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveSeriesInfo(Publication publication)
|
|
||||||
{
|
|
||||||
string seriesInfoPath = Path.Join(downloadLocation, publication.folderName, "series.json");
|
|
||||||
if(!File.Exists(seriesInfoPath))
|
|
||||||
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class DownloadClient
|
internal class DownloadClient
|
||||||
{
|
{
|
||||||
private readonly TimeSpan _requestSpeed;
|
private readonly TimeSpan _requestSpeed;
|
||||||
|
@ -10,7 +10,7 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
public MangaDex(string downloadLocation) : base(downloadLocation)
|
public MangaDex(string downloadLocation) : base(downloadLocation)
|
||||||
{
|
{
|
||||||
name = "MangaDex";
|
name = "MangaDex.org";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Publication[] GetPublications(string publicationTitle = "")
|
public override Publication[] GetPublications(string publicationTitle = "")
|
||||||
@ -102,6 +102,7 @@ public class MangaDex : Connector
|
|||||||
year,
|
year,
|
||||||
originalLanguage,
|
originalLanguage,
|
||||||
status,
|
status,
|
||||||
|
this,
|
||||||
manga["id"]!.GetValue<string>()
|
manga["id"]!.GetValue<string>()
|
||||||
);
|
);
|
||||||
publications.Add(pub);
|
publications.Add(pub);
|
||||||
@ -187,12 +188,6 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
public override void DownloadCover(Publication publication)
|
public override void DownloadCover(Publication publication)
|
||||||
{
|
{
|
||||||
string publicationPath = Path.Join(downloadLocation, publication.folderName);
|
|
||||||
DirectoryInfo dirInfo = new DirectoryInfo(publicationPath);
|
|
||||||
foreach(FileInfo fileInfo in dirInfo.EnumerateFiles())
|
|
||||||
if (fileInfo.Name.Contains("cover."))
|
|
||||||
return;
|
|
||||||
|
|
||||||
DownloadClient.RequestResult requestResult = _downloadClient.MakeRequest($"https://api.mangadex.org/cover/{publication.posterUrl}");
|
DownloadClient.RequestResult requestResult = _downloadClient.MakeRequest($"https://api.mangadex.org/cover/{publication.posterUrl}");
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
|
@ -1,22 +1,24 @@
|
|||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
public struct Publication
|
public struct Publication
|
||||||
{
|
{
|
||||||
public string sortName { get; }
|
public string sortName { get; }
|
||||||
[JsonIgnore]public string[,] altTitles { get; }
|
public string[,] altTitles { get; }
|
||||||
public string? description { get; }
|
public string? description { get; }
|
||||||
public string[] tags { get; }
|
public string[] tags { get; }
|
||||||
public string? posterUrl { get; }
|
public string? posterUrl { get; }
|
||||||
[JsonIgnore]public string[,]? links { get; }
|
public string[,]? links { get; }
|
||||||
public int? year { get; }
|
public int? year { get; }
|
||||||
public string? originalLanguage { get; }
|
public string? originalLanguage { get; }
|
||||||
public string status { get; }
|
public string status { get; }
|
||||||
public string folderName { get; }
|
public string folderName { get; }
|
||||||
|
public Connector connector { get; }
|
||||||
public string downloadUrl { get; }
|
public string downloadUrl { get; }
|
||||||
|
|
||||||
public Publication(string sortName, string? description, string[,] altTitles, string[] tags, string? posterUrl, string[,]? links, int? year, string? originalLanguage, string status, string downloadUrl)
|
public Publication(string sortName, string? description, string[,] altTitles, string[] tags, string? posterUrl, string[,]? links, int? year, string? originalLanguage, string status, Connector connector, string downloadUrl)
|
||||||
{
|
{
|
||||||
this.sortName = sortName;
|
this.sortName = sortName;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@ -27,6 +29,7 @@ public struct Publication
|
|||||||
this.year = year;
|
this.year = year;
|
||||||
this.originalLanguage = originalLanguage;
|
this.originalLanguage = originalLanguage;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
this.connector = connector;
|
||||||
this.downloadUrl = downloadUrl;
|
this.downloadUrl = downloadUrl;
|
||||||
this.folderName = string.Concat(sortName.Split(Path.GetInvalidPathChars()));
|
this.folderName = string.Concat(sortName.Split(Path.GetInvalidPathChars()));
|
||||||
}
|
}
|
||||||
@ -34,7 +37,7 @@ public struct Publication
|
|||||||
public string GetSeriesInfo()
|
public string GetSeriesInfo()
|
||||||
{
|
{
|
||||||
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
|
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
|
||||||
return System.Text.Json.JsonSerializer.Serialize(si);
|
return JsonSerializer.Serialize(si, JsonSerializerOptions.Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal struct SeriesInfo
|
internal struct SeriesInfo
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
namespace Tranga;
|
|
||||||
|
|
||||||
public static class TaskExecutor
|
|
||||||
{
|
|
||||||
public static void Execute(Connector[] connectors, TrangaTask trangaTask, Dictionary<Publication, List<Chapter>> chapterCollection)
|
|
||||||
{
|
|
||||||
Connector? connector = connectors.FirstOrDefault(c => c.name == trangaTask.connectorName);
|
|
||||||
if (connector is null)
|
|
||||||
throw new ArgumentException($"Connector {trangaTask.connectorName} is not a known connector.");
|
|
||||||
trangaTask.lastExecuted = DateTime.Now;
|
|
||||||
|
|
||||||
switch (trangaTask.task)
|
|
||||||
{
|
|
||||||
case TrangaTask.Task.DownloadNewChapters:
|
|
||||||
DownloadNewChapters(connector, (Publication)trangaTask.publication!, trangaTask.language, chapterCollection);
|
|
||||||
break;
|
|
||||||
case TrangaTask.Task.UpdateChapters:
|
|
||||||
UpdateChapters(connector, (Publication)trangaTask.publication!, trangaTask.language, chapterCollection);
|
|
||||||
break;
|
|
||||||
case TrangaTask.Task.UpdatePublications:
|
|
||||||
UpdatePublications(connector, chapterCollection);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void UpdatePublications(Connector connector, Dictionary<Publication, List<Chapter>> chapterCollection)
|
|
||||||
{
|
|
||||||
Publication[] publications = connector.GetPublications();
|
|
||||||
foreach (Publication publication in publications)
|
|
||||||
chapterCollection.TryAdd(publication, new List<Chapter>());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void DownloadNewChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
|
|
||||||
{
|
|
||||||
List<Chapter> newChapters = UpdateChapters(connector, publication, language, chapterCollection);
|
|
||||||
foreach(Chapter newChapter in newChapters)
|
|
||||||
connector.DownloadChapter(publication, newChapter);
|
|
||||||
connector.DownloadCover(publication);
|
|
||||||
connector.SaveSeriesInfo(publication);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<Chapter> UpdateChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
|
|
||||||
{
|
|
||||||
List<Chapter> newChaptersList = new();
|
|
||||||
if (!chapterCollection.ContainsKey(publication))
|
|
||||||
return newChaptersList;
|
|
||||||
|
|
||||||
List<Chapter> currentChapters = chapterCollection[publication];
|
|
||||||
Chapter[] newChapters = connector.GetChapters(publication, language);
|
|
||||||
|
|
||||||
newChaptersList = newChapters.ToList()
|
|
||||||
.ExceptBy(currentChapters.Select(cChapter => cChapter.url), nChapter => nChapter.url).ToList();
|
|
||||||
return newChaptersList;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +1,15 @@
|
|||||||
using Newtonsoft.Json;
|
namespace Tranga;
|
||||||
using Tranga.Connectors;
|
|
||||||
|
|
||||||
namespace Tranga;
|
|
||||||
|
|
||||||
public class TaskManager
|
public class TaskManager
|
||||||
{
|
{
|
||||||
private readonly Dictionary<Publication, List<Chapter>> _chapterCollection;
|
private readonly Dictionary<Publication, Chapter[]> _chapterCollection;
|
||||||
private readonly HashSet<TrangaTask> _allTasks;
|
private readonly HashSet<TrangaTask> _allTasks;
|
||||||
private bool _continueRunning = true;
|
private bool _continueRunning = true;
|
||||||
private readonly Connector[] connectors;
|
|
||||||
private readonly string folderPath;
|
public TaskManager()
|
||||||
|
|
||||||
public TaskManager(string folderPath)
|
|
||||||
{
|
{
|
||||||
this.folderPath = folderPath;
|
|
||||||
this.connectors = new Connector[]{ new MangaDex(folderPath) };
|
|
||||||
_chapterCollection = new();
|
_chapterCollection = new();
|
||||||
_allTasks = ImportTasks(Directory.GetCurrentDirectory());
|
_allTasks = new ();
|
||||||
Thread taskChecker = new(TaskCheckerThread);
|
Thread taskChecker = new(TaskCheckerThread);
|
||||||
taskChecker.Start();
|
taskChecker.Start();
|
||||||
}
|
}
|
||||||
@ -25,81 +18,37 @@ public class TaskManager
|
|||||||
{
|
{
|
||||||
while (_continueRunning)
|
while (_continueRunning)
|
||||||
{
|
{
|
||||||
foreach (TrangaTask task in _allTasks)
|
foreach (TrangaTask task in _allTasks.Where(trangaTask => (DateTime.Now - trangaTask.lastExecuted) > trangaTask.reoccurrence))
|
||||||
{
|
{
|
||||||
if(task.ShouldExecute())
|
if (!task.lastExecutedSuccessfully)
|
||||||
TaskExecutor.Execute(this.connectors, task, this._chapterCollection);
|
{
|
||||||
|
task.Abort();
|
||||||
|
//Add logging that task has failed
|
||||||
|
}
|
||||||
|
task.Execute();
|
||||||
}
|
}
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTask(TrangaTask.Task task, string connectorName, Publication? publication, TimeSpan reoccurrence,
|
public bool PublicationAlreadyAdded(Publication publication)
|
||||||
string language = "")
|
|
||||||
{
|
{
|
||||||
Connector? connector = connectors.FirstOrDefault(c => c.name == connectorName);
|
throw new NotImplementedException();
|
||||||
if (connector is null)
|
//TODO fuzzy check publications
|
||||||
throw new ArgumentException($"Connector {connectorName} is not a known connector.");
|
|
||||||
|
|
||||||
if (!_allTasks.Any(trangaTask => trangaTask.task != task && trangaTask.connectorName != connector.name &&
|
|
||||||
trangaTask.publication?.downloadUrl != publication?.downloadUrl))
|
|
||||||
{
|
|
||||||
_allTasks.Add(new TrangaTask(connector.name, task, publication, reoccurrence, language));
|
|
||||||
ExportTasks(Directory.GetCurrentDirectory());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveTask(TrangaTask.Task task, string connectorName, Publication? publication)
|
public Publication[] GetAddedPublications()
|
||||||
{
|
{
|
||||||
_allTasks.RemoveWhere(trangaTask =>
|
throw new NotImplementedException();
|
||||||
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
|
||||||
trangaTask.publication?.downloadUrl == publication?.downloadUrl);
|
|
||||||
ExportTasks(Directory.GetCurrentDirectory());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, Connector> GetAvailableConnectors()
|
public TrangaTask[] GetTasks()
|
||||||
{
|
{
|
||||||
return this.connectors.ToDictionary(connector => connector.name, connector => connector);
|
return _allTasks.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrangaTask[] GetAllTasks()
|
|
||||||
{
|
|
||||||
TrangaTask[] ret = new TrangaTask[_allTasks.Count];
|
|
||||||
_allTasks.CopyTo(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Publication[] GetAllPublications()
|
|
||||||
{
|
|
||||||
return this._chapterCollection.Keys.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Shutdown()
|
public void Shutdown()
|
||||||
{
|
{
|
||||||
_continueRunning = false;
|
_continueRunning = false;
|
||||||
ExportTasks(Directory.GetCurrentDirectory());
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashSet<TrangaTask> ImportTasks(string importFolderPath)
|
|
||||||
{
|
|
||||||
string filePath = Path.Join(importFolderPath, "tasks.json");
|
|
||||||
if (!File.Exists(filePath))
|
|
||||||
return new HashSet<TrangaTask>();
|
|
||||||
|
|
||||||
string toRead = File.ReadAllText(filePath);
|
|
||||||
|
|
||||||
TrangaTask[] importTasks = JsonConvert.DeserializeObject<TrangaTask[]>(toRead)!;
|
|
||||||
|
|
||||||
foreach(TrangaTask task in importTasks.Where(task => task.publication is not null))
|
|
||||||
this._chapterCollection.Add((Publication)task.publication!, new List<Chapter>());
|
|
||||||
|
|
||||||
return importTasks.ToHashSet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ExportTasks(string exportFolderPath)
|
|
||||||
{
|
|
||||||
string filePath = Path.Join(exportFolderPath, "tasks.json");
|
|
||||||
string toWrite = JsonConvert.SerializeObject(_allTasks.ToArray());
|
|
||||||
File.WriteAllText(filePath,toWrite);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,8 +6,4 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -2,34 +2,63 @@
|
|||||||
|
|
||||||
public class TrangaTask
|
public class TrangaTask
|
||||||
{
|
{
|
||||||
|
private readonly Action _taskAction;
|
||||||
|
private Task? _task;
|
||||||
|
public bool lastExecutedSuccessfully => _task is not null && _task.IsCompleted;
|
||||||
public TimeSpan reoccurrence { get; }
|
public TimeSpan reoccurrence { get; }
|
||||||
public DateTime lastExecuted { get; set; }
|
public DateTime lastExecuted { get; private set; }
|
||||||
public string connectorName { get; }
|
|
||||||
public Task task { get; }
|
|
||||||
public Publication? publication { get; }
|
|
||||||
public string language { get; }
|
|
||||||
|
|
||||||
public TrangaTask(string connectorName, Task task, Publication? publication, TimeSpan reoccurrence, string language = "")
|
public TrangaTask(Action taskAction, TimeSpan reoccurrence)
|
||||||
{
|
{
|
||||||
if (task != Task.UpdatePublications && publication is null)
|
this._taskAction = taskAction;
|
||||||
throw new ArgumentException($"Publication has to be not null for task {task}");
|
|
||||||
this.publication = publication;
|
|
||||||
this.reoccurrence = reoccurrence;
|
this.reoccurrence = reoccurrence;
|
||||||
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
|
||||||
this.connectorName = connectorName;
|
|
||||||
this.task = task;
|
|
||||||
this.language = language;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ShouldExecute()
|
public void Abort()
|
||||||
{
|
{
|
||||||
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence;
|
if(_task is not null && !_task.IsCompleted)
|
||||||
|
_task.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Task
|
public void Execute()
|
||||||
{
|
{
|
||||||
UpdatePublications,
|
lastExecuted = DateTime.Now;
|
||||||
UpdateChapters,
|
_task = new (_taskAction);
|
||||||
DownloadNewChapters
|
_task.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TrangaTask CreateDownloadChapterTask(Connector connector, Publication publication, Chapter chapter, TimeSpan reoccurrence)
|
||||||
|
{
|
||||||
|
void TaskAction()
|
||||||
|
{
|
||||||
|
connector.DownloadChapter(publication, chapter);
|
||||||
|
}
|
||||||
|
return new TrangaTask(TaskAction, reoccurrence);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TrangaTask CreateUpdateChaptersTask(ref Dictionary<Publication, Chapter[]> chapterCollection, Connector connector, Publication publication, string language, TimeSpan reoccurrence)
|
||||||
|
{
|
||||||
|
Dictionary<Publication, Chapter[]> pChapterCollection = chapterCollection;
|
||||||
|
|
||||||
|
void TaskAction()
|
||||||
|
{
|
||||||
|
Chapter[] chapters = connector.GetChapters(publication, language);
|
||||||
|
if(pChapterCollection.TryAdd(publication, chapters))
|
||||||
|
pChapterCollection[publication] = chapters;
|
||||||
|
}
|
||||||
|
return new TrangaTask(TaskAction, reoccurrence);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TrangaTask CreateUpdatePublicationsTask(ref Dictionary<Publication, Chapter[]> chapterCollection, Connector connector, TimeSpan reoccurrence)
|
||||||
|
{
|
||||||
|
Dictionary<Publication, Chapter[]> pChapterCollection = chapterCollection;
|
||||||
|
|
||||||
|
void TaskAction()
|
||||||
|
{
|
||||||
|
Publication[] publications = connector.GetPublications();
|
||||||
|
foreach (Publication publication in publications)
|
||||||
|
pChapterCollection.TryAdd(publication, Array.Empty<Chapter>());
|
||||||
|
}
|
||||||
|
return new TrangaTask(TaskAction, reoccurrence);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user