Compare commits
14 Commits
1.5
...
c3342984ea
Author | SHA1 | Date | |
---|---|---|---|
c3342984ea | |||
ed4bdb5b33 | |||
0f0902c932 | |||
6508055b43 | |||
abc66511d8 | |||
9ed36c47b5 | |||
fd1b2a8470 | |||
8058749ab5 | |||
8737617e5f | |||
7e4f43f1e2 | |||
12b1b2afd6 | |||
0f9ac60fcd | |||
8c87f2948c | |||
e0fb817256 |
@ -6,7 +6,7 @@ COPY . /src/
|
||||
RUN dotnet restore API/API.csproj
|
||||
RUN dotnet publish -c Release -o /publish
|
||||
|
||||
FROM glax/tranga-base:dev as runtime
|
||||
FROM glax/tranga-base:latest as runtime
|
||||
WORKDIR /publish
|
||||
COPY --from=build-env /publish .
|
||||
EXPOSE 6531
|
||||
|
@ -80,11 +80,11 @@ public class RequestHandler
|
||||
private Dictionary<string, string> GetRequestVariables(string query)
|
||||
{
|
||||
Dictionary<string, string> ret = new();
|
||||
Regex queryRex = new (@"\?{1}([A-z]+=[A-z]+)+(&[A-z]+=[A-z]+)*");
|
||||
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('&'))
|
||||
foreach(string kvpair in query.Split('&').Where(str => str.Length>=3 ))
|
||||
ret.Add(kvpair.Split('=')[0], kvpair.Split('=')[1]);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Logging;
|
||||
@ -18,7 +19,10 @@ public class Server
|
||||
public Server(int port, TaskManager taskManager, Logger? logger = null)
|
||||
{
|
||||
this.logger = logger;
|
||||
this._listener.Prefixes.Add($"http://*:{port}/");
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
this._listener.Prefixes.Add($"http://*:{port}/");
|
||||
else
|
||||
this._listener.Prefixes.Add($"http://localhost:{port}/");
|
||||
this._requestHandler = new RequestHandler(taskManager, this);
|
||||
Listen();
|
||||
}
|
||||
@ -51,7 +55,14 @@ public class Server
|
||||
return;
|
||||
}
|
||||
|
||||
_requestHandler.HandleRequest(request, response);
|
||||
if (request.HttpMethod == "OPTIONS")
|
||||
{
|
||||
SendResponse(HttpStatusCode.OK, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
_requestHandler.HandleRequest(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
||||
@ -63,9 +74,16 @@ public class Server
|
||||
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>());
|
||||
try
|
||||
{
|
||||
response.OutputStream.Write(content is not null
|
||||
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
|
||||
: Array.Empty<byte>());
|
||||
}
|
||||
catch (HttpListenerException)
|
||||
{
|
||||
|
||||
}
|
||||
response.OutputStream.Close();
|
||||
|
||||
}
|
||||
|
14
Dockerfile
@ -1,14 +0,0 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
|
||||
WORKDIR /src
|
||||
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 glax/tranga-base:latest as runtime
|
||||
WORKDIR /publish
|
||||
COPY --from=build-env /publish .
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["dotnet", "/publish/Tranga-API.dll"]
|
36
README.md
@ -52,14 +52,14 @@
|
||||
<!-- ABOUT THE PROJECT -->
|
||||
## About The Project
|
||||
|
||||
Tranga can download Chapters and Metadata from Scanlation sites such as
|
||||
Tranga can download Chapters and Metadata from "Scanlation" sites such as
|
||||
|
||||
- [MangaDex.org](https://mangadex.org/)
|
||||
- [Manganato.com](https://manganato.com/)
|
||||
- [Mangasee](https://mangasee123.com/)
|
||||
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues)
|
||||
|
||||
and automatically start updates in [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/) to import them.
|
||||
|
||||
and automatically import them with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/). Also Notifications will be sent to your devices using [Gotify](https://gotify.net/) and [LunaSea](https://www.lunasea.app/).
|
||||
### Inspiration:
|
||||
|
||||
Because [Kaizoku](https://github.com/oae/kaizoku) was relying on [mangal](https://github.com/metafates/mangal) and mangal
|
||||
@ -76,19 +76,18 @@ That is why I wanted to create my own project, in a language I understand, and t
|
||||
- Newtonsoft.JSON
|
||||
- [PuppeteerSharp](https://www.puppeteersharp.com/)
|
||||
- [Html Agility Pack (HAP)](https://html-agility-pack.net/)
|
||||
- Love <3 Blåhaj 🦈
|
||||
- 💙 Blåhaj 🦈
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||
|  |  |
|
||||
|-----------------------------------:|:----------------------------------|
|
||||
|
||||

|
||||
|
||||
|  |  |
|
||||
|-----------------------------------:|:-------------------------------------------------:|
|
||||
|  |  |  |
|
||||
|-----------------------------------:|:-------------------------------------------------:|:-----------------------------------|
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
@ -110,39 +109,42 @@ 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
|
||||
### Docker-Website 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:
|
||||
After clicking 'Search' (or pressing Enter), the results will be presented below - this might, depending on the result-size, take a while because we are already preloading the cover-images.
|
||||
Next select the publication (by selecting the cover) 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.
|
||||
When selecting `Monitor` you will be presented with a new window and the selection of the interval you want to check for new chapters (Default: Every 3 hours).
|
||||
When selecting `Download Chapter` a list will open with all available chapters - that have not yet been downloaded - from which you can then select a range (see below).
|
||||
|
||||
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).
|
||||
Examples: `2-12`, `c1`, `ch 2`, `chapter 3`, `v 2`, `vol3-4`, `v2c4` (note: you can only specify a single chapter with this last syntax).
|
||||
|
||||
### Prerequisites
|
||||
|
||||
#### To Build
|
||||
[.NET-Core 7.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
|
||||
#### To Run
|
||||
[.NET-Core 7.0 Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) scroll down a bit, should be on the right the second item.
|
||||
|
||||
<!-- ROADMAP -->
|
||||
## Roadmap
|
||||
|
||||
- [ ] Docker ARM support
|
||||
- [ ] ?
|
||||
- [ ] ❓
|
||||
|
||||
See the [open issues](https://git.bernloehr.eu/glax/Tranga/issues) for a full list of proposed features (and known issues).
|
||||
See the [open issues](https://github.com/C9Glax/tranga/issues) for a full list of proposed features (and known issues).
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
@ -6,18 +6,18 @@ namespace Tranga.NotificationManagers;
|
||||
|
||||
public class LunaSea : NotificationManager
|
||||
{
|
||||
public string webhook { get; }
|
||||
public string id { get; }
|
||||
private readonly HttpClient _client = new();
|
||||
public LunaSea(string webhook, Logger? logger = null) : base(NotificationManagerType.LunaSea, logger)
|
||||
public LunaSea(string id, Logger? logger = null) : base(NotificationManagerType.LunaSea, logger)
|
||||
{
|
||||
this.webhook = webhook;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
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);
|
||||
HttpRequestMessage request = new(HttpMethod.Post, $"https://notify.lunasea.app/v1/custom/{id}");
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = _client.Send(request);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
|
@ -82,9 +82,8 @@ public class TaskManager
|
||||
}
|
||||
}
|
||||
|
||||
TrangaTask[] failedDownloadChapterTasks = _allTasks.Where(taskQuery =>
|
||||
taskQuery.state is TrangaTask.ExecutionState.Failed && taskQuery is DownloadChapterTask).ToArray();
|
||||
foreach (TrangaTask failedDownloadChapterTask in failedDownloadChapterTasks)
|
||||
foreach (TrangaTask failedDownloadChapterTask in _allTasks.Where(taskQuery =>
|
||||
taskQuery.state is TrangaTask.ExecutionState.Failed && taskQuery is DownloadChapterTask).ToArray())
|
||||
{
|
||||
DeleteTask(failedDownloadChapterTask);
|
||||
TrangaTask newTask = failedDownloadChapterTask.Clone();
|
||||
@ -92,13 +91,6 @@ public class TaskManager
|
||||
AddTask(newTask);
|
||||
}
|
||||
|
||||
TrangaTask[] successfulDownloadChapterTasks = _allTasks.Where(taskQuery =>
|
||||
taskQuery.state is TrangaTask.ExecutionState.Success && taskQuery is DownloadChapterTask).ToArray();
|
||||
foreach(TrangaTask successfulDownloadChapterTask in successfulDownloadChapterTasks)
|
||||
{
|
||||
DeleteTask(successfulDownloadChapterTask);
|
||||
}
|
||||
|
||||
if(waitingTasksCount != _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting))
|
||||
ExportDataAndSettings();
|
||||
waitingTasksCount = _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting);
|
||||
@ -166,6 +158,8 @@ public class TaskManager
|
||||
_runningDownloadChapterTasks[cRemoveTask].Cancel();
|
||||
_runningDownloadChapterTasks.Remove(cRemoveTask);
|
||||
}
|
||||
foreach(TrangaTask childTask in removeTask.childTasks)
|
||||
DeleteTask(childTask);
|
||||
}
|
||||
|
||||
public IEnumerable<TrangaTask> GetTasksMatching(TrangaTask.Task taskType, string? connectorName = null, string? searchString = null, string? internalId = null, string? chapterSortNumber = null)
|
||||
@ -369,9 +363,7 @@ 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));
|
||||
settings.ExportSettings();
|
||||
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Exporting tasks to {settings.tasksFilePath}");
|
||||
while(IsFileInUse(settings.tasksFilePath))
|
||||
|
@ -43,6 +43,29 @@ public class TrangaSettings
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void ExportSettings()
|
||||
{
|
||||
if (File.Exists(settingsFilePath))
|
||||
{
|
||||
bool inUse = true;
|
||||
while (inUse)
|
||||
{
|
||||
try
|
||||
{
|
||||
using FileStream stream = new (settingsFilePath, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||
stream.Close();
|
||||
inUse = false;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
inUse = true;
|
||||
Thread.Sleep(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this));
|
||||
}
|
||||
|
||||
public void UpdateSettings(UpdateField field, Logger? logger = null, params string[] values)
|
||||
{
|
||||
switch (field)
|
||||
@ -81,6 +104,7 @@ public class TrangaSettings
|
||||
newLunaSea.SendNotification("Success!", "LunaSea was added to Tranga!");
|
||||
break;
|
||||
}
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public enum UpdateField { DownloadLocation, Komga, Kavita, Gotify, LunaSea}
|
||||
|
@ -22,14 +22,14 @@ public abstract class TrangaTask
|
||||
public DateTime lastExecuted { get; set; }
|
||||
[Newtonsoft.Json.JsonIgnore] public ExecutionState state { get; set; }
|
||||
public Task task { get; }
|
||||
public string taskId { get; }
|
||||
public string taskId { get; init; }
|
||||
[Newtonsoft.Json.JsonIgnore] public TrangaTask? parentTask { get; set; }
|
||||
public string? parentTaskId { get; set; }
|
||||
[Newtonsoft.Json.JsonIgnore] protected HashSet<TrangaTask> childTasks { get; }
|
||||
[Newtonsoft.Json.JsonIgnore] internal 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;
|
||||
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; internal set; }
|
||||
[Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => lastChange.Add(GetRemainingTime());
|
||||
public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now);
|
||||
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
||||
|
||||
@ -72,9 +72,16 @@ public abstract class TrangaTask
|
||||
this.state = ExecutionState.Running;
|
||||
this.executionStarted = DateTime.Now;
|
||||
this.lastChange = DateTime.Now;
|
||||
if(parentTask is not null && parentTask.childTasks.All(ct => ct.state is ExecutionState.Waiting))
|
||||
parentTask.executionStarted = DateTime.Now;
|
||||
|
||||
HttpStatusCode statusCode = ExecuteTask(taskManager, logger, cancellationToken);
|
||||
|
||||
while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running))
|
||||
Thread.Sleep(1000);
|
||||
foreach(TrangaTask childTask in this.childTasks.ToArray())
|
||||
taskManager.DeleteTask(childTask);
|
||||
|
||||
if ((int)statusCode >= 200 && (int)statusCode < 300)
|
||||
{
|
||||
this.lastExecuted = DateTime.Now;
|
||||
@ -106,10 +113,10 @@ public abstract class TrangaTask
|
||||
|
||||
private TimeSpan GetRemainingTime()
|
||||
{
|
||||
if(progress == 0 || lastChange == DateTime.MaxValue || executionStarted == DateTime.UnixEpoch)
|
||||
return TimeSpan.Zero;
|
||||
if(progress == 0 || state is ExecutionState.Enqueued or ExecutionState.Waiting or ExecutionState.Failed || lastChange == DateTime.MaxValue)
|
||||
return DateTime.MaxValue.Subtract(lastChange).Subtract(TimeSpan.FromHours(1));
|
||||
TimeSpan elapsed = lastChange.Subtract(executionStarted);
|
||||
return elapsed.Divide(progress).Subtract(elapsed);
|
||||
return elapsed.Divide(progress).Multiply(1 - progress);
|
||||
}
|
||||
|
||||
public enum Task : byte
|
||||
|
@ -47,6 +47,9 @@ public class DownloadChapterTask : TrangaTask
|
||||
internal void IncrementProgress(double amount)
|
||||
{
|
||||
this._dctProgress += amount;
|
||||
this.lastChange = DateTime.Now;
|
||||
if(this.parentTask is not null)
|
||||
this.parentTask.lastChange = DateTime.Now;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@ -142,7 +142,7 @@
|
||||
<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">
|
||||
<label for="lunaseaWebhook"></label><input placeholder="device/:id or user/:id" 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">
|
||||
|
@ -195,7 +195,7 @@ function DownloadChapterTaskClick(){
|
||||
|
||||
function DeleteTaskClick(){
|
||||
taskToDelete = tasks.filter(tTask => tTask.publication.internalId === toEditId)[0];
|
||||
DeleteTask("DownloadNewChapters", taskToDelete.connectorName, toEditId);
|
||||
DeleteTask("MonitorPublication", taskToDelete.connectorName, toEditId);
|
||||
HidePublicationPopup();
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 2.1 MiB |
Before Width: | Height: | Size: 2.6 MiB After Width: | Height: | Size: 2.5 MiB |
BIN
screenshots/progress.png
Normal file
After Width: | Height: | Size: 354 KiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 1.8 MiB |
Before Width: | Height: | Size: 1.7 MiB After Width: | Height: | Size: 1.5 MiB |