mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-14 15:27:53 +02:00
Compare commits
118 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 |
@ -1,10 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>Tranga_API</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
@ -15,14 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Logging\Logging.csproj" />
|
||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||
</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>
|
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 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
|
||||
COPY --from=build-env /publish .
|
||||
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)
|
||||
{
|
||||
_logMessages.Add(value.logTime, value);
|
||||
while(!_logMessages.TryAdd(value.logTime, value))
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
public string[] GetLogMessage()
|
||||
|
34
README.md
34
README.md
@ -36,6 +36,7 @@
|
||||
<li>
|
||||
<a href="#getting-started">Getting Started</a>
|
||||
<ul>
|
||||
<li><a href="#prerequisites">Usage</a></li>
|
||||
<li><a href="#prerequisites">Prerequisites</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@ -55,8 +56,9 @@ Tranga can download Chapters and Metadata from Scanlation sites such as
|
||||
|
||||
- [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:
|
||||
|
||||
@ -72,6 +74,8 @@ That is why I wanted to create my own project, in a language I understand, and t
|
||||
|
||||
- .NET-Core
|
||||
- Newtonsoft.JSON
|
||||
- [PuppeteerSharp](https://www.puppeteersharp.com/)
|
||||
- [Html Agility Pack (HAP)](https://html-agility-pack.net/)
|
||||
- Love <3 Blåhaj 🦈
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
@ -106,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.
|
||||
|
||||
### 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
|
||||
|
||||
[.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
|
||||
|
||||
- [x] Web-UI #1
|
||||
- [ ] More Connectors
|
||||
- [x] Manganato #2
|
||||
- [ ] Docker ARM support
|
||||
- [ ] ?
|
||||
|
||||
See the [open issues](https://git.bernloehr.eu/glax/Tranga/issues) for a full list of proposed features (and known issues).
|
||||
|
@ -1,216 +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, logger);
|
||||
else
|
||||
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, new HashSet<LibraryManager>());
|
||||
|
||||
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.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.MapGet("/Tasks/GetTaskProgress", (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 -1f;
|
||||
|
||||
return task.progress;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return -1f;
|
||||
}
|
||||
});
|
||||
|
||||
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, string? kavitaUrl, string? kavitaApiKey) =>
|
||||
taskManager.UpdateSettings(downloadLocation, komgaUrl, komgaAuth, kavitaUrl, kavitaApiKey));
|
||||
|
||||
app.Run();
|
@ -1,28 +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"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7036;http://localhost:5177"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -2,6 +2,8 @@
|
||||
using Logging;
|
||||
using Tranga;
|
||||
using Tranga.LibraryManagers;
|
||||
using Tranga.NotificationManagers;
|
||||
using Tranga.TrangaTasks;
|
||||
|
||||
namespace Tranga_CLI;
|
||||
|
||||
@ -29,7 +31,7 @@ public static class Tranga_Cli
|
||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, Console.Out.Encoding, logFilePath);
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
||||
TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath, logger) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, new HashSet<LibraryManager>());
|
||||
TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath, logger) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, new HashSet<LibraryManager>(), new HashSet<NotificationManager>());
|
||||
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "User Input");
|
||||
@ -38,7 +40,7 @@ public static class Tranga_Cli
|
||||
while(tmpPath is null)
|
||||
tmpPath = Console.ReadLine();
|
||||
if (tmpPath.Length > 0)
|
||||
settings.downloadLocation = tmpPath;
|
||||
settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, logger, tmpPath);
|
||||
|
||||
Console.WriteLine($"Komga BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Komga))?.baseUrl}]:");
|
||||
string? tmpUrlKomga = Console.ReadLine();
|
||||
@ -47,32 +49,31 @@ public static class Tranga_Cli
|
||||
if (tmpUrlKomga.Length > 0)
|
||||
{
|
||||
Console.WriteLine("Username:");
|
||||
string? tmpUser = Console.ReadLine();
|
||||
while (tmpUser is null || tmpUser.Length < 1)
|
||||
tmpUser = Console.ReadLine();
|
||||
string? tmpKomgaUser = Console.ReadLine();
|
||||
while (tmpKomgaUser is null || tmpKomgaUser.Length < 1)
|
||||
tmpKomgaUser = Console.ReadLine();
|
||||
|
||||
Console.WriteLine("Password:");
|
||||
string tmpPass = string.Empty;
|
||||
string tmpKomgaPass = string.Empty;
|
||||
ConsoleKey key;
|
||||
do
|
||||
{
|
||||
var keyInfo = Console.ReadKey(intercept: true);
|
||||
key = keyInfo.Key;
|
||||
|
||||
if (key == ConsoleKey.Backspace && tmpPass.Length > 0)
|
||||
if (key == ConsoleKey.Backspace && tmpKomgaPass.Length > 0)
|
||||
{
|
||||
Console.Write("\b \b");
|
||||
tmpPass = tmpPass[0..^1];
|
||||
tmpKomgaPass = tmpKomgaPass[0..^1];
|
||||
}
|
||||
else if (!char.IsControl(keyInfo.KeyChar))
|
||||
{
|
||||
Console.Write("*");
|
||||
tmpPass += keyInfo.KeyChar;
|
||||
tmpKomgaPass += keyInfo.KeyChar;
|
||||
}
|
||||
} while (key != ConsoleKey.Enter);
|
||||
|
||||
settings.libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Komga));
|
||||
settings.libraryManagers.Add(new Komga(tmpUrlKomga, tmpUser, tmpPass, logger));
|
||||
settings.UpdateSettings(TrangaSettings.UpdateField.Komga, logger, tmpUrlKomga, tmpKomgaUser, tmpKomgaPass);
|
||||
}
|
||||
|
||||
Console.WriteLine($"Kavita BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Kavita))?.baseUrl}]:");
|
||||
@ -82,15 +83,50 @@ public static class Tranga_Cli
|
||||
if (tmpUrlKavita.Length > 0)
|
||||
{
|
||||
Console.WriteLine("Username:");
|
||||
string? tmpApiKey = Console.ReadLine();
|
||||
while (tmpApiKey is null || tmpApiKey.Length < 1)
|
||||
tmpApiKey = Console.ReadLine();
|
||||
string? tmpKavitaUser = Console.ReadLine();
|
||||
while (tmpKavitaUser is null || tmpKavitaUser.Length < 1)
|
||||
tmpKavitaUser = Console.ReadLine();
|
||||
|
||||
settings.libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Kavita));
|
||||
settings.libraryManagers.Add(new Kavita(tmpUrlKavita, tmpApiKey, 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.");
|
||||
foreach(NotificationManager nm in settings.notificationManagers)
|
||||
nm.SendNotification("Tranga", "Loaded.");
|
||||
TaskMode(settings, logger);
|
||||
}
|
||||
|
||||
@ -114,8 +150,12 @@ public static class Tranga_Cli
|
||||
switch (selection)
|
||||
{
|
||||
case ConsoleKey.L:
|
||||
while (!Console.KeyAvailable)
|
||||
{
|
||||
PrintTasks(taskManager.GetAllTasks(), logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.C:
|
||||
@ -139,17 +179,26 @@ public static class Tranga_Cli
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.R:
|
||||
while (!Console.KeyAvailable)
|
||||
{
|
||||
PrintTasks(
|
||||
taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running)
|
||||
.ToArray(), logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.K:
|
||||
while (!Console.KeyAvailable)
|
||||
{
|
||||
PrintTasks(
|
||||
taskManager.GetAllTasks().Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued)
|
||||
taskManager.GetAllTasks()
|
||||
.Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued)
|
||||
.ToArray(), logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.F:
|
||||
@ -219,18 +268,18 @@ public static class Tranga_Cli
|
||||
int tIndex = 0;
|
||||
Console.WriteLine($"Tasks (Running/Queue/Total): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
||||
string header =
|
||||
$"{"",-5}{"Task",-20} | {"Last Executed",-20} | {"Reoccurrence",-12} | {"State",-10} | {"Connector",-15} | {"Progress",-9} | 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(new string('-', header.Length));
|
||||
foreach (TrangaTask trangaTask in tasks)
|
||||
{
|
||||
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] : ""),-9} |{(taskSplit.Length > 6 ? taskSplit[6] : "")}");
|
||||
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");
|
||||
if (tasks.Length < 1)
|
||||
@ -238,13 +287,13 @@ public static class Tranga_Cli
|
||||
Console.Clear();
|
||||
Console.WriteLine("There are no available Tasks.");
|
||||
logger.WriteLine("Tranga_CLI", "No available Tasks.");
|
||||
return null;
|
||||
return Array.Empty<TrangaTask>();
|
||||
}
|
||||
PrintTasks(tasks, logger);
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Selecting Task to Remove (from queue)");
|
||||
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();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
@ -255,21 +304,20 @@ public static class Tranga_Cli
|
||||
Console.Clear();
|
||||
Console.WriteLine("aborted.");
|
||||
logger.WriteLine("Tranga_CLI", "aborted");
|
||||
return null;
|
||||
return Array.Empty<TrangaTask>();
|
||||
}
|
||||
|
||||
try
|
||||
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 tasks[selectedTaskIndex];
|
||||
return new[] { tasks[selectedTaskIndex] };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Exception: {e.Message}");
|
||||
logger.WriteLine("Tranga_CLI", e.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void AddMangaTaskToQueue(TaskManager taskManager, Logger logger)
|
||||
@ -287,8 +335,9 @@ public static class Tranga_Cli
|
||||
|
||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
TrangaTask newTask = taskManager.AddTask(TrangaTask.Task.DownloadNewChapters, connector.name, publication, reoccurrence, "en");
|
||||
Console.WriteLine(newTask);
|
||||
TrangaTask nTask = new MonitorPublicationTask(connector.name, (Publication)publication, reoccurrence, "en");
|
||||
taskManager.AddTask(nTask);
|
||||
Console.WriteLine(nTask);
|
||||
}
|
||||
|
||||
private static void AddTaskToQueue(TaskManager taskManager, Logger logger)
|
||||
@ -299,12 +348,10 @@ public static class Tranga_Cli
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask =>
|
||||
rTask.state is not TrangaTask.ExecutionState.Enqueued and not TrangaTask.ExecutionState.Running).ToArray();
|
||||
|
||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.AddTaskToQueue(selectedTask);
|
||||
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
||||
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
||||
foreach(TrangaTask task in selectedTasks)
|
||||
taskManager.AddTaskToQueue(task);
|
||||
}
|
||||
|
||||
private static void RemoveTaskFromQueue(TaskManager taskManager, Logger logger)
|
||||
@ -314,12 +361,10 @@ public static class Tranga_Cli
|
||||
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask => rTask.state is TrangaTask.ExecutionState.Enqueued).ToArray();
|
||||
|
||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.RemoveTaskFromQueue(selectedTask);
|
||||
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
||||
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
||||
foreach(TrangaTask task in selectedTasks)
|
||||
taskManager.RemoveTaskFromQueue(task);
|
||||
}
|
||||
|
||||
private static void TailLog(Logger logger)
|
||||
@ -364,10 +409,23 @@ public static class Tranga_Cli
|
||||
return;
|
||||
}
|
||||
|
||||
if (task is TrangaTask.Task.MonitorPublication)
|
||||
{
|
||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en");
|
||||
|
||||
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)
|
||||
@ -375,12 +433,10 @@ public static class Tranga_Cli
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Executing Task");
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(nTask => nTask.state is not TrangaTask.ExecutionState.Running).ToArray();
|
||||
|
||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.ExecuteTaskNow(selectedTask);
|
||||
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
||||
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
||||
foreach(TrangaTask task in selectedTasks)
|
||||
taskManager.ExecuteTaskNow(task);
|
||||
}
|
||||
|
||||
private static void DeleteTask(TaskManager taskManager, Logger logger)
|
||||
@ -388,12 +444,10 @@ public static class Tranga_Cli
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Delete Task");
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
|
||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.DeleteTask(selectedTask.task, selectedTask.connectorName, selectedTask.publication);
|
||||
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
||||
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
||||
foreach(TrangaTask task in selectedTasks)
|
||||
taskManager.DeleteTask(task);
|
||||
}
|
||||
|
||||
private static TrangaTask.Task? SelectTaskType(Logger logger)
|
||||
@ -444,6 +498,25 @@ public static class Tranga_Cli
|
||||
return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US"));
|
||||
}
|
||||
|
||||
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");
|
||||
|
10
Tranga.sln
10
Tranga.sln
@ -6,7 +6,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tr
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
||||
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
|
||||
Global
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.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}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,5 +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">
|
||||
<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/=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/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -20,16 +20,21 @@ public struct Chapter
|
||||
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
||||
{
|
||||
this.name = name;
|
||||
this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1";
|
||||
this.volumeNumber = volumeNumber;
|
||||
this.chapterNumber = chapterNumber;
|
||||
this.url = url;
|
||||
string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
|
||||
NumberFormatInfo nfi = new NumberFormatInfo()
|
||||
{
|
||||
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);
|
||||
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,8 +1,10 @@
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using Logging;
|
||||
using Tranga.TrangaTasks;
|
||||
using static System.IO.UnixFileMode;
|
||||
|
||||
namespace Tranga;
|
||||
@ -18,7 +20,7 @@ public abstract class Connector
|
||||
|
||||
protected readonly Logger? logger;
|
||||
|
||||
protected readonly string imageCachePath;
|
||||
private readonly string _imageCachePath;
|
||||
|
||||
protected Connector(string downloadLocation, string imageCachePath, Logger? logger)
|
||||
{
|
||||
@ -28,9 +30,9 @@ public abstract class Connector
|
||||
{
|
||||
//RequestTypes for RateLimits
|
||||
}, logger);
|
||||
this.imageCachePath = imageCachePath;
|
||||
this._imageCachePath = imageCachePath;
|
||||
if (!Directory.Exists(imageCachePath))
|
||||
Directory.CreateDirectory(this.imageCachePath);
|
||||
Directory.CreateDirectory(this._imageCachePath);
|
||||
}
|
||||
|
||||
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
||||
@ -52,6 +54,78 @@ public abstract class Connector
|
||||
/// <returns>Array of Chapters matching Publication and Language</returns>
|
||||
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>
|
||||
/// Retrieves the Chapter (+Images) from the website.
|
||||
/// Should later call DownloadChapterImages to retrieve the individual Images of the Chapter and create .cbz archive.
|
||||
@ -59,7 +133,8 @@ public abstract class Connector
|
||||
/// <param name="publication">Publication that contains Chapter</param>
|
||||
/// <param name="chapter">Chapter with Images to retrieve</param>
|
||||
/// <param name="parentTask">Will be used for progress-tracking</param>
|
||||
public abstract void DownloadChapter(Publication publication, Chapter chapter, TrangaTask parentTask);
|
||||
/// <param name="cancellationToken"></param>
|
||||
public abstract HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null);
|
||||
|
||||
/// <summary>
|
||||
/// Copies the already downloaded cover from cache to downloadLocation
|
||||
@ -68,11 +143,11 @@ public abstract class Connector
|
||||
/// <param name="settings">TrangaSettings</param>
|
||||
public void CopyCoverFromCacheToDownloadLocation(Publication publication, TrangaSettings settings)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {publication.sortName} {publication.internalId}");
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {publication.sortName} -> {publication.internalId}");
|
||||
//Check if Publication already has a Folder and cover
|
||||
string publicationFolder = publication.CreatePublicationFolder(downloadLocation);
|
||||
DirectoryInfo dirInfo = new (publicationFolder);
|
||||
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover.")))
|
||||
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Cover exists {publication.sortName}");
|
||||
return;
|
||||
@ -98,7 +173,7 @@ public abstract class Connector
|
||||
new XElement("Tags", string.Join(',',publication.tags)),
|
||||
new XElement("LanguageISO", publication.originalLanguage),
|
||||
new XElement("Title", chapter.name),
|
||||
new XElement("Writer", publication.author),
|
||||
new XElement("Writer", string.Join(',', publication.authors)),
|
||||
new XElement("Volume", chapter.volumeNumber),
|
||||
new XElement("Number", chapter.chapterNumber)
|
||||
);
|
||||
@ -111,7 +186,15 @@ public abstract class Connector
|
||||
/// <returns>true if chapter is present</returns>
|
||||
public bool CheckChapterIsDownloaded(Publication publication, Chapter chapter)
|
||||
{
|
||||
return File.Exists(GetArchiveFilePath(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>
|
||||
@ -120,7 +203,7 @@ public abstract class Connector
|
||||
/// <returns>Filepath</returns>
|
||||
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>
|
||||
@ -130,16 +213,15 @@ public abstract class Connector
|
||||
/// <param name="fullPath"></param>
|
||||
/// <param name="requestType">RequestType for Rate-Limit</param>
|
||||
/// <param name="referrer">referrer used in html request header</param>
|
||||
private void DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
|
||||
private HttpStatusCode DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
|
||||
{
|
||||
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
|
||||
if (requestResult.result != Stream.Null)
|
||||
{
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.result == Stream.Null)
|
||||
return requestResult.statusCode;
|
||||
byte[] buffer = new byte[requestResult.result.Length];
|
||||
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
||||
File.WriteAllBytes(fullPath, buffer);
|
||||
}else
|
||||
logger?.WriteLine(this.GetType().ToString(), "No Stream-Content in result.");
|
||||
return requestResult.statusCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -151,8 +233,11 @@ public abstract class Connector
|
||||
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
||||
/// <param name="requestType">RequestType for RateLimits</param>
|
||||
/// <param name="referrer">Used in http request header</param>
|
||||
protected void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, TrangaTask parentTask, string? comicInfoPath = null, string? referrer = null)
|
||||
/// <param name="cancellationToken"></param>
|
||||
protected HttpStatusCode DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, DownloadChapterTask parentTask, string? comicInfoPath = null, string? referrer = null, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||
return HttpStatusCode.RequestTimeout;
|
||||
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
|
||||
//Check if Publication Directory already exists
|
||||
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
||||
@ -160,7 +245,7 @@ public abstract class Connector
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
|
||||
if (File.Exists(saveArchiveFilePath)) //Don't download twice.
|
||||
return;
|
||||
return HttpStatusCode.OK;
|
||||
|
||||
//Create a temporary folder to store images
|
||||
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
||||
@ -171,9 +256,13 @@ public abstract class Connector
|
||||
{
|
||||
string[] split = imageUrl.Split('.');
|
||||
string extension = split[^1];
|
||||
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {(parentTask.publication?.sortName)![..(int)(parentTask.publication?.sortName.Length > 25 ? 25 : parentTask.publication?.sortName.Length)!],-25} {(parentTask.publication?.internalId)![..(int)(parentTask.publication?.internalId.Length > 25 ? 25 : parentTask.publication?.internalId.Length)!],-25} Total Task Progress: {parentTask.progress:00.0}%");
|
||||
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
|
||||
parentTask.tasksFinished++;
|
||||
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)
|
||||
@ -185,13 +274,14 @@ public abstract class Connector
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(saveArchiveFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||
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);
|
||||
string saveImagePath = Path.Join(_imageCachePath, filename);
|
||||
|
||||
if (File.Exists(saveImagePath))
|
||||
return filename;
|
||||
@ -206,11 +296,15 @@ public abstract class Connector
|
||||
|
||||
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, TimeSpan> _rateLimit;
|
||||
private Logger? logger;
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private readonly Logger? logger;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a httpClient
|
||||
@ -267,10 +361,12 @@ public abstract class Connector
|
||||
Thread.Sleep(_rateLimit[requestType] * 2);
|
||||
}
|
||||
}
|
||||
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
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
|
||||
|
@ -3,6 +3,7 @@ using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Logging;
|
||||
using Tranga.TrangaTasks;
|
||||
|
||||
namespace Tranga.Connectors;
|
||||
public class MangaDex : Connector
|
||||
@ -45,7 +46,7 @@ public class MangaDex : Connector
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(
|
||||
$"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;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
|
||||
@ -92,19 +93,21 @@ public class MangaDex : Connector
|
||||
}
|
||||
|
||||
string? posterId = null;
|
||||
string? authorId = null;
|
||||
HashSet<string> authorIds = new();
|
||||
if (manga.ContainsKey("relationships") && manga["relationships"] is not null)
|
||||
{
|
||||
JsonArray relationships = manga["relationships"]!.AsArray();
|
||||
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? coverCacheName = null;
|
||||
if (coverUrl is not null)
|
||||
coverCacheName = SaveCoverImageToCache(coverUrl, (byte)RequestType.AtHomeServer);
|
||||
|
||||
string? author = GetAuthor(authorId);
|
||||
List<string> authors = GetAuthors(authorIds);
|
||||
|
||||
Dictionary<string, string> linksDict = new();
|
||||
if (attributes.ContainsKey("links") && attributes["links"] is not null)
|
||||
@ -128,7 +131,7 @@ public class MangaDex : Connector
|
||||
|
||||
Publication pub = new (
|
||||
title,
|
||||
author,
|
||||
authors,
|
||||
description,
|
||||
altTitlesDict,
|
||||
tags.ToArray(),
|
||||
@ -162,7 +165,7 @@ public class MangaDex : Connector
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(
|
||||
$"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;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
|
||||
@ -204,17 +207,19 @@ public class MangaDex : Connector
|
||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||
}
|
||||
|
||||
public override void DownloadChapter(Publication publication, Chapter chapter, TrangaTask parentTask)
|
||||
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}");
|
||||
//Request URLs for Chapter-Images
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", (byte)RequestType.AtHomeServer);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
return;
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return requestResult.statusCode;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
if (result is null)
|
||||
return;
|
||||
return HttpStatusCode.NoContent;
|
||||
|
||||
string baseUrl = result["baseUrl"]!.GetValue<string>();
|
||||
string hash = result["chapter"]!["hash"]!.GetValue<string>();
|
||||
@ -228,7 +233,7 @@ public class MangaDex : Connector
|
||||
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
|
||||
|
||||
//Download Chapter-Images
|
||||
DownloadChapterImages(imageUrls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)RequestType.AtHomeServer, parentTask, comicInfoPath);
|
||||
return DownloadChapterImages(imageUrls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)RequestType.AtHomeServer, parentTask, comicInfoPath, cancellationToken:cancellationToken);
|
||||
}
|
||||
|
||||
private string? GetCoverUrl(string publicationId, string? posterId)
|
||||
@ -243,7 +248,7 @@ public class MangaDex : Connector
|
||||
//Request information where to download Cover
|
||||
DownloadClient.RequestResult requestResult =
|
||||
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;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
if (result is null)
|
||||
@ -256,21 +261,23 @@ public class MangaDex : Connector
|
||||
return coverUrl;
|
||||
}
|
||||
|
||||
private string? GetAuthor(string? authorId)
|
||||
private List<string> GetAuthors(IEnumerable<string> authorIds)
|
||||
{
|
||||
List<string> ret = new();
|
||||
foreach (string authorId in authorIds)
|
||||
{
|
||||
if (authorId is null)
|
||||
return null;
|
||||
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/author/{authorId}", (byte)RequestType.Author);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
return null;
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return ret;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
if (result is null)
|
||||
return null;
|
||||
return ret;
|
||||
|
||||
string author = result["data"]!["attributes"]!["name"]!.GetValue<string>();
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {author}");
|
||||
return author;
|
||||
string authorName = result["data"]!["attributes"]!["name"]!.GetValue<string>();
|
||||
ret.Add(authorName);
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {authorName}");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
using System.Net;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using HtmlAgilityPack;
|
||||
using Logging;
|
||||
using Tranga.TrangaTasks;
|
||||
|
||||
namespace Tranga.Connectors;
|
||||
|
||||
@ -22,11 +24,10 @@ public class Manganato : Connector
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
|
||||
string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '_');
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={sanitizedTitle})");
|
||||
string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}";
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Publication>();
|
||||
|
||||
return ParsePublicationsFromHtml(requestResult.result);
|
||||
@ -51,7 +52,7 @@ public class Manganato : Connector
|
||||
{
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(url, (byte)1);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Publication>();
|
||||
|
||||
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1]));
|
||||
@ -70,8 +71,8 @@ public class Manganato : Connector
|
||||
Dictionary<string, string> altTitles = new();
|
||||
Dictionary<string, string>? links = null;
|
||||
HashSet<string> tags = new();
|
||||
string? author = null, originalLanguage = null;
|
||||
int? year = DateTime.Now.Year;
|
||||
string[] authors = Array.Empty<string>();
|
||||
string originalLanguage = "";
|
||||
|
||||
HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("story-info-right"));
|
||||
|
||||
@ -93,7 +94,7 @@ public class Manganato : Connector
|
||||
altTitles.Add(i.ToString(), alts[i]);
|
||||
break;
|
||||
case "authors":
|
||||
author = value;
|
||||
authors = value.Split('-');
|
||||
break;
|
||||
case "status":
|
||||
status = value;
|
||||
@ -118,9 +119,9 @@ public class Manganato : Connector
|
||||
|
||||
string yearString = document.DocumentNode.Descendants("li").Last(li => li.HasClass("a-h")).Descendants("span")
|
||||
.First(s => s.HasClass("chapter-time")).InnerText;
|
||||
year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000;
|
||||
int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000;
|
||||
|
||||
return new Publication(sortName, author, description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
return new Publication(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, status, publicationId);
|
||||
}
|
||||
|
||||
@ -130,13 +131,20 @@ public class Manganato : Connector
|
||||
string requestUrl = $"https://chapmanganato.com/{publication.publicationId}";
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Chapter>();
|
||||
|
||||
return ParseChaptersFromHtml(requestResult.result);
|
||||
//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 Chapter[] ParseChaptersFromHtml(Stream html)
|
||||
private List<Chapter> ParseChaptersFromHtml(Stream html)
|
||||
{
|
||||
StreamReader reader = new (html);
|
||||
string htmlString = reader.ReadToEnd();
|
||||
@ -157,25 +165,27 @@ public class Manganato : Connector
|
||||
.GetAttributeValue("href", "");
|
||||
ret.Add(new Chapter(chapterName, volumeNumber, chapterNumber, url));
|
||||
}
|
||||
|
||||
return ret.ToArray();
|
||||
ret.Reverse();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override void DownloadChapter(Publication publication, Chapter chapter, TrangaTask parentTask)
|
||||
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 (requestResult.statusCode != HttpStatusCode.OK)
|
||||
return;
|
||||
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));
|
||||
|
||||
DownloadChapterImages(imageUrls, GetArchiveFilePath(publication, chapter), (byte)1, parentTask, comicInfoPath, "https://chapmanganato.com/");
|
||||
return DownloadChapterImages(imageUrls, GetArchiveFilePath(publication, chapter), (byte)1, parentTask, comicInfoPath, "https://chapmanganato.com/", cancellationToken);
|
||||
}
|
||||
|
||||
private string[] ParseImageUrlsFromHtml(Stream html)
|
||||
|
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;
|
||||
}
|
||||
}
|
@ -17,12 +17,13 @@ public abstract class LibraryManager
|
||||
|
||||
public LibraryType libraryType { get; }
|
||||
public string baseUrl { get; }
|
||||
protected string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
||||
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;
|
||||
@ -39,38 +40,35 @@ public abstract class LibraryManager
|
||||
|
||||
protected static class NetClient
|
||||
{
|
||||
public static Stream MakeRequest(string url, string auth, Logger? logger)
|
||||
public static Stream MakeRequest(string url, string authScheme, string auth, Logger? logger)
|
||||
{
|
||||
HttpClientHandler clientHandler = new ();
|
||||
HttpClient client = new(clientHandler);
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
|
||||
HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, auth);
|
||||
|
||||
HttpRequestMessage requestMessage = new ()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
logger?.WriteLine("LibraryManager", $"GET {url}");
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
logger?.WriteLine("LibraryManager", $"{(int)response.StatusCode} {response.StatusCode}: {response.ReasonPhrase}");
|
||||
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, auth, logger);
|
||||
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 auth, Logger? logger)
|
||||
public static bool MakePost(string url, string authScheme, string auth, Logger? logger)
|
||||
{
|
||||
HttpClientHandler clientHandler = new ();
|
||||
HttpClient client = new(clientHandler)
|
||||
HttpClient client = new()
|
||||
{
|
||||
DefaultRequestHeaders =
|
||||
{
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", new AuthenticationHeaderValue("Basic", auth).ToString() }
|
||||
{ "Authorization", new AuthenticationHeaderValue(authScheme, auth).ToString() }
|
||||
}
|
||||
};
|
||||
HttpRequestMessage requestMessage = new ()
|
||||
@ -78,12 +76,11 @@ public abstract class LibraryManager
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
logger?.WriteLine("LibraryManager", $"POST {url}");
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
logger?.WriteLine("LibraryManager", $"{(int)response.StatusCode} {response.StatusCode}: {response.ReasonPhrase}");
|
||||
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, auth, logger);
|
||||
return MakePost(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth, logger);
|
||||
else if (response.IsSuccessStatusCode)
|
||||
return true;
|
||||
else
|
||||
|
@ -1,20 +1,50 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
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 apiKey, Logger? logger) : base(baseUrl, apiKey, logger, LibraryType.Kavita)
|
||||
|
||||
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}", auth, logger);
|
||||
NetClient.MakePost($"{baseUrl}/api/Library/scan?libraryId={lib.id}", "Bearer", auth, logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -24,7 +54,7 @@ public class Kavita : LibraryManager
|
||||
private IEnumerable<KavitaLibrary> GetLibraries()
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/Library", auth, logger);
|
||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/Library", "Bearer", auth, logger);
|
||||
if (data == Stream.Null)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
||||
@ -42,7 +72,7 @@ public class Kavita : LibraryManager
|
||||
foreach (JsonNode? jsonNode in result)
|
||||
{
|
||||
var jObject = (JsonObject?)jsonNode;
|
||||
string libraryId = jObject!["id"]!.GetValue<string>();
|
||||
int libraryId = jObject!["id"]!.GetValue<int>();
|
||||
string libraryName = jObject!["name"]!.GetValue<string>();
|
||||
ret.Add(new KavitaLibrary(libraryId, libraryName));
|
||||
}
|
||||
@ -52,10 +82,10 @@ public class Kavita : LibraryManager
|
||||
|
||||
private struct KavitaLibrary
|
||||
{
|
||||
public string id { get; }
|
||||
public int id { get; }
|
||||
public string name { get; }
|
||||
|
||||
public KavitaLibrary(string id, string name)
|
||||
public KavitaLibrary(int id, string name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
@ -25,7 +25,7 @@ public class Komga : LibraryManager
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Updating Libraries");
|
||||
foreach (KomgaLibrary lib in GetLibraries())
|
||||
NetClient.MakePost($"{baseUrl}/api/v1/libraries/{lib.id}/scan", auth, logger);
|
||||
NetClient.MakePost($"{baseUrl}/api/v1/libraries/{lib.id}/scan", "Basic", auth, logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -35,7 +35,7 @@ public class Komga : LibraryManager
|
||||
private IEnumerable<KomgaLibrary> GetLibraries()
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", auth, logger);
|
||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", "Basic", auth, logger);
|
||||
if (data == Stream.Null)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
||||
|
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 = "";
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace Tranga;
|
||||
public readonly struct Publication
|
||||
{
|
||||
public string sortName { get; }
|
||||
public string? author { get; }
|
||||
public List<string> authors { get; }
|
||||
public Dictionary<string,string> altTitles { get; }
|
||||
// ReSharper disable trice MemberCanBePrivate.Global, trust
|
||||
public string? description { get; }
|
||||
@ -27,12 +27,24 @@ public readonly struct Publication
|
||||
public string publicationId { 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.author = author;
|
||||
this.authors = authors;
|
||||
this.description = description;
|
||||
this.altTitles = altTitles;
|
||||
this.tags = tags;
|
||||
@ -109,7 +121,7 @@ public readonly struct Publication
|
||||
this.year = year;
|
||||
if(status.ToLower() == "ongoing" || status.ToLower() == "hiatus")
|
||||
this.status = "Continuing";
|
||||
else if (status.ToLower() == "completed" || status.ToLower() == "cancelled")
|
||||
else if (status.ToLower() == "completed" || status.ToLower() == "cancelled" || status.ToLower() == "discontinued")
|
||||
this.status = "Ended";
|
||||
else
|
||||
this.status = status;
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Tranga.Connectors;
|
||||
using Tranga.LibraryManagers;
|
||||
using Tranga.TrangaTasks;
|
||||
|
||||
namespace Tranga;
|
||||
@ -13,56 +12,13 @@ namespace Tranga;
|
||||
public class TaskManager
|
||||
{
|
||||
public Dictionary<Publication, List<Chapter>> chapterCollection = new();
|
||||
private HashSet<TrangaTask> _allTasks;
|
||||
private HashSet<TrangaTask> _allTasks = new();
|
||||
private bool _continueRunning = true;
|
||||
private readonly Connector[] _connectors;
|
||||
private readonly Dictionary<Connector, List<TrangaTask>> _taskQueue = new();
|
||||
public TrangaSettings settings { get; }
|
||||
private Logger? logger { get; }
|
||||
|
||||
/// <param name="downloadFolderPath">Local path to save data (Manga) to</param>
|
||||
/// <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, HashSet<LibraryManager> libraryManagers, Logger? logger = null)
|
||||
{
|
||||
this.logger = logger;
|
||||
_allTasks = new HashSet<TrangaTask>();
|
||||
|
||||
this.settings = new TrangaSettings(downloadFolderPath, workingDirectory, libraryManagers);
|
||||
ExportDataAndSettings();
|
||||
|
||||
this._connectors = new Connector[]
|
||||
{
|
||||
new MangaDex(downloadFolderPath, imageCachePath, logger),
|
||||
new Manganato(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, string? kavitaUrl, string? kavitaApiKey)
|
||||
{
|
||||
if (komgaUrl is not null && komgaAuth is not null && komgaUrl.Length > 0 && komgaAuth.Length > 0)
|
||||
{
|
||||
settings.libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Komga));
|
||||
settings.libraryManagers.Add(new Komga(komgaUrl, komgaAuth, logger));
|
||||
}
|
||||
if (kavitaUrl is not null && kavitaApiKey is not null && kavitaUrl.Length > 0 && kavitaApiKey.Length > 0)
|
||||
{
|
||||
settings.libraryManagers.RemoveWhere(lm => lm.GetType() == typeof(Kavita));
|
||||
settings.libraryManagers.Add(new Kavita(kavitaUrl, kavitaApiKey, logger));
|
||||
}
|
||||
if (downloadLocation is not null && downloadLocation.Length > 0)
|
||||
settings.downloadLocation = downloadLocation;
|
||||
ExportDataAndSettings();
|
||||
}
|
||||
private readonly Dictionary<DownloadChapterTask, CancellationTokenSource> _runningDownloadChapterTasks = new();
|
||||
|
||||
public TaskManager(TrangaSettings settings, Logger? logger = null)
|
||||
{
|
||||
@ -70,11 +26,9 @@ public class TaskManager
|
||||
this._connectors = new Connector[]
|
||||
{
|
||||
new MangaDex(settings.downloadLocation, settings.coverImageCache, logger),
|
||||
new Manganato(settings.downloadLocation, settings.coverImageCache, logger)
|
||||
new Manganato(settings.downloadLocation, settings.coverImageCache, logger),
|
||||
new Mangasee(settings.downloadLocation, settings.coverImageCache, logger)
|
||||
};
|
||||
foreach(Connector cConnector in this._connectors)
|
||||
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
||||
_allTasks = new HashSet<TrangaTask>();
|
||||
|
||||
this.settings = settings;
|
||||
ImportData();
|
||||
@ -90,31 +44,64 @@ public class TaskManager
|
||||
private void TaskCheckerThread()
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), "Starting TaskCheckerThread.");
|
||||
int waitingTasksCount = _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting);
|
||||
while (_continueRunning)
|
||||
{
|
||||
//Check if previous tasks have finished and execute new tasks
|
||||
foreach (KeyValuePair<Connector, List<TrangaTask>> connectorTaskQueue in _taskQueue)
|
||||
foreach (TrangaTask waitingButExecute in _allTasks.Where(taskQuery =>
|
||||
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;
|
||||
}
|
||||
|
||||
foreach (TrangaTask enqueuedTask in _allTasks.Where(enqueuedTask => enqueuedTask.state is TrangaTask.ExecutionState.Enqueued))
|
||||
{
|
||||
switch (enqueuedTask.task)
|
||||
{
|
||||
case TrangaTask.Task.DownloadChapter:
|
||||
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();
|
||||
|
||||
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
|
||||
//Depending on type execute immediately or enqueue
|
||||
foreach (TrangaTask task in _allTasks.Where(aTask => aTask.ShouldExecute()))
|
||||
{
|
||||
task.state = TrangaTask.ExecutionState.Enqueued;
|
||||
if(task.task == TrangaTask.Task.UpdateLibraries)
|
||||
ExecuteTaskNow(task);
|
||||
else
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Task due: {task}");
|
||||
_taskQueue[GetConnector(task.connectorName!)].Add(task);
|
||||
}
|
||||
}
|
||||
waitingTasksCount = _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting);
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
@ -125,101 +112,112 @@ public class TaskManager
|
||||
/// <param name="task">Task to execute</param>
|
||||
public void ExecuteTaskNow(TrangaTask task)
|
||||
{
|
||||
if (!this._allTasks.Contains(task))
|
||||
return;
|
||||
|
||||
task.state = TrangaTask.ExecutionState.Running;
|
||||
CancellationTokenSource cToken = new ();
|
||||
Task t = new(() =>
|
||||
{
|
||||
task.Execute(this, this.logger);
|
||||
});
|
||||
task.Execute(this, this.logger, cToken.Token);
|
||||
}, cToken.Token);
|
||||
if(task is DownloadChapterTask chapterTask)
|
||||
_runningDownloadChapterTasks.Add(chapterTask, cToken);
|
||||
t.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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 = "")
|
||||
public void AddTask(TrangaTask newTask)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}");
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {newTask}");
|
||||
|
||||
TrangaTask? newTask = null;
|
||||
if (task == TrangaTask.Task.UpdateLibraries)
|
||||
switch (newTask.task)
|
||||
{
|
||||
newTask = new UpdateLibrariesTask(task, reoccurrence);
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Removing old {task}-Task.");
|
||||
case TrangaTask.Task.UpdateLibraries:
|
||||
//Only one UpdateKomgaLibrary Task
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Replacing old {newTask.task}-Task.");
|
||||
_allTasks.RemoveWhere(trangaTask => trangaTask.task is TrangaTask.Task.UpdateLibraries);
|
||||
_allTasks.Add(newTask);
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask}");
|
||||
}else if (task == TrangaTask.Task.DownloadNewChapters)
|
||||
{
|
||||
//Get appropriate Connector from available Connectors for TrangaTask
|
||||
Connector? connector = _connectors.FirstOrDefault(c => c.name == connectorName);
|
||||
if (connectorName is null)
|
||||
throw new ArgumentException($"connectorName can not be null for task {task}");
|
||||
|
||||
if (publication is null)
|
||||
throw new ArgumentException($"publication can not be null for task {task}");
|
||||
Publication pub = (Publication)publication;
|
||||
newTask = new DownloadNewChaptersTask(task, connector!.name, pub, reoccurrence, language);
|
||||
|
||||
if (!_allTasks.Any(trangaTask =>
|
||||
trangaTask.task == task && trangaTask.publication?.internalId == pub.internalId &&
|
||||
trangaTask.connectorName == connector.name))
|
||||
{
|
||||
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);
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Added new Task {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;
|
||||
}
|
||||
ExportDataAndSettings();
|
||||
|
||||
if (newTask is null)
|
||||
throw new Exception("Invalid path");
|
||||
return newTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
public void DeleteTask(TrangaTask removeTask)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task} {publication?.sortName}");
|
||||
if (task == TrangaTask.Task.UpdateLibraries)
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {removeTask}");
|
||||
_allTasks.Remove(removeTask);
|
||||
removeTask.parentTask?.RemoveChildTask(removeTask);
|
||||
if (removeTask is DownloadChapterTask cRemoveTask && _runningDownloadChapterTasks.ContainsKey(cRemoveTask))
|
||||
{
|
||||
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateLibraries);
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} from all Tasks.");
|
||||
_runningDownloadChapterTasks[cRemoveTask].Cancel();
|
||||
_runningDownloadChapterTasks.Remove(cRemoveTask);
|
||||
}
|
||||
else if (connectorName is null)
|
||||
throw new ArgumentException($"connectorName can not be null for Task {task}");
|
||||
else
|
||||
{
|
||||
foreach (List<TrangaTask> taskQueue in this._taskQueue.Values)
|
||||
if(taskQueue.RemoveAll(trangaTask =>
|
||||
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
||||
trangaTask.publication?.internalId == publication?.internalId) > 0)
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} {publication?.sortName} {publication?.internalId} from Queue.");
|
||||
else
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Task {task} {publication?.sortName} {publication?.internalId} was not in Queue.");
|
||||
if(_allTasks.RemoveWhere(trangaTask =>
|
||||
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
||||
trangaTask.publication?.internalId == publication?.internalId) > 0)
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} {publication?.sortName} {publication?.internalId} from all Tasks.");
|
||||
else
|
||||
logger?.WriteLine(this.GetType().ToString(), $"No Task {task} {publication?.sortName} {publication?.internalId} could be found.");
|
||||
}
|
||||
ExportDataAndSettings();
|
||||
|
||||
public IEnumerable<TrangaTask> GetTasksMatching(TrangaTask.Task taskType, string? connectorName = null, string? searchString = null, string? internalId = null, string? chapterSortNumber = null)
|
||||
{
|
||||
switch (taskType)
|
||||
{
|
||||
case TrangaTask.Task.UpdateLibraries:
|
||||
return _allTasks.Where(tTask => tTask.task == TrangaTask.Task.UpdateLibraries);
|
||||
case TrangaTask.Task.MonitorPublication:
|
||||
if(connectorName is null)
|
||||
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
|
||||
return _allTasks.Where(tTask =>
|
||||
tTask is MonitorPublicationTask mpt && mpt.connectorName == connectorName);
|
||||
|
||||
case TrangaTask.Task.DownloadChapter:
|
||||
if(connectorName is null)
|
||||
return _allTasks.Where(tTask => tTask.task == taskType);
|
||||
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>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -229,8 +227,6 @@ public class TaskManager
|
||||
public void RemoveTaskFromQueue(TrangaTask task)
|
||||
{
|
||||
task.lastExecuted = DateTime.Now;
|
||||
foreach (List<TrangaTask> taskList in this._taskQueue.Values)
|
||||
taskList.Remove(task);
|
||||
task.state = TrangaTask.ExecutionState.Waiting;
|
||||
}
|
||||
|
||||
@ -263,7 +259,7 @@ public class TaskManager
|
||||
Publication[] ret = connector.GetPublications(title ?? "");
|
||||
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>());
|
||||
}
|
||||
return ret;
|
||||
@ -275,6 +271,31 @@ public class TaskManager
|
||||
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>
|
||||
/// Return Connector with given Name
|
||||
/// </summary>
|
||||
@ -321,6 +342,17 @@ public class TaskManager
|
||||
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))
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Importing known publications from {settings.knownPublicationsPath}");
|
||||
@ -337,14 +369,34 @@ public class TaskManager
|
||||
private void ExportDataAndSettings()
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Exporting settings to {settings.settingsFilePath}");
|
||||
while(IsFileInUse(settings.settingsFilePath))
|
||||
Thread.Sleep(50);
|
||||
File.WriteAllText(settings.settingsFilePath, JsonConvert.SerializeObject(settings));
|
||||
|
||||
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));
|
||||
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Exporting known publications to {settings.knownPublicationsPath}");
|
||||
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;
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="PuppeteerSharp" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Tranga.LibraryManagers;
|
||||
using Tranga.NotificationManagers;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
@ -13,27 +14,74 @@ public class TrangaSettings
|
||||
[JsonIgnore] public string knownPublicationsPath => Path.Join(workingDirectory, "knownPublications.json");
|
||||
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||
public HashSet<LibraryManager> libraryManagers { get; }
|
||||
public HashSet<NotificationManager> notificationManagers { get; }
|
||||
|
||||
public TrangaSettings(string downloadLocation, string workingDirectory, HashSet<LibraryManager> libraryManagers)
|
||||
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.downloadLocation = downloadLocation;
|
||||
this.libraryManagers = libraryManagers;
|
||||
this.libraryManagers = libraryManagers??new();
|
||||
this.notificationManagers = notificationManagers??new();
|
||||
}
|
||||
|
||||
public static TrangaSettings LoadSettings(string importFilePath, Logger? logger)
|
||||
{
|
||||
if (!File.Exists(importFilePath))
|
||||
return new TrangaSettings(Path.Join(Directory.GetCurrentDirectory(), "Downloads"), Directory.GetCurrentDirectory(), new HashSet<LibraryManager>());
|
||||
return new TrangaSettings(Path.Join(Directory.GetCurrentDirectory(), "Downloads"),
|
||||
Directory.GetCurrentDirectory(), new HashSet<LibraryManager>(), new HashSet<NotificationManager>());
|
||||
|
||||
string toRead = File.ReadAllText(importFilePath);
|
||||
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(toRead, new JsonSerializerSettings() { Converters = { new LibraryManager.LibraryManagerJsonConverter()} })!;
|
||||
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;
|
||||
}
|
||||
|
||||
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,45 +1,51 @@
|
||||
using Logging;
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Stores information on Task, when implementing new Tasks also update the serializer
|
||||
/// </summary>
|
||||
[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 MemberCanBePrivate.Global I want it thaaat way
|
||||
public TimeSpan reoccurrence { get; }
|
||||
public DateTime lastExecuted { get; set; }
|
||||
public string? connectorName { get; }
|
||||
[Newtonsoft.Json.JsonIgnore] public ExecutionState state { get; set; }
|
||||
public Task task { get; }
|
||||
public Publication? publication { get; }
|
||||
public string? language { get; }
|
||||
[JsonIgnore]public ExecutionState state { get; set; }
|
||||
[JsonIgnore] public float progress => (tasksFinished != 0f ? tasksFinished / tasksCount : 0f);
|
||||
[JsonIgnore]public float tasksCount { get; set; }
|
||||
[JsonIgnore]public float tasksFinished { get; set; }
|
||||
public string taskId { get; }
|
||||
[Newtonsoft.Json.JsonIgnore] public TrangaTask? parentTask { 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
|
||||
{
|
||||
Waiting,
|
||||
Enqueued,
|
||||
Running
|
||||
};
|
||||
public enum ExecutionState { Waiting, Enqueued, Running, Failed, Success }
|
||||
|
||||
protected TrangaTask(Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence, string? language = null)
|
||||
protected TrangaTask(Task task, TimeSpan reoccurrence, TrangaTask? parentTask = null)
|
||||
{
|
||||
this.publication = publication;
|
||||
this.reoccurrence = reoccurrence;
|
||||
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
||||
this.connectorName = connectorName;
|
||||
this.task = task;
|
||||
this.language = language;
|
||||
this.tasksCount = 1;
|
||||
this.tasksFinished = 0;
|
||||
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>
|
||||
@ -47,57 +53,97 @@ public abstract class TrangaTask
|
||||
/// </summary>
|
||||
/// <param name="taskManager"></param>
|
||||
/// <param name="logger"></param>
|
||||
protected abstract void ExecuteTask(TaskManager taskManager, Logger? logger);
|
||||
/// <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>
|
||||
public void Execute(TaskManager taskManager, Logger? logger)
|
||||
/// <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;
|
||||
ExecuteTask(taskManager, logger);
|
||||
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 bool ShouldExecute()
|
||||
public void AddChildTask(TrangaTask childTask)
|
||||
{
|
||||
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence && state is ExecutionState.Waiting;
|
||||
this.childTasks.Add(childTask);
|
||||
}
|
||||
|
||||
public void RemoveChildTask(TrangaTask childTask)
|
||||
{
|
||||
this.childTasks.Remove(childTask);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
DownloadNewChapters = 2,
|
||||
UpdateLibraries = 3
|
||||
MonitorPublication = 2,
|
||||
UpdateLibraries = 3,
|
||||
DownloadChapter = 4,
|
||||
DownloadNewChapters = 2 //legacy
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{task}, {lastExecuted}, {reoccurrence}, {state} {(connectorName is not null ? $", {connectorName}" : "" )} {(publication is not null ? $", {progress:00.00}%" : "")} {(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));
|
||||
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.DownloadNewChapters)
|
||||
return jo.ToObject<DownloadNewChaptersTask>(serializer)!;
|
||||
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();
|
||||
}
|
||||
|
||||
|
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}";
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
using Logging;
|
||||
|
||||
namespace Tranga.TrangaTasks;
|
||||
|
||||
public class DownloadNewChaptersTask : TrangaTask
|
||||
{
|
||||
public DownloadNewChaptersTask(Task task, string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(task, connectorName, publication, reoccurrence, language)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
|
||||
{
|
||||
Publication pub = (Publication)this.publication!;
|
||||
Connector connector = taskManager.GetConnector(this.connectorName);
|
||||
|
||||
//Check if Publication already has a Folder
|
||||
pub.CreatePublicationFolder(taskManager.settings.downloadLocation);
|
||||
List<Chapter> newChapters = UpdateChapters(connector, pub, language!, ref taskManager.chapterCollection);
|
||||
this.tasksCount = newChapters.Count;
|
||||
|
||||
connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings);
|
||||
|
||||
pub.SaveSeriesInfoJson(connector.downloadLocation);
|
||||
|
||||
foreach(Chapter newChapter in newChapters)
|
||||
connector.DownloadChapter(pub, newChapter, this);
|
||||
}
|
||||
|
||||
/// <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.CheckChapterIsDownloaded(publication, nChapter)).ToList();
|
||||
|
||||
return newChaptersList;
|
||||
}
|
||||
}
|
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}";
|
||||
}
|
||||
}
|
@ -1,16 +1,30 @@
|
||||
using Logging;
|
||||
using System.Net;
|
||||
using Logging;
|
||||
|
||||
namespace Tranga.TrangaTasks;
|
||||
|
||||
public class UpdateLibrariesTask : TrangaTask
|
||||
{
|
||||
public UpdateLibrariesTask(Task task, TimeSpan reoccurrence) : base(task, null, null, reoccurrence)
|
||||
public UpdateLibrariesTask(TimeSpan reoccurrence) : base(Task.UpdateLibraries, reoccurrence)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
|
||||
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(){
|
||||
var uri = apiUri + "/Tranga/GetAvailableControllers";
|
||||
var uri = apiUri + "/Connectors";
|
||||
let json = await GetData(uri);
|
||||
return json;
|
||||
}
|
||||
|
||||
async function GetPublication(connectorName, title){
|
||||
var uri = apiUri + `/Tranga/GetPublicationsFromConnector?connectorName=${connectorName}&title=${title}`;
|
||||
async function GetPublicationFromConnector(connectorName, title){
|
||||
var uri = apiUri + `/Publications/FromConnector?connectorName=${connectorName}&title=${title}`;
|
||||
let json = await GetData(uri);
|
||||
return json;
|
||||
}
|
||||
|
||||
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);
|
||||
return json;
|
||||
}
|
||||
|
||||
async function GetTaskTypes(){
|
||||
var uri = apiUri + "/Tasks/GetTaskTypes";
|
||||
var uri = apiUri + "/Tasks/Types";
|
||||
let json = await GetData(uri);
|
||||
return json;
|
||||
}
|
||||
async function GetRunningTasks(){
|
||||
var uri = apiUri + "/Tasks/GetRunningTasks";
|
||||
var uri = apiUri + "/Tasks/RunningTasks";
|
||||
let json = await GetData(uri);
|
||||
return json;
|
||||
}
|
||||
|
||||
async function GetDownloadTasks(){
|
||||
var uri = apiUri + "/Tasks/Get?taskType=DownloadNewChapters";
|
||||
var uri = apiUri + "/Tasks?taskType=DownloadNewChapters";
|
||||
let json = await GetData(uri);
|
||||
return json;
|
||||
}
|
||||
|
||||
async function GetSettings(){
|
||||
var uri = apiUri + "/Settings/Get";
|
||||
var uri = apiUri + "/Settings";
|
||||
let json = await GetData(uri);
|
||||
return json;
|
||||
}
|
||||
|
||||
async function GetKomgaTask(){
|
||||
var uri = apiUri + "/Tasks/Get?taskType=UpdateLibraries";
|
||||
var uri = apiUri + "/Tasks?taskType=UpdateLibraries";
|
||||
let json = await GetData(uri);
|
||||
return json;
|
||||
}
|
||||
|
||||
function CreateTask(taskType, reoccurrence, connectorName, publicationId, language){
|
||||
var uri = apiUri + `/Tasks/Create?taskType=${taskType}&connectorName=${connectorName}&publicationId=${publicationId}&reoccurrenceTime=${reoccurrence}&language=${language}`;
|
||||
function CreateMonitorTask(connectorName, internalId, reoccurrence, language){
|
||||
var uri = apiUri + `/Tasks/CreateMonitorTask?connectorName=${connectorName}&internalId=${internalId}&reoccurrenceTime=${reoccurrence}&language=${language}`;
|
||||
PostData(uri);
|
||||
}
|
||||
|
||||
function StartTask(taskType, connectorName, publicationId){
|
||||
var uri = apiUri + `/Tasks/Start?taskType=${taskType}&connectorName=${connectorName}&publicationId=${publicationId}`;
|
||||
function CreateUpdateLibraryTask(reoccurrence){
|
||||
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);
|
||||
}
|
||||
|
||||
@ -104,13 +126,38 @@ function EnqueueTask(taskType, connectorName, publicationId){
|
||||
PostData(uri);
|
||||
}
|
||||
|
||||
function UpdateSettings(downloadLocation, komgaUrl, komgaAuth){
|
||||
var uri = apiUri + `/Settings/Update?downloadLocation=${downloadLocation}&komgaUrl=${komgaUrl}&komgaAuth=${komgaAuth}`;
|
||||
function UpdateDownloadLocation(downloadLocation){
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -120,7 +167,7 @@ function DequeueTask(taskType, connectorName, publicationId){
|
||||
}
|
||||
|
||||
async function GetQueue(){
|
||||
var uri = apiUri + "/Queue/GetList";
|
||||
var uri = apiUri + "/Queue/List";
|
||||
let json = await GetData(uri);
|
||||
return json;
|
||||
}
|
@ -25,7 +25,7 @@
|
||||
<p>+</p>
|
||||
</div>
|
||||
<publication>
|
||||
<img src="media/cover.jpg">
|
||||
<img alt="cover" src="media/cover.jpg">
|
||||
<publication-information>
|
||||
<connector-name class="pill">MangaDex</connector-name>
|
||||
<publication-name>Tensei Pandemic</publication-name>
|
||||
@ -33,28 +33,56 @@
|
||||
</publication>
|
||||
</content>
|
||||
|
||||
<popup id="addTaskPopup">
|
||||
<popup id="selectPublicationPopup">
|
||||
<blur-background id="blurBackgroundTaskPopup"></blur-background>
|
||||
<addtask-window>
|
||||
<window-titlebar>
|
||||
<p>Add Task</p>
|
||||
<img id="closePopupImg" src="media/close-x.svg" alt="Close">
|
||||
</window-titlebar>
|
||||
<window-content>
|
||||
<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>
|
||||
<popup-window>
|
||||
<popup-title>Select Publication</popup-title>
|
||||
<popup-content>
|
||||
<div>
|
||||
<label for="connectors">Connector</label>
|
||||
<select id="connectors">
|
||||
<option value=""></option>
|
||||
</select>
|
||||
</addtask-setting>
|
||||
<addtask-setting><label for="searchPublicationQuery">Search Title</label><input id="searchPublicationQuery" type="text"></addtask-setting>
|
||||
<input type="submit" value="Search" onclick="NewSearch();">
|
||||
</addtask-settings>
|
||||
</div>
|
||||
<div>
|
||||
<label for="searchPublicationQuery">Search Title</label><input id="searchPublicationQuery" type="text"></addtask-setting>
|
||||
</div>
|
||||
<input type="submit" value="Search" style="font-weight: bolder" onclick="NewSearch();">
|
||||
</popup-content>
|
||||
<div id="taskSelectOutput"></div>
|
||||
</window-content>
|
||||
</addtask-window>
|
||||
</popup-window>
|
||||
</popup>
|
||||
|
||||
<popup id="createMonitorTaskPopup">
|
||||
<blur-background id="blurBackgroundCreateMonitorTaskPopup"></blur-background>
|
||||
<popup-window>
|
||||
<popup-title>Create Task: Monitor Publication</popup-title>
|
||||
<popup-content>
|
||||
<div>
|
||||
<span>Run every</span>
|
||||
<label for="hours"></label><input id="hours" type="number" value="3" min="0" max="23"><span>hours</span>
|
||||
<label for="minutes"></label><input id="minutes" type="number" value="0" min="0" max="59"><span>minutes</span>
|
||||
<input type="submit" value="Create" onclick="AddMonitorTask()">
|
||||
</div>
|
||||
</popup-content>
|
||||
</popup-window>
|
||||
</popup>
|
||||
|
||||
<popup id="createDownloadChaptersTask">
|
||||
<blur-background id="blurBackgroundCreateDownloadChaptersTask"></blur-background>
|
||||
<popup-window>
|
||||
<popup-title>Create Task: Download Chapter(s)</popup-title>
|
||||
<popup-content>
|
||||
<div>
|
||||
<label for="selectedChapters">Chapters:</label><input id="selectedChapters" placeholder="Select"><input type="submit" value="Select" onclick="DownloadChapterTaskClick()">
|
||||
</div>
|
||||
<div id="chapterOutput">
|
||||
|
||||
</div>
|
||||
</popup-content>
|
||||
</popup-window>
|
||||
</popup>
|
||||
|
||||
<popup id="publicationViewerPopup">
|
||||
<blur-background id="blurBackgroundPublicationPopup"></blur-background>
|
||||
<publication-viewer>
|
||||
@ -71,15 +99,18 @@
|
||||
<publication-interactions>
|
||||
<publication-starttask>Start Task ▶️</publication-starttask>
|
||||
<publication-delete>Delete Task ❌</publication-delete>
|
||||
<publication-add>Add Task ➕</publication-add>
|
||||
<publication-add id="createMonitorTaskButton">Monitor ➕</publication-add>
|
||||
<publication-add id="createDownloadChapterTaskButton">Download Chapter ➕</publication-add>
|
||||
</publication-interactions>
|
||||
</publication-information>
|
||||
</publication-viewer>
|
||||
</popup>
|
||||
|
||||
<popup id="settingsPopup">
|
||||
<blur-background id="blurBackgroundSettingsPopup"></blur-background>
|
||||
<settings>
|
||||
<span style="font-weight: bold; text-align: center; font-size: 16pt;">Settings</span>
|
||||
<popup-window>
|
||||
<popup-title>Settings</popup-title>
|
||||
<popup-content>
|
||||
<div>
|
||||
<p class="title">Download Location:</p>
|
||||
<span id="downloadLocation"></span>
|
||||
@ -88,44 +119,59 @@
|
||||
<p class="title">API-URI</p>
|
||||
<label for="settingApiUri"></label><input placeholder="https://" type="text" id="settingApiUri">
|
||||
</div>
|
||||
<komga-settings>
|
||||
<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">
|
||||
</komga-settings>
|
||||
<kavita-settings>
|
||||
</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="kavitaApiKey"></label><input placeholder="API-Key" id="kavitaApiKey" type="text">
|
||||
</kavita-settings>
|
||||
<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>
|
||||
</settings>
|
||||
</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>
|
||||
<div onclick="ShowTasksQueue();">
|
||||
<img src="media/running.svg" alt="running"><div id="tasksRunningTag">0</div>
|
||||
</div>
|
||||
<div>
|
||||
<div onclick="ShowTasksQueue();">
|
||||
<img src="media/queue.svg" alt="queue"><div id="tasksQueuedTag">0</div>
|
||||
</div>
|
||||
<div>
|
||||
<img src="media/tasks.svg" alt="queue"><div id="totalTasksTag">0</div>
|
||||
</div>
|
||||
<p id="madeWith">Made with Blåhaj 🦈</p>
|
||||
</footer>
|
||||
</wrapper>
|
||||
<footer-tag-popup>
|
||||
<footer-tag-content>
|
||||
<footer-tag-task-name>Test</footer-tag-task-name>
|
||||
</footer-tag-content>
|
||||
</footer-tag-popup>
|
||||
|
||||
<script src="apiConnector.js"></script>
|
||||
<script src="interaction.js"></script>
|
||||
|
@ -10,7 +10,13 @@ const settingsPopup = document.querySelector("#settingsPopup");
|
||||
const settingsCog = document.querySelector("#settingscog");
|
||||
const selectRecurrence = document.querySelector("#selectReccurrence");
|
||||
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 publicationViewerWindow = document.querySelector("publication-viewer");
|
||||
const publicationViewerDescription = document.querySelector("#publicationViewerDescription");
|
||||
@ -19,33 +25,50 @@ const publicationViewerTags = document.querySelector("#publicationViewerTags");
|
||||
const publicationViewerAuthor = document.querySelector("#publicationViewerAuthor");
|
||||
const pubviewcover = document.querySelector("#pubviewcover");
|
||||
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 settingKomgaUrl = document.querySelector("#komgaUrl");
|
||||
const settingKomgaUser = document.querySelector("#komgaUsername");
|
||||
const settingKomgaPass = document.querySelector("#komgaPassword");
|
||||
const settingKavitaUrl = document.querySelector("#kavitaUrl");
|
||||
const settingKavitaApi = document.querySelector("#kavitaApiKey");
|
||||
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 settingKavitaConfigured = document.querySelector("#kavitaConfigured");
|
||||
const settingGotifyConfigured = document.querySelector("#gotifyConfigured");
|
||||
const settingLunaseaConfigured = document.querySelector("#lunaseaConfigured");
|
||||
const settingApiUri = document.querySelector("#settingApiUri");
|
||||
const tagTasksRunning = document.querySelector("#tasksRunningTag");
|
||||
const tagTasksQueued = document.querySelector("#tasksQueuedTag");
|
||||
const tagTasksTotal = document.querySelector("#totalTasksTag");
|
||||
const tagTaskPopup = document.querySelector("footer-tag-popup");
|
||||
const tagTasksPopupContent = document.querySelector("footer-tag-content");
|
||||
const downloadTasksPopup = document.querySelector("#downloadTasksPopup");
|
||||
const downloadTasksOutput = downloadTasksPopup.querySelector("popup-content");
|
||||
|
||||
searchbox.addEventListener("keyup", (event) => FilterResults());
|
||||
settingsCog.addEventListener("click", () => OpenSettings());
|
||||
document.querySelector("#blurBackgroundSettingsPopup").addEventListener("click", () => HideSettings());
|
||||
closetaskpopup.addEventListener("click", () => HideAddTaskPopup());
|
||||
document.querySelector("#blurBackgroundTaskPopup").addEventListener("click", () => HideAddTaskPopup());
|
||||
document.querySelector("#blurBackgroundSettingsPopup").addEventListener("click", () => settingsPopup.style.display = "none");
|
||||
document.querySelector("#blurBackgroundTaskPopup").addEventListener("click", () => selectPublicationPopup.style.display = "none");
|
||||
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());
|
||||
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) => {
|
||||
if(event.key === "Enter"){
|
||||
@ -59,12 +82,7 @@ searchPublicationQuery.addEventListener("keypress", (event) => {
|
||||
NewSearch();
|
||||
}
|
||||
});
|
||||
tagTasksRunning.addEventListener("mouseover", (event) => ShowRunningTasks(event));
|
||||
tagTasksRunning.addEventListener("mouseout", () => CloseTasksPopup());
|
||||
tagTasksQueued.addEventListener("mouseover", (event) => ShowQueuedTasks(event));
|
||||
tagTasksQueued.addEventListener("mouseout", () => CloseTasksPopup());
|
||||
tagTasksTotal.addEventListener("mouseover", (event) => ShowAllTasks(event));
|
||||
tagTasksTotal.addEventListener("mouseout", () => CloseTasksPopup());
|
||||
|
||||
|
||||
let availableConnectors;
|
||||
GetAvailableControllers()
|
||||
@ -81,18 +99,14 @@ GetAvailableControllers()
|
||||
|
||||
function NewSearch(){
|
||||
//Disable inputs
|
||||
selectRecurrence.disabled = true;
|
||||
connectorSelect.disabled = true;
|
||||
searchPublicationQuery.disabled = true;
|
||||
//Waitcursor
|
||||
document.body.style.cursor = "wait";
|
||||
selectRecurrence.style.cursor = "wait";
|
||||
connectorSelect.style.cursor = "wait";
|
||||
searchPublicationQuery.style.cursor = "wait";
|
||||
|
||||
//Empty previous results
|
||||
selectPublication.replaceChildren();
|
||||
GetPublication(connectorSelect.value, searchPublicationQuery.value)
|
||||
GetPublicationFromConnector(connectorSelect.value, searchPublicationQuery.value)
|
||||
.then(json =>
|
||||
json.forEach(publication => {
|
||||
var option = CreatePublication(publication, connectorSelect.value);
|
||||
@ -104,14 +118,10 @@ function NewSearch(){
|
||||
))
|
||||
.then(() => {
|
||||
//Re-enable inputs
|
||||
selectRecurrence.disabled = false;
|
||||
connectorSelect.disabled = false;
|
||||
searchPublicationQuery.disabled = false;
|
||||
//Cursor
|
||||
document.body.style.cursor = "initial";
|
||||
selectRecurrence.style.cursor = "initial";
|
||||
connectorSelect.style.cursor = "initial";
|
||||
searchPublicationQuery.style.cursor = "initial";
|
||||
});
|
||||
}
|
||||
|
||||
@ -136,18 +146,59 @@ function CreatePublication(publication, connector){
|
||||
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(){
|
||||
taskToDelete = tasks.filter(tTask => tTask.publication.internalId === toEditId)[0];
|
||||
DeleteTask("DownloadNewChapters", taskToDelete.connectorName, toEditId);
|
||||
HidePublicationPopup();
|
||||
}
|
||||
|
||||
function AddTaskClick(){
|
||||
CreateTask("DownloadNewChapters", selectRecurrence.value, connectorSelect.value, toEditId, "en")
|
||||
HideAddTaskPopup();
|
||||
HidePublicationPopup();
|
||||
}
|
||||
|
||||
function StartTaskClick(){
|
||||
var toEditTask = tasks.filter(task => task.publication.internalId == toEditId)[0];
|
||||
StartTask("DownloadNewChapters", toEditTask.connectorName, toEditId);
|
||||
@ -187,18 +238,20 @@ function ShowPublicationViewerWindow(publicationId, event, add){
|
||||
publicationViewerName.innerText = publication.sortName;
|
||||
publicationViewerTags.innerText = publication.tags.join(", ");
|
||||
publicationViewerDescription.innerText = publication.description;
|
||||
publicationViewerAuthor.innerText = publication.author;
|
||||
publicationViewerAuthor.innerText = publication.authors.join(',');
|
||||
pubviewcover.src = `imageCache/${publication.coverFileNameInCache}`;
|
||||
toEditId = publicationId;
|
||||
|
||||
//Check what action should be listed
|
||||
if(add){
|
||||
publicationAdd.style.display = "initial";
|
||||
createMonitorTaskButton.style.display = "initial";
|
||||
createDownloadChapterTaskButton.style.display = "initial";
|
||||
publicationDelete.style.display = "none";
|
||||
publicationTaskStart.style.display = "none";
|
||||
}
|
||||
else{
|
||||
publicationAdd.style.display = "none";
|
||||
createMonitorTaskButton.style.display = "none";
|
||||
createDownloadChapterTaskButton.style.display = "none";
|
||||
publicationDelete.style.display = "initial";
|
||||
publicationTaskStart.style.display = "initial";
|
||||
}
|
||||
@ -210,10 +263,8 @@ function HidePublicationPopup(){
|
||||
|
||||
function ShowNewTaskWindow(){
|
||||
selectPublication.replaceChildren();
|
||||
addTaskPopup.style.display = "block";
|
||||
}
|
||||
function HideAddTaskPopup(){
|
||||
addTaskPopup.style.display = "none";
|
||||
searchPublicationQuery.value = "";
|
||||
selectPublicationPopup.style.display = "flex";
|
||||
}
|
||||
|
||||
|
||||
@ -233,19 +284,21 @@ function OpenSettings(){
|
||||
settingsPopup.style.display = "flex";
|
||||
}
|
||||
|
||||
function HideSettings(){
|
||||
settingsPopup.style.display = "none";
|
||||
}
|
||||
|
||||
function GetSettingsClick(){
|
||||
settingApiUri.value = "";
|
||||
settingKomgaUrl.value = "";
|
||||
settingKomgaUser.value = "";
|
||||
settingKomgaPass.value = "";
|
||||
settingKavitaUrl.value = "";
|
||||
settingKavitaApi.value = "";
|
||||
settingKomgaConfigured.innerText = "❌";
|
||||
settingKavitaUrl.value = "";
|
||||
settingKavitaUser.value = "";
|
||||
settingKavitaPass.value = "";
|
||||
settingKavitaConfigured.innerText = "❌";
|
||||
settingGotifyUrl.value = "";
|
||||
settingGotifyAppToken.value = "";
|
||||
settingGotifyConfigured.innerText = "❌";
|
||||
settingLunaseaWebhook.value = "";
|
||||
settingLunaseaConfigured.innerText = "❌";
|
||||
|
||||
settingApiUri.placeholder = apiUri;
|
||||
|
||||
@ -254,15 +307,23 @@ function GetSettingsClick(){
|
||||
json.libraryManagers.forEach(lm => {
|
||||
if(lm.libraryType == 0){
|
||||
settingKomgaUrl.placeholder = lm.baseUrl;
|
||||
settingKomgaUser.placeholder = "Configured";
|
||||
settingKomgaUser.placeholder = "User";
|
||||
settingKomgaPass.placeholder = "***";
|
||||
settingKomgaConfigured.innerText = "✅";
|
||||
} else if(libraryType == 1){
|
||||
} else if(lm.libraryType == 1){
|
||||
settingKavitaUrl.placeholder = lm.baseUrl;
|
||||
settingKavitaApi.placeholder = "***";
|
||||
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 => {
|
||||
@ -272,82 +333,33 @@ function GetSettingsClick(){
|
||||
}
|
||||
|
||||
function UpdateLibrarySettings(){
|
||||
if(settingKomgaUser.value != "" && settingKomgaPass != ""){
|
||||
if(settingKomgaUrl.value != "" && settingKomgaUser.value != "" && settingKomgaPass.value != ""){
|
||||
var auth = utf8_to_b64(`${settingKomgaUser.value}:${settingKomgaPass.value}`);
|
||||
console.log(auth);
|
||||
|
||||
if(settingKomgaUrl.value != "")
|
||||
UpdateSettings("", settingKomgaUrl.value, auth, "", "");
|
||||
else
|
||||
UpdateSettings("", settingKomgaUrl.placeholder, auth, "", "");
|
||||
UpdateKomga(settingKomgaUrl.value, auth);
|
||||
CreateUpdateLibraryTask(libraryUpdateTime.value);
|
||||
}
|
||||
|
||||
if(settingKavitaUrl.value != "" && settingKavitaApi != ""){
|
||||
UpdateSettings("", "", "", settingKavitaUrl.value, settingKavitaApi.value);
|
||||
if(settingKavitaUrl.value != "" && settingKavitaUser.value != "" && settingKavitaPass.value != ""){
|
||||
UpdateKavita(settingKavitaUrl.value, settingKavitaUser.value, settingKavitaPass.value);
|
||||
CreateUpdateLibraryTask(libraryUpdateTime.value);
|
||||
}
|
||||
CreateTask("UpdateLibraries", libraryUpdateTime.value, "","","");
|
||||
setTimeout(() => GetSettingsClick(), 100);
|
||||
|
||||
if(settingGotifyUrl.value != "" && settingGotifyAppToken.value != ""){
|
||||
UpdateGotify(settingGotifyUrl.value, settingGotifyAppToken.value);
|
||||
}
|
||||
|
||||
if(settingLunaseaWebhook.value != ""){
|
||||
UpdateLunaSea(settingLunaseaWebhook.value);
|
||||
}
|
||||
|
||||
setTimeout(() => GetSettingsClick(), 200);
|
||||
}
|
||||
|
||||
function utf8_to_b64( str ) {
|
||||
return window.btoa(unescape(encodeURIComponent( str )));
|
||||
}
|
||||
|
||||
|
||||
function ShowRunningTasks(event){
|
||||
GetRunningTasks()
|
||||
.then(json => {
|
||||
tagTasksPopupContent.replaceChildren();
|
||||
json.forEach(task => {
|
||||
console.log(task);
|
||||
if(task.publication != null){
|
||||
var taskname = document.createElement("footer-tag-task-name");
|
||||
taskname.innerText = task.publication.sortName;
|
||||
tagTasksPopupContent.appendChild(taskname);
|
||||
}
|
||||
});
|
||||
if(tagTasksPopupContent.children.length > 0){
|
||||
tagTaskPopup.style.display = "block";
|
||||
tagTaskPopup.style.left = `${tagTasksRunning.offsetLeft - 20}px`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function ShowQueuedTasks(event){
|
||||
GetQueue()
|
||||
.then(json => {
|
||||
tagTasksPopupContent.replaceChildren();
|
||||
json.forEach(task => {
|
||||
var taskname = document.createElement("footer-tag-task-name");
|
||||
taskname.innerText = task.publication.sortName;
|
||||
tagTasksPopupContent.appendChild(taskname);
|
||||
});
|
||||
if(json.length > 0){
|
||||
tagTaskPopup.style.display = "block";
|
||||
tagTaskPopup.style.left = `${tagTasksQueued.offsetLeft- 20}px`;
|
||||
}
|
||||
});
|
||||
}
|
||||
function ShowAllTasks(event){
|
||||
GetDownloadTasks()
|
||||
.then(json => {
|
||||
tagTasksPopupContent.replaceChildren();
|
||||
json.forEach(task => {
|
||||
var taskname = document.createElement("footer-tag-task-name");
|
||||
taskname.innerText = task.publication.sortName;
|
||||
tagTasksPopupContent.appendChild(taskname);
|
||||
});
|
||||
if(json.length > 0){
|
||||
tagTaskPopup.style.display = "block";
|
||||
tagTaskPopup.style.left = `${tagTasksTotal.offsetLeft - 20}px`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function CloseTasksPopup(){
|
||||
tagTaskPopup.style.display = "none";
|
||||
}
|
||||
|
||||
function FilterResults(){
|
||||
if(searchBox.value.length > 0){
|
||||
tasksContent.childNodes.forEach(publication => {
|
||||
@ -368,12 +380,77 @@ function FilterResults(){
|
||||
}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
|
||||
ResetContent();
|
||||
downloadTasksOutput.replaceChildren();
|
||||
//Get Tasks and show them
|
||||
GetDownloadTasks()
|
||||
.then(json => json.forEach(task => {
|
||||
@ -386,16 +463,17 @@ GetDownloadTasks()
|
||||
GetRunningTasks()
|
||||
.then(json => {
|
||||
tagTasksRunning.innerText = json.length;
|
||||
json.forEach(task => {
|
||||
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
||||
});
|
||||
|
||||
GetDownloadTasks()
|
||||
.then(json => {
|
||||
tagTasksTotal.innerText = json.length;
|
||||
});
|
||||
|
||||
GetQueue()
|
||||
.then(json => {
|
||||
tagTasksQueued.innerText = json.length;
|
||||
json.forEach(task => {
|
||||
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
||||
});
|
||||
})
|
||||
|
||||
setInterval(() => {
|
||||
@ -425,14 +503,27 @@ setInterval(() => {
|
||||
tagTasksRunning.innerText = json.length;
|
||||
});
|
||||
|
||||
GetDownloadTasks()
|
||||
.then(json => {
|
||||
tagTasksTotal.innerText = json.length;
|
||||
});
|
||||
|
||||
GetQueue()
|
||||
.then(json => {
|
||||
tagTasksQueued.innerText = json.length;
|
||||
})
|
||||
|
||||
});
|
||||
}, 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('');
|
||||
}
|
@ -147,46 +147,22 @@ content {
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
settings {
|
||||
width: 50%;
|
||||
background-color: var(--accent-color);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
z-index: 10;
|
||||
position: absolute;
|
||||
left: 25%;
|
||||
top: 100px;
|
||||
border-radius: 5px;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
#settingsPopup{
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
settings > * {
|
||||
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;
|
||||
#settingsPopup popup-content{
|
||||
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 {
|
||||
@ -281,6 +257,186 @@ popup{
|
||||
left: 0;
|
||||
position: fixed;
|
||||
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 {
|
||||
@ -292,85 +448,14 @@ blur-background {
|
||||
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{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: start;
|
||||
align-content: start;
|
||||
max-height: 70vh;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
#publicationViewerPopup{
|
||||
@ -500,7 +585,7 @@ footer-tag-content{
|
||||
}
|
||||
|
||||
footer-tag-content > * {
|
||||
margin: 2px 0;
|
||||
margin: 2px 5px;
|
||||
}
|
||||
|
||||
footer-tag-popup::before{
|
||||
@ -512,7 +597,7 @@ footer-tag-popup::before{
|
||||
border-left: 10px solid transparent;
|
||||
border-top: 10px solid var(--second-background-color);
|
||||
border-bottom: 10px solid transparent;
|
||||
left: 0px;
|
||||
left: 0;
|
||||
bottom: -17px;
|
||||
border-radius: 0 0 0 5px;
|
||||
}
|
@ -7,7 +7,7 @@ services:
|
||||
- ./tranga:/usr/share/Tranga-API #1 when replacing ./tranga replace #2 with same value
|
||||
- ./Manga:/Manga
|
||||
ports:
|
||||
- 6531:80
|
||||
- "6531:6531"
|
||||
restart: unless-stopped
|
||||
tranga-website:
|
||||
image: glax/tranga-website:latest
|
||||
@ -15,7 +15,7 @@ services:
|
||||
volumes:
|
||||
- ./tranga/imageCache:/usr/share/nginx/html/imageCache:ro #2 when replacing Point to same value as #1/imageCache
|
||||
ports:
|
||||
- 9555:80
|
||||
- "9555:80"
|
||||
depends_on:
|
||||
- tranga-api
|
||||
restart: unless-stopped
|
Reference in New Issue
Block a user