mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-01 16:34:17 +02:00
Compare commits
18 Commits
e4f33bcca9
...
v1.2
Author | SHA1 | Date | |
---|---|---|---|
1cd819b21d | |||
27afedc1b4 | |||
fac0a3f7eb | |||
03ca480fe8 | |||
c2915468a5 | |||
8805c53cb8 | |||
adbbe3f6cc | |||
14b694d3be | |||
72ce75c6e0 | |||
8381951168 | |||
b24032d124 | |||
8bc23f7c69 | |||
48b7371a18 | |||
61ecefb615 | |||
8ff65bf400 | |||
932057cca0 | |||
67d06cd887 | |||
cbb012a659 |
@ -54,6 +54,7 @@
|
|||||||
Tranga can download Chapters and Metadata from Scanlation sites such as
|
Tranga can download Chapters and Metadata from Scanlation sites such as
|
||||||
|
|
||||||
- [MangaDex.org](https://mangadex.org/)
|
- [MangaDex.org](https://mangadex.org/)
|
||||||
|
- [Manganato.com](https://manganato.com/)
|
||||||
|
|
||||||
and automatically start updates in [Komga](https://komga.org/) to import them.
|
and automatically start updates in [Komga](https://komga.org/) to import them.
|
||||||
|
|
||||||
|
@ -12,26 +12,17 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "http://localhost:5177",
|
"applicationUrl": "http://localhost:5177"
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"https": {
|
"https": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "https://localhost:7036;http://localhost:5177",
|
"applicationUrl": "https://localhost:7036;http://localhost:5177"
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"IIS Express": {
|
"IIS Express": {
|
||||||
"commandName": "IISExpress",
|
"commandName": "IISExpress",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Manganato/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -126,9 +126,9 @@ public abstract class Connector
|
|||||||
/// <param name="imageUrl"></param>
|
/// <param name="imageUrl"></param>
|
||||||
/// <param name="fullPath"></param>
|
/// <param name="fullPath"></param>
|
||||||
/// <param name="requestType">RequestType for Rate-Limit</param>
|
/// <param name="requestType">RequestType for Rate-Limit</param>
|
||||||
private void DownloadImage(string imageUrl, string fullPath, byte requestType)
|
private void DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
|
||||||
{
|
{
|
||||||
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType);
|
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
|
||||||
byte[] buffer = new byte[requestResult.result.Length];
|
byte[] buffer = new byte[requestResult.result.Length];
|
||||||
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
||||||
File.WriteAllBytes(fullPath, buffer);
|
File.WriteAllBytes(fullPath, buffer);
|
||||||
@ -141,7 +141,7 @@ public abstract class Connector
|
|||||||
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
||||||
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
||||||
/// <param name="requestType">RequestType for RateLimits</param>
|
/// <param name="requestType">RequestType for RateLimits</param>
|
||||||
protected void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, string? comicInfoPath = null)
|
protected void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, string? comicInfoPath = null, string? referrer = null)
|
||||||
{
|
{
|
||||||
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
|
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
|
||||||
//Check if Publication Directory already exists
|
//Check if Publication Directory already exists
|
||||||
@ -162,7 +162,7 @@ public abstract class Connector
|
|||||||
string[] split = imageUrl.Split('.');
|
string[] split = imageUrl.Split('.');
|
||||||
string extension = split[^1];
|
string extension = split[^1];
|
||||||
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1}/{imageUrls.Length}");
|
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1}/{imageUrls.Length}");
|
||||||
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType);
|
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(comicInfoPath is not null)
|
if(comicInfoPath is not null)
|
||||||
@ -174,6 +174,23 @@ public abstract class Connector
|
|||||||
Directory.Delete(tempFolder, true); //Cleanup
|
Directory.Delete(tempFolder, true); //Cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected string SaveCoverImageToCache(string url, byte requestType)
|
||||||
|
{
|
||||||
|
string[] split = url.Split('/');
|
||||||
|
string filename = split[^1];
|
||||||
|
string saveImagePath = Path.Join(imageCachePath, filename);
|
||||||
|
|
||||||
|
if (File.Exists(saveImagePath))
|
||||||
|
return filename;
|
||||||
|
|
||||||
|
DownloadClient.RequestResult coverResult = downloadClient.MakeRequest(url, requestType);
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
coverResult.result.CopyTo(ms);
|
||||||
|
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Saving image to {saveImagePath}");
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
protected class DownloadClient
|
protected class DownloadClient
|
||||||
{
|
{
|
||||||
private static readonly HttpClient Client = new();
|
private static readonly HttpClient Client = new();
|
||||||
@ -202,7 +219,7 @@ public abstract class Connector
|
|||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="requestType">For RateLimits: Same Endpoints use same type</param>
|
/// <param name="requestType">For RateLimits: Same Endpoints use same type</param>
|
||||||
/// <returns>RequestResult with StatusCode and Stream of received data</returns>
|
/// <returns>RequestResult with StatusCode and Stream of received data</returns>
|
||||||
public RequestResult MakeRequest(string url, byte requestType)
|
public RequestResult MakeRequest(string url, byte requestType, string? referrer = null)
|
||||||
{
|
{
|
||||||
if (_rateLimit.TryGetValue(requestType, out TimeSpan value))
|
if (_rateLimit.TryGetValue(requestType, out TimeSpan value))
|
||||||
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value));
|
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value));
|
||||||
@ -224,6 +241,8 @@ public abstract class Connector
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
||||||
|
if(referrer is not null)
|
||||||
|
requestMessage.Headers.Referrer = new Uri(referrer);
|
||||||
_lastExecutedRateLimit[requestType] = DateTime.Now;
|
_lastExecutedRateLimit[requestType] = DateTime.Now;
|
||||||
response = Client.Send(requestMessage);
|
response = Client.Send(requestMessage);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ public class MangaDex : Connector
|
|||||||
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
||||||
string? coverCacheName = null;
|
string? coverCacheName = null;
|
||||||
if (coverUrl is not null)
|
if (coverUrl is not null)
|
||||||
coverCacheName = SaveImage(coverUrl);
|
coverCacheName = SaveCoverImageToCache(coverUrl, (byte)RequestType.AtHomeServer);
|
||||||
|
|
||||||
string? author = GetAuthor(authorId);
|
string? author = GetAuthor(authorId);
|
||||||
|
|
||||||
@ -273,21 +273,4 @@ public class MangaDex : Connector
|
|||||||
logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {author}");
|
logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {author}");
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string SaveImage(string url)
|
|
||||||
{
|
|
||||||
string[] split = url.Split('/');
|
|
||||||
string filename = split[^1];
|
|
||||||
string saveImagePath = Path.Join(imageCachePath, filename);
|
|
||||||
|
|
||||||
if (File.Exists(saveImagePath))
|
|
||||||
return filename;
|
|
||||||
|
|
||||||
DownloadClient.RequestResult coverResult = downloadClient.MakeRequest(url, (byte)RequestType.AtHomeServer);
|
|
||||||
using MemoryStream ms = new();
|
|
||||||
coverResult.result.CopyTo(ms);
|
|
||||||
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Saving image to {saveImagePath}");
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
}
|
}
|
197
Tranga/Connectors/Manganato.cs
Normal file
197
Tranga/Connectors/Manganato.cs
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Logging;
|
||||||
|
|
||||||
|
namespace Tranga.Connectors;
|
||||||
|
|
||||||
|
public class Manganato : Connector
|
||||||
|
{
|
||||||
|
public override string name { get; }
|
||||||
|
|
||||||
|
public Manganato(string downloadLocation, string imageCachePath, Logger? logger) : base(downloadLocation, imageCachePath, logger)
|
||||||
|
{
|
||||||
|
this.name = "Manganato";
|
||||||
|
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||||
|
{
|
||||||
|
{(byte)1, 100}
|
||||||
|
}, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Publication[] GetPublications(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
|
||||||
|
string sanitizedTitle = publicationTitle.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)
|
||||||
|
return Array.Empty<Publication>();
|
||||||
|
|
||||||
|
return ParsePublicationsFromHtml(requestResult.result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Publication[] ParsePublicationsFromHtml(Stream html)
|
||||||
|
{
|
||||||
|
StreamReader reader = new (html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
IEnumerable<HtmlNode> searchResults = document.DocumentNode.Descendants("div").Where(n => n.HasClass("search-story-item"));
|
||||||
|
List<string> urls = new();
|
||||||
|
foreach (HtmlNode mangaResult in searchResults)
|
||||||
|
{
|
||||||
|
urls.Add(mangaResult.Descendants("a").First(n => n.HasClass("item-title")).GetAttributes()
|
||||||
|
.First(a => a.Name == "href").Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<Publication> ret = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
DownloadClient.RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(url, (byte)1);
|
||||||
|
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||||
|
return Array.Empty<Publication>();
|
||||||
|
|
||||||
|
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Publication ParseSinglePublicationFromHtml(Stream html, string publicationId)
|
||||||
|
{
|
||||||
|
StreamReader reader = new (html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
string status = "";
|
||||||
|
Dictionary<string, string> altTitles = new();
|
||||||
|
Dictionary<string, string>? links = null;
|
||||||
|
HashSet<string> tags = new();
|
||||||
|
string? author = null, originalLanguage = null;
|
||||||
|
int? year = DateTime.Now.Year;
|
||||||
|
|
||||||
|
HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("story-info-right"));
|
||||||
|
|
||||||
|
string sortName = infoNode.Descendants("h1").First().InnerText;
|
||||||
|
|
||||||
|
HtmlNode infoTable = infoNode.Descendants().First(d => d.Name == "table");
|
||||||
|
|
||||||
|
foreach (HtmlNode row in infoTable.Descendants("tr"))
|
||||||
|
{
|
||||||
|
string key = row.SelectNodes("td").First().InnerText.ToLower();
|
||||||
|
string value = row.SelectNodes("td").Last().InnerText;
|
||||||
|
string keySanitized = string.Concat(Regex.Matches(key, "[a-z]"));
|
||||||
|
|
||||||
|
switch (keySanitized)
|
||||||
|
{
|
||||||
|
case "alternative":
|
||||||
|
string[] alts = value.Split(" ; ");
|
||||||
|
for(int i = 0; i < alts.Length; i++)
|
||||||
|
altTitles.Add(i.ToString(), alts[i]);
|
||||||
|
break;
|
||||||
|
case "authors":
|
||||||
|
author = value;
|
||||||
|
break;
|
||||||
|
case "status":
|
||||||
|
status = value;
|
||||||
|
break;
|
||||||
|
case "genres":
|
||||||
|
string[] genres = value.Split(" - ");
|
||||||
|
tags = genres.ToHashSet();
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string posterUrl = document.DocumentNode.Descendants("span").First(s => s.HasClass("info-image")).Descendants("img").First()
|
||||||
|
.GetAttributes().First(a => a.Name == "src").Value;
|
||||||
|
|
||||||
|
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1);
|
||||||
|
|
||||||
|
string description = document.DocumentNode.Descendants("div").First(d => d.HasClass("panel-story-info-description"))
|
||||||
|
.InnerText.Replace("Description :", "");
|
||||||
|
while (description.StartsWith('\n'))
|
||||||
|
description = description.Substring(1);
|
||||||
|
|
||||||
|
string yearString = document.DocumentNode.Descendants("li").Last(li => li.HasClass("a-h")).Descendants("span")
|
||||||
|
.First(s => s.HasClass("chapter-time")).InnerText;
|
||||||
|
year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000;
|
||||||
|
|
||||||
|
return new Publication(sortName, author, description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||||
|
year, originalLanguage, status, publicationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})");
|
||||||
|
string requestUrl = $"https://chapmanganato.com/{publication.publicationId}";
|
||||||
|
DownloadClient.RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||||
|
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
|
||||||
|
return ParseChaptersFromHtml(requestResult.result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Chapter[] ParseChaptersFromHtml(Stream html)
|
||||||
|
{
|
||||||
|
StreamReader reader = new (html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
List<Chapter> ret = new();
|
||||||
|
|
||||||
|
HtmlNode chapterList = document.DocumentNode.Descendants("ul").First(l => l.HasClass("row-content-chapter"));
|
||||||
|
|
||||||
|
foreach (HtmlNode chapterInfo in chapterList.Descendants("li"))
|
||||||
|
{
|
||||||
|
string fullString = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")).InnerText;
|
||||||
|
|
||||||
|
string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null;
|
||||||
|
string? chapterNumber = fullString.Split(':')[0].Split(' ')[^1];
|
||||||
|
string chapterName = string.Concat(fullString.Split(':')[1..]);
|
||||||
|
string url = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name"))
|
||||||
|
.GetAttributeValue("href", "");
|
||||||
|
ret.Add(new Chapter(chapterName, volumeNumber, chapterNumber, url));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DownloadChapter(Publication publication, Chapter chapter)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.result);
|
||||||
|
|
||||||
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
|
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
|
||||||
|
|
||||||
|
DownloadChapterImages(imageUrls, GetArchiveFilePath(publication, chapter), (byte)1, comicInfoPath, "https://chapmanganato.com/");
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] ParseImageUrlsFromHtml(Stream html)
|
||||||
|
{
|
||||||
|
StreamReader reader = new (html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
List<string> ret = new();
|
||||||
|
|
||||||
|
HtmlNode imageContainer =
|
||||||
|
document.DocumentNode.Descendants("div").First(i => i.HasClass("container-chapter-reader"));
|
||||||
|
foreach(HtmlNode imageNode in imageContainer.Descendants("img"))
|
||||||
|
ret.Add(imageNode.GetAttributeValue("src", ""));
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
}
|
@ -95,9 +95,9 @@ public readonly struct Publication
|
|||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
if(status == "ongoing" || status == "hiatus")
|
if(status.ToLower() == "ongoing" || status.ToLower() == "hiatus")
|
||||||
this.status = "Continuing";
|
this.status = "Continuing";
|
||||||
else if (status == "completed" || status == "cancelled")
|
else if (status.ToLower() == "completed" || status.ToLower() == "cancelled")
|
||||||
this.status = "Ended";
|
this.status = "Ended";
|
||||||
else
|
else
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
@ -39,7 +39,11 @@ public class TaskManager
|
|||||||
this.settings = new TrangaSettings(downloadFolderPath, workingDirectory, newKomga);
|
this.settings = new TrangaSettings(downloadFolderPath, workingDirectory, newKomga);
|
||||||
ExportDataAndSettings();
|
ExportDataAndSettings();
|
||||||
|
|
||||||
this._connectors = new Connector[]{ new MangaDex(downloadFolderPath, imageCachePath, logger) };
|
this._connectors = new Connector[]
|
||||||
|
{
|
||||||
|
new MangaDex(downloadFolderPath, imageCachePath, logger),
|
||||||
|
new Manganato(downloadFolderPath, imageCachePath, logger)
|
||||||
|
};
|
||||||
foreach(Connector cConnector in this._connectors)
|
foreach(Connector cConnector in this._connectors)
|
||||||
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
||||||
|
|
||||||
@ -59,7 +63,11 @@ public class TaskManager
|
|||||||
public TaskManager(TrangaSettings settings, Logger? logger = null)
|
public TaskManager(TrangaSettings settings, Logger? logger = null)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation, settings.coverImageCache, logger) };
|
this._connectors = new Connector[]
|
||||||
|
{
|
||||||
|
new MangaDex(settings.downloadLocation, settings.coverImageCache, logger),
|
||||||
|
new Manganato(settings.downloadLocation, settings.coverImageCache, logger)
|
||||||
|
};
|
||||||
foreach(Connector cConnector in this._connectors)
|
foreach(Connector cConnector in this._connectors)
|
||||||
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
||||||
_allTasks = new HashSet<TrangaTask>();
|
_allTasks = new HashSet<TrangaTask>();
|
||||||
@ -116,10 +124,9 @@ public class TaskManager
|
|||||||
if (!this._allTasks.Contains(task))
|
if (!this._allTasks.Contains(task))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Forcing Execution: {task}");
|
|
||||||
Task t = new(() =>
|
Task t = new(() =>
|
||||||
{
|
{
|
||||||
task.Execute(this);
|
task.Execute(this, this.logger);
|
||||||
});
|
});
|
||||||
t.Start();
|
t.Start();
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Tranga.TrangaTasks;
|
using Tranga.TrangaTasks;
|
||||||
|
|
||||||
@ -35,12 +36,29 @@ public abstract class TrangaTask
|
|||||||
this.task = task;
|
this.task = task;
|
||||||
this.language = language;
|
this.language = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set state to running
|
/// BL for concrete Tasks
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="taskManager"></param>
|
/// <param name="taskManager"></param>
|
||||||
public abstract void Execute(TaskManager taskManager);
|
/// <param name="logger"></param>
|
||||||
|
protected abstract void ExecuteTask(TaskManager taskManager, Logger? logger);
|
||||||
|
|
||||||
|
/// <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)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Executing Task {this}");
|
||||||
|
this.state = ExecutionState.Running;
|
||||||
|
ExecuteTask(taskManager, logger);
|
||||||
|
this.lastExecuted = DateTime.Now;
|
||||||
|
this.state = ExecutionState.Waiting;
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <returns>True if elapsed time since last execution is greater than set interval</returns>
|
/// <returns>True if elapsed time since last execution is greater than set interval</returns>
|
||||||
public bool ShouldExecute()
|
public bool ShouldExecute()
|
||||||
@ -48,10 +66,10 @@ public abstract class TrangaTask
|
|||||||
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence && state is ExecutionState.Waiting;
|
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence && state is ExecutionState.Waiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Task
|
public enum Task : byte
|
||||||
{
|
{
|
||||||
DownloadNewChapters,
|
DownloadNewChapters = 2,
|
||||||
UpdateKomgaLibrary
|
UpdateKomgaLibrary = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Tranga.TrangaTasks;
|
using Logging;
|
||||||
|
|
||||||
|
namespace Tranga.TrangaTasks;
|
||||||
|
|
||||||
public class DownloadNewChaptersTask : TrangaTask
|
public class DownloadNewChaptersTask : TrangaTask
|
||||||
{
|
{
|
||||||
@ -6,9 +8,8 @@ public class DownloadNewChaptersTask : TrangaTask
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Execute(TaskManager taskManager)
|
protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
|
||||||
{
|
{
|
||||||
this.state = ExecutionState.Running;
|
|
||||||
Publication pub = (Publication)this.publication!;
|
Publication pub = (Publication)this.publication!;
|
||||||
Connector connector = taskManager.GetConnector(this.connectorName);
|
Connector connector = taskManager.GetConnector(this.connectorName);
|
||||||
|
|
||||||
@ -24,8 +25,6 @@ public class DownloadNewChaptersTask : TrangaTask
|
|||||||
|
|
||||||
foreach(Chapter newChapter in newChapters)
|
foreach(Chapter newChapter in newChapters)
|
||||||
connector.DownloadChapter(pub, newChapter);
|
connector.DownloadChapter(pub, newChapter);
|
||||||
|
|
||||||
this.state = ExecutionState.Waiting;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Tranga.TrangaTasks;
|
using Logging;
|
||||||
|
|
||||||
|
namespace Tranga.TrangaTasks;
|
||||||
|
|
||||||
public class UpdateKomgaLibraryTask : TrangaTask
|
public class UpdateKomgaLibraryTask : TrangaTask
|
||||||
{
|
{
|
||||||
@ -6,9 +8,8 @@ public class UpdateKomgaLibraryTask : TrangaTask
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Execute(TaskManager taskManager)
|
protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
|
||||||
{
|
{
|
||||||
this.state = ExecutionState.Running;
|
|
||||||
if (taskManager.komga is null)
|
if (taskManager.komga is null)
|
||||||
return;
|
return;
|
||||||
Komga komga = taskManager.komga;
|
Komga komga = taskManager.komga;
|
||||||
@ -16,6 +17,5 @@ public class UpdateKomgaLibraryTask : TrangaTask
|
|||||||
Komga.KomgaLibrary[] allLibraries = komga.GetLibraries();
|
Komga.KomgaLibrary[] allLibraries = komga.GetLibraries();
|
||||||
foreach (Komga.KomgaLibrary lib in allLibraries)
|
foreach (Komga.KomgaLibrary lib in allLibraries)
|
||||||
komga.UpdateLibrary(lib.id);
|
komga.UpdateLibrary(lib.id);
|
||||||
this.state = ExecutionState.Waiting;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,12 +10,12 @@
|
|||||||
<wrapper>
|
<wrapper>
|
||||||
<topbar>
|
<topbar>
|
||||||
<titlebox>
|
<titlebox>
|
||||||
<img src="media/blahaj.png">
|
<img alt="website image is Blahaj" src="media/blahaj.png">
|
||||||
<span>Tranga</span>
|
<span>Tranga</span>
|
||||||
</titlebox>
|
</titlebox>
|
||||||
<spacer></spacer>
|
<spacer></spacer>
|
||||||
<searchdiv>
|
<searchdiv>
|
||||||
<input id="searchbox" placeholder="Filter" type="text">
|
<label for="searchbox"></label><input id="searchbox" placeholder="Filter" type="text">
|
||||||
</searchdiv>
|
</searchdiv>
|
||||||
<img id="settingscog" src="media/settings-cogwheel.svg" height="100%" alt="settingscog">
|
<img id="settingscog" src="media/settings-cogwheel.svg" height="100%" alt="settingscog">
|
||||||
</topbar>
|
</topbar>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
let tasks = [];
|
let tasks = [];
|
||||||
let toEditId;
|
let toEditId;
|
||||||
|
|
||||||
|
const searchBox = document.querySelector("#searchbox");
|
||||||
const searchPublicationQuery = document.querySelector("#searchPublicationQuery");
|
const searchPublicationQuery = document.querySelector("#searchPublicationQuery");
|
||||||
const selectPublication = document.querySelector("#taskSelectOutput");
|
const selectPublication = document.querySelector("#taskSelectOutput");
|
||||||
const connectorSelect = document.querySelector("#connectors");
|
const connectorSelect = document.querySelector("#connectors");
|
||||||
@ -34,6 +35,7 @@ const tagTasksTotal = document.querySelector("#totalTasksTag");
|
|||||||
const tagTaskPopup = document.querySelector("footer-tag-popup");
|
const tagTaskPopup = document.querySelector("footer-tag-popup");
|
||||||
const tagTasksPopupContent = document.querySelector("footer-tag-content");
|
const tagTasksPopupContent = document.querySelector("footer-tag-content");
|
||||||
|
|
||||||
|
searchbox.addEventListener("keyup", (event) => FilterResults());
|
||||||
settingsCog.addEventListener("click", () => OpenSettings());
|
settingsCog.addEventListener("click", () => OpenSettings());
|
||||||
document.querySelector("#blurBackgroundSettingsPopup").addEventListener("click", () => HideSettings());
|
document.querySelector("#blurBackgroundSettingsPopup").addEventListener("click", () => HideSettings());
|
||||||
closetaskpopup.addEventListener("click", () => HideAddTaskPopup());
|
closetaskpopup.addEventListener("click", () => HideAddTaskPopup());
|
||||||
@ -331,6 +333,30 @@ function CloseTasksPopup(){
|
|||||||
tagTaskPopup.style.display = "none";
|
tagTaskPopup.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function FilterResults(){
|
||||||
|
if(searchBox.value.length > 0){
|
||||||
|
tasksContent.childNodes.forEach(publication => {
|
||||||
|
publication.childNodes.forEach(item => {
|
||||||
|
if(item.nodeName.toLowerCase() == "publication-information"){
|
||||||
|
item.childNodes.forEach(information => {
|
||||||
|
if(information.nodeName.toLowerCase() == "publication-name"){
|
||||||
|
if(!information.textContent.toLowerCase().includes(searchBox.value.toLowerCase())){
|
||||||
|
publication.style.display = "none";
|
||||||
|
}else{
|
||||||
|
publication.style.display = "initial";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
tasksContent.childNodes.forEach(publication => publication.style.display = "initial");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//Resets the tasks shown
|
//Resets the tasks shown
|
||||||
ResetContent();
|
ResetContent();
|
||||||
//Get Tasks and show them
|
//Get Tasks and show them
|
||||||
|
@ -17,4 +17,5 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 9555:80
|
- 9555:80
|
||||||
depends_on:
|
depends_on:
|
||||||
- tranga-api
|
- tranga-api
|
||||||
|
restart: unless-stopped
|
Reference in New Issue
Block a user