mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 15:50:13 +01:00
Merge branch 'cuttingedge' into dev
This commit is contained in:
commit
e022bf3081
@ -164,7 +164,7 @@ public class JobBoss : GlobalBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
HashSet<string> coverFileNames = cachedPublications.Select(manga => manga.coverFileNameInCache!).ToHashSet();
|
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)))
|
if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga)))
|
||||||
File.Delete(fileName);
|
File.Delete(fileName);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
using PuppeteerSharp;
|
using PuppeteerSharp;
|
||||||
|
using PuppeteerSharp.Input;
|
||||||
|
|
||||||
namespace Tranga.MangaConnectors;
|
namespace Tranga.MangaConnectors;
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
{
|
{
|
||||||
if (content.Contains("text/html"))
|
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();
|
page.ClickAsync(clickButton).Wait();
|
||||||
string htmlString = page.GetContentAsync().Result;
|
string htmlString = page.GetContentAsync().Result;
|
||||||
stream = new MemoryStream(Encoding.Default.GetBytes(htmlString));
|
stream = new MemoryStream(Encoding.Default.GetBytes(htmlString));
|
||||||
|
@ -237,7 +237,7 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
return HttpStatusCode.Created;
|
return HttpStatusCode.Created;
|
||||||
|
|
||||||
//Create a temporary folder to store images
|
//Create a temporary folder to store images
|
||||||
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;
|
||||||
|
|
||||||
int chapter = 0;
|
int chapter = 0;
|
||||||
//Download all Images to temporary Folder
|
//Download all Images to temporary Folder
|
||||||
@ -260,8 +260,10 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
progressToken?.Increment();
|
progressToken?.Increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(comicInfoPath is not null)
|
if(comicInfoPath is not null){
|
||||||
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
||||||
|
File.Delete(comicInfoPath); //Delete tmp-file
|
||||||
|
}
|
||||||
|
|
||||||
Log($"Creating archive {saveArchiveFilePath}");
|
Log($"Creating archive {saveArchiveFilePath}");
|
||||||
//ZIP-it and ship-it
|
//ZIP-it and ship-it
|
||||||
|
@ -216,6 +216,7 @@ public class MangaDex : MangaConnector
|
|||||||
{
|
{
|
||||||
JsonObject chapter = (JsonObject)jsonNode!;
|
JsonObject chapter = (JsonObject)jsonNode!;
|
||||||
JsonObject attributes = chapter["attributes"]!.AsObject();
|
JsonObject attributes = chapter["attributes"]!.AsObject();
|
||||||
|
|
||||||
string chapterId = chapter["id"]!.GetValue<string>();
|
string chapterId = chapter["id"]!.GetValue<string>();
|
||||||
|
|
||||||
string? title = attributes.ContainsKey("title") && attributes["title"] is not null
|
string? title = attributes.ContainsKey("title") && attributes["title"] is not null
|
||||||
@ -230,6 +231,14 @@ public class MangaDex : MangaConnector
|
|||||||
? attributes["chapter"]!.GetValue<string>()
|
? attributes["chapter"]!.GetValue<string>()
|
||||||
: "null";
|
: "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")
|
if(chapterNum is not "null")
|
||||||
chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId));
|
chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId));
|
||||||
}
|
}
|
||||||
@ -252,7 +261,7 @@ public class MangaDex : MangaConnector
|
|||||||
Log($"Retrieving chapter-info {chapter} {chapterParentManga}");
|
Log($"Retrieving chapter-info {chapter} {chapterParentManga}");
|
||||||
//Request URLs for Chapter-Images
|
//Request URLs for Chapter-Images
|
||||||
RequestResult requestResult =
|
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)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
{
|
{
|
||||||
progressToken?.Cancel();
|
progressToken?.Cancel();
|
||||||
|
@ -206,6 +206,9 @@ public class Server : GlobalBase
|
|||||||
case "Settings/customRequestLimit":
|
case "Settings/customRequestLimit":
|
||||||
SendResponse(HttpStatusCode.OK, response, settings.requestLimits);
|
SendResponse(HttpStatusCode.OK, response, settings.requestLimits);
|
||||||
break;
|
break;
|
||||||
|
case "Settings/AprilFoolsMode":
|
||||||
|
SendResponse(HttpStatusCode.OK, response, settings.aprilFoolsMode);
|
||||||
|
break;
|
||||||
case "NotificationConnectors":
|
case "NotificationConnectors":
|
||||||
SendResponse(HttpStatusCode.OK, response, notificationConnectors);
|
SendResponse(HttpStatusCode.OK, response, notificationConnectors);
|
||||||
break;
|
break;
|
||||||
@ -397,7 +400,7 @@ public class Server : GlobalBase
|
|||||||
case "Settings/UpdateDownloadLocation":
|
case "Settings/UpdateDownloadLocation":
|
||||||
if (!requestVariables.TryGetValue("downloadLocation", out string? downloadLocation) ||
|
if (!requestVariables.TryGetValue("downloadLocation", out string? downloadLocation) ||
|
||||||
!requestVariables.TryGetValue("moveFiles", out string? moveFilesStr) ||
|
!requestVariables.TryGetValue("moveFiles", out string? moveFilesStr) ||
|
||||||
!Boolean.TryParse(moveFilesStr, out bool moveFiles))
|
!bool.TryParse(moveFilesStr, out bool moveFiles))
|
||||||
{
|
{
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
break;
|
break;
|
||||||
@ -405,6 +408,16 @@ public class Server : GlobalBase
|
|||||||
settings.UpdateDownloadLocation(downloadLocation, moveFiles);
|
settings.UpdateDownloadLocation(downloadLocation, moveFiles);
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
SendResponse(HttpStatusCode.Accepted, response);
|
||||||
break;
|
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":
|
/*case "Settings/UpdateWorkingDirectory":
|
||||||
if (!requestVariables.TryGetValue("workingDirectory", out string? workingDirectory))
|
if (!requestVariables.TryGetValue("workingDirectory", out string? workingDirectory))
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,8 @@ public partial class Tranga : GlobalBase
|
|||||||
new Bato(this),
|
new Bato(this),
|
||||||
new MangaLife(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);
|
jobBoss = new(this, this._connectors);
|
||||||
StartJobBoss();
|
StartJobBoss();
|
||||||
this._server = new Server(this);
|
this._server = new Server(this);
|
||||||
@ -71,10 +73,23 @@ public partial class Tranga : GlobalBase
|
|||||||
{
|
{
|
||||||
while (keepRunning)
|
while (keepRunning)
|
||||||
{
|
{
|
||||||
|
if(!settings.aprilFoolsMode & !IsAprilFirst())
|
||||||
jobBoss.CheckJobs();
|
jobBoss.CheckJobs();
|
||||||
|
else
|
||||||
|
Log("April Fools Mode in Effect");
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
t.Start();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Tranga.LibraryConnectors;
|
using Tranga.LibraryConnectors;
|
||||||
using Tranga.MangaConnectors;
|
using Tranga.MangaConnectors;
|
||||||
@ -13,14 +12,15 @@ public class TrangaSettings
|
|||||||
public string downloadLocation { get; private set; }
|
public string downloadLocation { get; private set; }
|
||||||
public string workingDirectory { get; private set; }
|
public string workingDirectory { get; private set; }
|
||||||
public int apiPortNumber { get; init; }
|
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 settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||||
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
|
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
|
||||||
[JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
|
[JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
|
||||||
[JsonIgnore] public string jobsFolderPath => Path.Join(workingDirectory, "jobs");
|
[JsonIgnore] public string jobsFolderPath => Path.Join(workingDirectory, "jobs");
|
||||||
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
[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";
|
[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 ()
|
[JsonIgnore]internal static readonly Dictionary<RequestType, int> DefaultRequestLimits = new ()
|
||||||
{
|
{
|
||||||
{RequestType.MangaInfo, 250},
|
{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)
|
public void UpdateDownloadLocation(string newPath, bool moveFiles = true)
|
||||||
{
|
{
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user