Merge branch 'cuttingedge' into dev

This commit is contained in:
Glax 2024-04-15 15:02:52 +02:00
commit e022bf3081
7 changed files with 57 additions and 11 deletions

View File

@ -164,7 +164,7 @@ public class JobBoss : GlobalBase
}
HashSet<string> coverFileNames = cachedPublications.Select(manga => manga.coverFileNameInCache!).ToHashSet();
foreach (string fileName in Directory.GetFiles(settings.coverImageCache))
foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) //Cleanup Unused Covers
{
if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga)))
File.Delete(fileName);

View File

@ -2,6 +2,7 @@
using System.Text;
using HtmlAgilityPack;
using PuppeteerSharp;
using PuppeteerSharp.Input;
namespace Tranga.MangaConnectors;
@ -81,7 +82,7 @@ internal class ChromiumDownloadClient : DownloadClient
{
if (content.Contains("text/html"))
{
if(clickButton is not null)
if (clickButton is not null && page.QuerySelectorAsync(clickButton).Result is not null)
page.ClickAsync(clickButton).Wait();
string htmlString = page.GetContentAsync().Result;
stream = new MemoryStream(Encoding.Default.GetBytes(htmlString));

View File

@ -237,7 +237,7 @@ public abstract class MangaConnector : GlobalBase
return HttpStatusCode.Created;
//Create a temporary folder to store images
string tempFolder = Directory.CreateTempSubdirectory().FullName;
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;
int chapter = 0;
//Download all Images to temporary Folder
@ -260,8 +260,10 @@ public abstract class MangaConnector : GlobalBase
progressToken?.Increment();
}
if(comicInfoPath is not null)
if(comicInfoPath is not null){
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
File.Delete(comicInfoPath); //Delete tmp-file
}
Log($"Creating archive {saveArchiveFilePath}");
//ZIP-it and ship-it

View File

@ -216,6 +216,7 @@ public class MangaDex : MangaConnector
{
JsonObject chapter = (JsonObject)jsonNode!;
JsonObject attributes = chapter["attributes"]!.AsObject();
string chapterId = chapter["id"]!.GetValue<string>();
string? title = attributes.ContainsKey("title") && attributes["title"] is not null
@ -230,6 +231,14 @@ public class MangaDex : MangaConnector
? attributes["chapter"]!.GetValue<string>()
: "null";
if (attributes.ContainsKey("pages") && attributes["pages"] is not null &&
attributes["pages"]!.GetValue<int>() < 1)
{
Log($"Skipping {chapterId} Vol.{volume} Ch.{chapterNum} {title} because it has no pages or is externally linked.");
continue;
}
if(chapterNum is not "null")
chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId));
}
@ -252,7 +261,7 @@ public class MangaDex : MangaConnector
Log($"Retrieving chapter-info {chapter} {chapterParentManga}");
//Request URLs for Chapter-Images
RequestResult requestResult =
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", RequestType.MangaDexImage);
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false", RequestType.MangaDexImage);
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
{
progressToken?.Cancel();

View File

@ -206,6 +206,9 @@ public class Server : GlobalBase
case "Settings/customRequestLimit":
SendResponse(HttpStatusCode.OK, response, settings.requestLimits);
break;
case "Settings/AprilFoolsMode":
SendResponse(HttpStatusCode.OK, response, settings.aprilFoolsMode);
break;
case "NotificationConnectors":
SendResponse(HttpStatusCode.OK, response, notificationConnectors);
break;
@ -397,7 +400,7 @@ public class Server : GlobalBase
case "Settings/UpdateDownloadLocation":
if (!requestVariables.TryGetValue("downloadLocation", out string? downloadLocation) ||
!requestVariables.TryGetValue("moveFiles", out string? moveFilesStr) ||
!Boolean.TryParse(moveFilesStr, out bool moveFiles))
!bool.TryParse(moveFilesStr, out bool moveFiles))
{
SendResponse(HttpStatusCode.BadRequest, response);
break;
@ -405,6 +408,16 @@ public class Server : GlobalBase
settings.UpdateDownloadLocation(downloadLocation, moveFiles);
SendResponse(HttpStatusCode.Accepted, response);
break;
case "Settings/AprilFoolsMode":
if (!requestVariables.TryGetValue("enabled", out string? aprilFoolsModeEnabledStr) ||
bool.TryParse(aprilFoolsModeEnabledStr, out bool aprilFoolsModeEnabled))
{
SendResponse(HttpStatusCode.BadRequest, response);
break;
}
settings.UpdateAprilFoolsMode(aprilFoolsModeEnabled);
SendResponse(HttpStatusCode.Accepted, response);
break;
/*case "Settings/UpdateWorkingDirectory":
if (!requestVariables.TryGetValue("workingDirectory", out string? workingDirectory))
{

View File

@ -26,6 +26,8 @@ public partial class Tranga : GlobalBase
new Bato(this),
new MangaLife(this)
};
foreach(DirectoryInfo dir in new DirectoryInfo(Path.GetTempPath()).GetDirectories("trangatemp"))//Cleanup old temp folders
dir.Delete();
jobBoss = new(this, this._connectors);
StartJobBoss();
this._server = new Server(this);
@ -71,10 +73,23 @@ public partial class Tranga : GlobalBase
{
while (keepRunning)
{
jobBoss.CheckJobs();
if(!settings.aprilFoolsMode & !IsAprilFirst())
jobBoss.CheckJobs();
else
Log("April Fools Mode in Effect");
Thread.Sleep(100);
}
});
t.Start();
}
private bool IsAprilFirst()
{
//UTC 01 Apr +-12hrs
DateTime start = new DateTime(DateTime.Now.Year, 03, 31, 12, 0, 0, DateTimeKind.Utc);
DateTime end = new DateTime(DateTime.Now.Year, 04, 02, 12, 0, 0, DateTimeKind.Utc);
if (DateTime.UtcNow > start && DateTime.UtcNow < end)
return true;
return false;
}
}

View File

@ -1,5 +1,4 @@
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using Tranga.LibraryConnectors;
using Tranga.MangaConnectors;
@ -13,14 +12,15 @@ public class TrangaSettings
public string downloadLocation { get; private set; }
public string workingDirectory { get; private set; }
public int apiPortNumber { get; init; }
public string userAgent { get; set; } = DefaultUserAgent;
public string userAgent { get; private set; } = DefaultUserAgent;
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
[JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
[JsonIgnore] public string jobsFolderPath => Path.Join(workingDirectory, "jobs");
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
[JsonIgnore] internal static readonly string DefaultUserAgent = $"Tranga ({Enum.GetName(Environment.OSVersion.Platform)}; {(Environment.Is64BitOperatingSystem ? "x64" : "")}) / 1.0";
public ushort? version { get; set; } = 1;
public ushort? version { get; } = 1;
public bool aprilFoolsMode { get; private set; } = true;
[JsonIgnore]internal static readonly Dictionary<RequestType, int> DefaultRequestLimits = new ()
{
{RequestType.MangaInfo, 250},
@ -102,6 +102,12 @@ public class TrangaSettings
})!;
}
public void UpdateAprilFoolsMode(bool enabled)
{
this.aprilFoolsMode = enabled;
ExportSettings();
}
public void UpdateDownloadLocation(string newPath, bool moveFiles = true)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))