mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-14 15:27:53 +02:00
Compare commits
193 Commits
Author | SHA1 | Date | |
---|---|---|---|
cdd2d94ba1 | |||
d5b7645cd2 | |||
9af5c1603e | |||
1035939309 | |||
3b542c04f6 | |||
a809b7c285 | |||
e883277400 | |||
23dfdc0933 | |||
edc24fff5b | |||
6cdccdf66b | |||
a4c9168551 | |||
821a1b7c3a | |||
b2b4256972 | |||
d2f46e4637 | |||
303fc293ba | |||
36c145da26 | |||
c822c74f42 | |||
dda4054d34 | |||
5b2546fdbc | |||
c11e3993ea | |||
02a382a99a | |||
c6c8f5cdf6 | |||
84842aed3c | |||
d9ced11cd1 | |||
25c90782dc | |||
e789c429cd | |||
93de471836 | |||
8b58e7dd13 | |||
b571bfa43d | |||
088d1c4647 | |||
f280c01802 | |||
1be10b310d | |||
a0469f3145 | |||
fcd81f03b3 | |||
76604d84d8 | |||
af822febbe | |||
8e207c3119 | |||
b6f8c8aab5 | |||
36f7cbd3e9 | |||
3b2643d949 | |||
9fd8bf1741 | |||
d5c9c5ba96 | |||
c8e27921ab | |||
6eaba07801 | |||
41929e0c72 | |||
4fcaca1a6e | |||
0e3c7f32d7 | |||
1c94625840 | |||
32f89f9dce | |||
234735a562 | |||
8b916eb854 | |||
29e1790c93 | |||
ac4c799a74 | |||
7c62883c37 | |||
02018253bf | |||
2aec884009 | |||
b3321ff030 | |||
16c1094875 | |||
5763d50409 | |||
ad43297358 | |||
b17800e0ef | |||
89c80d2997 | |||
6485b8744f | |||
a3a96b6b55 | |||
5bce3c6fdd | |||
5fa0c98d05 | |||
b166013770 | |||
02fe849046 | |||
d42393c83a | |||
c685bd622f | |||
dc83cc2194 | |||
7784f2024e | |||
4895079887 | |||
ab1ddc6dc8 | |||
87eade10cf | |||
1f3ac41b30 | |||
6a304bb330 | |||
b0642d1251 | |||
63b5139e93 | |||
e938784388 | |||
c436389426 | |||
5099e25f3f | |||
cf6fc3b8f6 | |||
f5141d0f8e | |||
5c753e7a7d | |||
17ce820cf3 | |||
5b4a3b9d7c | |||
f73997e563 | |||
437136804d | |||
e14683d21a | |||
5ae02ee0ed | |||
a2e9a3f34a | |||
bbf05e3dec | |||
d95839e5df | |||
5a303598fe | |||
db2103963e | |||
2c1105527a | |||
ed19dcb5c3 | |||
46f06c2685 | |||
d4f47e057c | |||
61712d0537 | |||
1f8f8c09e3 | |||
0522fa6215 | |||
0383a7d686 | |||
bd189984a9 | |||
58c01b2174 | |||
459558a514 | |||
721b316209 | |||
b1befa2ecc | |||
57a4cc4ab5 | |||
655e8db2b6 | |||
7cdf77cbb9 | |||
5a9aed4969 | |||
5b41f687d0 | |||
d6a62dc315 | |||
6d91788655 | |||
14785e5672 | |||
496d502cd2 | |||
7612411917 | |||
ed1402b5ec | |||
5adaee4821 | |||
2d82fe1489 | |||
783fd8129e | |||
4f29eff48e | |||
e0e7abb62b | |||
ae63a216a5 | |||
5d98295c59 | |||
0c580933f9 | |||
06f735aadd | |||
439d69d8e0 | |||
933df58712 | |||
165bbc412e | |||
6158fa072b | |||
0d3799e00d | |||
e977bed5a5 | |||
cacd5fede2 | |||
1bca99cb6a | |||
15fc367263 | |||
8bb6fb902b | |||
a57903cd5a | |||
1cd819b21d | |||
27afedc1b4 | |||
fac0a3f7eb | |||
03ca480fe8 | |||
c2915468a5 | |||
8805c53cb8 | |||
adbbe3f6cc | |||
14b694d3be | |||
72ce75c6e0 | |||
8381951168 | |||
b24032d124 | |||
8bc23f7c69 | |||
48b7371a18 | |||
61ecefb615 | |||
8ff65bf400 | |||
932057cca0 | |||
67d06cd887 | |||
cbb012a659 | |||
e4f33bcca9 | |||
fbba7c45b9 | |||
d9b6062767 | |||
d477cd1ccd | |||
f892db7dda | |||
16c1b5c506 | |||
d5ecc1c37d | |||
1b9ebd096b | |||
8619630269 | |||
2bc92556e3 | |||
f1ab823e7f | |||
8261d02cc7 | |||
8d3b8be95c | |||
60519910de | |||
0940afe41f | |||
3dc376c19f | |||
3e56ef842b | |||
5a44e3b8b9 | |||
732c2f119c | |||
81638f4b4a | |||
c547aa6422 | |||
d80980512e | |||
f9f802155d | |||
eef0955009 | |||
ec25900ac0 | |||
e5fe14a09e | |||
5dc91095f8 | |||
985ac8fc7a | |||
c9537a9963 | |||
4fd3c03804 | |||
a1e9dd0232 | |||
aa1f9b1b56 | |||
6069578b6e | |||
a84b768e24 | |||
d1a21af15d |
@ -1,10 +1,10 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<RootNamespace>Tranga_API</RootNamespace>
|
<Nullable>enable</Nullable>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@ -15,14 +15,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Logging\Logging.csproj" />
|
|
||||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.5" />
|
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.6" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
13
API/Dockerfile
Normal file
13
API/Dockerfile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
|
||||||
|
WORKDIR /src
|
||||||
|
COPY . /src/
|
||||||
|
RUN dotnet restore API/API.csproj
|
||||||
|
RUN dotnet publish -c Release -o /publish
|
||||||
|
|
||||||
|
FROM glax/tranga-base:dev as runtime
|
||||||
|
WORKDIR /publish
|
||||||
|
COPY --from=build-env /publish .
|
||||||
|
EXPOSE 6531
|
||||||
|
ENTRYPOINT ["dotnet", "/publish/API.dll"]
|
46
API/Program.cs
Normal file
46
API/Program.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Logging;
|
||||||
|
using Tranga;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
||||||
|
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
|
||||||
|
string logsFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/var/logs/Tranga" : Path.Join(applicationFolderPath, "logs");
|
||||||
|
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
||||||
|
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
||||||
|
|
||||||
|
Directory.CreateDirectory(logsFolderPath);
|
||||||
|
Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.ConsoleLogger }, Console.Out, Console.Out.Encoding, logFilePath);
|
||||||
|
|
||||||
|
logger.WriteLine("Tranga", "Loading settings.");
|
||||||
|
|
||||||
|
TrangaSettings settings;
|
||||||
|
if (File.Exists(settingsFilePath))
|
||||||
|
settings = TrangaSettings.LoadSettings(settingsFilePath, logger);
|
||||||
|
else
|
||||||
|
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, new HashSet<LibraryManager>(), new HashSet<NotificationManager>());
|
||||||
|
|
||||||
|
Directory.CreateDirectory(settings.workingDirectory);
|
||||||
|
Directory.CreateDirectory(settings.downloadLocation);
|
||||||
|
Directory.CreateDirectory(settings.coverImageCache);
|
||||||
|
|
||||||
|
logger.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}");
|
||||||
|
logger.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}");
|
||||||
|
logger.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}");
|
||||||
|
logger.WriteLine("Tranga",$"Logfile-Path: {logFilePath}");
|
||||||
|
logger.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}");
|
||||||
|
|
||||||
|
logger.WriteLine("Tranga", "Loading Taskmanager.");
|
||||||
|
TaskManager taskManager = new (settings, logger);
|
||||||
|
|
||||||
|
Server server = new (6531, taskManager, logger);
|
||||||
|
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
|
||||||
|
nm.SendNotification("Tranga-API", "Started Tranga-API");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
361
API/RequestHandler.cs
Normal file
361
API/RequestHandler.cs
Normal file
@ -0,0 +1,361 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Tranga;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public class RequestHandler
|
||||||
|
{
|
||||||
|
private TaskManager _taskManager;
|
||||||
|
private Server _parent;
|
||||||
|
|
||||||
|
private List<ValueTuple<HttpMethod, string, string[]>> _validRequestPaths = new()
|
||||||
|
{
|
||||||
|
new(HttpMethod.Get, "/", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Get, "/Connectors", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Get, "/Publications/Known", new[] { "internalId?" }),
|
||||||
|
new(HttpMethod.Get, "/Publications/FromConnector", new[] { "connectorName", "title" }),
|
||||||
|
new(HttpMethod.Get, "/Publications/Chapters",
|
||||||
|
new[] { "connectorName", "internalId", "onlyNew?", "onlyExisting?", "language?" }),
|
||||||
|
new(HttpMethod.Get, "/Tasks/Types", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Post, "/Tasks/CreateMonitorTask",
|
||||||
|
new[] { "connectorName", "internalId", "reoccurrenceTime", "language?" }),
|
||||||
|
new(HttpMethod.Post, "/Tasks/CreateUpdateLibraryTask", new[] { "reoccurrenceTime" }),
|
||||||
|
new(HttpMethod.Post, "/Tasks/CreateDownloadChaptersTask",
|
||||||
|
new[] { "connectorName", "internalId", "chapters", "language?" }),
|
||||||
|
new(HttpMethod.Get, "/Tasks", new[] { "taskType", "connectorName?", "publicationId?" }),
|
||||||
|
new(HttpMethod.Delete, "/Tasks", new[] { "taskType", "connectorName?", "searchString?" }),
|
||||||
|
new(HttpMethod.Get, "/Tasks/Progress",
|
||||||
|
new[] { "taskType", "connectorName", "publicationId", "chapterSortNumber?" }),
|
||||||
|
new(HttpMethod.Post, "/Tasks/Start", new[] { "taskType", "connectorName?", "internalId?" }),
|
||||||
|
new(HttpMethod.Get, "/Tasks/RunningTasks", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Get, "/Queue/List", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Post, "/Queue/Enqueue", new[] { "taskType", "connectorName?", "publicationId?" }),
|
||||||
|
new(HttpMethod.Delete, "/Queue/Dequeue", new[] { "taskType", "connectorName?", "publicationId?" }),
|
||||||
|
new(HttpMethod.Get, "/Settings", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Post, "/Settings/Update", new[]
|
||||||
|
{
|
||||||
|
"downloadLocation?", "komgaUrl?", "komgaAuth?", "kavitaUrl?", "kavitaUsername?",
|
||||||
|
"kavitaPassword?", "gotifyUrl?", "gotifyAppToken?", "lunaseaWebhook?"
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
public RequestHandler(TaskManager taskManager, Server parent)
|
||||||
|
{
|
||||||
|
this._taskManager = taskManager;
|
||||||
|
this._parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void HandleRequest(HttpListenerRequest request, HttpListenerResponse response)
|
||||||
|
{
|
||||||
|
string requestPath = request.Url!.LocalPath;
|
||||||
|
if (requestPath.Contains("favicon"))
|
||||||
|
{
|
||||||
|
_parent.SendResponse(HttpStatusCode.NoContent, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this._validRequestPaths.Any(path => path.Item1.Method == request.HttpMethod && path.Item2 == requestPath))
|
||||||
|
{
|
||||||
|
_parent.SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Dictionary<string, string> variables = GetRequestVariables(request.Url!.Query);
|
||||||
|
object? responseObject = null;
|
||||||
|
switch (request.HttpMethod)
|
||||||
|
{
|
||||||
|
case "GET":
|
||||||
|
responseObject = this.HandleGet(requestPath, variables);
|
||||||
|
break;
|
||||||
|
case "POST":
|
||||||
|
this.HandlePost(requestPath, variables);
|
||||||
|
break;
|
||||||
|
case "DELETE":
|
||||||
|
this.HandleDelete(requestPath, variables);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_parent.SendResponse(HttpStatusCode.OK, response, responseObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<string, string> GetRequestVariables(string query)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> ret = new();
|
||||||
|
Regex queryRex = new (@"\?{1}([A-z]+=[A-z]+)+(&[A-z]+=[A-z]+)*");
|
||||||
|
if (!queryRex.IsMatch(query))
|
||||||
|
return ret;
|
||||||
|
query = query.Substring(1);
|
||||||
|
foreach(string kvpair in query.Split('&'))
|
||||||
|
ret.Add(kvpair.Split('=')[0], kvpair.Split('=')[1]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleDelete(string requestPath, Dictionary<string, string> variables)
|
||||||
|
{
|
||||||
|
switch (requestPath)
|
||||||
|
{
|
||||||
|
case "/Tasks":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType1);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName1);
|
||||||
|
variables.TryGetValue("publicationId", out string? publicationId1);
|
||||||
|
if(taskType1 is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType1);
|
||||||
|
foreach(TrangaTask tTask in _taskManager.GetTasksMatching(task, connectorName1, internalId: publicationId1))
|
||||||
|
_taskManager.DeleteTask(tTask);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "/Queue/Dequeue":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType2);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName2);
|
||||||
|
variables.TryGetValue("publicationId", out string? publicationId2);
|
||||||
|
if(taskType2 is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType2);
|
||||||
|
TrangaTask? task = _taskManager
|
||||||
|
.GetTasksMatching(pTask, connectorName: connectorName2, internalId: publicationId2).FirstOrDefault();
|
||||||
|
|
||||||
|
if (task is null)
|
||||||
|
return;
|
||||||
|
_taskManager.RemoveTaskFromQueue(task);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandlePost(string requestPath, Dictionary<string, string> variables)
|
||||||
|
{
|
||||||
|
switch (requestPath)
|
||||||
|
{
|
||||||
|
|
||||||
|
case "/Tasks/CreateMonitorTask":
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName1);
|
||||||
|
variables.TryGetValue("internalId", out string? internalId1);
|
||||||
|
variables.TryGetValue("reoccurrenceTime", out string? reoccurrenceTime1);
|
||||||
|
variables.TryGetValue("language", out string? language1);
|
||||||
|
if (connectorName1 is null || internalId1 is null || reoccurrenceTime1 is null)
|
||||||
|
return;
|
||||||
|
Connector? connector1 =
|
||||||
|
_taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName1).Value;
|
||||||
|
if (connector1 is null)
|
||||||
|
return;
|
||||||
|
Publication? publication1 = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId1);
|
||||||
|
if (publication1 is null)
|
||||||
|
return;
|
||||||
|
_taskManager.AddTask(new MonitorPublicationTask(connectorName1, (Publication)publication1, TimeSpan.Parse(reoccurrenceTime1), language1 ?? "en"));
|
||||||
|
break;
|
||||||
|
case "/Tasks/CreateUpdateLibraryTask":
|
||||||
|
variables.TryGetValue("reoccurrenceTime", out string? reoccurrenceTime2);
|
||||||
|
if (reoccurrenceTime2 is null)
|
||||||
|
return;
|
||||||
|
_taskManager.AddTask(new UpdateLibrariesTask(TimeSpan.Parse(reoccurrenceTime2)));
|
||||||
|
break;
|
||||||
|
case "/Tasks/CreateDownloadChaptersTask":
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName2);
|
||||||
|
variables.TryGetValue("internalId", out string? internalId2);
|
||||||
|
variables.TryGetValue("chapters", out string? chapters);
|
||||||
|
variables.TryGetValue("language", out string? language2);
|
||||||
|
if (connectorName2 is null || internalId2 is null || chapters is null)
|
||||||
|
return;
|
||||||
|
Connector? connector2 =
|
||||||
|
_taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName2).Value;
|
||||||
|
if (connector2 is null)
|
||||||
|
return;
|
||||||
|
Publication? publication2 = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId2);
|
||||||
|
if (publication2 is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IEnumerable<Chapter> toDownload = connector2.SearchChapters((Publication)publication2, chapters, language2 ?? "en");
|
||||||
|
foreach(Chapter chapter in toDownload)
|
||||||
|
_taskManager.AddTask(new DownloadChapterTask(connectorName2, (Publication)publication2, chapter, "en"));
|
||||||
|
break;
|
||||||
|
case "/Tasks/Start":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType1);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName3);
|
||||||
|
variables.TryGetValue("internalId", out string? internalId3);
|
||||||
|
if (taskType1 is null)
|
||||||
|
return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType1);
|
||||||
|
TrangaTask? task = _taskManager
|
||||||
|
.GetTasksMatching(pTask, connectorName: connectorName3, internalId: internalId3).FirstOrDefault();
|
||||||
|
|
||||||
|
if (task is null)
|
||||||
|
return;
|
||||||
|
_taskManager.ExecuteTaskNow(task);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "/Queue/Enqueue":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType2);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName4);
|
||||||
|
variables.TryGetValue("publicationId", out string? publicationId);
|
||||||
|
if (taskType2 is null)
|
||||||
|
return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType2);
|
||||||
|
TrangaTask? task = _taskManager
|
||||||
|
.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId).FirstOrDefault();
|
||||||
|
|
||||||
|
if (task is null)
|
||||||
|
return;
|
||||||
|
_taskManager.AddTaskToQueue(task);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "/Settings/Update":
|
||||||
|
variables.TryGetValue("downloadLocation", out string? downloadLocation);
|
||||||
|
variables.TryGetValue("komgaUrl", out string? komgaUrl);
|
||||||
|
variables.TryGetValue("komgaAuth", out string? komgaAuth);
|
||||||
|
variables.TryGetValue("kavitaUrl", out string? kavitaUrl);
|
||||||
|
variables.TryGetValue("kavitaUsername", out string? kavitaUsername);
|
||||||
|
variables.TryGetValue("kavitaPassword", out string? kavitaPassword);
|
||||||
|
variables.TryGetValue("gotifyUrl", out string? gotifyUrl);
|
||||||
|
variables.TryGetValue("gotifyAppToken", out string? gotifyAppToken);
|
||||||
|
variables.TryGetValue("lunaseaWebhook", out string? lunaseaWebhook);
|
||||||
|
|
||||||
|
if (downloadLocation is not null && downloadLocation.Length > 0)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, _parent.logger, downloadLocation);
|
||||||
|
if (komgaUrl is not null && komgaAuth is not null && komgaUrl.Length > 5 && komgaAuth.Length > 0)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Komga, _parent.logger, komgaUrl, komgaAuth);
|
||||||
|
if (kavitaUrl is not null && kavitaPassword is not null && kavitaUsername is not null && kavitaUrl.Length > 5 &&
|
||||||
|
kavitaUsername.Length > 0 && kavitaPassword.Length > 0)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, _parent.logger, kavitaUrl, kavitaUsername,
|
||||||
|
kavitaPassword);
|
||||||
|
if (gotifyUrl is not null && gotifyAppToken is not null && gotifyUrl.Length > 5 && gotifyAppToken.Length > 0)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, _parent.logger, gotifyUrl, gotifyAppToken);
|
||||||
|
if(lunaseaWebhook is not null && lunaseaWebhook.Length > 5)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.LunaSea, _parent.logger, lunaseaWebhook);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private object? HandleGet(string requestPath, Dictionary<string, string> variables)
|
||||||
|
{
|
||||||
|
switch (requestPath)
|
||||||
|
{
|
||||||
|
case "/Connectors":
|
||||||
|
return this._taskManager.GetAvailableConnectors().Keys.ToArray();
|
||||||
|
case "/Publications/Known":
|
||||||
|
variables.TryGetValue("internalId", out string? internalId1);
|
||||||
|
if(internalId1 is null)
|
||||||
|
return _taskManager.GetAllPublications();
|
||||||
|
return new [] { _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId1) };
|
||||||
|
case "/Publications/FromConnector":
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName1);
|
||||||
|
variables.TryGetValue("title", out string? title);
|
||||||
|
if (connectorName1 is null || title is null)
|
||||||
|
return null;
|
||||||
|
Connector? connector1 = _taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName1).Value;
|
||||||
|
if (connector1 is null)
|
||||||
|
return null;
|
||||||
|
if(title.Length < 4)
|
||||||
|
return null;
|
||||||
|
return _taskManager.GetPublicationsFromConnector(connector1, title);
|
||||||
|
case "/Publications/Chapters":
|
||||||
|
string[] yes = { "true", "yes", "1", "y" };
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName2);
|
||||||
|
variables.TryGetValue("internalId", out string? internalId2);
|
||||||
|
variables.TryGetValue("onlyNew", out string? onlyNew);
|
||||||
|
variables.TryGetValue("onlyExisting", out string? onlyExisting);
|
||||||
|
variables.TryGetValue("language", out string? language);
|
||||||
|
if (connectorName2 is null || internalId2 is null)
|
||||||
|
return null;
|
||||||
|
bool newOnly = onlyNew is not null && yes.Contains(onlyNew);
|
||||||
|
bool existingOnly = onlyExisting is not null && yes.Contains(onlyExisting);
|
||||||
|
|
||||||
|
Connector? connector2 = _taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName2).Value;
|
||||||
|
if (connector2 is null)
|
||||||
|
return null;
|
||||||
|
Publication? publication = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId2);
|
||||||
|
if (publication is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if(newOnly)
|
||||||
|
return _taskManager.GetNewChaptersList(connector2, (Publication)publication, language??"en").ToArray();
|
||||||
|
else if (existingOnly)
|
||||||
|
return _taskManager.GetExistingChaptersList(connector2, (Publication)publication, language ?? "en").ToArray();
|
||||||
|
else
|
||||||
|
return connector2.GetChapters((Publication)publication, language??"en");
|
||||||
|
case "/Tasks/Types":
|
||||||
|
return Enum.GetNames(typeof(TrangaTask.Task));
|
||||||
|
case "/Tasks":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType1);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName3);
|
||||||
|
variables.TryGetValue("searchString", out string? searchString);
|
||||||
|
if (taskType1 is null)
|
||||||
|
return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType1);
|
||||||
|
return _taskManager.GetTasksMatching(task, connectorName:connectorName3, searchString:searchString);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case "/Tasks/Progress":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType2);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName4);
|
||||||
|
variables.TryGetValue("publicationId", out string? publicationId);
|
||||||
|
variables.TryGetValue("chapterSortNumber", out string? chapterSortNumber);
|
||||||
|
if (taskType2 is null || connectorName4 is null || publicationId is null)
|
||||||
|
return null;
|
||||||
|
Connector? connector =
|
||||||
|
_taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName4).Value;
|
||||||
|
if (connector is null)
|
||||||
|
return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask? task = null;
|
||||||
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType2);
|
||||||
|
if (pTask is TrangaTask.Task.MonitorPublication)
|
||||||
|
{
|
||||||
|
task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId).FirstOrDefault();
|
||||||
|
}else if (pTask is TrangaTask.Task.DownloadChapter && chapterSortNumber is not null)
|
||||||
|
{
|
||||||
|
task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId,
|
||||||
|
chapterSortNumber: chapterSortNumber).FirstOrDefault();
|
||||||
|
}
|
||||||
|
if (task is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return task.progress;
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case "/Tasks/RunningTasks":
|
||||||
|
return _taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running);
|
||||||
|
case "/Queue/List":
|
||||||
|
return _taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Enqueued).OrderBy(task => task.nextExecution);
|
||||||
|
case "/Settings":
|
||||||
|
return _taskManager.settings;
|
||||||
|
case "/":
|
||||||
|
default:
|
||||||
|
return this._validRequestPaths;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
72
API/Server.cs
Normal file
72
API/Server.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Tranga;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public class Server
|
||||||
|
{
|
||||||
|
private readonly HttpListener _listener = new ();
|
||||||
|
private readonly RequestHandler _requestHandler;
|
||||||
|
internal readonly Logger? logger;
|
||||||
|
|
||||||
|
private readonly Regex _validUrl =
|
||||||
|
new (@"https?:\/\/(www\.)?[-A-z0-9]{1,256}(\.[-a-zA-Z0-9]{1,6})?(:[0-9]{1,5})?(\/{1}[A-z0-9()@:%_\+.~#?&=]+)*\/?");
|
||||||
|
public Server(int port, TaskManager taskManager, Logger? logger = null)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this._listener.Prefixes.Add($"http://*:{port}/");
|
||||||
|
this._requestHandler = new RequestHandler(taskManager, this);
|
||||||
|
Listen();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Listen()
|
||||||
|
{
|
||||||
|
this._listener.Start();
|
||||||
|
foreach (string prefix in this._listener.Prefixes)
|
||||||
|
this.logger?.WriteLine(this.GetType().ToString(), $"Listening on {prefix}");
|
||||||
|
while (this._listener.IsListening)
|
||||||
|
{
|
||||||
|
HttpListenerContext context = this._listener.GetContextAsync().Result;
|
||||||
|
Task t = new (() =>
|
||||||
|
{
|
||||||
|
HandleContext(context);
|
||||||
|
});
|
||||||
|
t.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleContext(HttpListenerContext context)
|
||||||
|
{
|
||||||
|
HttpListenerRequest request = context.Request;
|
||||||
|
HttpListenerResponse response = context.Response;
|
||||||
|
//logger?.WriteLine(this.GetType().ToString(), $"New request: {request.HttpMethod} {request.Url}");
|
||||||
|
|
||||||
|
if (!_validUrl.IsMatch(request.Url!.ToString()))
|
||||||
|
{
|
||||||
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_requestHandler.HandleRequest(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
||||||
|
{
|
||||||
|
//logger?.WriteLine(this.GetType().ToString(), $"Sending response: {statusCode}");
|
||||||
|
response.StatusCode = (int)statusCode;
|
||||||
|
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
|
||||||
|
response.AddHeader("Access-Control-Allow-Methods", "GET, POST, DELETE");
|
||||||
|
response.AddHeader("Access-Control-Max-Age", "1728000");
|
||||||
|
response.AppendHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
response.ContentType = "application/json";
|
||||||
|
response.OutputStream.Write(content is not null
|
||||||
|
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
|
||||||
|
: Array.Empty<byte>());
|
||||||
|
response.OutputStream.Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,8 @@ COPY . /src/
|
|||||||
RUN dotnet restore Tranga-API/Tranga-API.csproj
|
RUN dotnet restore Tranga-API/Tranga-API.csproj
|
||||||
RUN dotnet publish -c Release -o /publish
|
RUN dotnet publish -c Release -o /publish
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
|
#FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
|
||||||
|
FROM glax/tranga-base:latest as runtime
|
||||||
WORKDIR /publish
|
WORKDIR /publish
|
||||||
COPY --from=build-env /publish .
|
COPY --from=build-env /publish .
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
8
Dockerfile-base
Normal file
8
Dockerfile-base
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
#FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
|
||||||
|
FROM mcr.microsoft.com/dotnet/runtime:7.0 as runtime
|
||||||
|
WORKDIR /publish
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get install -y libx11-6 libx11-xcb1 libatk1.0-0 libgtk-3-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2 libxshmfence1 libnss3
|
||||||
|
RUN apt-get autopurge -y
|
||||||
|
RUN apt-get autoclean -y
|
@ -14,7 +14,8 @@ public class MemoryLogger : LoggerBase
|
|||||||
|
|
||||||
protected override void Write(LogMessage value)
|
protected override void Write(LogMessage value)
|
||||||
{
|
{
|
||||||
_logMessages.Add(value.logTime, value);
|
while(!_logMessages.TryAdd(value.logTime, value))
|
||||||
|
Thread.Sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] GetLogMessage()
|
public string[] GetLogMessage()
|
||||||
|
35
README.md
35
README.md
@ -36,6 +36,7 @@
|
|||||||
<li>
|
<li>
|
||||||
<a href="#getting-started">Getting Started</a>
|
<a href="#getting-started">Getting Started</a>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><a href="#prerequisites">Usage</a></li>
|
||||||
<li><a href="#prerequisites">Prerequisites</a></li>
|
<li><a href="#prerequisites">Prerequisites</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
@ -54,8 +55,10 @@
|
|||||||
Tranga can download Chapters and Metadata from Scanlation sites such as
|
Tranga can download Chapters and Metadata from Scanlation sites such as
|
||||||
|
|
||||||
- [MangaDex.org](https://mangadex.org/)
|
- [MangaDex.org](https://mangadex.org/)
|
||||||
|
- [Manganato.com](https://manganato.com/)
|
||||||
|
- [Mangasee](https://mangasee123.com/)
|
||||||
|
|
||||||
and automatically start updates in [Komga](https://komga.org/) to import them.
|
and automatically start updates in [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/) to import them.
|
||||||
|
|
||||||
### Inspiration:
|
### Inspiration:
|
||||||
|
|
||||||
@ -71,6 +74,8 @@ That is why I wanted to create my own project, in a language I understand, and t
|
|||||||
|
|
||||||
- .NET-Core
|
- .NET-Core
|
||||||
- Newtonsoft.JSON
|
- Newtonsoft.JSON
|
||||||
|
- [PuppeteerSharp](https://www.puppeteersharp.com/)
|
||||||
|
- [Html Agility Pack (HAP)](https://html-agility-pack.net/)
|
||||||
- Love <3 Blåhaj 🦈
|
- Love <3 Blåhaj 🦈
|
||||||
|
|
||||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||||
@ -105,16 +110,36 @@ Download [docker-compose.yaml](https://git.bernloehr.eu/glax/Tranga/src/branch/m
|
|||||||
|
|
||||||
Wherever you are mounting `/usr/share/Tranga-API` you also need to mount that same path + `/imageCache` in the webserver container.
|
Wherever you are mounting `/usr/share/Tranga-API` you also need to mount that same path + `/imageCache` in the webserver container.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
There is two ways to download Mangas:
|
||||||
|
- Downloading everything and monitor for new Chapters
|
||||||
|
- Selecting specific Volumes/Chapters
|
||||||
|
|
||||||
|
On the website you add new tasks, by selecting the blue '+' field. Next select the connector/site you want to use, and enter a search term.
|
||||||
|
After pressing 'Search', the results will be presented below - this might, depending on the result-size, take a while.
|
||||||
|
Next select the publication and a new popup will open with two options:
|
||||||
|
- "Monitor" - Download all chapters and monitor for new ones
|
||||||
|
- "Download Chapter" - Download specific chapters only
|
||||||
|
|
||||||
|
When selecting `Monitor` you will be presented with a new window and the selection of the interval you want to check for new chapters.
|
||||||
|
When selecting `Download Chapter` a list will open with all available chapters from which you can then select a range.
|
||||||
|
|
||||||
|
The syntax for selecting chapters is as follows:
|
||||||
|
- To download a single Chapter enter either the index number (the number at the very start of the line) or its absolute number like so: `c(h)(apter)[number]`, spaces are allowed.
|
||||||
|
- To download a range of chapters enter either a range of index numbers (`3-6`) or chapters (`ch 12-23`).
|
||||||
|
- For volumes the syntax is as follows: `v(ol)[number](-[number])`, again spaces allowed.
|
||||||
|
|
||||||
|
Examples: `2-12`, `c1`, `ch 2`, `chapter 3`, `v 2`, `vol3-4`, `v2c4` (note: you can only specify a single chapter with this syntax).
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
[.NET-Core 7.0](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
|
[.NET-Core 7.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
|
||||||
|
|
||||||
<!-- ROADMAP -->
|
<!-- ROADMAP -->
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
- [x] Web-UI #1
|
- [ ] Docker ARM support
|
||||||
- [ ] More Connectors
|
|
||||||
- [ ] Manganato #2
|
|
||||||
- [ ] ?
|
- [ ] ?
|
||||||
|
|
||||||
See the [open issues](https://git.bernloehr.eu/glax/Tranga/issues) for a full list of proposed features (and known issues).
|
See the [open issues](https://git.bernloehr.eu/glax/Tranga/issues) for a full list of proposed features (and known issues).
|
||||||
|
@ -1,191 +0,0 @@
|
|||||||
using System.Runtime.InteropServices;
|
|
||||||
using Logging;
|
|
||||||
using Tranga;
|
|
||||||
|
|
||||||
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
|
||||||
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
|
|
||||||
string logsFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/var/logs/Tranga" : Path.Join(applicationFolderPath, "logs");
|
|
||||||
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
|
||||||
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
|
||||||
|
|
||||||
Directory.CreateDirectory(logsFolderPath);
|
|
||||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.ConsoleLogger }, Console.Out, Console.Out.Encoding, logFilePath);
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga", "Loading settings.");
|
|
||||||
|
|
||||||
TrangaSettings settings;
|
|
||||||
if (File.Exists(settingsFilePath))
|
|
||||||
settings = TrangaSettings.LoadSettings(settingsFilePath);
|
|
||||||
else
|
|
||||||
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, null);
|
|
||||||
|
|
||||||
Directory.CreateDirectory(settings.workingDirectory);
|
|
||||||
Directory.CreateDirectory(settings.downloadLocation);
|
|
||||||
Directory.CreateDirectory(settings.coverImageCache);
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}");
|
|
||||||
logger.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}");
|
|
||||||
logger.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}");
|
|
||||||
logger.WriteLine("Tranga",$"Logfile-Path: {logFilePath}");
|
|
||||||
logger.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}");
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga", "Loading Taskmanager.");
|
|
||||||
TaskManager taskManager = new (settings, logger);
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
|
||||||
builder.Services.AddSwaggerGen();
|
|
||||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
|
||||||
|
|
||||||
string corsHeader = "Tranga";
|
|
||||||
builder.Services.AddCors(options =>
|
|
||||||
{
|
|
||||||
options.AddPolicy(name: corsHeader,
|
|
||||||
policy =>
|
|
||||||
{
|
|
||||||
policy.AllowAnyOrigin();
|
|
||||||
policy.WithMethods("GET", "POST", "DELETE");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var app = builder.Build();
|
|
||||||
app.UseSwagger();
|
|
||||||
app.UseSwaggerUI();
|
|
||||||
app.UseSwagger();
|
|
||||||
app.UseSwaggerUI();
|
|
||||||
|
|
||||||
app.UseCors(corsHeader);
|
|
||||||
|
|
||||||
app.MapGet("/Tranga/GetAvailableControllers", () => taskManager.GetAvailableConnectors().Keys.ToArray());
|
|
||||||
|
|
||||||
app.MapGet("/Tranga/GetKnownPublications", () => taskManager.GetAllPublications());
|
|
||||||
|
|
||||||
app.MapGet("/Tranga/GetPublicationsFromConnector", (string connectorName, string title) =>
|
|
||||||
{
|
|
||||||
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
|
||||||
if (connector is null)
|
|
||||||
return Array.Empty<Publication>();
|
|
||||||
if(title.Length < 4)
|
|
||||||
return Array.Empty<Publication>();
|
|
||||||
return taskManager.GetPublicationsFromConnector(connector, title);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Tasks/GetTaskTypes", () => Enum.GetNames(typeof(TrangaTask.Task)));
|
|
||||||
|
|
||||||
|
|
||||||
app.MapPost("/Tasks/Create", (string taskType, string? connectorName, string? publicationId, string reoccurrenceTime, string? language) =>
|
|
||||||
{
|
|
||||||
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == publicationId);
|
|
||||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
taskManager.AddTask(task, connectorName, publication, TimeSpan.Parse(reoccurrenceTime), language??"");
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapDelete("/Tasks/Delete", (string taskType, string? connectorName, string? publicationId) =>
|
|
||||||
{
|
|
||||||
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == publicationId);
|
|
||||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
taskManager.DeleteTask(task, connectorName, publication);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? searchString) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
if (searchString is null || connectorName is null)
|
|
||||||
return taskManager.GetAllTasks().Where(tTask => tTask.task == task);
|
|
||||||
else
|
|
||||||
return taskManager.GetAllTasks().Where(tTask =>
|
|
||||||
tTask.task == task && tTask.connectorName == connectorName && tTask.ToString()
|
|
||||||
.Contains(searchString, StringComparison.InvariantCultureIgnoreCase));
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return Array.Empty<TrangaTask>();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapPost("/Tasks/Start", (string taskType, string? connectorName, string? publicationId) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
TrangaTask? task = null;
|
|
||||||
if (connectorName is null || publicationId is null)
|
|
||||||
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
|
||||||
tTask.task == pTask);
|
|
||||||
else
|
|
||||||
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
|
||||||
tTask.task == pTask && tTask.publication?.internalId == publicationId &&
|
|
||||||
tTask.connectorName == connectorName);
|
|
||||||
|
|
||||||
if (task is null)
|
|
||||||
return;
|
|
||||||
taskManager.ExecuteTaskNow(task);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Tasks/GetRunningTasks",
|
|
||||||
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running));
|
|
||||||
|
|
||||||
app.MapGet("/Queue/GetList",
|
|
||||||
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Enqueued));
|
|
||||||
|
|
||||||
app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
TrangaTask? task = null;
|
|
||||||
if (connectorName is null || publicationId is null)
|
|
||||||
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
|
||||||
tTask.task == pTask);
|
|
||||||
else
|
|
||||||
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
|
||||||
tTask.task == pTask && tTask.publication?.internalId == publicationId &&
|
|
||||||
tTask.connectorName == connectorName);
|
|
||||||
|
|
||||||
if (task is null)
|
|
||||||
return;
|
|
||||||
taskManager.AddTaskToQueue(task);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapDelete("/Queue/Dequeue", (string taskType, string? connectorName, string? publicationId) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
TrangaTask? task = null;
|
|
||||||
if (connectorName is null || publicationId is null)
|
|
||||||
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
|
||||||
tTask.task == pTask);
|
|
||||||
else
|
|
||||||
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
|
||||||
tTask.task == pTask && tTask.publication?.internalId == publicationId &&
|
|
||||||
tTask.connectorName == connectorName);
|
|
||||||
|
|
||||||
if (task is null)
|
|
||||||
return;
|
|
||||||
taskManager.RemoveTaskFromQueue(task);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Settings/Get", () => taskManager.settings);
|
|
||||||
|
|
||||||
app.MapPost("/Settings/Update", (string? downloadLocation, string? komgaUrl, string? komgaAuth) => taskManager.UpdateSettings(downloadLocation, komgaUrl, komgaAuth) );
|
|
||||||
|
|
||||||
app.Run();
|
|
@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"iisSettings": {
|
|
||||||
"windowsAuthentication": false,
|
|
||||||
"anonymousAuthentication": true,
|
|
||||||
"iisExpress": {
|
|
||||||
"applicationUrl": "http://localhost:1716",
|
|
||||||
"sslPort": 44391
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
|
||||||
"http": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"applicationUrl": "http://localhost:5177",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"https": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"applicationUrl": "https://localhost:7036;http://localhost:5177",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"IIS Express": {
|
|
||||||
"commandName": "IISExpress",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
|
@ -9,12 +9,6 @@
|
|||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="..\.dockerignore">
|
|
||||||
<Link>.dockerignore</Link>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Logging;
|
using Logging;
|
||||||
using Tranga;
|
using Tranga;
|
||||||
|
using Tranga.LibraryManagers;
|
||||||
|
using Tranga.NotificationManagers;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
|
||||||
namespace Tranga_CLI;
|
namespace Tranga_CLI;
|
||||||
|
|
||||||
@ -25,14 +28,10 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine($"Logfile-Path: {logFilePath}");
|
Console.WriteLine($"Logfile-Path: {logFilePath}");
|
||||||
Console.WriteLine($"Settings-File-Path: {settingsFilePath}");
|
Console.WriteLine($"Settings-File-Path: {settingsFilePath}");
|
||||||
|
|
||||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, null, logFilePath);
|
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, Console.Out.Encoding, logFilePath);
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
||||||
TrangaSettings settings;
|
TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath, logger) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, new HashSet<LibraryManager>(), new HashSet<NotificationManager>());
|
||||||
if (File.Exists(settingsFilePath))
|
|
||||||
settings = TrangaSettings.LoadSettings(settingsFilePath);
|
|
||||||
else
|
|
||||||
settings = new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, null);
|
|
||||||
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "User Input");
|
logger.WriteLine("Tranga_CLI", "User Input");
|
||||||
@ -41,43 +40,93 @@ public static class Tranga_Cli
|
|||||||
while(tmpPath is null)
|
while(tmpPath is null)
|
||||||
tmpPath = Console.ReadLine();
|
tmpPath = Console.ReadLine();
|
||||||
if (tmpPath.Length > 0)
|
if (tmpPath.Length > 0)
|
||||||
settings.downloadLocation = tmpPath;
|
settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, logger, tmpPath);
|
||||||
|
|
||||||
Console.WriteLine($"Komga BaseURL [{settings.komga?.baseUrl}]:");
|
Console.WriteLine($"Komga BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Komga))?.baseUrl}]:");
|
||||||
string? tmpUrl = Console.ReadLine();
|
string? tmpUrlKomga = Console.ReadLine();
|
||||||
while (tmpUrl is null)
|
while (tmpUrlKomga is null)
|
||||||
tmpUrl = Console.ReadLine();
|
tmpUrlKomga = Console.ReadLine();
|
||||||
if (tmpUrl.Length > 0)
|
if (tmpUrlKomga.Length > 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Username:");
|
Console.WriteLine("Username:");
|
||||||
string? tmpUser = Console.ReadLine();
|
string? tmpKomgaUser = Console.ReadLine();
|
||||||
while (tmpUser is null || tmpUser.Length < 1)
|
while (tmpKomgaUser is null || tmpKomgaUser.Length < 1)
|
||||||
tmpUser = Console.ReadLine();
|
tmpKomgaUser = Console.ReadLine();
|
||||||
|
|
||||||
Console.WriteLine("Password:");
|
Console.WriteLine("Password:");
|
||||||
string tmpPass = string.Empty;
|
string tmpKomgaPass = string.Empty;
|
||||||
ConsoleKey key;
|
ConsoleKey key;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
var keyInfo = Console.ReadKey(intercept: true);
|
var keyInfo = Console.ReadKey(intercept: true);
|
||||||
key = keyInfo.Key;
|
key = keyInfo.Key;
|
||||||
|
|
||||||
if (key == ConsoleKey.Backspace && tmpPass.Length > 0)
|
if (key == ConsoleKey.Backspace && tmpKomgaPass.Length > 0)
|
||||||
{
|
{
|
||||||
Console.Write("\b \b");
|
Console.Write("\b \b");
|
||||||
tmpPass = tmpPass[0..^1];
|
tmpKomgaPass = tmpKomgaPass[0..^1];
|
||||||
}
|
}
|
||||||
else if (!char.IsControl(keyInfo.KeyChar))
|
else if (!char.IsControl(keyInfo.KeyChar))
|
||||||
{
|
{
|
||||||
Console.Write("*");
|
Console.Write("*");
|
||||||
tmpPass += keyInfo.KeyChar;
|
tmpKomgaPass += keyInfo.KeyChar;
|
||||||
}
|
}
|
||||||
} while (key != ConsoleKey.Enter);
|
} while (key != ConsoleKey.Enter);
|
||||||
|
|
||||||
|
settings.UpdateSettings(TrangaSettings.UpdateField.Komga, logger, tmpUrlKomga, tmpKomgaUser, tmpKomgaPass);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"Kavita BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Kavita))?.baseUrl}]:");
|
||||||
|
string? tmpUrlKavita = Console.ReadLine();
|
||||||
|
while (tmpUrlKavita is null)
|
||||||
|
tmpUrlKavita = Console.ReadLine();
|
||||||
|
if (tmpUrlKavita.Length > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Username:");
|
||||||
|
string? tmpKavitaUser = Console.ReadLine();
|
||||||
|
while (tmpKavitaUser is null || tmpKavitaUser.Length < 1)
|
||||||
|
tmpKavitaUser = Console.ReadLine();
|
||||||
|
|
||||||
settings.komga = new Komga(tmpUrl, tmpUser, tmpPass, logger);
|
Console.WriteLine("Password:");
|
||||||
|
string tmpKavitaPass = string.Empty;
|
||||||
|
ConsoleKey key;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
var keyInfo = Console.ReadKey(intercept: true);
|
||||||
|
key = keyInfo.Key;
|
||||||
|
|
||||||
|
if (key == ConsoleKey.Backspace && tmpKavitaPass.Length > 0)
|
||||||
|
{
|
||||||
|
Console.Write("\b \b");
|
||||||
|
tmpKavitaPass = tmpKavitaPass[0..^1];
|
||||||
|
}
|
||||||
|
else if (!char.IsControl(keyInfo.KeyChar))
|
||||||
|
{
|
||||||
|
Console.Write("*");
|
||||||
|
tmpKavitaPass += keyInfo.KeyChar;
|
||||||
|
}
|
||||||
|
} while (key != ConsoleKey.Enter);
|
||||||
|
|
||||||
|
settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, logger, tmpUrlKavita, tmpKavitaUser, tmpKavitaPass);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"Gotify BaseURL [{((Gotify?)settings.notificationManagers.FirstOrDefault(lm => lm.GetType() == typeof(Gotify)))?.endpoint}]:");
|
||||||
|
string? tmpGotifyUrl = Console.ReadLine();
|
||||||
|
while (tmpGotifyUrl is null)
|
||||||
|
tmpGotifyUrl = Console.ReadLine();
|
||||||
|
if (tmpGotifyUrl.Length > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("AppToken:");
|
||||||
|
string? tmpGotifyAppToken = Console.ReadLine();
|
||||||
|
while (tmpGotifyAppToken is null || tmpGotifyAppToken.Length < 1)
|
||||||
|
tmpGotifyAppToken = Console.ReadLine();
|
||||||
|
|
||||||
|
settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, logger, tmpGotifyUrl, tmpGotifyAppToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Loaded.");
|
logger.WriteLine("Tranga_CLI", "Loaded.");
|
||||||
|
foreach(NotificationManager nm in settings.notificationManagers)
|
||||||
|
nm.SendNotification("Tranga", "Loaded.");
|
||||||
TaskMode(settings, logger);
|
TaskMode(settings, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +134,7 @@ public static class Tranga_Cli
|
|||||||
{
|
{
|
||||||
TaskManager taskManager = new (settings, logger);
|
TaskManager taskManager = new (settings, logger);
|
||||||
ConsoleKey selection = ConsoleKey.EraseEndOfFile;
|
ConsoleKey selection = ConsoleKey.EraseEndOfFile;
|
||||||
PrintMenu(taskManager, taskManager.settings.downloadLocation, logger);
|
PrintMenu(taskManager, taskManager.settings.downloadLocation);
|
||||||
while (selection != ConsoleKey.Q)
|
while (selection != ConsoleKey.Q)
|
||||||
{
|
{
|
||||||
int taskCount = taskManager.GetAllTasks().Length;
|
int taskCount = taskManager.GetAllTasks().Length;
|
||||||
@ -101,12 +150,16 @@ public static class Tranga_Cli
|
|||||||
switch (selection)
|
switch (selection)
|
||||||
{
|
{
|
||||||
case ConsoleKey.L:
|
case ConsoleKey.L:
|
||||||
PrintTasks(taskManager.GetAllTasks(), logger);
|
while (!Console.KeyAvailable)
|
||||||
Console.WriteLine("Press any key.");
|
{
|
||||||
|
PrintTasks(taskManager.GetAllTasks(), logger);
|
||||||
|
Console.WriteLine("Press any key.");
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.C:
|
case ConsoleKey.C:
|
||||||
CreateTask(taskManager, taskManager.settings, logger);
|
CreateTask(taskManager, logger);
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
@ -126,17 +179,26 @@ public static class Tranga_Cli
|
|||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.R:
|
case ConsoleKey.R:
|
||||||
PrintTasks(
|
while (!Console.KeyAvailable)
|
||||||
taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running)
|
{
|
||||||
.ToArray(), logger);
|
PrintTasks(
|
||||||
Console.WriteLine("Press any key.");
|
taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running)
|
||||||
|
.ToArray(), logger);
|
||||||
|
Console.WriteLine("Press any key.");
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.K:
|
case ConsoleKey.K:
|
||||||
PrintTasks(
|
while (!Console.KeyAvailable)
|
||||||
taskManager.GetAllTasks().Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued)
|
{
|
||||||
.ToArray(), logger);
|
PrintTasks(
|
||||||
Console.WriteLine("Press any key.");
|
taskManager.GetAllTasks()
|
||||||
|
.Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued)
|
||||||
|
.ToArray(), logger);
|
||||||
|
Console.WriteLine("Press any key.");
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.F:
|
case ConsoleKey.F:
|
||||||
@ -159,7 +221,7 @@ public static class Tranga_Cli
|
|||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PrintMenu(taskManager, taskManager.settings.downloadLocation, logger);
|
PrintMenu(taskManager, taskManager.settings.downloadLocation);
|
||||||
}
|
}
|
||||||
Thread.Sleep(200);
|
Thread.Sleep(200);
|
||||||
}
|
}
|
||||||
@ -179,7 +241,7 @@ public static class Tranga_Cli
|
|||||||
taskManager.Shutdown(false);
|
taskManager.Shutdown(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PrintMenu(TaskManager taskManager, string folderPath, Logger logger)
|
private static void 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);
|
||||||
@ -206,18 +268,18 @@ public static class Tranga_Cli
|
|||||||
int tIndex = 0;
|
int tIndex = 0;
|
||||||
Console.WriteLine($"Tasks (Running/Queue/Total): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
Console.WriteLine($"Tasks (Running/Queue/Total): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
||||||
string header =
|
string header =
|
||||||
$"{"",-5}{"Task",-20} | {"Last Executed",-20} | {"Reoccurrence",-12} | {"State",-10} | {"Connector",-15} | Publication/Manga";
|
$"{"",-5}{"Task",-20} | {"Last Executed",-20} | {"Reoccurrence",-12} | {"State",-10} | {"Progress",-9} | {"Finished",-20} | {"Remaining",-12} | {"Connector",-15} | Publication/Manga ";
|
||||||
Console.WriteLine(header);
|
Console.WriteLine(header);
|
||||||
Console.WriteLine(new string('-', header.Length));
|
Console.WriteLine(new string('-', header.Length));
|
||||||
foreach (TrangaTask trangaTask in tasks)
|
foreach (TrangaTask trangaTask in tasks)
|
||||||
{
|
{
|
||||||
string[] taskSplit = trangaTask.ToString().Split(", ");
|
string[] taskSplit = trangaTask.ToString().Split(", ");
|
||||||
Console.WriteLine($"{tIndex++:000}: {taskSplit[0],-20} | {taskSplit[1],-20} | {taskSplit[2],-12} | {taskSplit[3],-10} | {(taskSplit.Length > 4 ? taskSplit[4] : ""),-15} | {(taskSplit.Length > 5 ? taskSplit[5] : "")}");
|
Console.WriteLine($"{tIndex++:000}: {taskSplit[0],-20} | {taskSplit[1],-20} | {taskSplit[2],-12} | {taskSplit[3],-10} | {taskSplit[4],-9} | {taskSplit[5],-20} | {taskSplit[6][..12],-12} | {(taskSplit.Length > 7 ? taskSplit[7] : ""),-15} | {(taskSplit.Length > 8 ? taskSplit[8] : "")} {(taskSplit.Length > 9 ? taskSplit[9] : "")} {(taskSplit.Length > 10 ? taskSplit[10] : "")}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TrangaTask? SelectTask(TrangaTask[] tasks, Logger logger)
|
private static TrangaTask[] SelectTasks(TrangaTask[] tasks, Logger logger)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select task");
|
logger.WriteLine("Tranga_CLI", "Menu: Select task");
|
||||||
if (tasks.Length < 1)
|
if (tasks.Length < 1)
|
||||||
@ -225,13 +287,13 @@ public static class Tranga_Cli
|
|||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("There are no available Tasks.");
|
Console.WriteLine("There are no available Tasks.");
|
||||||
logger.WriteLine("Tranga_CLI", "No available Tasks.");
|
logger.WriteLine("Tranga_CLI", "No available Tasks.");
|
||||||
return null;
|
return Array.Empty<TrangaTask>();
|
||||||
}
|
}
|
||||||
PrintTasks(tasks, logger);
|
PrintTasks(tasks, logger);
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Selecting Task to Remove (from queue)");
|
logger.WriteLine("Tranga_CLI", "Selecting Task to Remove (from queue)");
|
||||||
Console.WriteLine("Enter q to abort");
|
Console.WriteLine("Enter q to abort");
|
||||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
Console.WriteLine($"Select Task(s) (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)
|
||||||
@ -242,21 +304,20 @@ public static class Tranga_Cli
|
|||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("aborted.");
|
Console.WriteLine("aborted.");
|
||||||
logger.WriteLine("Tranga_CLI", "aborted");
|
logger.WriteLine("Tranga_CLI", "aborted");
|
||||||
return null;
|
return Array.Empty<TrangaTask>();
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
|
||||||
return tasks[selectedTaskIndex];
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
|
||||||
logger.WriteLine("Tranga_CLI", e.Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
if (selectedTask.Contains('-'))
|
||||||
|
{
|
||||||
|
int start = Convert.ToInt32(selectedTask.Split('-')[0]);
|
||||||
|
int end = Convert.ToInt32(selectedTask.Split('-')[1]);
|
||||||
|
return tasks[start..end];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||||
|
return new[] { tasks[selectedTaskIndex] };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddMangaTaskToQueue(TaskManager taskManager, Logger logger)
|
private static void AddMangaTaskToQueue(TaskManager taskManager, Logger logger)
|
||||||
@ -264,18 +325,19 @@ public static class Tranga_Cli
|
|||||||
Console.Clear();
|
Console.Clear();
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Add Manga Download to queue");
|
logger.WriteLine("Tranga_CLI", "Menu: Add Manga Download to queue");
|
||||||
|
|
||||||
Connector? connector = SelectConnector(taskManager.settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
Connector? connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
||||||
if (connector is null)
|
if (connector is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Publication? publication = SelectPublication(taskManager, connector!, logger);
|
Publication? publication = SelectPublication(taskManager, connector, logger);
|
||||||
if (publication is null)
|
if (publication is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||||
TrangaTask newTask = taskManager.AddTask(TrangaTask.Task.DownloadNewChapters, connector?.name, publication, reoccurrence, "en");
|
TrangaTask nTask = new MonitorPublicationTask(connector.name, (Publication)publication, reoccurrence, "en");
|
||||||
Console.WriteLine(newTask);
|
taskManager.AddTask(nTask);
|
||||||
|
Console.WriteLine(nTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddTaskToQueue(TaskManager taskManager, Logger logger)
|
private static void AddTaskToQueue(TaskManager taskManager, Logger logger)
|
||||||
@ -286,12 +348,10 @@ public static class Tranga_Cli
|
|||||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask =>
|
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask =>
|
||||||
rTask.state is not TrangaTask.ExecutionState.Enqueued and not TrangaTask.ExecutionState.Running).ToArray();
|
rTask.state is not TrangaTask.ExecutionState.Enqueued and not TrangaTask.ExecutionState.Running).ToArray();
|
||||||
|
|
||||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
||||||
if (selectedTask is null)
|
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
||||||
return;
|
foreach(TrangaTask task in selectedTasks)
|
||||||
|
taskManager.AddTaskToQueue(task);
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
|
||||||
taskManager.AddTaskToQueue(selectedTask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RemoveTaskFromQueue(TaskManager taskManager, Logger logger)
|
private static void RemoveTaskFromQueue(TaskManager taskManager, Logger logger)
|
||||||
@ -301,12 +361,10 @@ public static class Tranga_Cli
|
|||||||
|
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask => rTask.state is TrangaTask.ExecutionState.Enqueued).ToArray();
|
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask => rTask.state is TrangaTask.ExecutionState.Enqueued).ToArray();
|
||||||
|
|
||||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
||||||
if (selectedTask is null)
|
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
||||||
return;
|
foreach(TrangaTask task in selectedTasks)
|
||||||
|
taskManager.RemoveTaskFromQueue(task);
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
|
||||||
taskManager.RemoveTaskFromQueue(selectedTask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TailLog(Logger logger)
|
private static void TailLog(Logger logger)
|
||||||
@ -327,34 +385,47 @@ public static class Tranga_Cli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateTask(TaskManager taskManager, TrangaSettings settings, Logger logger)
|
private static void CreateTask(TaskManager taskManager, Logger logger)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Creating Task");
|
logger.WriteLine("Tranga_CLI", "Menu: Creating Task");
|
||||||
TrangaTask.Task? tmpTask = SelectTaskType(logger);
|
TrangaTask.Task? tmpTask = SelectTaskType(logger);
|
||||||
if (tmpTask is null)
|
if (tmpTask is null)
|
||||||
return;
|
return;
|
||||||
TrangaTask.Task task = (TrangaTask.Task)tmpTask!;
|
TrangaTask.Task task = (TrangaTask.Task)tmpTask;
|
||||||
|
|
||||||
Connector? connector = null;
|
Connector? connector = null;
|
||||||
if (task != TrangaTask.Task.UpdateKomgaLibrary)
|
if (task != TrangaTask.Task.UpdateLibraries)
|
||||||
{
|
{
|
||||||
connector = SelectConnector(settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
||||||
if (connector is null)
|
if (connector is null)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Publication? publication = null;
|
Publication? publication = null;
|
||||||
if (task != TrangaTask.Task.UpdatePublications && task != TrangaTask.Task.UpdateKomgaLibrary)
|
if (task != TrangaTask.Task.UpdateLibraries)
|
||||||
{
|
{
|
||||||
publication = SelectPublication(taskManager, connector!, logger);
|
publication = SelectPublication(taskManager, connector!, logger);
|
||||||
if (publication is null)
|
if (publication is null)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
if (task is TrangaTask.Task.MonitorPublication)
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
{
|
||||||
TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en");
|
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
||||||
Console.WriteLine(newTask);
|
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||||
|
|
||||||
|
TrangaTask newTask = new MonitorPublicationTask(connector!.name, (Publication)publication!, reoccurrence, "en");
|
||||||
|
taskManager.AddTask(newTask);
|
||||||
|
Console.WriteLine(newTask);
|
||||||
|
}else if (task is TrangaTask.Task.DownloadChapter)
|
||||||
|
{
|
||||||
|
foreach (Chapter chapter in SelectChapters(connector!, (Publication)publication!, logger))
|
||||||
|
{
|
||||||
|
TrangaTask newTask = new DownloadChapterTask(connector!.name, (Publication)publication, chapter, "en");
|
||||||
|
taskManager.AddTask(newTask);
|
||||||
|
Console.WriteLine(newTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ExecuteTaskNow(TaskManager taskManager, Logger logger)
|
private static void ExecuteTaskNow(TaskManager taskManager, Logger logger)
|
||||||
@ -362,12 +433,10 @@ public static class Tranga_Cli
|
|||||||
logger.WriteLine("Tranga_CLI", "Menu: Executing Task");
|
logger.WriteLine("Tranga_CLI", "Menu: Executing Task");
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(nTask => nTask.state is not TrangaTask.ExecutionState.Running).ToArray();
|
TrangaTask[] tasks = taskManager.GetAllTasks().Where(nTask => nTask.state is not TrangaTask.ExecutionState.Running).ToArray();
|
||||||
|
|
||||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
||||||
if (selectedTask is null)
|
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
||||||
return;
|
foreach(TrangaTask task in selectedTasks)
|
||||||
|
taskManager.ExecuteTaskNow(task);
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
|
||||||
taskManager.ExecuteTaskNow(selectedTask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DeleteTask(TaskManager taskManager, Logger logger)
|
private static void DeleteTask(TaskManager taskManager, Logger logger)
|
||||||
@ -375,12 +444,10 @@ public static class Tranga_Cli
|
|||||||
logger.WriteLine("Tranga_CLI", "Menu: Delete Task");
|
logger.WriteLine("Tranga_CLI", "Menu: Delete Task");
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||||
|
|
||||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
||||||
if (selectedTask is null)
|
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
||||||
return;
|
foreach(TrangaTask task in selectedTasks)
|
||||||
|
taskManager.DeleteTask(task);
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
|
||||||
taskManager.DeleteTask(selectedTask.task, selectedTask.connectorName, selectedTask.publication);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TrangaTask.Task? SelectTaskType(Logger logger)
|
private static TrangaTask.Task? SelectTaskType(Logger logger)
|
||||||
@ -431,7 +498,26 @@ 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 Connector? SelectConnector(string folderPath, Connector[] connectors, Logger logger)
|
private static Chapter[] SelectChapters(Connector connector, Publication publication, Logger logger)
|
||||||
|
{
|
||||||
|
logger.WriteLine("Tranga_CLI", "Menu: Select Chapters");
|
||||||
|
Chapter[] availableChapters = connector.GetChapters(publication, "en");
|
||||||
|
int cIndex = 0;
|
||||||
|
Console.WriteLine("Chapters:");
|
||||||
|
foreach(Chapter chapter in availableChapters)
|
||||||
|
Console.WriteLine($"{cIndex++}: Vol.{chapter.volumeNumber} Ch.{chapter.chapterNumber} - {chapter.name}");
|
||||||
|
|
||||||
|
Console.WriteLine("Enter q to abort");
|
||||||
|
Console.WriteLine($"Select Chapter(s):");
|
||||||
|
|
||||||
|
string? selectedChapters = Console.ReadLine();
|
||||||
|
while(selectedChapters is null || selectedChapters.Length < 1)
|
||||||
|
selectedChapters = Console.ReadLine();
|
||||||
|
|
||||||
|
return connector.SearchChapters(publication, selectedChapters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Connector? SelectConnector(Connector[] connectors, Logger logger)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select Connector");
|
logger.WriteLine("Tranga_CLI", "Menu: Select Connector");
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
10
Tranga.sln
10
Tranga.sln
@ -6,7 +6,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tr
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{48F4E495-75BC-4402-8E03-DEC5B79D7E83}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -26,9 +26,9 @@ Global
|
|||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.Build.0 = Release|Any CPU
|
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gotify/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Manganato/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mangasee/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -20,16 +20,21 @@ public struct Chapter
|
|||||||
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1";
|
this.volumeNumber = volumeNumber;
|
||||||
this.chapterNumber = chapterNumber;
|
this.chapterNumber = chapterNumber;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
|
|
||||||
NumberFormatInfo nfi = new NumberFormatInfo()
|
NumberFormatInfo nfi = new NumberFormatInfo()
|
||||||
{
|
{
|
||||||
NumberDecimalSeparator = "."
|
NumberDecimalSeparator = "."
|
||||||
};
|
};
|
||||||
sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber) * Convert.ToDecimal(this.chapterNumber, nfi), 1)
|
sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber ?? "1") * Convert.ToDecimal(this.chapterNumber, nfi), 1)
|
||||||
.ToString(nfi);
|
.ToString(nfi);
|
||||||
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {sortNumber}";
|
|
||||||
|
string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
|
||||||
|
string volStr = this.volumeNumber is not null ? $"Vol.{this.volumeNumber} " : "";
|
||||||
|
string chNumberStr = this.chapterNumber is not null ? $"Ch.{chapterNumber} " : "";
|
||||||
|
string chNameStr = chapterName.Length > 0 ? $"- {chapterName}" : "";
|
||||||
|
chNameStr = chNameStr.Replace("Volume", "").Replace("volume", "");
|
||||||
|
this.fileName = $"{volStr}{chNumberStr}{chNameStr}";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,11 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Logging;
|
using Logging;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
using static System.IO.UnixFileMode;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
@ -14,9 +18,9 @@ public abstract class Connector
|
|||||||
internal string downloadLocation { get; } //Location of local files
|
internal string downloadLocation { get; } //Location of local files
|
||||||
protected DownloadClient downloadClient { get; init; }
|
protected DownloadClient downloadClient { get; init; }
|
||||||
|
|
||||||
protected Logger? logger;
|
protected readonly Logger? logger;
|
||||||
|
|
||||||
protected string imageCachePath;
|
private readonly string _imageCachePath;
|
||||||
|
|
||||||
protected Connector(string downloadLocation, string imageCachePath, Logger? logger)
|
protected Connector(string downloadLocation, string imageCachePath, Logger? logger)
|
||||||
{
|
{
|
||||||
@ -26,7 +30,9 @@ public abstract class Connector
|
|||||||
{
|
{
|
||||||
//RequestTypes for RateLimits
|
//RequestTypes for RateLimits
|
||||||
}, logger);
|
}, logger);
|
||||||
this.imageCachePath = imageCachePath;
|
this._imageCachePath = imageCachePath;
|
||||||
|
if (!Directory.Exists(imageCachePath))
|
||||||
|
Directory.CreateDirectory(this._imageCachePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
||||||
@ -47,36 +53,112 @@ public abstract class Connector
|
|||||||
/// <param name="language">Language of the Chapters</param>
|
/// <param name="language">Language of the Chapters</param>
|
||||||
/// <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))
|
||||||
|
{
|
||||||
|
string volumeNumber = singleResultRegex.Match(volume).Value;
|
||||||
|
return availableChapters.Where(aCh =>
|
||||||
|
aCh.volumeNumber is not null &&
|
||||||
|
aCh.volumeNumber.Equals(volumeNumber, 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))
|
||||||
|
{
|
||||||
|
string chapterNumber = singleResultRegex.Match(chapter).Value;
|
||||||
|
return availableChapters.Where(aCh =>
|
||||||
|
aCh.chapterNumber is not null &&
|
||||||
|
aCh.chapterNumber.Equals(chapterNumber, 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.
|
/// Should later call DownloadChapterImages to retrieve the individual Images of the Chapter and create .cbz archive.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="publication">Publication that contains Chapter</param>
|
/// <param name="publication">Publication that contains Chapter</param>
|
||||||
/// <param name="chapter">Chapter with Images to retrieve</param>
|
/// <param name="chapter">Chapter with Images to retrieve</param>
|
||||||
public abstract void DownloadChapter(Publication publication, Chapter chapter);
|
/// <param name="parentTask">Will be used for progress-tracking</param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <summary>
|
public abstract HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null);
|
||||||
/// Retrieves the Cover from the Website
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="publication">Publication to retrieve Cover for</param>
|
|
||||||
public abstract void DownloadCover(Publication publication);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the series-info to series.json in the Publication Folder
|
/// Copies the already downloaded cover from cache to downloadLocation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="publication">Publication to save series.json for</param>
|
/// <param name="publication">Publication to retrieve Cover for</param>
|
||||||
public void SaveSeriesInfo(Publication publication)
|
/// <param name="settings">TrangaSettings</param>
|
||||||
|
public void CopyCoverFromCacheToDownloadLocation(Publication publication, TrangaSettings settings)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Saving series.json for {publication.sortName}");
|
logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {publication.sortName} -> {publication.internalId}");
|
||||||
//Check if Publication already has a Folder and a series.json
|
//Check if Publication already has a Folder and cover
|
||||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
string publicationFolder = publication.CreatePublicationFolder(downloadLocation);
|
||||||
if(!Directory.Exists(publicationFolder))
|
DirectoryInfo dirInfo = new (publicationFolder);
|
||||||
Directory.CreateDirectory(publicationFolder);
|
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
||||||
|
{
|
||||||
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
logger?.WriteLine(this.GetType().ToString(), $"Cover exists {publication.sortName}");
|
||||||
if(!File.Exists(seriesInfoPath))
|
return;
|
||||||
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
}
|
||||||
|
|
||||||
|
string fileInCache = Path.Join(settings.coverImageCache, publication.coverFileNameInCache);
|
||||||
|
string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" );
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {fileInCache} -> {newFilePath}");
|
||||||
|
File.Copy(fileInCache, newFilePath, true);
|
||||||
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(newFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -84,16 +166,16 @@ public abstract class Connector
|
|||||||
/// See ComicInfo.xml
|
/// See ComicInfo.xml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>XML-string</returns>
|
/// <returns>XML-string</returns>
|
||||||
protected static string CreateComicInfo(Publication publication, Chapter chapter, Logger? logger)
|
protected static string GetComicInfoXmlString(Publication publication, Chapter chapter, Logger? logger)
|
||||||
{
|
{
|
||||||
logger?.WriteLine("Connector", $"Creating ComicInfo.Xml for {publication.sortName} Chapter {chapter.volumeNumber} {chapter.chapterNumber}");
|
logger?.WriteLine("Connector", $"Creating ComicInfo.Xml for {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
XElement comicInfo = new XElement("ComicInfo",
|
XElement comicInfo = new XElement("ComicInfo",
|
||||||
new XElement("Tags", string.Join(',',publication.tags)),
|
new XElement("Tags", string.Join(',',publication.tags)),
|
||||||
new XElement("LanguageISO", publication.originalLanguage),
|
new XElement("LanguageISO", publication.originalLanguage),
|
||||||
new XElement("Title", chapter.name),
|
new XElement("Title", chapter.name),
|
||||||
new XElement("Writer", publication.author),
|
new XElement("Writer", string.Join(',', publication.authors)),
|
||||||
new XElement("Volume", chapter.volumeNumber),
|
new XElement("Volume", chapter.volumeNumber),
|
||||||
new XElement("Number", chapter.chapterNumber) //TODO check if this is correct at some point
|
new XElement("Number", chapter.chapterNumber)
|
||||||
);
|
);
|
||||||
return comicInfo.ToString();
|
return comicInfo.ToString();
|
||||||
}
|
}
|
||||||
@ -102,18 +184,26 @@ public abstract class Connector
|
|||||||
/// Checks if a chapter-archive is already present
|
/// Checks if a chapter-archive is already present
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>true if chapter is present</returns>
|
/// <returns>true if chapter is present</returns>
|
||||||
public bool ChapterIsDownloaded(Publication publication, Chapter chapter)
|
public bool CheckChapterIsDownloaded(Publication publication, Chapter chapter)
|
||||||
{
|
{
|
||||||
return File.Exists(CreateFullFilepath(publication, chapter));
|
Regex legalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");
|
||||||
|
string oldFilePath = Path.Join(downloadLocation, publication.folderName, $"{string.Concat(legalCharacters.Matches(chapter.name ?? ""))} - V{chapter.volumeNumber}C{chapter.chapterNumber} - {chapter.sortNumber}.cbz");
|
||||||
|
string oldFilePath2 = Path.Join(downloadLocation, publication.folderName, $"{string.Concat(legalCharacters.Matches(chapter.name ?? ""))} - VC{chapter.chapterNumber} - {chapter.chapterNumber}.cbz");
|
||||||
|
string newFilePath = GetArchiveFilePath(publication, chapter);
|
||||||
|
if (File.Exists(oldFilePath))
|
||||||
|
File.Move(oldFilePath, newFilePath);
|
||||||
|
else if (File.Exists(oldFilePath2))
|
||||||
|
File.Move(oldFilePath2, newFilePath);
|
||||||
|
return File.Exists(newFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates full file path of chapter-archive
|
/// Creates full file path of chapter-archive
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Filepath</returns>
|
/// <returns>Filepath</returns>
|
||||||
protected string CreateFullFilepath(Publication publication, Chapter chapter)
|
protected string GetArchiveFilePath(Publication publication, Chapter chapter)
|
||||||
{
|
{
|
||||||
return Path.Join(downloadLocation, publication.folderName, $"{chapter.fileName}.cbz");
|
return Path.Join(downloadLocation, publication.folderName, $"{publication.folderName} - {chapter.fileName}.cbz");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -121,14 +211,17 @@ public abstract class Connector
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="imageUrl"></param>
|
/// <param name="imageUrl"></param>
|
||||||
/// <param name="fullPath"></param>
|
/// <param name="fullPath"></param>
|
||||||
/// <param name="downloadClient">DownloadClient of the connector</param>
|
/// <param name="requestType">RequestType for Rate-Limit</param>
|
||||||
/// <param name="requestType">Requesttype for ratelimit</param>
|
/// <param name="referrer">referrer used in html request header</param>
|
||||||
protected static void DownloadImage(string imageUrl, string fullPath, DownloadClient downloadClient, byte requestType)
|
private HttpStatusCode DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
|
||||||
{
|
{
|
||||||
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType);
|
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.result == Stream.Null)
|
||||||
|
return requestResult.statusCode;
|
||||||
byte[] buffer = new byte[requestResult.result.Length];
|
byte[] buffer = new byte[requestResult.result.Length];
|
||||||
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
||||||
File.WriteAllBytes(fullPath, buffer);
|
File.WriteAllBytes(fullPath, buffer);
|
||||||
|
return requestResult.statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -136,19 +229,23 @@ public abstract class Connector
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="imageUrls">List of URLs to download Images from</param>
|
/// <param name="imageUrls">List of URLs to download Images from</param>
|
||||||
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
||||||
/// <param name="downloadClient">DownloadClient of the connector</param>
|
/// <param name="parentTask">Used for progress tracking</param>
|
||||||
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
||||||
/// <param name="requestType">RequestType for RateLimits</param>
|
/// <param name="requestType">RequestType for RateLimits</param>
|
||||||
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, byte requestType, Logger? logger, string? comicInfoPath = null)
|
/// <param name="referrer">Used in http request header</param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
protected HttpStatusCode DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, DownloadChapterTask parentTask, string? comicInfoPath = null, string? referrer = null, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
logger?.WriteLine("Connector", "Downloading Images");
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
|
||||||
//Check if Publication Directory already exists
|
//Check if Publication Directory already exists
|
||||||
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
||||||
if (!Directory.Exists(directoryPath))
|
if (!Directory.Exists(directoryPath))
|
||||||
Directory.CreateDirectory(directoryPath);
|
Directory.CreateDirectory(directoryPath);
|
||||||
|
|
||||||
if (File.Exists(saveArchiveFilePath)) //Don't download twice.
|
if (File.Exists(saveArchiveFilePath)) //Don't download twice.
|
||||||
return;
|
return HttpStatusCode.OK;
|
||||||
|
|
||||||
//Create a temporary folder to store images
|
//Create a temporary folder to store images
|
||||||
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
||||||
@ -159,31 +256,61 @@ public abstract class Connector
|
|||||||
{
|
{
|
||||||
string[] split = imageUrl.Split('.');
|
string[] split = imageUrl.Split('.');
|
||||||
string extension = split[^1];
|
string extension = split[^1];
|
||||||
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient, requestType);
|
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {parentTask.publication.sortName} {parentTask.publication.internalId} Vol.{parentTask.chapter.volumeNumber} Ch.{parentTask.chapter.chapterNumber} {parentTask.progress:P2}");
|
||||||
|
HttpStatusCode status = DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
|
||||||
|
if ((int)status < 200 || (int)status >= 300)
|
||||||
|
return status;
|
||||||
|
parentTask.IncrementProgress(1.0 / imageUrls.Length);
|
||||||
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(comicInfoPath is not null)
|
if(comicInfoPath is not null)
|
||||||
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
||||||
|
|
||||||
logger?.WriteLine("Connector", "Creating archive");
|
logger?.WriteLine("Connector", $"Creating archive {saveArchiveFilePath}");
|
||||||
//ZIP-it and ship-it
|
//ZIP-it and ship-it
|
||||||
ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath);
|
ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath);
|
||||||
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(saveArchiveFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||||
Directory.Delete(tempFolder, true); //Cleanup
|
Directory.Delete(tempFolder, true); //Cleanup
|
||||||
|
return HttpStatusCode.OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string SaveCoverImageToCache(string url, byte requestType)
|
||||||
|
{
|
||||||
|
string[] split = url.Split('/');
|
||||||
|
string filename = split[^1];
|
||||||
|
string saveImagePath = Path.Join(_imageCachePath, filename);
|
||||||
|
|
||||||
|
if (File.Exists(saveImagePath))
|
||||||
|
return filename;
|
||||||
|
|
||||||
|
DownloadClient.RequestResult coverResult = downloadClient.MakeRequest(url, requestType);
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
coverResult.result.CopyTo(ms);
|
||||||
|
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Saving image to {saveImagePath}");
|
||||||
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class DownloadClient
|
protected class DownloadClient
|
||||||
{
|
{
|
||||||
private static readonly HttpClient Client = new();
|
private static readonly HttpClient Client = new()
|
||||||
|
{
|
||||||
|
Timeout = TimeSpan.FromSeconds(60)
|
||||||
|
};
|
||||||
|
|
||||||
private readonly Dictionary<byte, DateTime> _lastExecutedRateLimit;
|
private readonly Dictionary<byte, DateTime> _lastExecutedRateLimit;
|
||||||
private readonly Dictionary<byte, TimeSpan> _rateLimit;
|
private readonly Dictionary<byte, TimeSpan> _rateLimit;
|
||||||
private Logger? logger;
|
// ReSharper disable once InconsistentNaming
|
||||||
|
private readonly Logger? logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a httpClient
|
/// Creates a httpClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="delay">minimum delay between requests (to avoid spam)</param>
|
|
||||||
/// <param name="rateLimitRequestsPerMinute">Rate limits for requests. byte is RequestType, int maximum requests per minute for RequestType</param>
|
/// <param name="rateLimitRequestsPerMinute">Rate limits for requests. byte is RequestType, int maximum requests per minute for RequestType</param>
|
||||||
|
/// <param name="logger"></param>
|
||||||
public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, Logger? logger)
|
public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, Logger? logger)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@ -198,8 +325,9 @@ public abstract class Connector
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="requestType">For RateLimits: Same Endpoints use same type</param>
|
/// <param name="requestType">For RateLimits: Same Endpoints use same type</param>
|
||||||
|
/// <param name="referrer">Used in http request header</param>
|
||||||
/// <returns>RequestResult with StatusCode and Stream of received data</returns>
|
/// <returns>RequestResult with StatusCode and Stream of received data</returns>
|
||||||
public RequestResult MakeRequest(string url, byte requestType)
|
public RequestResult MakeRequest(string url, byte requestType, string? referrer = null)
|
||||||
{
|
{
|
||||||
if (_rateLimit.TryGetValue(requestType, out TimeSpan value))
|
if (_rateLimit.TryGetValue(requestType, out TimeSpan value))
|
||||||
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value));
|
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value));
|
||||||
@ -221,19 +349,24 @@ public abstract class Connector
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
||||||
|
if(referrer is not null)
|
||||||
|
requestMessage.Headers.Referrer = new Uri(referrer);
|
||||||
_lastExecutedRateLimit[requestType] = DateTime.Now;
|
_lastExecutedRateLimit[requestType] = DateTime.Now;
|
||||||
response = Client.Send(requestMessage);
|
response = Client.Send(requestMessage);
|
||||||
}
|
}
|
||||||
catch (HttpRequestException e)
|
catch (HttpRequestException e)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), e.Message);
|
logger?.WriteLine(this.GetType().ToString(), e.Message);
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Waiting {_rateLimit[requestType] * 2}... Retrying.");
|
||||||
Thread.Sleep(_rateLimit[requestType] * 2);
|
Thread.Sleep(_rateLimit[requestType] * 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}");
|
logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}");
|
||||||
return new RequestResult(response.StatusCode, resultString);
|
return new RequestResult(response.StatusCode, Stream.Null);
|
||||||
|
}
|
||||||
|
return new RequestResult(response.StatusCode, response.Content.ReadAsStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct RequestResult
|
public struct RequestResult
|
||||||
|
@ -3,6 +3,7 @@ using System.Net;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using Logging;
|
using Logging;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
|
||||||
namespace Tranga.Connectors;
|
namespace Tranga.Connectors;
|
||||||
public class MangaDex : Connector
|
public class MangaDex : Connector
|
||||||
@ -38,13 +39,14 @@ public class MangaDex : Connector
|
|||||||
int offset = 0; //"Page"
|
int offset = 0; //"Page"
|
||||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||||
HashSet<Publication> publications = new();
|
HashSet<Publication> publications = new();
|
||||||
|
int loadedPublicationData = 0;
|
||||||
while (offset < total) //As long as we haven't requested all "Pages"
|
while (offset < total) //As long as we haven't requested all "Pages"
|
||||||
{
|
{
|
||||||
//Request next Page
|
//Request next Page
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest(
|
downloadClient.MakeRequest(
|
||||||
$"https://api.mangadex.org/manga?limit={limit}&title={publicationTitle}&offset={offset}", (byte)RequestType.Manga);
|
$"https://api.mangadex.org/manga?limit={limit}&title={publicationTitle}&offset={offset}", (byte)RequestType.Manga);
|
||||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
break;
|
break;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
|
||||||
@ -58,6 +60,7 @@ public class MangaDex : Connector
|
|||||||
//Loop each Manga and extract information from JSON
|
//Loop each Manga and extract information from JSON
|
||||||
foreach (JsonNode? mangeNode in mangaInResult)
|
foreach (JsonNode? mangeNode in mangaInResult)
|
||||||
{
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Getting publication data. {++loadedPublicationData}/{total}");
|
||||||
JsonObject manga = (JsonObject)mangeNode!;
|
JsonObject manga = (JsonObject)mangeNode!;
|
||||||
JsonObject attributes = manga["attributes"]!.AsObject();
|
JsonObject attributes = manga["attributes"]!.AsObject();
|
||||||
|
|
||||||
@ -90,19 +93,21 @@ public class MangaDex : Connector
|
|||||||
}
|
}
|
||||||
|
|
||||||
string? posterId = null;
|
string? posterId = null;
|
||||||
string? authorId = null;
|
HashSet<string> authorIds = new();
|
||||||
if (manga.ContainsKey("relationships") && manga["relationships"] is not null)
|
if (manga.ContainsKey("relationships") && manga["relationships"] is not null)
|
||||||
{
|
{
|
||||||
JsonArray relationships = manga["relationships"]!.AsArray();
|
JsonArray relationships = manga["relationships"]!.AsArray();
|
||||||
posterId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "cover_art")!["id"]!.GetValue<string>();
|
posterId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "cover_art")!["id"]!.GetValue<string>();
|
||||||
authorId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "author")!["id"]!.GetValue<string>();
|
foreach (JsonNode? node in relationships.Where(relationship =>
|
||||||
|
relationship!["type"]!.GetValue<string>() == "author"))
|
||||||
|
authorIds.Add(node!["id"]!.GetValue<string>());
|
||||||
}
|
}
|
||||||
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
||||||
string? coverCacheName = null;
|
string? coverCacheName = null;
|
||||||
if (coverUrl is not null)
|
if (coverUrl is not null)
|
||||||
coverCacheName = SaveImage(coverUrl);
|
coverCacheName = SaveCoverImageToCache(coverUrl, (byte)RequestType.AtHomeServer);
|
||||||
|
|
||||||
string? author = GetAuthor(authorId);
|
List<string> authors = GetAuthors(authorIds);
|
||||||
|
|
||||||
Dictionary<string, string> linksDict = new();
|
Dictionary<string, string> linksDict = new();
|
||||||
if (attributes.ContainsKey("links") && attributes["links"] is not null)
|
if (attributes.ContainsKey("links") && attributes["links"] is not null)
|
||||||
@ -126,7 +131,7 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
Publication pub = new (
|
Publication pub = new (
|
||||||
title,
|
title,
|
||||||
author,
|
authors,
|
||||||
description,
|
description,
|
||||||
altTitlesDict,
|
altTitlesDict,
|
||||||
tags.ToArray(),
|
tags.ToArray(),
|
||||||
@ -142,12 +147,13 @@ public class MangaDex : Connector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Done getting publications (title={publicationTitle})");
|
||||||
return publications.ToArray();
|
return publications.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters {publication.sortName} (language={language})");
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})");
|
||||||
const int limit = 100; //How many values we want returned at once
|
const int limit = 100; //How many values we want returned at once
|
||||||
int offset = 0; //"Page"
|
int offset = 0; //"Page"
|
||||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||||
@ -159,7 +165,7 @@ public class MangaDex : Connector
|
|||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest(
|
downloadClient.MakeRequest(
|
||||||
$"https://api.mangadex.org/manga/{publication.publicationId}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}", (byte)RequestType.Feed);
|
$"https://api.mangadex.org/manga/{publication.publicationId}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}", (byte)RequestType.Feed);
|
||||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
break;
|
break;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
|
||||||
@ -197,20 +203,23 @@ public class MangaDex : Connector
|
|||||||
{
|
{
|
||||||
NumberDecimalSeparator = "."
|
NumberDecimalSeparator = "."
|
||||||
};
|
};
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}");
|
||||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DownloadChapter(Publication publication, Chapter chapter)
|
public override HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Download Chapter {publication.sortName} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
//Request URLs for Chapter-Images
|
//Request URLs for Chapter-Images
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", (byte)RequestType.AtHomeServer);
|
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", (byte)RequestType.AtHomeServer);
|
||||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return;
|
return requestResult.statusCode;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
return;
|
return HttpStatusCode.NoContent;
|
||||||
|
|
||||||
string baseUrl = result["baseUrl"]!.GetValue<string>();
|
string baseUrl = result["baseUrl"]!.GetValue<string>();
|
||||||
string hash = result["chapter"]!["hash"]!.GetValue<string>();
|
string hash = result["chapter"]!["hash"]!.GetValue<string>();
|
||||||
@ -221,24 +230,25 @@ public class MangaDex : Connector
|
|||||||
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
||||||
|
|
||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter, logger));
|
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
|
||||||
|
|
||||||
//Download Chapter-Images
|
//Download Chapter-Images
|
||||||
DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, (byte)RequestType.AtHomeServer, logger, comicInfoPath);
|
return DownloadChapterImages(imageUrls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)RequestType.AtHomeServer, parentTask, comicInfoPath, cancellationToken:cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string? GetCoverUrl(string publicationId, string? posterId)
|
private string? GetCoverUrl(string publicationId, string? posterId)
|
||||||
{
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Getting CoverUrl for {publicationId}");
|
||||||
if (posterId is null)
|
if (posterId is null)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"No posterId");
|
logger?.WriteLine(this.GetType().ToString(), $"No posterId, aborting");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Request information where to download Cover
|
//Request information where to download Cover
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.CoverUrl);
|
downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.CoverUrl);
|
||||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return null;
|
return null;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
@ -247,70 +257,27 @@ public class MangaDex : Connector
|
|||||||
string fileName = result["data"]!["attributes"]!["fileName"]!.GetValue<string>();
|
string fileName = result["data"]!["attributes"]!["fileName"]!.GetValue<string>();
|
||||||
|
|
||||||
string coverUrl = $"https://uploads.mangadex.org/covers/{publicationId}/{fileName}";
|
string coverUrl = $"https://uploads.mangadex.org/covers/{publicationId}/{fileName}";
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Got Cover-Url for {publicationId} -> {coverUrl}");
|
||||||
return coverUrl;
|
return coverUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string? GetAuthor(string? authorId)
|
private List<string> GetAuthors(IEnumerable<string> authorIds)
|
||||||
{
|
{
|
||||||
if (authorId is null)
|
List<string> ret = new();
|
||||||
return null;
|
foreach (string authorId in authorIds)
|
||||||
|
|
||||||
DownloadClient.RequestResult requestResult =
|
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/author/{authorId}", (byte)RequestType.Author);
|
|
||||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
|
||||||
return null;
|
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
|
||||||
if (result is null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
string author = result["data"]!["attributes"]!["name"]!.GetValue<string>();
|
|
||||||
return author;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void DownloadCover(Publication publication)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Download cover {publication.sortName}");
|
|
||||||
//Check if Publication already has a Folder and cover
|
|
||||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
|
||||||
if(!Directory.Exists(publicationFolder))
|
|
||||||
Directory.CreateDirectory(publicationFolder);
|
|
||||||
DirectoryInfo dirInfo = new (publicationFolder);
|
|
||||||
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover.")))
|
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Cover exists {publication.sortName}");
|
DownloadClient.RequestResult requestResult =
|
||||||
return;
|
downloadClient.MakeRequest($"https://api.mangadex.org/author/{authorId}", (byte)RequestType.Author);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return ret;
|
||||||
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
if (result is null)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
string authorName = result["data"]!["attributes"]!["name"]!.GetValue<string>();
|
||||||
|
ret.Add(authorName);
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {authorName}");
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
if (publication.posterUrl is null || publication.posterUrl!.Contains("http"))
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"No Poster-URL in publication");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get file-extension (jpg, png)
|
|
||||||
string[] split = publication.posterUrl.Split('.');
|
|
||||||
string extension = split[^1];
|
|
||||||
|
|
||||||
string outFolderPath = Path.Join(downloadLocation, publication.folderName);
|
|
||||||
Directory.CreateDirectory(outFolderPath);
|
|
||||||
|
|
||||||
//Download cover-Image
|
|
||||||
DownloadImage(publication.posterUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this.downloadClient, (byte)RequestType.AtHomeServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string SaveImage(string url)
|
|
||||||
{
|
|
||||||
string[] split = url.Split('/');
|
|
||||||
string filename = split[^1];
|
|
||||||
string saveImagePath = Path.Join(imageCachePath, filename);
|
|
||||||
|
|
||||||
if (File.Exists(saveImagePath))
|
|
||||||
return filename;
|
|
||||||
|
|
||||||
DownloadClient.RequestResult coverResult = downloadClient.MakeRequest(url, (byte)RequestType.AtHomeServer);
|
|
||||||
using MemoryStream ms = new();
|
|
||||||
coverResult.result.CopyTo(ms);
|
|
||||||
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
|
||||||
return filename;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
206
Tranga/Connectors/Manganato.cs
Normal file
206
Tranga/Connectors/Manganato.cs
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Logging;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
|
||||||
|
namespace Tranga.Connectors;
|
||||||
|
|
||||||
|
public class Manganato : Connector
|
||||||
|
{
|
||||||
|
public override string name { get; }
|
||||||
|
|
||||||
|
public Manganato(string downloadLocation, string imageCachePath, Logger? logger) : base(downloadLocation, imageCachePath, logger)
|
||||||
|
{
|
||||||
|
this.name = "Manganato";
|
||||||
|
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||||
|
{
|
||||||
|
{(byte)1, 60}
|
||||||
|
}, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Publication[] GetPublications(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
|
||||||
|
string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '_');
|
||||||
|
string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}";
|
||||||
|
DownloadClient.RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return Array.Empty<Publication>();
|
||||||
|
|
||||||
|
return ParsePublicationsFromHtml(requestResult.result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Publication[] ParsePublicationsFromHtml(Stream html)
|
||||||
|
{
|
||||||
|
StreamReader reader = new (html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
IEnumerable<HtmlNode> searchResults = document.DocumentNode.Descendants("div").Where(n => n.HasClass("search-story-item"));
|
||||||
|
List<string> urls = new();
|
||||||
|
foreach (HtmlNode mangaResult in searchResults)
|
||||||
|
{
|
||||||
|
urls.Add(mangaResult.Descendants("a").First(n => n.HasClass("item-title")).GetAttributes()
|
||||||
|
.First(a => a.Name == "href").Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<Publication> ret = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
DownloadClient.RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(url, (byte)1);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return Array.Empty<Publication>();
|
||||||
|
|
||||||
|
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Publication ParseSinglePublicationFromHtml(Stream html, string publicationId)
|
||||||
|
{
|
||||||
|
StreamReader reader = new (html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
string status = "";
|
||||||
|
Dictionary<string, string> altTitles = new();
|
||||||
|
Dictionary<string, string>? links = null;
|
||||||
|
HashSet<string> tags = new();
|
||||||
|
string[] authors = Array.Empty<string>();
|
||||||
|
string originalLanguage = "";
|
||||||
|
|
||||||
|
HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("story-info-right"));
|
||||||
|
|
||||||
|
string sortName = infoNode.Descendants("h1").First().InnerText;
|
||||||
|
|
||||||
|
HtmlNode infoTable = infoNode.Descendants().First(d => d.Name == "table");
|
||||||
|
|
||||||
|
foreach (HtmlNode row in infoTable.Descendants("tr"))
|
||||||
|
{
|
||||||
|
string key = row.SelectNodes("td").First().InnerText.ToLower();
|
||||||
|
string value = row.SelectNodes("td").Last().InnerText;
|
||||||
|
string keySanitized = string.Concat(Regex.Matches(key, "[a-z]"));
|
||||||
|
|
||||||
|
switch (keySanitized)
|
||||||
|
{
|
||||||
|
case "alternative":
|
||||||
|
string[] alts = value.Split(" ; ");
|
||||||
|
for(int i = 0; i < alts.Length; i++)
|
||||||
|
altTitles.Add(i.ToString(), alts[i]);
|
||||||
|
break;
|
||||||
|
case "authors":
|
||||||
|
authors = value.Split('-');
|
||||||
|
break;
|
||||||
|
case "status":
|
||||||
|
status = value;
|
||||||
|
break;
|
||||||
|
case "genres":
|
||||||
|
string[] genres = value.Split(" - ");
|
||||||
|
tags = genres.ToHashSet();
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string posterUrl = document.DocumentNode.Descendants("span").First(s => s.HasClass("info-image")).Descendants("img").First()
|
||||||
|
.GetAttributes().First(a => a.Name == "src").Value;
|
||||||
|
|
||||||
|
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1);
|
||||||
|
|
||||||
|
string description = document.DocumentNode.Descendants("div").First(d => d.HasClass("panel-story-info-description"))
|
||||||
|
.InnerText.Replace("Description :", "");
|
||||||
|
while (description.StartsWith('\n'))
|
||||||
|
description = description.Substring(1);
|
||||||
|
|
||||||
|
string yearString = document.DocumentNode.Descendants("li").Last(li => li.HasClass("a-h")).Descendants("span")
|
||||||
|
.First(s => s.HasClass("chapter-time")).InnerText;
|
||||||
|
int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000;
|
||||||
|
|
||||||
|
return new Publication(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||||
|
year, originalLanguage, status, publicationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})");
|
||||||
|
string requestUrl = $"https://chapmanganato.com/{publication.publicationId}";
|
||||||
|
DownloadClient.RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
NumberFormatInfo chapterNumberFormatInfo = new()
|
||||||
|
{
|
||||||
|
NumberDecimalSeparator = "."
|
||||||
|
};
|
||||||
|
List<Chapter> chapters = ParseChaptersFromHtml(requestResult.result);
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}");
|
||||||
|
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Chapter> ParseChaptersFromHtml(Stream html)
|
||||||
|
{
|
||||||
|
StreamReader reader = new (html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
List<Chapter> ret = new();
|
||||||
|
|
||||||
|
HtmlNode chapterList = document.DocumentNode.Descendants("ul").First(l => l.HasClass("row-content-chapter"));
|
||||||
|
|
||||||
|
foreach (HtmlNode chapterInfo in chapterList.Descendants("li"))
|
||||||
|
{
|
||||||
|
string fullString = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")).InnerText;
|
||||||
|
|
||||||
|
string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null;
|
||||||
|
string? chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Replace('-','.');
|
||||||
|
string chapterName = string.Concat(fullString.Split(':')[1..]);
|
||||||
|
string url = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name"))
|
||||||
|
.GetAttributeValue("href", "");
|
||||||
|
ret.Add(new Chapter(chapterName, volumeNumber, chapterNumber, url));
|
||||||
|
}
|
||||||
|
ret.Reverse();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
||||||
|
{
|
||||||
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
|
string requestUrl = chapter.url;
|
||||||
|
DownloadClient.RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return requestResult.statusCode;
|
||||||
|
|
||||||
|
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.result);
|
||||||
|
|
||||||
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
|
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
|
||||||
|
|
||||||
|
return DownloadChapterImages(imageUrls, GetArchiveFilePath(publication, chapter), (byte)1, parentTask, comicInfoPath, "https://chapmanganato.com/", cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] ParseImageUrlsFromHtml(Stream html)
|
||||||
|
{
|
||||||
|
StreamReader reader = new (html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
List<string> ret = new();
|
||||||
|
|
||||||
|
HtmlNode imageContainer =
|
||||||
|
document.DocumentNode.Descendants("div").First(i => i.HasClass("container-chapter-reader"));
|
||||||
|
foreach(HtmlNode imageNode in imageContainer.Descendants("img"))
|
||||||
|
ret.Add(imageNode.GetAttributeValue("src", ""));
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
}
|
245
Tranga/Connectors/Mangasee.cs
Normal file
245
Tranga/Connectors/Mangasee.cs
Normal file
@ -0,0 +1,245 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using PuppeteerSharp;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
|
||||||
|
namespace Tranga.Connectors;
|
||||||
|
|
||||||
|
public class Mangasee : Connector
|
||||||
|
{
|
||||||
|
public override string name { get; }
|
||||||
|
private IBrowser? _browser = null;
|
||||||
|
private const string ChromiumVersion = "1154303";
|
||||||
|
|
||||||
|
public Mangasee(string downloadLocation, string imageCachePath, Logger? logger) : base(downloadLocation,
|
||||||
|
imageCachePath, logger)
|
||||||
|
{
|
||||||
|
this.name = "Mangasee";
|
||||||
|
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||||
|
{
|
||||||
|
{ (byte)1, 60 }
|
||||||
|
}, logger);
|
||||||
|
|
||||||
|
Task d = new Task(DownloadBrowser);
|
||||||
|
d.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void DownloadBrowser()
|
||||||
|
{
|
||||||
|
BrowserFetcher browserFetcher = new BrowserFetcher();
|
||||||
|
foreach(string rev in browserFetcher.LocalRevisions().Where(rev => rev != ChromiumVersion))
|
||||||
|
browserFetcher.Remove(rev);
|
||||||
|
if (!browserFetcher.LocalRevisions().Contains(ChromiumVersion))
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), "Downloading headless browser");
|
||||||
|
DateTime last = DateTime.Now.Subtract(TimeSpan.FromSeconds(5));
|
||||||
|
browserFetcher.DownloadProgressChanged += (sender, args) =>
|
||||||
|
{
|
||||||
|
double currentBytes = Convert.ToDouble(args.BytesReceived) / Convert.ToDouble(args.TotalBytesToReceive);
|
||||||
|
if (args.TotalBytesToReceive == args.BytesReceived)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), "Browser downloaded.");
|
||||||
|
}
|
||||||
|
else if (DateTime.Now > last.AddSeconds(5))
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Browser download progress: {currentBytes:P2}");
|
||||||
|
last = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
if (!browserFetcher.CanDownloadAsync(ChromiumVersion).Result)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Can't download browser version {ChromiumVersion}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await browserFetcher.DownloadAsync(ChromiumVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), "Starting browser.");
|
||||||
|
this._browser = await Puppeteer.LaunchAsync(new LaunchOptions
|
||||||
|
{
|
||||||
|
Headless = true,
|
||||||
|
ExecutablePath = browserFetcher.GetExecutablePath(ChromiumVersion),
|
||||||
|
Args = new [] {
|
||||||
|
"--disable-gpu",
|
||||||
|
"--disable-dev-shm-usage",
|
||||||
|
"--disable-setuid-sandbox",
|
||||||
|
"--no-sandbox"}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Publication[] GetPublications(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
|
||||||
|
string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '+');
|
||||||
|
string requestUrl = $"https://mangasee123.com/_search.php";
|
||||||
|
DownloadClient.RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return Array.Empty<Publication>();
|
||||||
|
|
||||||
|
return ParsePublicationsFromHtml(requestResult.result, publicationTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Publication[] ParsePublicationsFromHtml(Stream html, string publicationTitle)
|
||||||
|
{
|
||||||
|
string jsonString = new StreamReader(html).ReadToEnd();
|
||||||
|
List<SearchResultItem> result = JsonConvert.DeserializeObject<List<SearchResultItem>>(jsonString)!;
|
||||||
|
Dictionary<SearchResultItem, int> queryFiltered = new();
|
||||||
|
foreach (SearchResultItem resultItem in result)
|
||||||
|
{
|
||||||
|
foreach (string term in publicationTitle.Split(' '))
|
||||||
|
if (resultItem.i.Contains(term, StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
if (!queryFiltered.TryAdd(resultItem, 0))
|
||||||
|
queryFiltered[resultItem]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
queryFiltered = queryFiltered.Where(item => item.Value >= publicationTitle.Split(' ').Length - 1)
|
||||||
|
.ToDictionary(item => item.Key, item => item.Value);
|
||||||
|
|
||||||
|
HashSet<Publication> ret = new();
|
||||||
|
List<SearchResultItem> orderedFiltered =
|
||||||
|
queryFiltered.OrderBy(item => item.Value).ToDictionary(item => item.Key, item => item.Value).Keys.ToList();
|
||||||
|
|
||||||
|
foreach (SearchResultItem orderedItem in orderedFiltered)
|
||||||
|
{
|
||||||
|
DownloadClient.RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", (byte)1);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return Array.Empty<Publication>();
|
||||||
|
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, orderedItem.s, orderedItem.i, orderedItem.a));
|
||||||
|
}
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Publication ParseSinglePublicationFromHtml(Stream html, string sortName, string publicationId, string[] a)
|
||||||
|
{
|
||||||
|
StreamReader reader = new (html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
|
||||||
|
string originalLanguage = "", status = "";
|
||||||
|
Dictionary<string, string> altTitles = new(), links = new();
|
||||||
|
HashSet<string> tags = new();
|
||||||
|
|
||||||
|
HtmlNode posterNode =
|
||||||
|
document.DocumentNode.Descendants("img").First(img => img.HasClass("img-fluid") && img.HasClass("bottom-5"));
|
||||||
|
string posterUrl = posterNode.GetAttributeValue("src", "");
|
||||||
|
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1);
|
||||||
|
|
||||||
|
HtmlNode attributes = document.DocumentNode.Descendants("div")
|
||||||
|
.First(div => div.HasClass("col-md-9") && div.HasClass("col-sm-8") && div.HasClass("top-5"))
|
||||||
|
.Descendants("ul").First();
|
||||||
|
|
||||||
|
HtmlNode[] authorsNodes = attributes.Descendants("li")
|
||||||
|
.First(node => node.InnerText.Contains("author(s):", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
.Descendants("a").ToArray();
|
||||||
|
List<string> authors = new();
|
||||||
|
foreach(HtmlNode authorNode in authorsNodes)
|
||||||
|
authors.Add(authorNode.InnerText);
|
||||||
|
|
||||||
|
HtmlNode[] genreNodes = attributes.Descendants("li")
|
||||||
|
.First(node => node.InnerText.Contains("genre(s):", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
.Descendants("a").ToArray();
|
||||||
|
foreach (HtmlNode genreNode in genreNodes)
|
||||||
|
tags.Add(genreNode.InnerText);
|
||||||
|
|
||||||
|
HtmlNode yearNode = attributes.Descendants("li")
|
||||||
|
.First(node => node.InnerText.Contains("released:", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
.Descendants("a").First();
|
||||||
|
int year = Convert.ToInt32(yearNode.InnerText);
|
||||||
|
|
||||||
|
HtmlNode[] statusNodes = attributes.Descendants("li")
|
||||||
|
.First(node => node.InnerText.Contains("status:", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
.Descendants("a").ToArray();
|
||||||
|
foreach(HtmlNode statusNode in statusNodes)
|
||||||
|
if (statusNode.InnerText.Contains("publish", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
status = statusNode.InnerText.Split(' ')[0];
|
||||||
|
|
||||||
|
HtmlNode descriptionNode = attributes.Descendants("li").First(node => node.InnerText.Contains("description:", StringComparison.CurrentCultureIgnoreCase)).Descendants("div").First();
|
||||||
|
string description = descriptionNode.InnerText;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
foreach(string at in a)
|
||||||
|
altTitles.Add((i++).ToString(), at);
|
||||||
|
|
||||||
|
return new Publication(sortName, authors, description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||||
|
year, originalLanguage, status, publicationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once ClassNeverInstantiated.Local Will be instantiated during deserialization
|
||||||
|
private class SearchResultItem
|
||||||
|
{
|
||||||
|
#pragma warning disable CS8618 //Will always be set
|
||||||
|
public string i { get; set; }
|
||||||
|
public string s { get; set; }
|
||||||
|
public string[] a { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||||
|
{
|
||||||
|
XDocument doc = XDocument.Load($"https://mangasee123.com/rss/{publication.publicationId}.xml");
|
||||||
|
XElement[] chapterItems = doc.Descendants("item").ToArray();
|
||||||
|
List<Chapter> ret = new();
|
||||||
|
foreach (XElement chapter in chapterItems)
|
||||||
|
{
|
||||||
|
string? volumeNumber = "1";
|
||||||
|
string chapterName = chapter.Descendants("title").First().Value;
|
||||||
|
string chapterNumber = Regex.Matches(chapterName, "[0-9]+")[^1].ToString();
|
||||||
|
|
||||||
|
string url = chapter.Descendants("link").First().Value;
|
||||||
|
url = url.Replace(Regex.Matches(url,"(-page-[0-9])")[0].ToString(),"");
|
||||||
|
ret.Add(new Chapter("", volumeNumber, chapterNumber, url));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
NumberFormatInfo chapterNumberFormatInfo = new()
|
||||||
|
{
|
||||||
|
NumberDecimalSeparator = "."
|
||||||
|
};
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}");
|
||||||
|
return ret.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
||||||
|
{
|
||||||
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
while (this._browser is null && !(cancellationToken?.IsCancellationRequested??false))
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), "Waiting for headless browser to download...");
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
if (cancellationToken?.IsCancellationRequested??false)
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
|
IPage page = _browser!.NewPageAsync().Result;
|
||||||
|
IResponse response = page.GoToAsync(chapter.url).Result;
|
||||||
|
if (response.Ok)
|
||||||
|
{
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(page.GetContentAsync().Result);
|
||||||
|
|
||||||
|
HtmlNode gallery = document.DocumentNode.Descendants("div").First(div => div.HasClass("ImageGallery"));
|
||||||
|
HtmlNode[] images = gallery.Descendants("img").Where(img => img.HasClass("img-fluid")).ToArray();
|
||||||
|
List<string> urls = new();
|
||||||
|
foreach(HtmlNode galleryImage in images)
|
||||||
|
urls.Add(galleryImage.GetAttributeValue("src", ""));
|
||||||
|
|
||||||
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
|
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
|
||||||
|
|
||||||
|
return DownloadChapterImages(urls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)1, parentTask, comicInfoPath, cancellationToken:cancellationToken);
|
||||||
|
}
|
||||||
|
return response.Status;
|
||||||
|
}
|
||||||
|
}
|
148
Tranga/Komga.cs
148
Tranga/Komga.cs
@ -1,148 +0,0 @@
|
|||||||
using System.Net;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Text.Json.Nodes;
|
|
||||||
using Logging;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
||||||
|
|
||||||
namespace Tranga;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides connectivity to Komga-API
|
|
||||||
/// Can fetch and update libraries
|
|
||||||
/// </summary>
|
|
||||||
public class Komga
|
|
||||||
{
|
|
||||||
public string baseUrl { get; }
|
|
||||||
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
|
||||||
|
|
||||||
private Logger? logger;
|
|
||||||
|
|
||||||
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
|
||||||
/// <param name="username">Komga Username</param>
|
|
||||||
/// <param name="password">Komga password, will be base64 encoded. yea</param>
|
|
||||||
public Komga(string baseUrl, string username, string password, Logger? logger)
|
|
||||||
{
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
this.auth = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}"));
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
|
||||||
/// <param name="auth">Base64 string of username and password (username):(password)</param>
|
|
||||||
[JsonConstructor]
|
|
||||||
public Komga(string baseUrl, string auth, Logger? logger)
|
|
||||||
{
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
this.auth = auth;
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Fetches all libraries available to the user
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Array of KomgaLibraries</returns>
|
|
||||||
public KomgaLibrary[] GetLibraries()
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
|
||||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", auth);
|
|
||||||
if (data == Stream.Null)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
|
||||||
return Array.Empty<KomgaLibrary>();
|
|
||||||
}
|
|
||||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
|
||||||
if (result is null)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
|
||||||
return Array.Empty<KomgaLibrary>();
|
|
||||||
}
|
|
||||||
|
|
||||||
HashSet<KomgaLibrary> ret = new();
|
|
||||||
|
|
||||||
foreach (JsonNode? jsonNode in result)
|
|
||||||
{
|
|
||||||
var jObject = (JsonObject?)jsonNode;
|
|
||||||
string libraryId = jObject!["id"]!.GetValue<string>();
|
|
||||||
string libraryName = jObject!["name"]!.GetValue<string>();
|
|
||||||
ret.Add(new KomgaLibrary(libraryId, libraryName));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates library with given id
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="libraryId">Id of the Komga-Library</param>
|
|
||||||
/// <returns>true if successful</returns>
|
|
||||||
public bool UpdateLibrary(string libraryId)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Updating Libraries");
|
|
||||||
return NetClient.MakePost($"{baseUrl}/api/v1/libraries/{libraryId}/scan", auth);
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct KomgaLibrary
|
|
||||||
{
|
|
||||||
public string id { get; }
|
|
||||||
public string name { get; }
|
|
||||||
|
|
||||||
public KomgaLibrary(string id, string name)
|
|
||||||
{
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class NetClient
|
|
||||||
{
|
|
||||||
public static Stream MakeRequest(string url, string auth)
|
|
||||||
{
|
|
||||||
HttpClientHandler clientHandler = new ();
|
|
||||||
clientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => true;
|
|
||||||
HttpClient client = new(clientHandler);
|
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
|
|
||||||
|
|
||||||
HttpRequestMessage requestMessage = new ()
|
|
||||||
{
|
|
||||||
Method = HttpMethod.Get,
|
|
||||||
RequestUri = new Uri(url)
|
|
||||||
};
|
|
||||||
HttpResponseMessage response = client.Send(requestMessage);
|
|
||||||
Stream ret;
|
|
||||||
if (response.StatusCode is HttpStatusCode.Unauthorized)
|
|
||||||
{
|
|
||||||
ret = MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, auth);
|
|
||||||
}else
|
|
||||||
return response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool MakePost(string url, string auth)
|
|
||||||
{
|
|
||||||
HttpClientHandler clientHandler = new HttpClientHandler();
|
|
||||||
clientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => true;
|
|
||||||
HttpClient client = new(clientHandler)
|
|
||||||
{
|
|
||||||
DefaultRequestHeaders =
|
|
||||||
{
|
|
||||||
{ "Accept", "application/json" },
|
|
||||||
{ "Authorization", new AuthenticationHeaderValue("Basic", auth).ToString() }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
HttpRequestMessage requestMessage = new HttpRequestMessage
|
|
||||||
{
|
|
||||||
Method = HttpMethod.Post,
|
|
||||||
RequestUri = new Uri(url)
|
|
||||||
};
|
|
||||||
HttpResponseMessage response = client.Send(requestMessage);
|
|
||||||
bool ret;
|
|
||||||
if (response.StatusCode is HttpStatusCode.Unauthorized)
|
|
||||||
{
|
|
||||||
ret = MakePost(response.RequestMessage!.RequestUri!.AbsoluteUri, auth);
|
|
||||||
}else
|
|
||||||
return response.IsSuccessStatusCode;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
120
Tranga/LibraryManager.cs
Normal file
120
Tranga/LibraryManager.cs
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Tranga.LibraryManagers;
|
||||||
|
|
||||||
|
namespace Tranga;
|
||||||
|
|
||||||
|
public abstract class LibraryManager
|
||||||
|
{
|
||||||
|
public enum LibraryType : byte
|
||||||
|
{
|
||||||
|
Komga = 0,
|
||||||
|
Kavita = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
public LibraryType libraryType { get; }
|
||||||
|
public string baseUrl { get; }
|
||||||
|
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
||||||
|
protected Logger? logger;
|
||||||
|
|
||||||
|
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
||||||
|
/// <param name="auth">Base64 string of username and password (username):(password)</param>
|
||||||
|
/// <param name="logger"></param>
|
||||||
|
/// <param name="libraryType"></param>
|
||||||
|
protected LibraryManager(string baseUrl, string auth, Logger? logger, LibraryType libraryType)
|
||||||
|
{
|
||||||
|
this.baseUrl = baseUrl;
|
||||||
|
this.auth = auth;
|
||||||
|
this.logger = logger;
|
||||||
|
this.libraryType = libraryType;
|
||||||
|
}
|
||||||
|
public abstract void UpdateLibrary();
|
||||||
|
|
||||||
|
public void AddLogger(Logger newLogger)
|
||||||
|
{
|
||||||
|
this.logger = newLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class NetClient
|
||||||
|
{
|
||||||
|
public static Stream MakeRequest(string url, string authScheme, string auth, Logger? logger)
|
||||||
|
{
|
||||||
|
HttpClient client = new();
|
||||||
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, auth);
|
||||||
|
|
||||||
|
HttpRequestMessage requestMessage = new ()
|
||||||
|
{
|
||||||
|
Method = HttpMethod.Get,
|
||||||
|
RequestUri = new Uri(url)
|
||||||
|
};
|
||||||
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
|
logger?.WriteLine("LibraryManager", $"GET {url} -> {(int)response.StatusCode}: {response.ReasonPhrase}");
|
||||||
|
|
||||||
|
if(response.StatusCode is HttpStatusCode.Unauthorized && response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||||
|
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth, logger);
|
||||||
|
else if (response.IsSuccessStatusCode)
|
||||||
|
return response.Content.ReadAsStream();
|
||||||
|
else
|
||||||
|
return Stream.Null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool MakePost(string url, string authScheme, string auth, Logger? logger)
|
||||||
|
{
|
||||||
|
HttpClient client = new()
|
||||||
|
{
|
||||||
|
DefaultRequestHeaders =
|
||||||
|
{
|
||||||
|
{ "Accept", "application/json" },
|
||||||
|
{ "Authorization", new AuthenticationHeaderValue(authScheme, auth).ToString() }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
HttpRequestMessage requestMessage = new ()
|
||||||
|
{
|
||||||
|
Method = HttpMethod.Post,
|
||||||
|
RequestUri = new Uri(url)
|
||||||
|
};
|
||||||
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
|
logger?.WriteLine("LibraryManager", $"POST {url} -> {(int)response.StatusCode}: {response.ReasonPhrase}");
|
||||||
|
|
||||||
|
if(response.StatusCode is HttpStatusCode.Unauthorized && response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||||
|
return MakePost(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth, logger);
|
||||||
|
else if (response.IsSuccessStatusCode)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LibraryManagerJsonConverter : JsonConverter
|
||||||
|
{
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return (objectType == typeof(LibraryManager));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
JObject jo = JObject.Load(reader);
|
||||||
|
if (jo["libraryType"]!.Value<Int64>() == (Int64)LibraryType.Komga)
|
||||||
|
return jo.ToObject<Komga>(serializer)!;
|
||||||
|
|
||||||
|
if (jo["libraryType"]!.Value<Int64>() == (Int64)LibraryType.Kavita)
|
||||||
|
return jo.ToObject<Kavita>(serializer)!;
|
||||||
|
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanWrite => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Don't call this
|
||||||
|
/// </summary>
|
||||||
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new Exception("Dont call this");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
94
Tranga/LibraryManagers/Kavita.cs
Normal file
94
Tranga/LibraryManagers/Kavita.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||||
|
|
||||||
|
namespace Tranga.LibraryManagers;
|
||||||
|
|
||||||
|
public class Kavita : LibraryManager
|
||||||
|
{
|
||||||
|
|
||||||
|
public Kavita(string baseUrl, string username, string password, Logger? logger) : base(baseUrl, GetToken(baseUrl, username, password), logger, LibraryType.Kavita)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonConstructor]
|
||||||
|
public Kavita(string baseUrl, string auth, Logger? logger) : base(baseUrl, auth, logger, LibraryType.Kavita)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetToken(string baseUrl, string username, string password)
|
||||||
|
{
|
||||||
|
HttpClient client = new()
|
||||||
|
{
|
||||||
|
DefaultRequestHeaders =
|
||||||
|
{
|
||||||
|
{ "Accept", "application/json" }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
HttpRequestMessage requestMessage = new ()
|
||||||
|
{
|
||||||
|
Method = HttpMethod.Post,
|
||||||
|
RequestUri = new Uri($"{baseUrl}/api/Account/login"),
|
||||||
|
Content = new StringContent($"{{\"username\":\"{username}\",\"password\":\"{password}\"}}", System.Text.Encoding.UTF8, "application/json")
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
|
||||||
|
if (result is not null)
|
||||||
|
return result!["token"]!.GetValue<string>();
|
||||||
|
else return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateLibrary()
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Updating Libraries");
|
||||||
|
foreach (KavitaLibrary lib in GetLibraries())
|
||||||
|
NetClient.MakePost($"{baseUrl}/api/Library/scan?libraryId={lib.id}", "Bearer", auth, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches all libraries available to the user
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Array of KavitaLibrary</returns>
|
||||||
|
private IEnumerable<KavitaLibrary> GetLibraries()
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
||||||
|
Stream data = NetClient.MakeRequest($"{baseUrl}/api/Library", "Bearer", auth, logger);
|
||||||
|
if (data == Stream.Null)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
||||||
|
return Array.Empty<KavitaLibrary>();
|
||||||
|
}
|
||||||
|
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||||
|
if (result is null)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
||||||
|
return Array.Empty<KavitaLibrary>();
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<KavitaLibrary> ret = new();
|
||||||
|
|
||||||
|
foreach (JsonNode? jsonNode in result)
|
||||||
|
{
|
||||||
|
var jObject = (JsonObject?)jsonNode;
|
||||||
|
int libraryId = jObject!["id"]!.GetValue<int>();
|
||||||
|
string libraryName = jObject!["name"]!.GetValue<string>();
|
||||||
|
ret.Add(new KavitaLibrary(libraryId, libraryName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct KavitaLibrary
|
||||||
|
{
|
||||||
|
public int id { get; }
|
||||||
|
public string name { get; }
|
||||||
|
|
||||||
|
public KavitaLibrary(int id, string name)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
75
Tranga/LibraryManagers/Komga.cs
Normal file
75
Tranga/LibraryManagers/Komga.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||||
|
|
||||||
|
namespace Tranga.LibraryManagers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides connectivity to Komga-API
|
||||||
|
/// Can fetch and update libraries
|
||||||
|
/// </summary>
|
||||||
|
public class Komga : LibraryManager
|
||||||
|
{
|
||||||
|
public Komga(string baseUrl, string username, string password, Logger? logger)
|
||||||
|
: base(baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")), logger, LibraryType.Komga)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonConstructor]
|
||||||
|
public Komga(string baseUrl, string auth, Logger? logger) : base(baseUrl, auth, logger, LibraryType.Komga)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateLibrary()
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Updating Libraries");
|
||||||
|
foreach (KomgaLibrary lib in GetLibraries())
|
||||||
|
NetClient.MakePost($"{baseUrl}/api/v1/libraries/{lib.id}/scan", "Basic", auth, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches all libraries available to the user
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Array of KomgaLibraries</returns>
|
||||||
|
private IEnumerable<KomgaLibrary> GetLibraries()
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
||||||
|
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", "Basic", auth, logger);
|
||||||
|
if (data == Stream.Null)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
||||||
|
return Array.Empty<KomgaLibrary>();
|
||||||
|
}
|
||||||
|
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||||
|
if (result is null)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
||||||
|
return Array.Empty<KomgaLibrary>();
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<KomgaLibrary> ret = new();
|
||||||
|
|
||||||
|
foreach (JsonNode? jsonNode in result)
|
||||||
|
{
|
||||||
|
var jObject = (JsonObject?)jsonNode;
|
||||||
|
string libraryId = jObject!["id"]!.GetValue<string>();
|
||||||
|
string libraryName = jObject!["name"]!.GetValue<string>();
|
||||||
|
ret.Add(new KomgaLibrary(libraryId, libraryName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct KomgaLibrary
|
||||||
|
{
|
||||||
|
public string id { get; }
|
||||||
|
public string name { get; }
|
||||||
|
|
||||||
|
public KomgaLibrary(string id, string name)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
Tranga/NotificationManager.cs
Normal file
52
Tranga/NotificationManager.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Tranga.NotificationManagers;
|
||||||
|
|
||||||
|
namespace Tranga;
|
||||||
|
|
||||||
|
public abstract class NotificationManager
|
||||||
|
{
|
||||||
|
protected readonly Logger? logger;
|
||||||
|
public NotificationManagerType notificationManagerType;
|
||||||
|
|
||||||
|
protected NotificationManager(NotificationManagerType notificationManagerType, Logger? logger = null)
|
||||||
|
{
|
||||||
|
this.notificationManagerType = notificationManagerType;
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum NotificationManagerType : byte { Gotify = 0, LunaSea = 1 }
|
||||||
|
|
||||||
|
public abstract void SendNotification(string title, string notificationText);
|
||||||
|
|
||||||
|
public class NotificationManagerJsonConverter : JsonConverter
|
||||||
|
{
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return (objectType == typeof(NotificationManager));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue,
|
||||||
|
JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
JObject jo = JObject.Load(reader);
|
||||||
|
if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationManagerType.Gotify)
|
||||||
|
return jo.ToObject<Gotify>(serializer)!;
|
||||||
|
else if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationManagerType.LunaSea)
|
||||||
|
return jo.ToObject<LunaSea>(serializer)!;
|
||||||
|
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanWrite => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Don't call this
|
||||||
|
/// </summary>
|
||||||
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new Exception("Dont call this");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
Tranga/NotificationManagers/Gotify.cs
Normal file
49
Tranga/NotificationManagers/Gotify.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System.Text;
|
||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Tranga.NotificationManagers;
|
||||||
|
|
||||||
|
public class Gotify : NotificationManager
|
||||||
|
{
|
||||||
|
public string endpoint { get; }
|
||||||
|
public string appToken { get; }
|
||||||
|
private readonly HttpClient _client = new();
|
||||||
|
|
||||||
|
public Gotify(string endpoint, string appToken, Logger? logger = null) : base(NotificationManagerType.Gotify, logger)
|
||||||
|
{
|
||||||
|
this.endpoint = endpoint;
|
||||||
|
this.appToken = appToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SendNotification(string title, string notificationText)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Sending notification: {title} - {notificationText}");
|
||||||
|
MessageData message = new(title, notificationText);
|
||||||
|
HttpRequestMessage request = new(HttpMethod.Post, $"{endpoint}/message");
|
||||||
|
request.Headers.Add("X-Gotify-Key", this.appToken);
|
||||||
|
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
||||||
|
HttpResponseMessage response = _client.Send(request);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
StreamReader sr = new (response.Content.ReadAsStream());
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"{response.StatusCode}: {sr.ReadToEnd()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MessageData
|
||||||
|
{
|
||||||
|
public string message { get; }
|
||||||
|
public long priority { get; }
|
||||||
|
public string title { get; }
|
||||||
|
public Dictionary<string, object> extras { get; }
|
||||||
|
|
||||||
|
public MessageData(string title, string message)
|
||||||
|
{
|
||||||
|
this.title = title;
|
||||||
|
this.message = message;
|
||||||
|
this.extras = new();
|
||||||
|
this.priority = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
Tranga/NotificationManagers/LunaSea.cs
Normal file
43
Tranga/NotificationManagers/LunaSea.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System.Text;
|
||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Tranga.NotificationManagers;
|
||||||
|
|
||||||
|
public class LunaSea : NotificationManager
|
||||||
|
{
|
||||||
|
public string webhook { get; }
|
||||||
|
private readonly HttpClient _client = new();
|
||||||
|
public LunaSea(string webhook, Logger? logger = null) : base(NotificationManagerType.LunaSea, logger)
|
||||||
|
{
|
||||||
|
this.webhook = webhook;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SendNotification(string title, string notificationText)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Sending notification: {title} - {notificationText}");
|
||||||
|
MessageData message = new(title, notificationText);
|
||||||
|
HttpRequestMessage request = new(HttpMethod.Post, webhook);
|
||||||
|
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
||||||
|
HttpResponseMessage response = _client.Send(request);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
StreamReader sr = new (response.Content.ReadAsStream());
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"{response.StatusCode}: {sr.ReadToEnd()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MessageData
|
||||||
|
{
|
||||||
|
public string title { get; }
|
||||||
|
public string body { get; }
|
||||||
|
public string image { get; }
|
||||||
|
|
||||||
|
public MessageData(string title, string body)
|
||||||
|
{
|
||||||
|
this.title = title;
|
||||||
|
this.body = body;
|
||||||
|
this.image = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
using System.Text;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using static System.IO.UnixFileMode;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
@ -10,7 +12,7 @@ namespace Tranga;
|
|||||||
public readonly struct Publication
|
public readonly struct Publication
|
||||||
{
|
{
|
||||||
public string sortName { get; }
|
public string sortName { get; }
|
||||||
public string? author { get; }
|
public List<string> authors { get; }
|
||||||
public Dictionary<string,string> altTitles { get; }
|
public Dictionary<string,string> altTitles { get; }
|
||||||
// ReSharper disable trice MemberCanBePrivate.Global, trust
|
// ReSharper disable trice MemberCanBePrivate.Global, trust
|
||||||
public string? description { get; }
|
public string? description { get; }
|
||||||
@ -25,12 +27,24 @@ public readonly struct Publication
|
|||||||
public string publicationId { get; }
|
public string publicationId { get; }
|
||||||
public string internalId { get; }
|
public string internalId { get; }
|
||||||
|
|
||||||
private static readonly Regex LegalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");
|
private static readonly Regex LegalCharacters = new Regex(@"[A-Z]*[a-z]*[0-9]* *\.*-*,*'*\'*\)*\(*~*!*");
|
||||||
|
|
||||||
public Publication(string sortName, string? author, string? description, Dictionary<string,string> altTitles, string[] tags, string? posterUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string publicationId)
|
[JsonConstructor] //Legacy
|
||||||
|
public Publication(string sortName, string? author, string? description, Dictionary<string, string> altTitles,
|
||||||
|
string[] tags, string? posterUrl, string? coverFileNameInCache, Dictionary<string, string>? links, int? year,
|
||||||
|
string? originalLanguage, string status, string publicationId)
|
||||||
|
{
|
||||||
|
List<string> pAuthors = new();
|
||||||
|
if(author is not null)
|
||||||
|
pAuthors.Add(author);
|
||||||
|
this = new Publication(sortName, pAuthors, description, altTitles, tags, posterUrl,
|
||||||
|
coverFileNameInCache, links, year, originalLanguage, status, publicationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Publication(string sortName, List<string> authors, string? description, Dictionary<string,string> altTitles, string[] tags, string? posterUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string publicationId)
|
||||||
{
|
{
|
||||||
this.sortName = sortName;
|
this.sortName = sortName;
|
||||||
this.author = author;
|
this.authors = authors;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.altTitles = altTitles;
|
this.altTitles = altTitles;
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
@ -42,9 +56,31 @@ public readonly struct Publication
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
this.publicationId = publicationId;
|
this.publicationId = publicationId;
|
||||||
this.folderName = string.Concat(LegalCharacters.Matches(sortName));
|
this.folderName = string.Concat(LegalCharacters.Matches(sortName));
|
||||||
|
while (this.folderName.EndsWith('.'))
|
||||||
|
this.folderName = this.folderName.Substring(0, this.folderName.Length - 1);
|
||||||
string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter));
|
string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter));
|
||||||
this.internalId = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{onlyLowerLetters}{this.year}"));
|
this.internalId = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{onlyLowerLetters}{this.year}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string CreatePublicationFolder(string downloadDirectory)
|
||||||
|
{
|
||||||
|
string publicationFolder = Path.Join(downloadDirectory, this.folderName);
|
||||||
|
if(!Directory.Exists(publicationFolder))
|
||||||
|
Directory.CreateDirectory(publicationFolder);
|
||||||
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(publicationFolder, GroupRead | GroupWrite | GroupExecute | OtherRead | OtherWrite | OtherExecute | UserRead | UserWrite | UserExecute);
|
||||||
|
return publicationFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveSeriesInfoJson(string downloadDirectory)
|
||||||
|
{
|
||||||
|
string publicationFolder = CreatePublicationFolder(downloadDirectory);
|
||||||
|
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
||||||
|
if(!File.Exists(seriesInfoPath))
|
||||||
|
File.WriteAllText(seriesInfoPath,this.GetSeriesInfoJson());
|
||||||
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(seriesInfoPath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||||
|
}
|
||||||
|
|
||||||
/// <returns>Serialized JSON String for series.json</returns>
|
/// <returns>Serialized JSON String for series.json</returns>
|
||||||
public string GetSeriesInfoJson()
|
public string GetSeriesInfoJson()
|
||||||
@ -83,9 +119,9 @@ public readonly struct Publication
|
|||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
if(status == "ongoing" || status == "hiatus")
|
if(status.ToLower() == "ongoing" || status.ToLower() == "hiatus")
|
||||||
this.status = "Continuing";
|
this.status = "Continuing";
|
||||||
else if (status == "completed" || status == "cancelled")
|
else if (status.ToLower() == "completed" || status.ToLower() == "cancelled" || status.ToLower() == "discontinued")
|
||||||
this.status = "Ended";
|
this.status = "Ended";
|
||||||
else
|
else
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
@ -1,129 +0,0 @@
|
|||||||
using Logging;
|
|
||||||
|
|
||||||
namespace Tranga;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Executes TrangaTasks
|
|
||||||
/// Based on the TrangaTask.Task a method is called.
|
|
||||||
/// The chapterCollection is updated with new Publications/Chapters.
|
|
||||||
/// </summary>
|
|
||||||
public static class TaskExecutor
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Executes TrangaTask.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="taskManager">Parent</param>
|
|
||||||
/// <param name="trangaTask">Task to execute</param>
|
|
||||||
/// <param name="chapterCollection">Current chapterCollection to update</param>
|
|
||||||
/// <param name="logger"></param>
|
|
||||||
/// <exception cref="ArgumentException">Is thrown when there is no Connector available with the name of the TrangaTask.connectorName</exception>
|
|
||||||
public static void Execute(TaskManager taskManager, TrangaTask trangaTask, Logger? logger)
|
|
||||||
{
|
|
||||||
//Only execute task if it is not already being executed.
|
|
||||||
if (trangaTask.state == TrangaTask.ExecutionState.Running)
|
|
||||||
{
|
|
||||||
logger?.WriteLine("TaskExecutor", $"Task already running {trangaTask}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
trangaTask.state = TrangaTask.ExecutionState.Running;
|
|
||||||
logger?.WriteLine("TaskExecutor", $"Starting Task {trangaTask}");
|
|
||||||
|
|
||||||
//Connector is not needed for all tasks
|
|
||||||
Connector? connector = null;
|
|
||||||
if (trangaTask.task != TrangaTask.Task.UpdateKomgaLibrary)
|
|
||||||
connector = taskManager.GetConnector(trangaTask.connectorName!);
|
|
||||||
|
|
||||||
//Call appropriate Method based on TrangaTask.Task
|
|
||||||
switch (trangaTask.task)
|
|
||||||
{
|
|
||||||
case TrangaTask.Task.DownloadNewChapters:
|
|
||||||
DownloadNewChapters(connector!, (Publication)trangaTask.publication!, trangaTask.language, ref taskManager._chapterCollection);
|
|
||||||
break;
|
|
||||||
case TrangaTask.Task.UpdateChapters:
|
|
||||||
UpdateChapters(connector!, (Publication)trangaTask.publication!, trangaTask.language, ref taskManager._chapterCollection);
|
|
||||||
break;
|
|
||||||
case TrangaTask.Task.UpdatePublications:
|
|
||||||
UpdatePublications(connector!, ref taskManager._chapterCollection);
|
|
||||||
break;
|
|
||||||
case TrangaTask.Task.UpdateKomgaLibrary:
|
|
||||||
UpdateKomgaLibrary(taskManager);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger?.WriteLine("TaskExecutor", $"Task finished! {trangaTask}");
|
|
||||||
trangaTask.lastExecuted = DateTime.Now;
|
|
||||||
trangaTask.state = TrangaTask.ExecutionState.Waiting;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates all Komga-Libraries
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="taskManager">Parent</param>
|
|
||||||
private static void UpdateKomgaLibrary(TaskManager taskManager)
|
|
||||||
{
|
|
||||||
if (taskManager.komga is null)
|
|
||||||
return;
|
|
||||||
Komga komga = taskManager.komga;
|
|
||||||
|
|
||||||
Komga.KomgaLibrary[] allLibraries = komga.GetLibraries();
|
|
||||||
foreach (Komga.KomgaLibrary lib in allLibraries)
|
|
||||||
komga.UpdateLibrary(lib.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates the available Publications from a Connector (all of them)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="connector">Connector to receive Publications from</param>
|
|
||||||
/// <param name="chapterCollection"></param>
|
|
||||||
private static void UpdatePublications(Connector connector, ref Dictionary<Publication, List<Chapter>> chapterCollection)
|
|
||||||
{
|
|
||||||
Publication[] publications = connector.GetPublications();
|
|
||||||
foreach (Publication publication in publications)
|
|
||||||
chapterCollection.TryAdd(publication, new List<Chapter>());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks for new Chapters and Downloads new ones.
|
|
||||||
/// If no Chapters had been downloaded previously, download also cover and create series.json
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="connector">Connector to use</param>
|
|
||||||
/// <param name="publication">Publication to check</param>
|
|
||||||
/// <param name="language">Language to receive chapters for</param>
|
|
||||||
/// <param name="chapterCollection"></param>
|
|
||||||
private static void DownloadNewChapters(Connector connector, Publication publication, string language, ref Dictionary<Publication, List<Chapter>> chapterCollection)
|
|
||||||
{
|
|
||||||
//Check if Publication already has a Folder
|
|
||||||
string publicationFolder = Path.Join(connector.downloadLocation, publication.folderName);
|
|
||||||
if(!Directory.Exists(publicationFolder))
|
|
||||||
Directory.CreateDirectory(publicationFolder);
|
|
||||||
List<Chapter> newChapters = UpdateChapters(connector, publication, language, ref chapterCollection);
|
|
||||||
|
|
||||||
connector.DownloadCover(publication);
|
|
||||||
|
|
||||||
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
|
||||||
if(!File.Exists(seriesInfoPath))
|
|
||||||
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
|
||||||
|
|
||||||
foreach(Chapter newChapter in newChapters)
|
|
||||||
connector.DownloadChapter(publication, newChapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates the available Chapters of a Publication
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="connector">Connector to use</param>
|
|
||||||
/// <param name="publication">Publication to check</param>
|
|
||||||
/// <param name="language">Language to receive chapters for</param>
|
|
||||||
/// <param name="chapterCollection"></param>
|
|
||||||
/// <returns>List of Chapters that were previously not in collection</returns>
|
|
||||||
private static List<Chapter> UpdateChapters(Connector connector, Publication publication, string language, ref Dictionary<Publication, List<Chapter>> chapterCollection)
|
|
||||||
{
|
|
||||||
List<Chapter> newChaptersList = new();
|
|
||||||
chapterCollection.TryAdd(publication, newChaptersList); //To ensure publication is actually in collection
|
|
||||||
|
|
||||||
Chapter[] newChapters = connector.GetChapters(publication, language);
|
|
||||||
newChaptersList = newChapters.Where(nChapter => !connector.ChapterIsDownloaded(publication, nChapter)).ToList();
|
|
||||||
|
|
||||||
return newChaptersList;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
using Logging;
|
using Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Tranga.Connectors;
|
using Tranga.Connectors;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
@ -10,63 +11,28 @@ namespace Tranga;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TaskManager
|
public class TaskManager
|
||||||
{
|
{
|
||||||
public Dictionary<Publication, List<Chapter>> _chapterCollection = new();
|
public Dictionary<Publication, List<Chapter>> chapterCollection = new();
|
||||||
private HashSet<TrangaTask> _allTasks;
|
private HashSet<TrangaTask> _allTasks = new();
|
||||||
private bool _continueRunning = true;
|
private bool _continueRunning = true;
|
||||||
private readonly Connector[] _connectors;
|
private readonly Connector[] _connectors;
|
||||||
private readonly Dictionary<Connector, List<TrangaTask>> _taskQueue = new();
|
|
||||||
public TrangaSettings settings { get; }
|
public TrangaSettings settings { get; }
|
||||||
private Logger? logger { get; }
|
private Logger? logger { get; }
|
||||||
public Komga? komga => settings.komga;
|
|
||||||
|
|
||||||
/// <param name="downloadFolderPath">Local path to save data (Manga) to</param>
|
private readonly Dictionary<DownloadChapterTask, CancellationTokenSource> _runningDownloadChapterTasks = new();
|
||||||
/// <param name="workingDirectory">Path to the working directory</param>
|
|
||||||
/// <param name="imageCachePath">Path to the cover-image cache</param>
|
|
||||||
/// <param name="komgaBaseUrl">The Url of the Komga-instance that you want to update</param>
|
|
||||||
/// <param name="komgaUsername">The Komga username</param>
|
|
||||||
/// <param name="komgaPassword">The Komga password</param>
|
|
||||||
/// <param name="logger"></param>
|
|
||||||
public TaskManager(string downloadFolderPath, string workingDirectory, string imageCachePath, string? komgaBaseUrl = null, string? komgaUsername = null, string? komgaPassword = null, Logger? logger = null)
|
|
||||||
{
|
|
||||||
this.logger = logger;
|
|
||||||
_allTasks = new HashSet<TrangaTask>();
|
|
||||||
|
|
||||||
Komga? newKomga = null;
|
|
||||||
if (komgaBaseUrl != null && komgaUsername != null && komgaPassword != null)
|
|
||||||
newKomga = new Komga(komgaBaseUrl, komgaUsername, komgaPassword, logger);
|
|
||||||
|
|
||||||
this.settings = new TrangaSettings(downloadFolderPath, workingDirectory, newKomga);
|
|
||||||
ExportData();
|
|
||||||
|
|
||||||
this._connectors = new Connector[]{ new MangaDex(downloadFolderPath, imageCachePath, logger) };
|
|
||||||
foreach(Connector cConnector in this._connectors)
|
|
||||||
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
|
||||||
|
|
||||||
Thread taskChecker = new(TaskCheckerThread);
|
|
||||||
taskChecker.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateSettings(string? downloadLocation, string? komgaUrl, string? komgaAuth)
|
|
||||||
{
|
|
||||||
Komga? komga = null;
|
|
||||||
if (komgaUrl is not null && komgaAuth is not null)
|
|
||||||
komga = new Komga(komgaUrl, komgaAuth, null);
|
|
||||||
settings.downloadLocation = downloadLocation ?? settings.downloadLocation;
|
|
||||||
settings.komga = komga ?? komga;
|
|
||||||
ExportData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TaskManager(TrangaSettings settings, Logger? logger = null)
|
public TaskManager(TrangaSettings settings, Logger? logger = null)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation, settings.coverImageCache, logger) };
|
this._connectors = new Connector[]
|
||||||
foreach(Connector cConnector in this._connectors)
|
{
|
||||||
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
new MangaDex(settings.downloadLocation, settings.coverImageCache, logger),
|
||||||
_allTasks = new HashSet<TrangaTask>();
|
new Manganato(settings.downloadLocation, settings.coverImageCache, logger),
|
||||||
|
new Mangasee(settings.downloadLocation, settings.coverImageCache, logger)
|
||||||
|
};
|
||||||
|
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
ImportData();
|
ImportData();
|
||||||
ExportData();
|
ExportDataAndSettings();
|
||||||
Thread taskChecker = new(TaskCheckerThread);
|
Thread taskChecker = new(TaskCheckerThread);
|
||||||
taskChecker.Start();
|
taskChecker.Start();
|
||||||
}
|
}
|
||||||
@ -78,31 +44,64 @@ public class TaskManager
|
|||||||
private void TaskCheckerThread()
|
private void TaskCheckerThread()
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), "Starting TaskCheckerThread.");
|
logger?.WriteLine(this.GetType().ToString(), "Starting TaskCheckerThread.");
|
||||||
|
int waitingTasksCount = _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting);
|
||||||
while (_continueRunning)
|
while (_continueRunning)
|
||||||
{
|
{
|
||||||
//Check if previous tasks have finished and execute new tasks
|
foreach (TrangaTask waitingButExecute in _allTasks.Where(taskQuery =>
|
||||||
foreach (KeyValuePair<Connector, List<TrangaTask>> connectorTaskQueue in _taskQueue)
|
taskQuery.nextExecution < DateTime.Now &&
|
||||||
|
taskQuery.state is TrangaTask.ExecutionState.Waiting))
|
||||||
{
|
{
|
||||||
if(connectorTaskQueue.Value.RemoveAll(task => task.state == TrangaTask.ExecutionState.Waiting) > 0)
|
waitingButExecute.state = TrangaTask.ExecutionState.Enqueued;
|
||||||
ExportData();
|
|
||||||
|
|
||||||
if (connectorTaskQueue.Value.Count > 0 && connectorTaskQueue.Value.All(task => task.state is TrangaTask.ExecutionState.Enqueued))
|
|
||||||
ExecuteTaskNow(connectorTaskQueue.Value.First());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if task should be executed
|
foreach (TrangaTask enqueuedTask in _allTasks.Where(enqueuedTask => enqueuedTask.state is TrangaTask.ExecutionState.Enqueued))
|
||||||
//Depending on type execute immediately or enqueue
|
|
||||||
foreach (TrangaTask task in _allTasks.Where(aTask => aTask.ShouldExecute()))
|
|
||||||
{
|
{
|
||||||
task.state = TrangaTask.ExecutionState.Enqueued;
|
switch (enqueuedTask.task)
|
||||||
if(task.connectorName is null)
|
|
||||||
ExecuteTaskNow(task);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Task due: {task}");
|
case TrangaTask.Task.DownloadChapter:
|
||||||
_taskQueue[GetConnector(task.connectorName!)].Add(task);
|
case TrangaTask.Task.MonitorPublication:
|
||||||
|
if (!_allTasks.Any(taskQuery =>
|
||||||
|
{
|
||||||
|
if (taskQuery.state is not TrangaTask.ExecutionState.Running) return false;
|
||||||
|
switch (taskQuery)
|
||||||
|
{
|
||||||
|
case DownloadChapterTask dct when enqueuedTask is DownloadChapterTask eDct && dct.connectorName == eDct.connectorName:
|
||||||
|
case MonitorPublicationTask mpt when enqueuedTask is MonitorPublicationTask eMpt && mpt.connectorName == eMpt.connectorName:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
ExecuteTaskNow(enqueuedTask);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TrangaTask.Task.UpdateLibraries:
|
||||||
|
ExecuteTaskNow(enqueuedTask);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TrangaTask[] failedDownloadChapterTasks = _allTasks.Where(taskQuery =>
|
||||||
|
taskQuery.state is TrangaTask.ExecutionState.Failed && taskQuery is DownloadChapterTask).ToArray();
|
||||||
|
foreach (TrangaTask failedDownloadChapterTask in failedDownloadChapterTasks)
|
||||||
|
{
|
||||||
|
DeleteTask(failedDownloadChapterTask);
|
||||||
|
TrangaTask newTask = failedDownloadChapterTask.Clone();
|
||||||
|
failedDownloadChapterTask.parentTask?.AddChildTask(newTask);
|
||||||
|
AddTask(newTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
TrangaTask[] successfulDownloadChapterTasks = _allTasks.Where(taskQuery =>
|
||||||
|
taskQuery.state is TrangaTask.ExecutionState.Success && taskQuery is DownloadChapterTask).ToArray();
|
||||||
|
foreach(TrangaTask successfulDownloadChapterTask in successfulDownloadChapterTasks)
|
||||||
|
{
|
||||||
|
DeleteTask(successfulDownloadChapterTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(waitingTasksCount != _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting))
|
||||||
|
ExportDataAndSettings();
|
||||||
|
waitingTasksCount = _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting);
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,105 +112,112 @@ public class TaskManager
|
|||||||
/// <param name="task">Task to execute</param>
|
/// <param name="task">Task to execute</param>
|
||||||
public void ExecuteTaskNow(TrangaTask task)
|
public void ExecuteTaskNow(TrangaTask task)
|
||||||
{
|
{
|
||||||
if (!this._allTasks.Contains(task))
|
task.state = TrangaTask.ExecutionState.Running;
|
||||||
return;
|
CancellationTokenSource cToken = new ();
|
||||||
|
Task t = new(() =>
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Forcing Execution: {task}");
|
|
||||||
Task t = new Task(() =>
|
|
||||||
{
|
{
|
||||||
TaskExecutor.Execute(this, task, logger);
|
task.Execute(this, this.logger, cToken.Token);
|
||||||
});
|
}, cToken.Token);
|
||||||
|
if(task is DownloadChapterTask chapterTask)
|
||||||
|
_runningDownloadChapterTasks.Add(chapterTask, cToken);
|
||||||
t.Start();
|
t.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public void AddTask(TrangaTask newTask)
|
||||||
/// Creates and adds a new Task to the task-Collection
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="task">TrangaTask.Task to later execute</param>
|
|
||||||
/// <param name="connectorName">Name of the connector to use</param>
|
|
||||||
/// <param name="publication">Publication to execute Task on, can be null in case of unrelated Task</param>
|
|
||||||
/// <param name="reoccurrence">Time-Interval between Executions</param>
|
|
||||||
/// <param name="language">language, should Task require parameter. Can be empty</param>
|
|
||||||
/// <exception cref="ArgumentException">Is thrown when connectorName is not a available Connector</exception>
|
|
||||||
public TrangaTask AddTask(TrangaTask.Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence,
|
|
||||||
string language = "")
|
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}");
|
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {newTask}");
|
||||||
|
|
||||||
TrangaTask newTask;
|
switch (newTask.task)
|
||||||
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
|
||||||
{
|
{
|
||||||
newTask = new TrangaTask(task, null, null, reoccurrence, language);
|
case TrangaTask.Task.UpdateLibraries:
|
||||||
|
//Only one UpdateKomgaLibrary Task
|
||||||
//Check if same task already exists
|
logger?.WriteLine(this.GetType().ToString(), $"Replacing old {newTask.task}-Task.");
|
||||||
// ReSharper disable once SimplifyLinqExpressionUseAll readabilty
|
_allTasks.RemoveWhere(trangaTask => trangaTask.task is TrangaTask.Task.UpdateLibraries);
|
||||||
if (!_allTasks.Any(trangaTask => trangaTask.task == task))
|
|
||||||
{
|
|
||||||
_allTasks.Add(newTask);
|
_allTasks.Add(newTask);
|
||||||
}
|
break;
|
||||||
|
case TrangaTask.Task.MonitorPublication:
|
||||||
|
if (!_allTasks.Any(mTask => mTask is MonitorPublicationTask mpt && newTask is MonitorPublicationTask nMpt &&
|
||||||
|
mpt.publication.internalId == nMpt.publication.internalId &&
|
||||||
|
mpt.connectorName == nMpt.connectorName))
|
||||||
|
_allTasks.Add(newTask);
|
||||||
|
else
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask}");
|
||||||
|
break;
|
||||||
|
case TrangaTask.Task.DownloadChapter:
|
||||||
|
if (!_allTasks.Any(mTask => mTask is DownloadChapterTask dct && newTask is DownloadChapterTask nDct &&
|
||||||
|
dct.publication.internalId == nDct.publication.internalId &&
|
||||||
|
dct.connectorName == nDct.connectorName &&
|
||||||
|
dct.chapter.sortNumber == nDct.chapter.sortNumber))
|
||||||
|
_allTasks.Add(newTask);
|
||||||
|
else
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask}");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
ExportDataAndSettings();
|
||||||
{
|
|
||||||
if(connectorName is null)
|
|
||||||
throw new ArgumentException($"connectorName can not be null for task {task}");
|
|
||||||
|
|
||||||
//Get appropriate Connector from available Connectors for TrangaTask
|
|
||||||
Connector? connector = _connectors.FirstOrDefault(c => c.name == connectorName);
|
|
||||||
if (connector is null)
|
|
||||||
throw new ArgumentException($"Connector {connectorName} is not a known connector.");
|
|
||||||
|
|
||||||
newTask = new TrangaTask(task, connector.name, publication, reoccurrence, language);
|
|
||||||
|
|
||||||
//Check if same task already exists
|
|
||||||
if (!_allTasks.Any(trangaTask => trangaTask.task == task && trangaTask.connectorName == connector.name &&
|
|
||||||
trangaTask.publication?.internalId == publication?.internalId))
|
|
||||||
{
|
|
||||||
if(task != TrangaTask.Task.UpdatePublications)
|
|
||||||
_chapterCollection.TryAdd((Publication)publication!, new List<Chapter>());
|
|
||||||
_allTasks.Add(newTask);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Publication already exists {publication?.internalId}");
|
|
||||||
}
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask.ToString()}");
|
|
||||||
ExportData();
|
|
||||||
|
|
||||||
return newTask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public void DeleteTask(TrangaTask removeTask)
|
||||||
/// Removes Task from task-collection
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="task">TrangaTask.Task type</param>
|
|
||||||
/// <param name="connectorName">Name of Connector that was used</param>
|
|
||||||
/// <param name="publication">Publication that was used</param>
|
|
||||||
public void DeleteTask(TrangaTask.Task task, string? connectorName, Publication? publication)
|
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task} {publication?.sortName}");
|
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {removeTask}");
|
||||||
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
_allTasks.Remove(removeTask);
|
||||||
|
removeTask.parentTask?.RemoveChildTask(removeTask);
|
||||||
|
if (removeTask is DownloadChapterTask cRemoveTask && _runningDownloadChapterTasks.ContainsKey(cRemoveTask))
|
||||||
{
|
{
|
||||||
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateKomgaLibrary);
|
_runningDownloadChapterTasks[cRemoveTask].Cancel();
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} from all Tasks.");
|
_runningDownloadChapterTasks.Remove(cRemoveTask);
|
||||||
}
|
}
|
||||||
else if (connectorName is null)
|
}
|
||||||
throw new ArgumentException($"connectorName can not be null for Task {task}");
|
|
||||||
else
|
public IEnumerable<TrangaTask> GetTasksMatching(TrangaTask.Task taskType, string? connectorName = null, string? searchString = null, string? internalId = null, string? chapterSortNumber = null)
|
||||||
|
{
|
||||||
|
switch (taskType)
|
||||||
{
|
{
|
||||||
foreach (List<TrangaTask> taskQueue in this._taskQueue.Values)
|
case TrangaTask.Task.UpdateLibraries:
|
||||||
if(taskQueue.RemoveAll(trangaTask =>
|
return _allTasks.Where(tTask => tTask.task == TrangaTask.Task.UpdateLibraries);
|
||||||
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
case TrangaTask.Task.MonitorPublication:
|
||||||
trangaTask.publication?.internalId == publication?.internalId) > 0)
|
if(connectorName is null)
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} {publication?.sortName} {publication?.internalId} from Queue.");
|
return _allTasks.Where(tTask => tTask.task == taskType);
|
||||||
|
GetConnector(connectorName);//Name check
|
||||||
|
if (searchString is not null)
|
||||||
|
{
|
||||||
|
return _allTasks.Where(mTask =>
|
||||||
|
mTask is MonitorPublicationTask mpt && mpt.connectorName == connectorName &&
|
||||||
|
mpt.ToString().Contains(searchString, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
}
|
||||||
|
else if (internalId is not null)
|
||||||
|
{
|
||||||
|
return _allTasks.Where(mTask =>
|
||||||
|
mTask is MonitorPublicationTask mpt && mpt.connectorName == connectorName &&
|
||||||
|
mpt.publication.internalId == internalId);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Task {task} {publication?.sortName} {publication?.internalId} was not in Queue.");
|
return _allTasks.Where(tTask =>
|
||||||
if(_allTasks.RemoveWhere(trangaTask =>
|
tTask is MonitorPublicationTask mpt && mpt.connectorName == connectorName);
|
||||||
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
|
||||||
trangaTask.publication?.internalId == publication?.internalId) > 0)
|
case TrangaTask.Task.DownloadChapter:
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} {publication?.sortName} {publication?.internalId} from all Tasks.");
|
if(connectorName is null)
|
||||||
else
|
return _allTasks.Where(tTask => tTask.task == taskType);
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"No Task {task} {publication?.sortName} {publication?.internalId} could be found.");
|
GetConnector(connectorName);//Name check
|
||||||
|
if (searchString is not null)
|
||||||
|
{
|
||||||
|
return _allTasks.Where(mTask =>
|
||||||
|
mTask is DownloadChapterTask dct && dct.connectorName == connectorName &&
|
||||||
|
dct.ToString().Contains(searchString, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
}
|
||||||
|
else if (internalId is not null && chapterSortNumber is not null)
|
||||||
|
{
|
||||||
|
return _allTasks.Where(mTask =>
|
||||||
|
mTask is DownloadChapterTask dct && dct.connectorName == connectorName &&
|
||||||
|
dct.publication.publicationId == internalId &&
|
||||||
|
dct.chapter.sortNumber == chapterSortNumber);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return _allTasks.Where(mTask =>
|
||||||
|
mTask is DownloadChapterTask dct && dct.connectorName == connectorName);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return Array.Empty<TrangaTask>();
|
||||||
}
|
}
|
||||||
ExportData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -221,8 +227,6 @@ public class TaskManager
|
|||||||
public void RemoveTaskFromQueue(TrangaTask task)
|
public void RemoveTaskFromQueue(TrangaTask task)
|
||||||
{
|
{
|
||||||
task.lastExecuted = DateTime.Now;
|
task.lastExecuted = DateTime.Now;
|
||||||
foreach (List<TrangaTask> taskList in this._taskQueue.Values)
|
|
||||||
taskList.Remove(task);
|
|
||||||
task.state = TrangaTask.ExecutionState.Waiting;
|
task.state = TrangaTask.ExecutionState.Waiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,8 +259,8 @@ public class TaskManager
|
|||||||
Publication[] ret = connector.GetPublications(title ?? "");
|
Publication[] ret = connector.GetPublications(title ?? "");
|
||||||
foreach (Publication publication in ret)
|
foreach (Publication publication in ret)
|
||||||
{
|
{
|
||||||
if(!_chapterCollection.Any(pub => pub.Key.sortName == publication.sortName))
|
if(chapterCollection.All(pub => pub.Key.internalId != publication.internalId))
|
||||||
this._chapterCollection.TryAdd(publication, new List<Chapter>());
|
this.chapterCollection.TryAdd(publication, new List<Chapter>());
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -264,7 +268,32 @@ public class TaskManager
|
|||||||
/// <returns>All added Publications</returns>
|
/// <returns>All added Publications</returns>
|
||||||
public Publication[] GetAllPublications()
|
public Publication[] GetAllPublications()
|
||||||
{
|
{
|
||||||
return this._chapterCollection.Keys.ToArray();
|
return this.chapterCollection.Keys.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the available Chapters of a Publication
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connector">Connector to use</param>
|
||||||
|
/// <param name="publication">Publication to check</param>
|
||||||
|
/// <param name="language">Language to receive chapters for</param>
|
||||||
|
/// <returns>List of Chapters that were previously not in collection</returns>
|
||||||
|
public List<Chapter> GetNewChaptersList(Connector connector, Publication publication, string language)
|
||||||
|
{
|
||||||
|
List<Chapter> newChaptersList = new();
|
||||||
|
chapterCollection.TryAdd(publication, newChaptersList); //To ensure publication is actually in collection
|
||||||
|
|
||||||
|
Chapter[] newChapters = connector.GetChapters(publication, language);
|
||||||
|
newChaptersList = newChapters.Where(nChapter => !connector.CheckChapterIsDownloaded(publication, nChapter)).ToList();
|
||||||
|
|
||||||
|
return newChaptersList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Chapter> GetExistingChaptersList(Connector connector, Publication publication, string language)
|
||||||
|
{
|
||||||
|
Chapter[] newChapters = connector.GetChapters(publication, language);
|
||||||
|
return newChapters.Where(nChapter => connector.CheckChapterIsDownloaded(publication, nChapter)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -279,7 +308,7 @@ public class TaskManager
|
|||||||
Connector? ret = this._connectors.FirstOrDefault(connector => connector.name == connectorName);
|
Connector? ret = this._connectors.FirstOrDefault(connector => connector.name == connectorName);
|
||||||
if (ret is null)
|
if (ret is null)
|
||||||
throw new Exception($"Connector {connectorName} is not an available Connector.");
|
throw new Exception($"Connector {connectorName} is not an available Connector.");
|
||||||
return (Connector)ret!;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -290,7 +319,7 @@ public class TaskManager
|
|||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Shutting down (forced={force})");
|
logger?.WriteLine(this.GetType().ToString(), $"Shutting down (forced={force})");
|
||||||
_continueRunning = false;
|
_continueRunning = false;
|
||||||
ExportData();
|
ExportDataAndSettings();
|
||||||
|
|
||||||
if(force)
|
if(force)
|
||||||
Environment.Exit(_allTasks.Count(task => task.state is TrangaTask.ExecutionState.Enqueued or TrangaTask.ExecutionState.Running));
|
Environment.Exit(_allTasks.Count(task => task.state is TrangaTask.ExecutionState.Enqueued or TrangaTask.ExecutionState.Running));
|
||||||
@ -310,33 +339,64 @@ public class TaskManager
|
|||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Importing tasks from {settings.tasksFilePath}");
|
logger?.WriteLine(this.GetType().ToString(), $"Importing tasks from {settings.tasksFilePath}");
|
||||||
buffer = File.ReadAllText(settings.tasksFilePath);
|
buffer = File.ReadAllText(settings.tasksFilePath);
|
||||||
this._allTasks = JsonConvert.DeserializeObject<HashSet<TrangaTask>>(buffer)!;
|
this._allTasks = JsonConvert.DeserializeObject<HashSet<TrangaTask>>(buffer, new JsonSerializerSettings() { Converters = { new TrangaTask.TrangaTaskJsonConverter() } })!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (TrangaTask task in this._allTasks.Where(tTask => tTask.parentTaskId is not null))
|
||||||
|
{
|
||||||
|
TrangaTask? parentTask = this._allTasks.FirstOrDefault(pTask => pTask.taskId == task.parentTaskId);
|
||||||
|
if (parentTask is not null)
|
||||||
|
{
|
||||||
|
task.parentTask = parentTask;
|
||||||
|
parentTask.AddChildTask(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (File.Exists(settings.knownPublicationsPath))
|
if (File.Exists(settings.knownPublicationsPath))
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Importing known publications from {settings.knownPublicationsPath}");
|
logger?.WriteLine(this.GetType().ToString(), $"Importing known publications from {settings.knownPublicationsPath}");
|
||||||
buffer = File.ReadAllText(settings.knownPublicationsPath);
|
buffer = File.ReadAllText(settings.knownPublicationsPath);
|
||||||
Publication[] publications = JsonConvert.DeserializeObject<Publication[]>(buffer)!;
|
Publication[] publications = JsonConvert.DeserializeObject<Publication[]>(buffer)!;
|
||||||
foreach (Publication publication in publications)
|
foreach (Publication publication in publications)
|
||||||
this._chapterCollection.TryAdd(publication, new List<Chapter>());
|
this.chapterCollection.TryAdd(publication, new List<Chapter>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Exports data (settings, tasks) to file
|
/// Exports data (settings, tasks) to file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ExportData()
|
private void ExportDataAndSettings()
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Exporting settings to {settings.settingsFilePath}");
|
logger?.WriteLine(this.GetType().ToString(), $"Exporting settings to {settings.settingsFilePath}");
|
||||||
|
while(IsFileInUse(settings.settingsFilePath))
|
||||||
|
Thread.Sleep(50);
|
||||||
File.WriteAllText(settings.settingsFilePath, JsonConvert.SerializeObject(settings));
|
File.WriteAllText(settings.settingsFilePath, JsonConvert.SerializeObject(settings));
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Exporting tasks to {settings.tasksFilePath}");
|
logger?.WriteLine(this.GetType().ToString(), $"Exporting tasks to {settings.tasksFilePath}");
|
||||||
|
while(IsFileInUse(settings.tasksFilePath))
|
||||||
|
Thread.Sleep(50);
|
||||||
File.WriteAllText(settings.tasksFilePath, JsonConvert.SerializeObject(this._allTasks));
|
File.WriteAllText(settings.tasksFilePath, JsonConvert.SerializeObject(this._allTasks));
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Exporting known publications to {settings.knownPublicationsPath}");
|
logger?.WriteLine(this.GetType().ToString(), $"Exporting known publications to {settings.knownPublicationsPath}");
|
||||||
File.WriteAllText(settings.knownPublicationsPath, JsonConvert.SerializeObject(this._chapterCollection.Keys.ToArray()));
|
while(IsFileInUse(settings.knownPublicationsPath))
|
||||||
|
Thread.Sleep(50);
|
||||||
|
File.WriteAllText(settings.knownPublicationsPath, JsonConvert.SerializeObject(this.chapterCollection.Keys.ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsFileInUse(string path)
|
||||||
|
{
|
||||||
|
if (!File.Exists(path))
|
||||||
|
return false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using FileStream stream = new (path, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||||
|
stream.Close();
|
||||||
|
}
|
||||||
|
catch (IOException)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,7 +7,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="PuppeteerSharp" Version="10.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using Newtonsoft.Json;
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Tranga.LibraryManagers;
|
||||||
|
using Tranga.NotificationManagers;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
@ -6,27 +9,79 @@ public class TrangaSettings
|
|||||||
{
|
{
|
||||||
public string downloadLocation { get; set; }
|
public string downloadLocation { get; set; }
|
||||||
public string workingDirectory { get; set; }
|
public string workingDirectory { get; set; }
|
||||||
[JsonIgnore]public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||||
[JsonIgnore]public string tasksFilePath => Path.Join(workingDirectory, "tasks.json");
|
[JsonIgnore] public string tasksFilePath => Path.Join(workingDirectory, "tasks.json");
|
||||||
[JsonIgnore]public string knownPublicationsPath => Path.Join(workingDirectory, "knownPublications.json");
|
[JsonIgnore] public string knownPublicationsPath => Path.Join(workingDirectory, "knownPublications.json");
|
||||||
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||||
public Komga? komga { get; set; }
|
public HashSet<LibraryManager> libraryManagers { get; }
|
||||||
|
public HashSet<NotificationManager> notificationManagers { get; }
|
||||||
|
|
||||||
public TrangaSettings(string downloadLocation, string workingDirectory, Komga? komga)
|
public TrangaSettings(string downloadLocation, string workingDirectory, HashSet<LibraryManager>? libraryManagers,
|
||||||
|
HashSet<NotificationManager>? notificationManagers)
|
||||||
{
|
{
|
||||||
|
if (downloadLocation.Length < 1 || workingDirectory.Length < 1)
|
||||||
|
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
|
||||||
this.workingDirectory = workingDirectory;
|
this.workingDirectory = workingDirectory;
|
||||||
this.downloadLocation = downloadLocation;
|
this.downloadLocation = downloadLocation;
|
||||||
this.komga = komga;
|
this.libraryManagers = libraryManagers??new();
|
||||||
|
this.notificationManagers = notificationManagers??new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TrangaSettings LoadSettings(string importFilePath)
|
public static TrangaSettings LoadSettings(string importFilePath, Logger? logger)
|
||||||
{
|
{
|
||||||
if (!File.Exists(importFilePath))
|
if (!File.Exists(importFilePath))
|
||||||
return new TrangaSettings(Path.Join(Directory.GetCurrentDirectory(), "Downloads"), Directory.GetCurrentDirectory(), null);
|
return new TrangaSettings(Path.Join(Directory.GetCurrentDirectory(), "Downloads"),
|
||||||
|
Directory.GetCurrentDirectory(), new HashSet<LibraryManager>(), new HashSet<NotificationManager>());
|
||||||
|
|
||||||
string toRead = File.ReadAllText(importFilePath);
|
string toRead = File.ReadAllText(importFilePath);
|
||||||
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(toRead)!;
|
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(toRead,
|
||||||
|
new JsonSerializerSettings { Converters = { new NotificationManager.NotificationManagerJsonConverter(), new LibraryManager.LibraryManagerJsonConverter() } })!;
|
||||||
|
if (logger is not null)
|
||||||
|
foreach (LibraryManager lm in settings.libraryManagers)
|
||||||
|
lm.AddLogger(logger);
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateSettings(UpdateField field, Logger? logger = null, params string[] values)
|
||||||
|
{
|
||||||
|
switch (field)
|
||||||
|
{
|
||||||
|
case UpdateField.DownloadLocation:
|
||||||
|
if (values.Length != 1)
|
||||||
|
return;
|
||||||
|
this.downloadLocation = values[0];
|
||||||
|
break;
|
||||||
|
case UpdateField.Komga:
|
||||||
|
if (values.Length != 2)
|
||||||
|
return;
|
||||||
|
libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Komga));
|
||||||
|
libraryManagers.Add(new Komga(values[0], values[1], logger));
|
||||||
|
break;
|
||||||
|
case UpdateField.Kavita:
|
||||||
|
if (values.Length != 3)
|
||||||
|
return;
|
||||||
|
libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Kavita));
|
||||||
|
libraryManagers.Add(new Kavita(values[0], values[1], values[2], logger));
|
||||||
|
break;
|
||||||
|
case UpdateField.Gotify:
|
||||||
|
if (values.Length != 2)
|
||||||
|
return;
|
||||||
|
notificationManagers.RemoveWhere(nm => nm.GetType() == typeof(Gotify));
|
||||||
|
Gotify newGotify = new(values[0], values[1], logger);
|
||||||
|
notificationManagers.Add(newGotify);
|
||||||
|
newGotify.SendNotification("Success!", "Gotify was added to Tranga!");
|
||||||
|
break;
|
||||||
|
case UpdateField.LunaSea:
|
||||||
|
if(values.Length != 1)
|
||||||
|
return;
|
||||||
|
notificationManagers.RemoveWhere(nm => nm.GetType() == typeof(LunaSea));
|
||||||
|
LunaSea newLunaSea = new(values[0], logger);
|
||||||
|
notificationManagers.Add(newLunaSea);
|
||||||
|
newLunaSea.SendNotification("Success!", "LunaSea was added to Tranga!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum UpdateField { DownloadLocation, Komga, Kavita, Gotify, LunaSea}
|
||||||
}
|
}
|
@ -1,61 +1,160 @@
|
|||||||
using Newtonsoft.Json;
|
using System.Net;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
using JsonConverter = Newtonsoft.Json.JsonConverter;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stores information on Task
|
/// Stores information on Task, when implementing new Tasks also update the serializer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TrangaTask
|
[JsonDerivedType(typeof(MonitorPublicationTask), 2)]
|
||||||
|
[JsonDerivedType(typeof(UpdateLibrariesTask), 3)]
|
||||||
|
[JsonDerivedType(typeof(DownloadChapterTask), 4)]
|
||||||
|
public abstract class TrangaTask
|
||||||
{
|
{
|
||||||
// ReSharper disable once CommentTypo ...Tell me why!
|
// ReSharper disable once CommentTypo ...Tell me why!
|
||||||
// ReSharper disable once MemberCanBePrivate.Global I want it thaaat way
|
// ReSharper disable once MemberCanBePrivate.Global I want it thaaat way
|
||||||
public TimeSpan reoccurrence { get; }
|
public TimeSpan reoccurrence { get; }
|
||||||
public DateTime lastExecuted { get; set; }
|
public DateTime lastExecuted { get; set; }
|
||||||
public string? connectorName { get; }
|
[Newtonsoft.Json.JsonIgnore] public ExecutionState state { get; set; }
|
||||||
public Task task { get; }
|
public Task task { get; }
|
||||||
public Publication? publication { get; }
|
public string taskId { get; }
|
||||||
public string language { get; }
|
[Newtonsoft.Json.JsonIgnore] public TrangaTask? parentTask { get; set; }
|
||||||
[JsonIgnore]public ExecutionState state { get; set; }
|
public string? parentTaskId { get; set; }
|
||||||
|
[Newtonsoft.Json.JsonIgnore] protected HashSet<TrangaTask> childTasks { get; }
|
||||||
|
public double progress => GetProgress();
|
||||||
|
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
||||||
|
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; }
|
||||||
|
[Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => progress != 0 ? lastChange.Add(GetRemainingTime()) : DateTime.MaxValue;
|
||||||
|
public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now);
|
||||||
|
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
||||||
|
|
||||||
public enum ExecutionState
|
public enum ExecutionState { Waiting, Enqueued, Running, Failed, Success }
|
||||||
{
|
|
||||||
Waiting,
|
|
||||||
Enqueued,
|
|
||||||
Running
|
|
||||||
};
|
|
||||||
|
|
||||||
public TrangaTask(Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence, string language = "")
|
protected TrangaTask(Task task, TimeSpan reoccurrence, TrangaTask? parentTask = null)
|
||||||
{
|
{
|
||||||
if(task != Task.UpdateKomgaLibrary && connectorName is null)
|
|
||||||
throw new ArgumentException($"connectorName can not be null for task {task}");
|
|
||||||
|
|
||||||
if (publication is null && task != Task.UpdatePublications && task != Task.UpdateKomgaLibrary)
|
|
||||||
throw new ArgumentException($"Publication can not be null for task {task}");
|
|
||||||
|
|
||||||
this.publication = publication;
|
|
||||||
this.reoccurrence = reoccurrence;
|
this.reoccurrence = reoccurrence;
|
||||||
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
||||||
this.connectorName = connectorName;
|
|
||||||
this.task = task;
|
this.task = task;
|
||||||
this.language = language;
|
this.executionStarted = DateTime.UnixEpoch;
|
||||||
|
this.lastChange = DateTime.MaxValue;
|
||||||
|
this.taskId = Convert.ToBase64String(BitConverter.GetBytes(new Random().Next()));
|
||||||
|
this.childTasks = new();
|
||||||
|
this.parentTask = parentTask;
|
||||||
|
this.parentTaskId = parentTask?.taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// BL for concrete Tasks
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="taskManager"></param>
|
||||||
|
/// <param name="logger"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
protected abstract HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null);
|
||||||
|
|
||||||
|
public abstract TrangaTask Clone();
|
||||||
|
|
||||||
|
protected abstract double GetProgress();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Execute the task
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="taskManager">Should be the parent taskManager</param>
|
||||||
|
/// <param name="logger"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
public void Execute(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Executing Task {this}");
|
||||||
|
this.state = ExecutionState.Running;
|
||||||
|
this.executionStarted = DateTime.Now;
|
||||||
|
this.lastChange = DateTime.Now;
|
||||||
|
HttpStatusCode statusCode = ExecuteTask(taskManager, logger, cancellationToken);
|
||||||
|
while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running))
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
if ((int)statusCode >= 200 && (int)statusCode < 300)
|
||||||
|
{
|
||||||
|
this.lastExecuted = DateTime.Now;
|
||||||
|
if (this is DownloadChapterTask)
|
||||||
|
this.state = ExecutionState.Success;
|
||||||
|
else
|
||||||
|
this.state = ExecutionState.Waiting;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (this is DownloadChapterTask && statusCode == HttpStatusCode.NotFound)
|
||||||
|
this.state = ExecutionState.Success;
|
||||||
|
else
|
||||||
|
this.state = ExecutionState.Failed;
|
||||||
|
this.lastExecuted = DateTime.MaxValue;
|
||||||
|
}
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <returns>True if elapsed time since last execution is greater than set interval</returns>
|
public void AddChildTask(TrangaTask childTask)
|
||||||
public bool ShouldExecute()
|
|
||||||
{
|
{
|
||||||
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence && state is ExecutionState.Waiting;
|
this.childTasks.Add(childTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Task
|
public void RemoveChildTask(TrangaTask childTask)
|
||||||
{
|
{
|
||||||
UpdatePublications,
|
this.childTasks.Remove(childTask);
|
||||||
UpdateChapters,
|
}
|
||||||
DownloadNewChapters,
|
|
||||||
UpdateKomgaLibrary
|
private TimeSpan GetRemainingTime()
|
||||||
|
{
|
||||||
|
if(progress == 0 || lastChange == DateTime.MaxValue || executionStarted == DateTime.UnixEpoch)
|
||||||
|
return TimeSpan.Zero;
|
||||||
|
TimeSpan elapsed = lastChange.Subtract(executionStarted);
|
||||||
|
return elapsed.Divide(progress).Subtract(elapsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Task : byte
|
||||||
|
{
|
||||||
|
MonitorPublication = 2,
|
||||||
|
UpdateLibraries = 3,
|
||||||
|
DownloadChapter = 4,
|
||||||
|
DownloadNewChapters = 2 //legacy
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{task}, {lastExecuted}, {reoccurrence}, {state} {(connectorName is not null ? $", {connectorName}" : "" )} {(publication is not null ? $", {publication?.sortName}": "")}";
|
return $"{task}, {lastExecuted}, {reoccurrence}, {state}, {progress:P2}, {executionApproximatelyFinished}, {executionApproximatelyRemaining}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TrangaTaskJsonConverter : JsonConverter
|
||||||
|
{
|
||||||
|
public override bool CanConvert(Type objectType)
|
||||||
|
{
|
||||||
|
return objectType == typeof(TrangaTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
JObject jo = JObject.Load(reader);
|
||||||
|
if (jo["task"]!.Value<Int64>() == (Int64)Task.MonitorPublication)
|
||||||
|
return jo.ToObject<MonitorPublicationTask>(serializer)!;
|
||||||
|
|
||||||
|
if (jo["task"]!.Value<Int64>() == (Int64)Task.UpdateLibraries)
|
||||||
|
return jo.ToObject<UpdateLibrariesTask>(serializer)!;
|
||||||
|
|
||||||
|
if (jo["task"]!.Value<Int64>() == (Int64)Task.DownloadChapter)
|
||||||
|
return jo.ToObject<DownloadChapterTask>(serializer)!;
|
||||||
|
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanWrite => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Don't call this
|
||||||
|
/// </summary>
|
||||||
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new Exception("Dont call this");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
56
Tranga/TrangaTasks/DownloadChapterTask.cs
Normal file
56
Tranga/TrangaTasks/DownloadChapterTask.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Logging;
|
||||||
|
|
||||||
|
namespace Tranga.TrangaTasks;
|
||||||
|
|
||||||
|
public class DownloadChapterTask : TrangaTask
|
||||||
|
{
|
||||||
|
public string connectorName { get; }
|
||||||
|
public Publication publication { get; }
|
||||||
|
public string language { get; }
|
||||||
|
public Chapter chapter { get; }
|
||||||
|
|
||||||
|
private double _dctProgress = 0;
|
||||||
|
|
||||||
|
public DownloadChapterTask(string connectorName, Publication publication, Chapter chapter, string language = "en", MonitorPublicationTask? parentTask = null) : base(Task.DownloadChapter, TimeSpan.Zero, parentTask)
|
||||||
|
{
|
||||||
|
this.chapter = chapter;
|
||||||
|
this.connectorName = connectorName;
|
||||||
|
this.publication = publication;
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
|
{
|
||||||
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
Connector connector = taskManager.GetConnector(this.connectorName);
|
||||||
|
connector.CopyCoverFromCacheToDownloadLocation(this.publication, taskManager.settings);
|
||||||
|
HttpStatusCode downloadSuccess = connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken);
|
||||||
|
if((int)downloadSuccess >= 200 && (int)downloadSuccess < 300 && parentTask is not null)
|
||||||
|
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
|
||||||
|
nm.SendNotification("New Chapter downloaded", $"{this.publication.sortName} {this.chapter.chapterNumber} {this.chapter.name}");
|
||||||
|
return downloadSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override TrangaTask Clone()
|
||||||
|
{
|
||||||
|
return new DownloadChapterTask(this.connectorName, this.publication, this.chapter,
|
||||||
|
this.language, (MonitorPublicationTask?)this.parentTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override double GetProgress()
|
||||||
|
{
|
||||||
|
return _dctProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void IncrementProgress(double amount)
|
||||||
|
{
|
||||||
|
this._dctProgress += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{base.ToString()}, {connectorName}, {publication.sortName} {publication.internalId}, Vol.{chapter.volumeNumber} Ch.{chapter.chapterNumber}";
|
||||||
|
}
|
||||||
|
}
|
60
Tranga/TrangaTasks/MonitorPublicationTask.cs
Normal file
60
Tranga/TrangaTasks/MonitorPublicationTask.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Logging;
|
||||||
|
|
||||||
|
namespace Tranga.TrangaTasks;
|
||||||
|
|
||||||
|
public class MonitorPublicationTask : TrangaTask
|
||||||
|
{
|
||||||
|
public string connectorName { get; }
|
||||||
|
public Publication publication { get; }
|
||||||
|
public string language { get; }
|
||||||
|
public MonitorPublicationTask(string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(Task.MonitorPublication, reoccurrence)
|
||||||
|
{
|
||||||
|
this.connectorName = connectorName;
|
||||||
|
this.publication = publication;
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
|
{
|
||||||
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
Connector connector = taskManager.GetConnector(this.connectorName);
|
||||||
|
|
||||||
|
//Check if Publication already has a Folder
|
||||||
|
publication.CreatePublicationFolder(taskManager.settings.downloadLocation);
|
||||||
|
List<Chapter> newChapters = taskManager.GetNewChaptersList(connector, publication, language);
|
||||||
|
|
||||||
|
connector.CopyCoverFromCacheToDownloadLocation(publication, taskManager.settings);
|
||||||
|
|
||||||
|
publication.SaveSeriesInfoJson(connector.downloadLocation);
|
||||||
|
|
||||||
|
foreach (Chapter newChapter in newChapters)
|
||||||
|
{
|
||||||
|
DownloadChapterTask newTask = new (this.connectorName, publication, newChapter, this.language, this);
|
||||||
|
this.childTasks.Add(newTask);
|
||||||
|
newTask.state = ExecutionState.Enqueued;
|
||||||
|
taskManager.AddTask(newTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
return HttpStatusCode.OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override TrangaTask Clone()
|
||||||
|
{
|
||||||
|
return new MonitorPublicationTask(this.connectorName, this.publication, this.reoccurrence,
|
||||||
|
this.language);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override double GetProgress()
|
||||||
|
{
|
||||||
|
if (this.childTasks.Count > 0)
|
||||||
|
return this.childTasks.Sum(ct => ct.progress) / childTasks.Count;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{base.ToString()}, {connectorName}, {publication.sortName} {publication.internalId}";
|
||||||
|
}
|
||||||
|
}
|
30
Tranga/TrangaTasks/UpdateLibrariesTask.cs
Normal file
30
Tranga/TrangaTasks/UpdateLibrariesTask.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System.Net;
|
||||||
|
using Logging;
|
||||||
|
|
||||||
|
namespace Tranga.TrangaTasks;
|
||||||
|
|
||||||
|
public class UpdateLibrariesTask : TrangaTask
|
||||||
|
{
|
||||||
|
public UpdateLibrariesTask(TimeSpan reoccurrence) : base(Task.UpdateLibraries, reoccurrence)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
|
{
|
||||||
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
foreach(LibraryManager lm in taskManager.settings.libraryManagers)
|
||||||
|
lm.UpdateLibrary();
|
||||||
|
return HttpStatusCode.OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override TrangaTask Clone()
|
||||||
|
{
|
||||||
|
return new UpdateLibrariesTask(this.reoccurrence);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override double GetProgress()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
@ -43,59 +43,81 @@ function DeleteData(uri){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function GetAvailableControllers(){
|
async function GetAvailableControllers(){
|
||||||
var uri = apiUri + "/Tranga/GetAvailableControllers";
|
var uri = apiUri + "/Connectors";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetPublication(connectorName, title){
|
async function GetPublicationFromConnector(connectorName, title){
|
||||||
var uri = apiUri + `/Tranga/GetPublicationsFromConnector?connectorName=${connectorName}&title=${title}`;
|
var uri = apiUri + `/Publications/FromConnector?connectorName=${connectorName}&title=${title}`;
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetKnownPublications(){
|
async function GetKnownPublications(){
|
||||||
var uri = apiUri + "/Tranga/GetKnownPublications";
|
var uri = apiUri + "/Publications/Known";
|
||||||
|
let json = await GetData(uri);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function GetPublication(internalId){
|
||||||
|
var uri = apiUri + `/Publications/Known?internalId=${internalId}`;
|
||||||
|
let json = await GetData(uri);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function GetChapters(internalId, connectorName, onlyNew, language){
|
||||||
|
var uri = apiUri + `/Publications/Chapters?internalId=${internalId}&connectorName=${connectorName}&onlyNew=${onlyNew}&language=${language}`;
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetTaskTypes(){
|
async function GetTaskTypes(){
|
||||||
var uri = apiUri + "/Tasks/GetTaskTypes";
|
var uri = apiUri + "/Tasks/Types";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
async function GetRunningTasks(){
|
async function GetRunningTasks(){
|
||||||
var uri = apiUri + "/Tasks/GetRunningTasks";
|
var uri = apiUri + "/Tasks/RunningTasks";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetDownloadTasks(){
|
async function GetDownloadTasks(){
|
||||||
var uri = apiUri + "/Tasks/Get?taskType=DownloadNewChapters";
|
var uri = apiUri + "/Tasks?taskType=DownloadNewChapters";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetSettings(){
|
async function GetSettings(){
|
||||||
var uri = apiUri + "/Settings/Get";
|
var uri = apiUri + "/Settings";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetKomgaTask(){
|
async function GetKomgaTask(){
|
||||||
var uri = apiUri + "/Tasks/Get?taskType=UpdateKomgaLibrary";
|
var uri = apiUri + "/Tasks?taskType=UpdateLibraries";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CreateTask(taskType, reoccurrence, connectorName, publicationId, language){
|
function CreateMonitorTask(connectorName, internalId, reoccurrence, language){
|
||||||
var uri = apiUri + `/Tasks/Create?taskType=${taskType}&connectorName=${connectorName}&publicationId=${publicationId}&reoccurrenceTime=${reoccurrence}&language=${language}`;
|
var uri = apiUri + `/Tasks/CreateMonitorTask?connectorName=${connectorName}&internalId=${internalId}&reoccurrenceTime=${reoccurrence}&language=${language}`;
|
||||||
PostData(uri);
|
PostData(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
function StartTask(taskType, connectorName, publicationId){
|
function CreateUpdateLibraryTask(reoccurrence){
|
||||||
var uri = apiUri + `/Tasks/Start?taskType=${taskType}&connectorName=${connectorName}&publicationId=${publicationId}`;
|
var uri = apiUri + `/Tasks/CreateUpdateLibraryTask?reoccurrenceTime=${reoccurrence}`;
|
||||||
|
PostData(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CreateDownloadChaptersTask(connectorName, internalId, chapters, language){
|
||||||
|
var uri = apiUri + `/Tasks/CreateDownloadChaptersTask?connectorName=${connectorName}&internalId=${internalId}&chapters=${chapters}&language=${language}`;
|
||||||
|
PostData(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
function StartTask(taskType, connectorName, internalId){
|
||||||
|
var uri = apiUri + `/Tasks/Start?taskType=${taskType}&connectorName=${connectorName}&internalId=${internalId}`;
|
||||||
PostData(uri);
|
PostData(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,13 +126,38 @@ function EnqueueTask(taskType, connectorName, publicationId){
|
|||||||
PostData(uri);
|
PostData(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
function UpdateSettings(downloadLocation, komgaUrl, komgaAuth){
|
function UpdateDownloadLocation(downloadLocation){
|
||||||
var uri = apiUri + `/Settings/Update?downloadLocation=${downloadLocation}&komgaUrl=${komgaUrl}&komgaAuth=${komgaAuth}`;
|
var uri = apiUri + "/Settings/Update?"
|
||||||
|
uri += "&downloadLocation="+downloadLocation;
|
||||||
|
PostData(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
function UpdateKomga(komgaUrl, komgaAuth){
|
||||||
|
var uri = apiUri + "/Settings/Update?"
|
||||||
|
uri += `&komgaUrl=${komgaUrl}&komgaAuth=${komgaAuth}`;
|
||||||
|
PostData(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
function UpdateKavita(kavitaUrl, kavitaUser, kavitaPass){
|
||||||
|
var uri = apiUri + "/Settings/Update?"
|
||||||
|
uri += `&kavitaUrl=${kavitaUrl}&kavitaUsername=${kavitaUser}&kavitaPassword=${kavitaPass}`;
|
||||||
|
PostData(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
function UpdateGotify(gotifyUrl, gotifyAppToken){
|
||||||
|
var uri = apiUri + "/Settings/Update?"
|
||||||
|
uri += `&gotifyUrl=${gotifyUrl}&gotifyAppToken=${gotifyAppToken}`;
|
||||||
|
PostData(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
function UpdateLunaSea(lunaseaWebhook){
|
||||||
|
var uri = apiUri + "/Settings/Update?"
|
||||||
|
uri += `&lunaseaWebhook=${lunaseaWebhook}`;
|
||||||
PostData(uri);
|
PostData(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DeleteTask(taskType, connectorName, publicationId){
|
function DeleteTask(taskType, connectorName, publicationId){
|
||||||
var uri = apiUri + `/Tasks/Delete?taskType=${taskType}&connectorName=${connectorName}&publicationId=${publicationId}`;
|
var uri = apiUri + `/Tasks?taskType=${taskType}&connectorName=${connectorName}&publicationId=${publicationId}`;
|
||||||
DeleteData(uri);
|
DeleteData(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +167,7 @@ function DequeueTask(taskType, connectorName, publicationId){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function GetQueue(){
|
async function GetQueue(){
|
||||||
var uri = apiUri + "/Queue/GetList";
|
var uri = apiUri + "/Queue/List";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
BIN
Website/favicon.ico
Normal file
BIN
Website/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
@ -4,108 +4,175 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Tranga</title>
|
<title>Tranga</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<topbar>
|
<wrapper>
|
||||||
<titlebox>
|
<topbar>
|
||||||
<img src="media/blahaj.png">
|
<titlebox>
|
||||||
<span>Tranga</span>
|
<img alt="website image is Blahaj" src="media/blahaj.png">
|
||||||
</titlebox>
|
<span>Tranga</span>
|
||||||
<spacer></spacer>
|
</titlebox>
|
||||||
<searchdiv>
|
<spacer></spacer>
|
||||||
<input id="searchbox" placeholder="Filter" type="text">
|
<searchdiv>
|
||||||
</searchdiv>
|
<label for="searchbox"></label><input id="searchbox" placeholder="Filter" type="text">
|
||||||
<img id="settingscog" src="media/settings-cogwheel.svg" height="100%" alt="settingscog">
|
</searchdiv>
|
||||||
</topbar>
|
<img id="settingscog" src="media/settings-cogwheel.svg" height="100%" alt="settingscog">
|
||||||
<viewport>
|
</topbar>
|
||||||
<content>
|
<viewport>
|
||||||
<div id="addPublication">
|
<content>
|
||||||
<p>+</p>
|
<div id="addPublication">
|
||||||
</div>
|
<p>+</p>
|
||||||
<publication>
|
</div>
|
||||||
<img src="media/cover.jpg">
|
<publication>
|
||||||
<publication-information>
|
<img alt="cover" src="media/cover.jpg">
|
||||||
<connector-name class="pill">MangaDex</connector-name>
|
<publication-information>
|
||||||
<publication-name>Tensei Pandemic</publication-name>
|
<connector-name class="pill">MangaDex</connector-name>
|
||||||
</publication-information>
|
<publication-name>Tensei Pandemic</publication-name>
|
||||||
</publication>
|
</publication-information>
|
||||||
</content>
|
</publication>
|
||||||
|
</content>
|
||||||
<popup id="addTaskPopup">
|
|
||||||
<blur-background id="blurBackgroundTaskPopup"></blur-background>
|
<popup id="selectPublicationPopup">
|
||||||
<addtask-window>
|
<blur-background id="blurBackgroundTaskPopup"></blur-background>
|
||||||
<window-titlebar>
|
<popup-window>
|
||||||
<p>Add Task</p>
|
<popup-title>Select Publication</popup-title>
|
||||||
<img id="closePopupImg" src="media/close-x.svg" alt="Close">
|
<popup-content>
|
||||||
</window-titlebar>
|
<div>
|
||||||
<window-content>
|
<label for="connectors">Connector</label>
|
||||||
<addtask-settings>
|
|
||||||
<addtask-setting><label for="selectReccurrence">Recurrence</label><input id="selectReccurrence" type="time" value="01:00:00" step="3600"></addtask-setting>
|
|
||||||
<addtask-setting><label for="connectors">Connector</label>
|
|
||||||
<select id="connectors">
|
<select id="connectors">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
</select>
|
</select>
|
||||||
</addtask-setting>
|
</div>
|
||||||
<addtask-setting><label for="searchPublicationQuery">Search Title</label><input id="searchPublicationQuery" type="text"></addtask-setting>
|
<div>
|
||||||
<input type="submit" value="Search" onclick="NewSearch();">
|
<label for="searchPublicationQuery">Search Title</label><input id="searchPublicationQuery" type="text"></addtask-setting>
|
||||||
</addtask-settings>
|
</div>
|
||||||
|
<input type="submit" value="Search" style="font-weight: bolder" onclick="NewSearch();">
|
||||||
|
</popup-content>
|
||||||
<div id="taskSelectOutput"></div>
|
<div id="taskSelectOutput"></div>
|
||||||
</window-content>
|
</popup-window>
|
||||||
</addtask-window>
|
</popup>
|
||||||
</popup>
|
|
||||||
<popup id="publicationViewerPopup">
|
<popup id="createMonitorTaskPopup">
|
||||||
<blur-background id="blurBackgroundPublicationPopup"></blur-background>
|
<blur-background id="blurBackgroundCreateMonitorTaskPopup"></blur-background>
|
||||||
<publication-viewer>
|
<popup-window>
|
||||||
<img id="pubviewcover" src="media/cover.jpg" alt="cover">
|
<popup-title>Create Task: Monitor Publication</popup-title>
|
||||||
<publication-information>
|
<popup-content>
|
||||||
<publication-name id="publicationViewerName">Tensei Pandemic</publication-name>
|
<div>
|
||||||
<publication-author id="publicationViewerAuthor">Imamura Hinata</publication-author>
|
<span>Run every</span>
|
||||||
<publication-description id="publicationViewerDescription">Imamura Hinata is a high school boy with a cute appearance.
|
<label for="hours"></label><input id="hours" type="number" value="3" min="0" max="23"><span>hours</span>
|
||||||
Since his trauma with the first love, he wanted to be more manly than anybody else. But one day he woke up to something different…
|
<label for="minutes"></label><input id="minutes" type="number" value="0" min="0" max="59"><span>minutes</span>
|
||||||
The total opposite of his ideal male body!
|
<input type="submit" value="Create" onclick="AddMonitorTask()">
|
||||||
Pandemic love comedy!
|
</div>
|
||||||
</publication-description>
|
</popup-content>
|
||||||
<publication-delete>Delete Task ❌</publication-delete>
|
</popup-window>
|
||||||
<publication-add>Add Task ➕</publication-add>
|
</popup>
|
||||||
</publication-information>
|
|
||||||
</publication-viewer>
|
<popup id="createDownloadChaptersTask">
|
||||||
</popup>
|
<blur-background id="blurBackgroundCreateDownloadChaptersTask"></blur-background>
|
||||||
<popup id="settingsPopup">
|
<popup-window>
|
||||||
<blur-background id="blurBackgroundSettingsPopup"></blur-background>
|
<popup-title>Create Task: Download Chapter(s)</popup-title>
|
||||||
<settings>
|
<popup-content>
|
||||||
<span style="font-weight: bold; text-align: center; font-size: 16pt;">Settings</span>
|
<div>
|
||||||
<div>
|
<label for="selectedChapters">Chapters:</label><input id="selectedChapters" placeholder="Select"><input type="submit" value="Select" onclick="DownloadChapterTaskClick()">
|
||||||
<p class="title">Download Location:</p>
|
</div>
|
||||||
<span id="downloadLocation"></span>
|
<div id="chapterOutput">
|
||||||
</div>
|
|
||||||
<div>
|
</div>
|
||||||
<p class="title">API-URI</p>
|
</popup-content>
|
||||||
<label for="settingApiUri"></label><input placeholder="https://" type="text" id="settingApiUri">
|
</popup-window>
|
||||||
</div>
|
</popup>
|
||||||
<komga-settings>
|
|
||||||
<span class="title">Komga</span>
|
<popup id="publicationViewerPopup">
|
||||||
<div>Configured: <span id="komgaConfigured">✅❌</span></div>
|
<blur-background id="blurBackgroundPublicationPopup"></blur-background>
|
||||||
<label for="komgaUrl"></label><input placeholder="URL" id="komgaUrl" type="text">
|
<publication-viewer>
|
||||||
<label for="komgaUsername"></label><input placeholder="Username" id="komgaUsername" type="text">
|
<img id="pubviewcover" src="media/cover.jpg" alt="cover">
|
||||||
<label for="komgaPassword"></label><input placeholder="Password" id="komgaPassword" type="password">
|
<publication-information>
|
||||||
<label for="komgaUpdateTime" style="margin-right: 5px;">Update Time</label><input id="komgaUpdateTime" type="time" value="00:01:00" step="10">
|
<publication-name id="publicationViewerName">Tensei Pandemic</publication-name>
|
||||||
<input type="submit" value="Update" onclick="UpdateKomgaSettings()">
|
<publication-tags id="publicationViewerTags"></publication-tags>
|
||||||
</komga-settings>
|
<publication-author id="publicationViewerAuthor">Imamura Hinata</publication-author>
|
||||||
</settings>
|
<publication-description id="publicationViewerDescription">Imamura Hinata is a high school boy with a cute appearance.
|
||||||
</popup>
|
Since his trauma with the first love, he wanted to be more manly than anybody else. But one day he woke up to something different…
|
||||||
</viewport>
|
The total opposite of his ideal male body!
|
||||||
<footer>
|
Pandemic love comedy!
|
||||||
<div>
|
</publication-description>
|
||||||
<img src="media/running.svg" alt="running"><div id="tasksRunningTag">0</div>
|
<publication-interactions>
|
||||||
</div>
|
<publication-starttask>Start Task ▶️</publication-starttask>
|
||||||
<div>
|
<publication-delete>Delete Task ❌</publication-delete>
|
||||||
<img src="media/queue.svg" alt="queue"><div id="tasksQueuedTag">0</div>
|
<publication-add id="createMonitorTaskButton">Monitor ➕</publication-add>
|
||||||
</div>
|
<publication-add id="createDownloadChapterTaskButton">Download Chapter ➕</publication-add>
|
||||||
<div>
|
</publication-interactions>
|
||||||
<img src="media/tasks.svg" alt="queue"><div id="totalTasksTag">0</div>
|
</publication-information>
|
||||||
</div>
|
</publication-viewer>
|
||||||
<p id="madeWith">Made with Blåhaj 🦈</p>
|
</popup>
|
||||||
</footer>
|
|
||||||
|
<popup id="settingsPopup">
|
||||||
|
<blur-background id="blurBackgroundSettingsPopup"></blur-background>
|
||||||
|
<popup-window>
|
||||||
|
<popup-title>Settings</popup-title>
|
||||||
|
<popup-content>
|
||||||
|
<div>
|
||||||
|
<p class="title">Download Location:</p>
|
||||||
|
<span id="downloadLocation"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="title">API-URI</p>
|
||||||
|
<label for="settingApiUri"></label><input placeholder="https://" type="text" id="settingApiUri">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="title">Komga</span>
|
||||||
|
<div>Configured: <span id="komgaConfigured">✅❌</span></div>
|
||||||
|
<label for="komgaUrl"></label><input placeholder="URL" id="komgaUrl" type="text">
|
||||||
|
<label for="komgaUsername"></label><input placeholder="Username" id="komgaUsername" type="text">
|
||||||
|
<label for="komgaPassword"></label><input placeholder="Password" id="komgaPassword" type="password">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="title">Kavita</span>
|
||||||
|
<div>Configured: <span id="kavitaConfigured">✅❌</span></div>
|
||||||
|
<label for="kavitaUrl"></label><input placeholder="URL" id="kavitaUrl" type="text">
|
||||||
|
<label for="kavitaUsername"></label><input placeholder="Username" id="kavitaUsername" type="text">
|
||||||
|
<label for="kavitaPassword"></label><input placeholder="Password" id="kavitaPassword" type="password">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="title">Gotify</span>
|
||||||
|
<div>Configured: <span id="gotifyConfigured">✅❌</span></div>
|
||||||
|
<label for="gotifyUrl"></label><input placeholder="URL" id="gotifyUrl" type="text">
|
||||||
|
<label for="gotifyAppToken"></label><input placeholder="App-Token" id="gotifyAppToken" type="text">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="title">LunaSea</span>
|
||||||
|
<div>Configured: <span id="lunaseaConfigured">✅❌</span></div>
|
||||||
|
<label for="lunaseaWebhook"></label><input placeholder="Webhook-Url" id="lunaseaWebhook" type="text">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="libraryUpdateTime" style="margin-right: 5px;">Update Time</label><input id="libraryUpdateTime" type="time" value="00:01:00" step="10">
|
||||||
|
<input type="submit" value="Update" onclick="UpdateLibrarySettings()">
|
||||||
|
</div>
|
||||||
|
</popup-content>
|
||||||
|
</popup-window>
|
||||||
|
</popup>
|
||||||
|
|
||||||
|
<popup id="downloadTasksPopup">
|
||||||
|
<blur-background id="blurBackgroundTasksQueuePopup"></blur-background>
|
||||||
|
<popup-window>
|
||||||
|
<popup-title>Task Progress</popup-title>
|
||||||
|
<popup-content>
|
||||||
|
|
||||||
|
</popup-content>
|
||||||
|
</popup-window>
|
||||||
|
</popup>
|
||||||
|
</viewport>
|
||||||
|
<footer>
|
||||||
|
<div onclick="ShowTasksQueue();">
|
||||||
|
<img src="media/running.svg" alt="running"><div id="tasksRunningTag">0</div>
|
||||||
|
</div>
|
||||||
|
<div onclick="ShowTasksQueue();">
|
||||||
|
<img src="media/queue.svg" alt="queue"><div id="tasksQueuedTag">0</div>
|
||||||
|
</div>
|
||||||
|
<p id="madeWith">Made with Blåhaj 🦈</p>
|
||||||
|
</footer>
|
||||||
|
</wrapper>
|
||||||
|
|
||||||
<script src="apiConnector.js"></script>
|
<script src="apiConnector.js"></script>
|
||||||
<script src="interaction.js"></script>
|
<script src="interaction.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
let tasks = [];
|
let tasks = [];
|
||||||
let toEditId;
|
let toEditId;
|
||||||
|
|
||||||
|
const searchBox = document.querySelector("#searchbox");
|
||||||
const searchPublicationQuery = document.querySelector("#searchPublicationQuery");
|
const searchPublicationQuery = document.querySelector("#searchPublicationQuery");
|
||||||
const selectPublication = document.querySelector("#taskSelectOutput");
|
const selectPublication = document.querySelector("#taskSelectOutput");
|
||||||
const connectorSelect = document.querySelector("#connectors");
|
const connectorSelect = document.querySelector("#connectors");
|
||||||
@ -9,34 +10,66 @@ const settingsPopup = document.querySelector("#settingsPopup");
|
|||||||
const settingsCog = document.querySelector("#settingscog");
|
const settingsCog = document.querySelector("#settingscog");
|
||||||
const selectRecurrence = document.querySelector("#selectReccurrence");
|
const selectRecurrence = document.querySelector("#selectReccurrence");
|
||||||
const tasksContent = document.querySelector("content");
|
const tasksContent = document.querySelector("content");
|
||||||
const addTaskPopup = document.querySelector("#addTaskPopup");
|
const selectPublicationPopup = document.querySelector("#selectPublicationPopup");
|
||||||
|
const createMonitorTaskButton = document.querySelector("#createMonitorTaskButton");
|
||||||
|
const createDownloadChapterTaskButton = document.querySelector("#createDownloadChapterTaskButton");
|
||||||
|
const createMonitorTaskPopup = document.querySelector("#createMonitorTaskPopup");
|
||||||
|
const createDownloadChaptersTask = document.querySelector("#createDownloadChaptersTask");
|
||||||
|
const chapterOutput = document.querySelector("#chapterOutput");
|
||||||
|
const selectedChapters = document.querySelector("#selectedChapters");
|
||||||
const publicationViewerPopup = document.querySelector("#publicationViewerPopup");
|
const publicationViewerPopup = document.querySelector("#publicationViewerPopup");
|
||||||
const publicationViewerWindow = document.querySelector("publication-viewer");
|
const publicationViewerWindow = document.querySelector("publication-viewer");
|
||||||
const publicationViewerDescription = document.querySelector("#publicationViewerDescription");
|
const publicationViewerDescription = document.querySelector("#publicationViewerDescription");
|
||||||
const publicationViewerName = document.querySelector("#publicationViewerName");
|
const publicationViewerName = document.querySelector("#publicationViewerName");
|
||||||
|
const publicationViewerTags = document.querySelector("#publicationViewerTags");
|
||||||
const publicationViewerAuthor = document.querySelector("#publicationViewerAuthor");
|
const publicationViewerAuthor = document.querySelector("#publicationViewerAuthor");
|
||||||
const pubviewcover = document.querySelector("#pubviewcover");
|
const pubviewcover = document.querySelector("#pubviewcover");
|
||||||
const publicationDelete = document.querySelector("publication-delete");
|
const publicationDelete = document.querySelector("publication-delete");
|
||||||
const publicationAdd = document.querySelector("publication-add");
|
const publicationTaskStart = document.querySelector("publication-starttask");
|
||||||
const closetaskpopup = document.querySelector("#closePopupImg");
|
|
||||||
const settingDownloadLocation = document.querySelector("#downloadLocation");
|
const settingDownloadLocation = document.querySelector("#downloadLocation");
|
||||||
const settingKomgaUrl = document.querySelector("#komgaUrl");
|
const settingKomgaUrl = document.querySelector("#komgaUrl");
|
||||||
const settingKomgaUser = document.querySelector("#komgaUsername");
|
const settingKomgaUser = document.querySelector("#komgaUsername");
|
||||||
const settingKomgaPass = document.querySelector("#komgaPassword");
|
const settingKomgaPass = document.querySelector("#komgaPassword");
|
||||||
const settingKomgaTime = document.querySelector("#komgaUpdateTime");
|
const settingKavitaUrl = document.querySelector("#kavitaUrl");
|
||||||
|
const settingKavitaUser = document.querySelector("#kavitaUsername");
|
||||||
|
const settingKavitaPass = document.querySelector("#kavitaPassword");
|
||||||
|
const settingGotifyUrl = document.querySelector("#gotifyUrl");
|
||||||
|
const settingGotifyAppToken = document.querySelector("#gotifyAppToken");
|
||||||
|
const settingLunaseaWebhook = document.querySelector("#lunaseaWebhook");
|
||||||
|
const libraryUpdateTime = document.querySelector("#libraryUpdateTime");
|
||||||
const settingKomgaConfigured = document.querySelector("#komgaConfigured");
|
const settingKomgaConfigured = document.querySelector("#komgaConfigured");
|
||||||
|
const settingKavitaConfigured = document.querySelector("#kavitaConfigured");
|
||||||
|
const settingGotifyConfigured = document.querySelector("#gotifyConfigured");
|
||||||
|
const settingLunaseaConfigured = document.querySelector("#lunaseaConfigured");
|
||||||
const settingApiUri = document.querySelector("#settingApiUri");
|
const settingApiUri = document.querySelector("#settingApiUri");
|
||||||
const tagTasksRunning = document.querySelector("#tasksRunningTag");
|
const tagTasksRunning = document.querySelector("#tasksRunningTag");
|
||||||
const tagTasksQueued = document.querySelector("#tasksQueuedTag");
|
const tagTasksQueued = document.querySelector("#tasksQueuedTag");
|
||||||
const tagTasksTotal = document.querySelector("#totalTasksTag");
|
const downloadTasksPopup = document.querySelector("#downloadTasksPopup");
|
||||||
|
const downloadTasksOutput = downloadTasksPopup.querySelector("popup-content");
|
||||||
|
|
||||||
|
searchbox.addEventListener("keyup", (event) => FilterResults());
|
||||||
settingsCog.addEventListener("click", () => OpenSettings());
|
settingsCog.addEventListener("click", () => OpenSettings());
|
||||||
document.querySelector("#blurBackgroundSettingsPopup").addEventListener("click", () => HideSettings());
|
document.querySelector("#blurBackgroundSettingsPopup").addEventListener("click", () => settingsPopup.style.display = "none");
|
||||||
closetaskpopup.addEventListener("click", () => HideAddTaskPopup());
|
document.querySelector("#blurBackgroundTaskPopup").addEventListener("click", () => selectPublicationPopup.style.display = "none");
|
||||||
document.querySelector("#blurBackgroundTaskPopup").addEventListener("click", () => HideAddTaskPopup());
|
|
||||||
document.querySelector("#blurBackgroundPublicationPopup").addEventListener("click", () => HidePublicationPopup());
|
document.querySelector("#blurBackgroundPublicationPopup").addEventListener("click", () => HidePublicationPopup());
|
||||||
|
document.querySelector("#blurBackgroundCreateMonitorTaskPopup").addEventListener("click", () => createMonitorTaskPopup.style.display = "none");
|
||||||
|
document.querySelector("#blurBackgroundCreateDownloadChaptersTask").addEventListener("click", () => createDownloadChaptersTask.style.display = "none");
|
||||||
|
document.querySelector("#blurBackgroundTasksQueuePopup").addEventListener("click", () => downloadTasksPopup.style.display = "none");
|
||||||
|
selectedChapters.addEventListener("keypress", (event) => {
|
||||||
|
if(event.key === "Enter"){
|
||||||
|
DownloadChapterTaskClick();
|
||||||
|
}
|
||||||
|
})
|
||||||
publicationDelete.addEventListener("click", () => DeleteTaskClick());
|
publicationDelete.addEventListener("click", () => DeleteTaskClick());
|
||||||
publicationAdd.addEventListener("click", () => AddTaskClick());
|
createMonitorTaskButton.addEventListener("click", () => {
|
||||||
|
HidePublicationPopup();
|
||||||
|
createMonitorTaskPopup.style.display = "block";
|
||||||
|
});
|
||||||
|
createDownloadChapterTaskButton.addEventListener("click", () => {
|
||||||
|
HidePublicationPopup();
|
||||||
|
OpenDownloadChapterTaskPopup();
|
||||||
|
});
|
||||||
|
publicationTaskStart.addEventListener("click", () => StartTaskClick());
|
||||||
settingApiUri.addEventListener("keypress", (event) => {
|
settingApiUri.addEventListener("keypress", (event) => {
|
||||||
if(event.key === "Enter"){
|
if(event.key === "Enter"){
|
||||||
apiUri = settingApiUri.value;
|
apiUri = settingApiUri.value;
|
||||||
@ -50,6 +83,7 @@ searchPublicationQuery.addEventListener("keypress", (event) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
let availableConnectors;
|
let availableConnectors;
|
||||||
GetAvailableControllers()
|
GetAvailableControllers()
|
||||||
.then(json => availableConnectors = json)
|
.then(json => availableConnectors = json)
|
||||||
@ -65,13 +99,14 @@ GetAvailableControllers()
|
|||||||
|
|
||||||
function NewSearch(){
|
function NewSearch(){
|
||||||
//Disable inputs
|
//Disable inputs
|
||||||
selectRecurrence.disabled = true;
|
|
||||||
connectorSelect.disabled = true;
|
connectorSelect.disabled = true;
|
||||||
searchPublicationQuery.disabled = true;
|
searchPublicationQuery.disabled = true;
|
||||||
|
//Waitcursor
|
||||||
|
document.body.style.cursor = "wait";
|
||||||
|
|
||||||
//Empty previous results
|
//Empty previous results
|
||||||
selectPublication.replaceChildren();
|
selectPublication.replaceChildren();
|
||||||
GetPublication(connectorSelect.value, searchPublicationQuery.value)
|
GetPublicationFromConnector(connectorSelect.value, searchPublicationQuery.value)
|
||||||
.then(json =>
|
.then(json =>
|
||||||
json.forEach(publication => {
|
json.forEach(publication => {
|
||||||
var option = CreatePublication(publication, connectorSelect.value);
|
var option = CreatePublication(publication, connectorSelect.value);
|
||||||
@ -83,9 +118,10 @@ function NewSearch(){
|
|||||||
))
|
))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
//Re-enable inputs
|
//Re-enable inputs
|
||||||
selectRecurrence.disabled = false;
|
|
||||||
connectorSelect.disabled = false;
|
connectorSelect.disabled = false;
|
||||||
searchPublicationQuery.disabled = false;
|
searchPublicationQuery.disabled = false;
|
||||||
|
//Cursor
|
||||||
|
document.body.style.cursor = "initial";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,15 +146,62 @@ function CreatePublication(publication, connector){
|
|||||||
return publicationElement;
|
return publicationElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function AddMonitorTask(){
|
||||||
|
var hours = document.querySelector("#hours").value;
|
||||||
|
var minutes = document.querySelector("#minutes").value;
|
||||||
|
CreateMonitorTask(connectorSelect.value, toEditId, `${hours}:${minutes}:00`, "en");
|
||||||
|
HidePublicationPopup();
|
||||||
|
createMonitorTaskPopup.style.display = "none";
|
||||||
|
selectPublicationPopup.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
function OpenDownloadChapterTaskPopup(){
|
||||||
|
selectedChapters.value = "";
|
||||||
|
chapterOutput.replaceChildren();
|
||||||
|
createDownloadChaptersTask.style.display = "block";
|
||||||
|
GetChapters(toEditId, connectorSelect.value, true, "en").then((json) => {
|
||||||
|
var i = 0;
|
||||||
|
json.forEach(chapter => {
|
||||||
|
var chapterDom = document.createElement("div");
|
||||||
|
var indexDom = document.createElement("span");
|
||||||
|
indexDom.className = "index";
|
||||||
|
indexDom.innerText = i++;
|
||||||
|
chapterDom.appendChild(indexDom);
|
||||||
|
|
||||||
|
var volDom = document.createElement("span");
|
||||||
|
volDom.className = "vol";
|
||||||
|
volDom.innerText = chapter.volumeNumber;
|
||||||
|
chapterDom.appendChild(volDom);
|
||||||
|
|
||||||
|
var chDom = document.createElement("span");
|
||||||
|
chDom.className = "ch";
|
||||||
|
chDom.innerText = chapter.chapterNumber;
|
||||||
|
chapterDom.appendChild(chDom);
|
||||||
|
|
||||||
|
var titleDom = document.createElement("span");
|
||||||
|
titleDom.innerText = chapter.name;
|
||||||
|
chapterDom.appendChild(titleDom);
|
||||||
|
chapterOutput.appendChild(chapterDom);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function DownloadChapterTaskClick(){
|
||||||
|
CreateDownloadChaptersTask(connectorSelect.value, toEditId, selectedChapters.value, "en");
|
||||||
|
HidePublicationPopup();
|
||||||
|
createDownloadChaptersTask.style.display = "none";
|
||||||
|
selectPublicationPopup.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
function DeleteTaskClick(){
|
function DeleteTaskClick(){
|
||||||
taskToDelete = tasks.filter(tTask => tTask.publication.internalId === toEditId)[0];
|
taskToDelete = tasks.filter(tTask => tTask.publication.internalId === toEditId)[0];
|
||||||
DeleteTask("DownloadNewChapters", taskToDelete.connectorName, toEditId);
|
DeleteTask("DownloadNewChapters", taskToDelete.connectorName, toEditId);
|
||||||
HidePublicationPopup();
|
HidePublicationPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
function AddTaskClick(){
|
function StartTaskClick(){
|
||||||
CreateTask("DownloadNewChapters", selectRecurrence.value, connectorSelect.value, toEditId, "en")
|
var toEditTask = tasks.filter(task => task.publication.internalId == toEditId)[0];
|
||||||
HideAddTaskPopup();
|
StartTask("DownloadNewChapters", toEditTask.connectorName, toEditId);
|
||||||
HidePublicationPopup();
|
HidePublicationPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,8 +219,6 @@ function ResetContent(){
|
|||||||
tasksContent.appendChild(add);
|
tasksContent.appendChild(add);
|
||||||
}
|
}
|
||||||
function ShowPublicationViewerWindow(publicationId, event, add){
|
function ShowPublicationViewerWindow(publicationId, event, add){
|
||||||
|
|
||||||
|
|
||||||
//Show popup
|
//Show popup
|
||||||
publicationViewerPopup.style.display = "block";
|
publicationViewerPopup.style.display = "block";
|
||||||
|
|
||||||
@ -155,19 +236,24 @@ function ShowPublicationViewerWindow(publicationId, event, add){
|
|||||||
//Edit information inside the window
|
//Edit information inside the window
|
||||||
var publication = publications.filter(pub => pub.internalId === publicationId)[0];
|
var publication = publications.filter(pub => pub.internalId === publicationId)[0];
|
||||||
publicationViewerName.innerText = publication.sortName;
|
publicationViewerName.innerText = publication.sortName;
|
||||||
|
publicationViewerTags.innerText = publication.tags.join(", ");
|
||||||
publicationViewerDescription.innerText = publication.description;
|
publicationViewerDescription.innerText = publication.description;
|
||||||
publicationViewerAuthor.innerText = publication.author;
|
publicationViewerAuthor.innerText = publication.authors.join(',');
|
||||||
pubviewcover.src = `imageCache/${publication.coverFileNameInCache}`;
|
pubviewcover.src = `imageCache/${publication.coverFileNameInCache}`;
|
||||||
toEditId = publicationId;
|
toEditId = publicationId;
|
||||||
|
|
||||||
//Check what action should be listed
|
//Check what action should be listed
|
||||||
if(add){
|
if(add){
|
||||||
publicationAdd.style.display = "block";
|
createMonitorTaskButton.style.display = "initial";
|
||||||
|
createDownloadChapterTaskButton.style.display = "initial";
|
||||||
publicationDelete.style.display = "none";
|
publicationDelete.style.display = "none";
|
||||||
|
publicationTaskStart.style.display = "none";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
publicationAdd.style.display = "none";
|
createMonitorTaskButton.style.display = "none";
|
||||||
publicationDelete.style.display = "block";
|
createDownloadChapterTaskButton.style.display = "none";
|
||||||
|
publicationDelete.style.display = "initial";
|
||||||
|
publicationTaskStart.style.display = "initial";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,10 +263,8 @@ function HidePublicationPopup(){
|
|||||||
|
|
||||||
function ShowNewTaskWindow(){
|
function ShowNewTaskWindow(){
|
||||||
selectPublication.replaceChildren();
|
selectPublication.replaceChildren();
|
||||||
addTaskPopup.style.display = "block";
|
searchPublicationQuery.value = "";
|
||||||
}
|
selectPublicationPopup.style.display = "flex";
|
||||||
function HideAddTaskPopup(){
|
|
||||||
addTaskPopup.style.display = "none";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -200,46 +284,173 @@ function OpenSettings(){
|
|||||||
settingsPopup.style.display = "flex";
|
settingsPopup.style.display = "flex";
|
||||||
}
|
}
|
||||||
|
|
||||||
function HideSettings(){
|
|
||||||
settingsPopup.style.display = "none";
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetSettingsClick(){
|
function GetSettingsClick(){
|
||||||
settingApiUri.value = "";
|
settingApiUri.value = "";
|
||||||
settingKomgaUrl.value = "";
|
settingKomgaUrl.value = "";
|
||||||
settingKomgaUser.value = "";
|
settingKomgaUser.value = "";
|
||||||
settingKomgaPass.value = "";
|
settingKomgaPass.value = "";
|
||||||
|
settingKomgaConfigured.innerText = "❌";
|
||||||
|
settingKavitaUrl.value = "";
|
||||||
|
settingKavitaUser.value = "";
|
||||||
|
settingKavitaPass.value = "";
|
||||||
|
settingKavitaConfigured.innerText = "❌";
|
||||||
|
settingGotifyUrl.value = "";
|
||||||
|
settingGotifyAppToken.value = "";
|
||||||
|
settingGotifyConfigured.innerText = "❌";
|
||||||
|
settingLunaseaWebhook.value = "";
|
||||||
|
settingLunaseaConfigured.innerText = "❌";
|
||||||
|
|
||||||
settingApiUri.placeholder = apiUri;
|
settingApiUri.placeholder = apiUri;
|
||||||
|
|
||||||
GetSettings().then(json => {
|
GetSettings().then(json => {
|
||||||
settingDownloadLocation.innerText = json.downloadLocation;
|
settingDownloadLocation.innerText = json.downloadLocation;
|
||||||
if(json.komga != null)
|
json.libraryManagers.forEach(lm => {
|
||||||
settingKomgaUrl.placeholder = json.komga.baseUrl;
|
if(lm.libraryType == 0){
|
||||||
|
settingKomgaUrl.placeholder = lm.baseUrl;
|
||||||
|
settingKomgaUser.placeholder = "User";
|
||||||
|
settingKomgaPass.placeholder = "***";
|
||||||
|
settingKomgaConfigured.innerText = "✅";
|
||||||
|
} else if(lm.libraryType == 1){
|
||||||
|
settingKavitaUrl.placeholder = lm.baseUrl;
|
||||||
|
settingKavitaUser.placeholder = "User";
|
||||||
|
settingKavitaPass.placeholder = "***";
|
||||||
|
settingKavitaConfigured.innerText = "✅";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
json.notificationManagers.forEach(nm => {
|
||||||
|
if(nm.notificationManagerType == 0){
|
||||||
|
settingGotifyConfigured.innerText = "✅";
|
||||||
|
} else if(nm.notificationManagerType == 1){
|
||||||
|
settingLunaseaConfigured.innerText = "✅";
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
GetKomgaTask().then(json => {
|
GetKomgaTask().then(json => {
|
||||||
if(json.length > 0)
|
if(json.length > 0)
|
||||||
settingKomgaConfigured.innerText = "✅";
|
libraryUpdateTime.value = json[0].reoccurrence;
|
||||||
else
|
|
||||||
settingKomgaConfigured.innerText = "❌";
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function UpdateKomgaSettings(){
|
function UpdateLibrarySettings(){
|
||||||
var auth = utf8_to_b64(`${settingKomgaUser.value}:${settingKomgaPass.value}`);
|
if(settingKomgaUrl.value != "" && settingKomgaUser.value != "" && settingKomgaPass.value != ""){
|
||||||
console.log(auth);
|
var auth = utf8_to_b64(`${settingKomgaUser.value}:${settingKomgaPass.value}`);
|
||||||
UpdateSettings("", settingKomgaUrl.value, auth);
|
console.log(auth);
|
||||||
CreateTask("UpdateKomgaLibrary", settingKomgaTime.value, "","","");
|
UpdateKomga(settingKomgaUrl.value, auth);
|
||||||
setTimeout(() => GetSettingsClick(), 500);
|
CreateUpdateLibraryTask(libraryUpdateTime.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(settingKavitaUrl.value != "" && settingKavitaUser.value != "" && settingKavitaPass.value != ""){
|
||||||
|
UpdateKavita(settingKavitaUrl.value, settingKavitaUser.value, settingKavitaPass.value);
|
||||||
|
CreateUpdateLibraryTask(libraryUpdateTime.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(settingGotifyUrl.value != "" && settingGotifyAppToken.value != ""){
|
||||||
|
UpdateGotify(settingGotifyUrl.value, settingGotifyAppToken.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(settingLunaseaWebhook.value != ""){
|
||||||
|
UpdateLunaSea(settingLunaseaWebhook.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => GetSettingsClick(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
function utf8_to_b64( str ) {
|
function utf8_to_b64( str ) {
|
||||||
return window.btoa(unescape(encodeURIComponent( str )));
|
return window.btoa(unescape(encodeURIComponent( str )));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function FilterResults(){
|
||||||
|
if(searchBox.value.length > 0){
|
||||||
|
tasksContent.childNodes.forEach(publication => {
|
||||||
|
publication.childNodes.forEach(item => {
|
||||||
|
if(item.nodeName.toLowerCase() == "publication-information"){
|
||||||
|
item.childNodes.forEach(information => {
|
||||||
|
if(information.nodeName.toLowerCase() == "publication-name"){
|
||||||
|
if(!information.textContent.toLowerCase().includes(searchBox.value.toLowerCase())){
|
||||||
|
publication.style.display = "none";
|
||||||
|
}else{
|
||||||
|
publication.style.display = "initial";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
tasksContent.childNodes.forEach(publication => publication.style.display = "initial");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ShowTasksQueue(){
|
||||||
|
|
||||||
|
downloadTasksOutput.replaceChildren();
|
||||||
|
GetRunningTasks()
|
||||||
|
.then(json => {
|
||||||
|
tagTasksRunning.innerText = json.length;
|
||||||
|
json.forEach(task => {
|
||||||
|
if(task.task == 2 || task.task == 4) {
|
||||||
|
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
||||||
|
document.querySelector(`#progress${GetValidSelector(task.taskId)}`).value = task.progress;
|
||||||
|
var finishedHours = task.executionApproximatelyRemaining.split(':')[0];
|
||||||
|
var finishedMinutes = task.executionApproximatelyRemaining.split(':')[1];
|
||||||
|
var finishedSeconds = task.executionApproximatelyRemaining.split(':')[2].split('.')[0];
|
||||||
|
document.querySelector(`#progressStr${GetValidSelector(task.taskId)}`).innerText = `${finishedHours}:${finishedMinutes}:${finishedSeconds}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
GetQueue()
|
||||||
|
.then(json => {
|
||||||
|
tagTasksQueued.innerText = json.length;
|
||||||
|
json.forEach(task => {
|
||||||
|
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
downloadTasksPopup.style.display = "flex";
|
||||||
|
}
|
||||||
|
|
||||||
|
function CreateProgressChild(task){
|
||||||
|
var child = document.createElement("div");
|
||||||
|
var img = document.createElement('img');
|
||||||
|
img.src = `imageCache/${task.publication.coverFileNameInCache}`;
|
||||||
|
child.appendChild(img);
|
||||||
|
|
||||||
|
var name = document.createElement("span");
|
||||||
|
name.innerText = task.publication.sortName;
|
||||||
|
name.className = "pubTitle";
|
||||||
|
child.appendChild(name);
|
||||||
|
|
||||||
|
|
||||||
|
var progress = document.createElement("progress");
|
||||||
|
progress.id = `progress${GetValidSelector(task.taskId)}`;
|
||||||
|
child.appendChild(progress);
|
||||||
|
|
||||||
|
var progressStr = document.createElement("span");
|
||||||
|
progressStr.innerText = " \t∞";
|
||||||
|
progressStr.className = "progressStr";
|
||||||
|
progressStr.id = `progressStr${GetValidSelector(task.taskId)}`;
|
||||||
|
child.appendChild(progressStr);
|
||||||
|
|
||||||
|
if(task.chapter != undefined){
|
||||||
|
var chapterNumber = document.createElement("span");
|
||||||
|
chapterNumber.className = "chapterNumber";
|
||||||
|
chapterNumber.innerText = `Vol.${task.chapter.volumeNumber} Ch.${task.chapter.chapterNumber}`;
|
||||||
|
child.appendChild(chapterNumber);
|
||||||
|
|
||||||
|
var chapterName = document.createElement("span");
|
||||||
|
chapterName.className = "chapterName";
|
||||||
|
chapterName.innerText = task.chapter.name;
|
||||||
|
child.appendChild(chapterName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
//Resets the tasks shown
|
//Resets the tasks shown
|
||||||
ResetContent();
|
ResetContent();
|
||||||
|
downloadTasksOutput.replaceChildren();
|
||||||
//Get Tasks and show them
|
//Get Tasks and show them
|
||||||
GetDownloadTasks()
|
GetDownloadTasks()
|
||||||
.then(json => json.forEach(task => {
|
.then(json => json.forEach(task => {
|
||||||
@ -252,16 +463,17 @@ GetDownloadTasks()
|
|||||||
GetRunningTasks()
|
GetRunningTasks()
|
||||||
.then(json => {
|
.then(json => {
|
||||||
tagTasksRunning.innerText = json.length;
|
tagTasksRunning.innerText = json.length;
|
||||||
});
|
json.forEach(task => {
|
||||||
|
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
||||||
GetDownloadTasks()
|
});
|
||||||
.then(json => {
|
|
||||||
tagTasksTotal.innerText = json.length;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
GetQueue()
|
GetQueue()
|
||||||
.then(json => {
|
.then(json => {
|
||||||
tagTasksQueued.innerText = json.length;
|
tagTasksQueued.innerText = json.length;
|
||||||
|
json.forEach(task => {
|
||||||
|
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
@ -290,15 +502,28 @@ setInterval(() => {
|
|||||||
.then(json => {
|
.then(json => {
|
||||||
tagTasksRunning.innerText = json.length;
|
tagTasksRunning.innerText = json.length;
|
||||||
});
|
});
|
||||||
|
|
||||||
GetDownloadTasks()
|
|
||||||
.then(json => {
|
|
||||||
tagTasksTotal.innerText = json.length;
|
|
||||||
});
|
|
||||||
|
|
||||||
GetQueue()
|
GetQueue()
|
||||||
.then(json => {
|
.then(json => {
|
||||||
tagTasksQueued.innerText = json.length;
|
tagTasksQueued.innerText = json.length;
|
||||||
})
|
});
|
||||||
|
}, 1000);
|
||||||
}, 1000);
|
|
||||||
|
setInterval(() => {
|
||||||
|
GetRunningTasks().then((json) => {
|
||||||
|
json.forEach(task => {
|
||||||
|
if(task.task == 2 || task.task == 4){
|
||||||
|
document.querySelector(`#progress${GetValidSelector(task.taskId)}`).value = task.progress;
|
||||||
|
var finishedHours = task.executionApproximatelyRemaining.split(':')[0];
|
||||||
|
var finishedMinutes = task.executionApproximatelyRemaining.split(':')[1];
|
||||||
|
var finishedSeconds = task.executionApproximatelyRemaining.split(':')[2].split('.')[0];
|
||||||
|
document.querySelector(`#progressStr${GetValidSelector(task.taskId)}`).innerText = `${finishedHours}:${finishedMinutes}:${finishedSeconds}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},500);
|
||||||
|
|
||||||
|
function GetValidSelector(str){
|
||||||
|
var clean = [...str.matchAll(/[a-zA-Z0-9]*-*_*/g)];
|
||||||
|
return clean.join('');
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
:root{
|
:root{
|
||||||
--background-color: #eee;
|
--background-color: #030304;
|
||||||
--second-background-color: #fff;
|
--second-background-color: #fff;
|
||||||
--primary-color: #f5a9b8;
|
--primary-color: #f5a9b8;
|
||||||
--secondary-color: #5bcefa;
|
--secondary-color: #5bcefa;
|
||||||
@ -11,15 +11,19 @@
|
|||||||
body{
|
body{
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
display: flex;
|
|
||||||
flex-flow: column;
|
|
||||||
flex-wrap: nowrap;
|
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
background-color: var(--background-color);
|
background-color: var(--background-color);
|
||||||
font-family: "Inter", sans-serif;
|
font-family: "Inter", sans-serif;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: column;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
background-placeholder{
|
background-placeholder{
|
||||||
background-color: var(--second-background-color);
|
background-color: var(--second-background-color);
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
@ -49,6 +53,7 @@ titlebox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
titlebox span{
|
titlebox span{
|
||||||
|
cursor: default;
|
||||||
font-size: 24pt;
|
font-size: 24pt;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
background: linear-gradient(150deg, var(--primary-color), var(--accent-color));
|
background: linear-gradient(150deg, var(--primary-color), var(--accent-color));
|
||||||
@ -60,6 +65,7 @@ titlebox span{
|
|||||||
titlebox img {
|
titlebox img {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
cursor: grab;
|
||||||
}
|
}
|
||||||
|
|
||||||
spacer{
|
spacer{
|
||||||
@ -115,6 +121,7 @@ footer > div {
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
flex-wrap: nowrap;
|
flex-wrap: nowrap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
footer > div > *{
|
footer > div > *{
|
||||||
@ -126,6 +133,7 @@ footer > div > *{
|
|||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
margin-right: 20px;
|
margin-right: 20px;
|
||||||
|
cursor: url("media/blahaj.png"), grab;
|
||||||
}
|
}
|
||||||
|
|
||||||
content {
|
content {
|
||||||
@ -139,46 +147,22 @@ content {
|
|||||||
align-content: start;
|
align-content: start;
|
||||||
}
|
}
|
||||||
|
|
||||||
settings {
|
|
||||||
width: 50%;
|
|
||||||
background-color: var(--accent-color);
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
z-index: 10;
|
|
||||||
position: absolute;
|
|
||||||
left: 25%;
|
|
||||||
top: 25%;
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 10px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#settingsPopup{
|
#settingsPopup{
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
settings > * {
|
#settingsPopup popup-content{
|
||||||
margin: 0 20%;
|
|
||||||
}
|
|
||||||
|
|
||||||
settings input {
|
|
||||||
margin: 3px 0;
|
|
||||||
padding: 3px;
|
|
||||||
border-radius: 3px;
|
|
||||||
border: 1px solid rgba(0,0,0,0.2);
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
settings .title {
|
|
||||||
font-weight: bolder;
|
|
||||||
font-size: 14pt;
|
|
||||||
margin: 15px 0 2px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
komga-settings {
|
|
||||||
margin-top: 20px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
flex-wrap: nowrap;
|
align-items: start;
|
||||||
|
margin: 15px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#settingsPopup popup-content > * {
|
||||||
|
margin: 5px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#settingsPopup popup-content .title {
|
||||||
|
font-weight: bolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
#addPublication {
|
#addPublication {
|
||||||
@ -229,7 +213,7 @@ publication::after{
|
|||||||
left: 0; top: 0;
|
left: 0; top: 0;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
width: 100%; height: 100%;
|
width: 100%; height: 100%;
|
||||||
background: linear-gradient(rgba(0,0,0,0.7), rgba(0, 0, 0, 0.6),rgba(0, 0, 0, 0.2));
|
background: linear-gradient(rgba(0,0,0,0.8), rgba(0, 0, 0, 0.7),rgba(0, 0, 0, 0.2));
|
||||||
}
|
}
|
||||||
|
|
||||||
publication-information {
|
publication-information {
|
||||||
@ -273,6 +257,186 @@ popup{
|
|||||||
left: 0;
|
left: 0;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
popup popup-window {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 3;
|
||||||
|
left: 25%;
|
||||||
|
top: 100px;
|
||||||
|
width: 50%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background-color: var(--second-background-color);
|
||||||
|
border-radius: 3px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
popup popup-window popup-title {
|
||||||
|
height: 30px;
|
||||||
|
font-size: 14pt;
|
||||||
|
font-weight: bolder;
|
||||||
|
padding: 5px 10px;
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
color: var(--accent-color)
|
||||||
|
}
|
||||||
|
|
||||||
|
popup popup-window popup-content{
|
||||||
|
margin: 15px 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
popup popup-window popup-content div > * {
|
||||||
|
margin: 2px 3px 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
popup popup-window popup-content input, select {
|
||||||
|
padding: 3px 4px;
|
||||||
|
width: 130px;
|
||||||
|
border: 1px solid lightgrey;
|
||||||
|
background-color: var(--accent-color);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#selectPublicationPopup publication {
|
||||||
|
width: 150px;
|
||||||
|
height: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createTaskPopup {
|
||||||
|
z-index: 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createTaskPopup input {
|
||||||
|
height: 30px;
|
||||||
|
width: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createMonitorTaskPopup, #createDownloadChaptersTask {
|
||||||
|
z-index: 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createMonitorTaskPopup input[type="number"] {
|
||||||
|
width: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createDownloadChaptersTask popup-content {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createDownloadChaptersTask popup-content > * {
|
||||||
|
margin: 3px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createDownloadChaptersTask #chapterOutput {
|
||||||
|
max-height: 50vh;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createDownloadChaptersTask #chapterOutput .index{
|
||||||
|
display: inline-block;
|
||||||
|
width: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createDownloadChaptersTask #chapterOutput .index::after{
|
||||||
|
content: ':';
|
||||||
|
}
|
||||||
|
|
||||||
|
#createDownloadChaptersTask #chapterOutput .vol::before{
|
||||||
|
content: 'Vol.';
|
||||||
|
}
|
||||||
|
|
||||||
|
#createDownloadChaptersTask #chapterOutput .vol{
|
||||||
|
display: inline-block;
|
||||||
|
width: 45px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#createDownloadChaptersTask #chapterOutput .ch::before{
|
||||||
|
content: 'Ch.';
|
||||||
|
}
|
||||||
|
|
||||||
|
#createDownloadChaptersTask #chapterOutput .ch {
|
||||||
|
display: inline-block;
|
||||||
|
width: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-window {
|
||||||
|
left: 0;
|
||||||
|
top: 80px;
|
||||||
|
margin: 0 0 0 10px;
|
||||||
|
height: calc(100vh - 140px);
|
||||||
|
width: 400px;
|
||||||
|
max-width: 95vw;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-content {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: start;
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-content > div {
|
||||||
|
display: block;
|
||||||
|
height: 80px;
|
||||||
|
position: relative;
|
||||||
|
margin: 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-content > div > img {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
height: 100%;
|
||||||
|
width: 60px;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-content > div > span {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
width: max-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-content > div > .pubTitle {
|
||||||
|
left: 70px;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-content > div > .chapterName {
|
||||||
|
left: 70px;
|
||||||
|
top: 28pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-content > div > .chapterNumber {
|
||||||
|
left: 70px;
|
||||||
|
top: 14pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-content > div > progress {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
left: 150px;
|
||||||
|
bottom: 0;
|
||||||
|
width: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloadTasksPopup popup-content > div > .progressStr {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
left: 70px;
|
||||||
|
bottom: 0;
|
||||||
|
width: 70px;
|
||||||
}
|
}
|
||||||
|
|
||||||
blur-background {
|
blur-background {
|
||||||
@ -284,85 +448,14 @@ blur-background {
|
|||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
addtask-window {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
flex-wrap: nowrap;
|
|
||||||
position: absolute;
|
|
||||||
left: 12.5%;
|
|
||||||
top: 15%;
|
|
||||||
width: 75%;
|
|
||||||
min-height: 70%;
|
|
||||||
max-height: 80%;
|
|
||||||
padding: 0;
|
|
||||||
background-color: var(--accent-color);
|
|
||||||
border-radius: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
window-titlebar {
|
|
||||||
width: 100%;
|
|
||||||
height: 60px;
|
|
||||||
background-color: var(--primary-color);
|
|
||||||
border-radius: 5px 5px 0 0;
|
|
||||||
color: var(--accent-color);
|
|
||||||
display: flex block;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
window-titlebar p {
|
|
||||||
margin: 0 30px;
|
|
||||||
font-size: 14pt;
|
|
||||||
font-weight: bolder;
|
|
||||||
letter-spacing: 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
window-titlebar #closePopupImg {
|
|
||||||
height: 70%;
|
|
||||||
cursor: pointer;
|
|
||||||
margin-right: 20px;
|
|
||||||
filter: invert(100%) sepia(0%) saturate(100%) hue-rotate(115deg) brightness(116%) contrast(101%);
|
|
||||||
}
|
|
||||||
|
|
||||||
window-content {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 20px 5%;
|
|
||||||
overflow-x: scroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
addtask-settings{
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
addtask-settings select, addtask-settings input{
|
|
||||||
padding: 5px;
|
|
||||||
font-size: 10pt;
|
|
||||||
border: 1px solid rgba(0,0,0,0.2);
|
|
||||||
border-radius: 3px;
|
|
||||||
background-color: transparent;
|
|
||||||
margin: 10px 0;
|
|
||||||
width: 150px;
|
|
||||||
}
|
|
||||||
|
|
||||||
addtask-settings label {
|
|
||||||
font-weight: bolder;
|
|
||||||
margin: 0 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
addtask-settings addtask-setting{
|
|
||||||
margin: 0 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#taskSelectOutput{
|
#taskSelectOutput{
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: start;
|
justify-content: start;
|
||||||
align-content: start;
|
align-content: start;
|
||||||
|
max-height: 70vh;
|
||||||
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
#publicationViewerPopup{
|
#publicationViewerPopup{
|
||||||
@ -372,17 +465,13 @@ addtask-settings addtask-setting{
|
|||||||
publication-viewer{
|
publication-viewer{
|
||||||
display: block;
|
display: block;
|
||||||
width: 450px;
|
width: 450px;
|
||||||
height: 300px;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 200px;
|
top: 200px;
|
||||||
left: 400px;
|
left: 400px;
|
||||||
background-color: var(--accent-color);
|
background-color: var(--accent-color);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
padding: 15px;
|
||||||
|
|
||||||
publication-viewer{
|
|
||||||
padding: 30px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publication-viewer::after{
|
publication-viewer::after{
|
||||||
@ -390,7 +479,8 @@ publication-viewer::after{
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0; top: 0;
|
left: 0; top: 0;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
width: 100%; height: 100%;
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
background: rgba(0,0,0,0.8);
|
background: rgba(0,0,0,0.8);
|
||||||
backdrop-filter: blur(3px);
|
backdrop-filter: blur(3px);
|
||||||
}
|
}
|
||||||
@ -406,16 +496,32 @@ publication-viewer img {
|
|||||||
z-index: 0;
|
z-index: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
publication-viewer publication-information publication-name{
|
publication-viewer publication-information > * {
|
||||||
margin: 5px 0;
|
margin: 5px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
publication-viewer publication-information publication-author {
|
publication-viewer publication-information publication-name {
|
||||||
margin: 5px 0;
|
width: initial;
|
||||||
|
overflow-x: scroll;
|
||||||
|
white-space: nowrap;
|
||||||
|
scrollbar-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
publication-viewer publication-information publication-tags::before {
|
||||||
|
content: "Tags";
|
||||||
|
display: block;
|
||||||
|
font-weight: bolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
publication-viewer publication-information publication-tags {
|
||||||
|
overflow-x: scroll;
|
||||||
|
white-space: nowrap;
|
||||||
|
scrollbar-width: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
publication-viewer publication-information publication-author::before {
|
publication-viewer publication-information publication-author::before {
|
||||||
content: "Author: ";
|
content: "Author: ";
|
||||||
|
font-weight: bolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
publication-viewer publication-information publication-description::before {
|
publication-viewer publication-information publication-description::before {
|
||||||
@ -427,24 +533,71 @@ publication-viewer publication-information publication-description::before {
|
|||||||
publication-viewer publication-information publication-description {
|
publication-viewer publication-information publication-description {
|
||||||
font-size: 12pt;
|
font-size: 12pt;
|
||||||
margin: 5px 0;
|
margin: 5px 0;
|
||||||
max-height: 200px;
|
height: 145px;
|
||||||
overflow-x: scroll;
|
overflow-x: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
publication-viewer publication-information publication-delete {
|
publication-viewer publication-information publication-interactions {
|
||||||
position: absolute;
|
display: flex;
|
||||||
bottom: 0px;
|
flex-direction: row;
|
||||||
right: 0px;
|
justify-content: end;
|
||||||
color: red;
|
align-items: start;
|
||||||
margin: 20px;
|
width: 100%;
|
||||||
font-size: 16pt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publication-viewer publication-information publication-add {
|
publication-viewer publication-information publication-interactions > * {
|
||||||
position: absolute;
|
margin: 0 10px;
|
||||||
bottom: 0px;
|
|
||||||
right: 0px;
|
|
||||||
color: limegreen;
|
|
||||||
margin: 20px;
|
|
||||||
font-size: 16pt;
|
font-size: 16pt;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
publication-viewer publication-information publication-interactions publication-starttask {
|
||||||
|
color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
publication-viewer publication-information publication-interactions publication-delete {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
publication-viewer publication-information publication-interactions publication-add {
|
||||||
|
color: limegreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer-tag-popup {
|
||||||
|
display: none;
|
||||||
|
padding: 2px 4px;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 58px;
|
||||||
|
left: 20px;
|
||||||
|
background-color: var(--second-background-color);
|
||||||
|
z-index: 8;
|
||||||
|
border-radius: 5px;
|
||||||
|
max-height: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer-tag-content{
|
||||||
|
position: relative;
|
||||||
|
max-height: 400px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer-tag-content > * {
|
||||||
|
margin: 2px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer-tag-popup::before{
|
||||||
|
content: "";
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
position: absolute;
|
||||||
|
border-right: 10px solid var(--second-background-color);
|
||||||
|
border-left: 10px solid transparent;
|
||||||
|
border-top: 10px solid var(--second-background-color);
|
||||||
|
border-bottom: 10px solid transparent;
|
||||||
|
left: 0;
|
||||||
|
bottom: -17px;
|
||||||
|
border-radius: 0 0 0 5px;
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
services:
|
version: '3'
|
||||||
|
services:
|
||||||
tranga-api:
|
tranga-api:
|
||||||
image: glax/tranga-api:latest
|
image: glax/tranga-api:latest
|
||||||
container_name: tranga-api
|
container_name: tranga-api
|
||||||
@ -6,7 +7,7 @@
|
|||||||
- ./tranga:/usr/share/Tranga-API #1 when replacing ./tranga replace #2 with same value
|
- ./tranga:/usr/share/Tranga-API #1 when replacing ./tranga replace #2 with same value
|
||||||
- ./Manga:/Manga
|
- ./Manga:/Manga
|
||||||
ports:
|
ports:
|
||||||
- 6531:80
|
- "6531:6531"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
tranga-website:
|
tranga-website:
|
||||||
image: glax/tranga-website:latest
|
image: glax/tranga-website:latest
|
||||||
@ -14,6 +15,7 @@
|
|||||||
volumes:
|
volumes:
|
||||||
- ./tranga/imageCache:/usr/share/nginx/html/imageCache:ro #2 when replacing Point to same value as #1/imageCache
|
- ./tranga/imageCache:/usr/share/nginx/html/imageCache:ro #2 when replacing Point to same value as #1/imageCache
|
||||||
ports:
|
ports:
|
||||||
- 9555:80
|
- "9555:80"
|
||||||
depends_on:
|
depends_on:
|
||||||
- tranga-api
|
- tranga-api
|
||||||
|
restart: unless-stopped
|
Reference in New Issue
Block a user