Compare commits
11 Commits
fc884adc9f
...
3c3f7bb95a
Author | SHA1 | Date | |
---|---|---|---|
3c3f7bb95a | |||
032ee95716 | |||
dfa8e66f34 | |||
1bd20791b8 | |||
6d723b6355 | |||
7b91bb699f | |||
63b493fa9c | |||
69d6884517 | |||
f4336f9777 | |||
ea37e81ece | |||
21af75f410 |
@ -47,37 +47,18 @@ internal sealed class TrangaCli : Command<TrangaCli.Settings>
|
|||||||
string? logFolderPath = settings.fileLoggerPath ?? "";
|
string? logFolderPath = settings.fileLoggerPath ?? "";
|
||||||
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFolderPath);
|
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFolderPath);
|
||||||
|
|
||||||
TrangaSettings? trangaSettings = null;
|
if(settings.workingDirectory is not null)
|
||||||
|
TrangaSettings.LoadFromWorkingDirectory(settings.workingDirectory);
|
||||||
if (settings.downloadLocation is not null && settings.workingDirectory is not null)
|
|
||||||
{
|
|
||||||
trangaSettings = new TrangaSettings(settings.downloadLocation, settings.workingDirectory);
|
|
||||||
}else if (settings.downloadLocation is not null)
|
|
||||||
{
|
|
||||||
if (trangaSettings is null)
|
|
||||||
trangaSettings = new TrangaSettings(downloadLocation: settings.downloadLocation);
|
|
||||||
else
|
|
||||||
trangaSettings = new TrangaSettings(downloadLocation: settings.downloadLocation, settings.workingDirectory);
|
|
||||||
}else if (settings.workingDirectory is not null)
|
|
||||||
{
|
|
||||||
if (trangaSettings is null)
|
|
||||||
trangaSettings = new TrangaSettings(downloadLocation: settings.workingDirectory);
|
|
||||||
else
|
|
||||||
trangaSettings = new TrangaSettings(settings.downloadLocation, settings.workingDirectory);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
TrangaSettings.CreateOrUpdate();
|
||||||
trangaSettings = new TrangaSettings();
|
if(settings.downloadLocation is not null)
|
||||||
}
|
TrangaSettings.CreateOrUpdate(downloadDirectory: settings.downloadLocation);
|
||||||
|
|
||||||
Directory.CreateDirectory(trangaSettings.downloadLocation);
|
|
||||||
Directory.CreateDirectory(trangaSettings.workingDirectory);
|
|
||||||
|
|
||||||
Tranga.Tranga? api = null;
|
Tranga.Tranga? api = null;
|
||||||
|
|
||||||
Thread trangaApi = new Thread(() =>
|
Thread trangaApi = new Thread(() =>
|
||||||
{
|
{
|
||||||
api = new(logger, trangaSettings);
|
api = new(logger);
|
||||||
});
|
});
|
||||||
trangaApi.Start();
|
trangaApi.Start();
|
||||||
|
|
||||||
@ -120,7 +101,7 @@ internal sealed class TrangaCli : Command<TrangaCli.Settings>
|
|||||||
parameters.Add(new ValueTuple<string, string>(name, value));
|
parameters.Add(new ValueTuple<string, string>(name, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
string requestString = $"http://localhost:{trangaSettings.apiPortNumber}/{requestPath}";
|
string requestString = $"http://localhost:{TrangaSettings.apiPortNumber}/{requestPath}";
|
||||||
if (parameters.Any())
|
if (parameters.Any())
|
||||||
{
|
{
|
||||||
requestString += "?";
|
requestString += "?";
|
||||||
|
@ -87,15 +87,15 @@ public readonly struct Chapter : IComparable
|
|||||||
/// Checks if a chapter-archive is already present
|
/// Checks if a chapter-archive is already present
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>true if chapter is present</returns>
|
/// <returns>true if chapter is present</returns>
|
||||||
internal bool CheckChapterIsDownloaded(string downloadLocation)
|
internal bool CheckChapterIsDownloaded()
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(Path.Join(downloadLocation, parentManga.folderName)))
|
if (!Directory.Exists(Path.Join(TrangaSettings.downloadLocation, parentManga.folderName)))
|
||||||
return false;
|
return false;
|
||||||
FileInfo[] archives = new DirectoryInfo(Path.Join(downloadLocation, parentManga.folderName)).GetFiles().Where(file => file.Name.Split('.')[^1] == "cbz").ToArray();
|
FileInfo[] archives = new DirectoryInfo(Path.Join(TrangaSettings.downloadLocation, parentManga.folderName)).GetFiles().Where(file => file.Name.Split('.')[^1] == "cbz").ToArray();
|
||||||
Regex volChRex = new(@"(?:Vol(?:ume)?\.([0-9]+)\D*)?Ch(?:apter)?\.([0-9]+(?:\.[0-9]+)*)");
|
Regex volChRex = new(@"(?:Vol(?:ume)?\.([0-9]+)\D*)?Ch(?:apter)?\.([0-9]+(?:\.[0-9]+)*)");
|
||||||
|
|
||||||
Chapter t = this;
|
Chapter t = this;
|
||||||
string thisPath = GetArchiveFilePath(downloadLocation);
|
string thisPath = GetArchiveFilePath();
|
||||||
FileInfo? archive = archives.FirstOrDefault(archive =>
|
FileInfo? archive = archives.FirstOrDefault(archive =>
|
||||||
{
|
{
|
||||||
Match m = volChRex.Match(archive.Name);
|
Match m = volChRex.Match(archive.Name);
|
||||||
@ -112,9 +112,9 @@ public readonly struct Chapter : IComparable
|
|||||||
/// Creates full file path of chapter-archive
|
/// Creates full file path of chapter-archive
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Filepath</returns>
|
/// <returns>Filepath</returns>
|
||||||
internal string GetArchiveFilePath(string downloadLocation)
|
internal string GetArchiveFilePath()
|
||||||
{
|
{
|
||||||
return Path.Join(downloadLocation, parentManga.folderName, $"{parentManga.folderName} - {this.fileName}.cbz");
|
return Path.Join(TrangaSettings.downloadLocation, parentManga.folderName, $"{parentManga.folderName} - {this.fileName}.cbz");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -14,7 +14,6 @@ public abstract class GlobalBase
|
|||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Logger? logger { get; init; }
|
public Logger? logger { get; init; }
|
||||||
protected TrangaSettings settings { get; init; }
|
|
||||||
protected HashSet<NotificationConnector> notificationConnectors { get; init; }
|
protected HashSet<NotificationConnector> notificationConnectors { get; init; }
|
||||||
protected HashSet<LibraryConnector> libraryConnectors { get; init; }
|
protected HashSet<LibraryConnector> libraryConnectors { get; init; }
|
||||||
private Dictionary<string, Manga> cachedPublications { get; init; }
|
private Dictionary<string, Manga> cachedPublications { get; init; }
|
||||||
@ -25,19 +24,17 @@ public abstract class GlobalBase
|
|||||||
protected GlobalBase(GlobalBase clone)
|
protected GlobalBase(GlobalBase clone)
|
||||||
{
|
{
|
||||||
this.logger = clone.logger;
|
this.logger = clone.logger;
|
||||||
this.settings = clone.settings;
|
|
||||||
this.notificationConnectors = clone.notificationConnectors;
|
this.notificationConnectors = clone.notificationConnectors;
|
||||||
this.libraryConnectors = clone.libraryConnectors;
|
this.libraryConnectors = clone.libraryConnectors;
|
||||||
this.cachedPublications = clone.cachedPublications;
|
this.cachedPublications = clone.cachedPublications;
|
||||||
this._connectors = clone._connectors;
|
this._connectors = clone._connectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GlobalBase(Logger? logger, TrangaSettings settings)
|
protected GlobalBase(Logger? logger)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.settings = settings;
|
this.notificationConnectors = TrangaSettings.LoadNotificationConnectors(this);
|
||||||
this.notificationConnectors = settings.LoadNotificationConnectors(this);
|
this.libraryConnectors = TrangaSettings.LoadLibraryConnectors(this);
|
||||||
this.libraryConnectors = settings.LoadLibraryConnectors(this);
|
|
||||||
this.cachedPublications = new();
|
this.cachedPublications = new();
|
||||||
this._connectors = new();
|
this._connectors = new();
|
||||||
}
|
}
|
||||||
@ -73,7 +70,7 @@ public abstract class GlobalBase
|
|||||||
|
|
||||||
internal void ImportManga()
|
internal void ImportManga()
|
||||||
{
|
{
|
||||||
string folder = settings.mangaCacheFolderPath;
|
string folder = TrangaSettings.mangaCacheFolderPath;
|
||||||
Directory.CreateDirectory(folder);
|
Directory.CreateDirectory(folder);
|
||||||
|
|
||||||
foreach (FileInfo fileInfo in new DirectoryInfo(folder).GetFiles())
|
foreach (FileInfo fileInfo in new DirectoryInfo(folder).GetFiles())
|
||||||
@ -94,7 +91,7 @@ public abstract class GlobalBase
|
|||||||
|
|
||||||
private void ExportManga()
|
private void ExportManga()
|
||||||
{
|
{
|
||||||
string folder = settings.mangaCacheFolderPath;
|
string folder = TrangaSettings.mangaCacheFolderPath;
|
||||||
Directory.CreateDirectory(folder);
|
Directory.CreateDirectory(folder);
|
||||||
foreach (Manga manga in cachedPublications.Values)
|
foreach (Manga manga in cachedPublications.Values)
|
||||||
{
|
{
|
||||||
@ -132,20 +129,20 @@ public abstract class GlobalBase
|
|||||||
notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnector.notificationConnectorType);
|
notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnector.notificationConnectorType);
|
||||||
notificationConnectors.Add(notificationConnector);
|
notificationConnectors.Add(notificationConnector);
|
||||||
|
|
||||||
while(IsFileInUse(settings.notificationConnectorsFilePath))
|
while(IsFileInUse(TrangaSettings.notificationConnectorsFilePath))
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
Log("Exporting notificationConnectors");
|
Log("Exporting notificationConnectors");
|
||||||
File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
|
File.WriteAllText(TrangaSettings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DeleteNotificationConnector(NotificationConnector.NotificationConnectorType notificationConnectorType)
|
protected void DeleteNotificationConnector(NotificationConnector.NotificationConnectorType notificationConnectorType)
|
||||||
{
|
{
|
||||||
Log($"Removing {notificationConnectorType}");
|
Log($"Removing {notificationConnectorType}");
|
||||||
notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnectorType);
|
notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnectorType);
|
||||||
while(IsFileInUse(settings.notificationConnectorsFilePath))
|
while(IsFileInUse(TrangaSettings.notificationConnectorsFilePath))
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
Log("Exporting notificationConnectors");
|
Log("Exporting notificationConnectors");
|
||||||
File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
|
File.WriteAllText(TrangaSettings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UpdateLibraries()
|
protected void UpdateLibraries()
|
||||||
@ -160,20 +157,20 @@ public abstract class GlobalBase
|
|||||||
libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryConnector.libraryType);
|
libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryConnector.libraryType);
|
||||||
libraryConnectors.Add(libraryConnector);
|
libraryConnectors.Add(libraryConnector);
|
||||||
|
|
||||||
while(IsFileInUse(settings.libraryConnectorsFilePath))
|
while(IsFileInUse(TrangaSettings.libraryConnectorsFilePath))
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
Log("Exporting libraryConnectors");
|
Log("Exporting libraryConnectors");
|
||||||
File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors, Formatting.Indented));
|
File.WriteAllText(TrangaSettings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors, Formatting.Indented));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DeleteLibraryConnector(LibraryConnector.LibraryType libraryType)
|
protected void DeleteLibraryConnector(LibraryConnector.LibraryType libraryType)
|
||||||
{
|
{
|
||||||
Log($"Removing {libraryType}");
|
Log($"Removing {libraryType}");
|
||||||
libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryType);
|
libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryType);
|
||||||
while(IsFileInUse(settings.libraryConnectorsFilePath))
|
while(IsFileInUse(TrangaSettings.libraryConnectorsFilePath))
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
Log("Exporting libraryConnectors");
|
Log("Exporting libraryConnectors");
|
||||||
File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors, Formatting.Indented));
|
File.WriteAllText(TrangaSettings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors, Formatting.Indented));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool IsFileInUse(string filePath) => IsFileInUse(filePath, this.logger);
|
protected bool IsFileInUse(string filePath) => IsFileInUse(filePath, this.logger);
|
||||||
|
@ -38,7 +38,7 @@ public class DownloadNewChapters : Job
|
|||||||
Log($"Manga {mangaInternalId} is missing! Can not execute job.");
|
Log($"Manga {mangaInternalId} is missing! Can not execute job.");
|
||||||
return Array.Empty<Job>();
|
return Array.Empty<Job>();
|
||||||
}
|
}
|
||||||
manga.Value.SaveSeriesInfoJson(settings.downloadLocation);
|
manga.Value.SaveSeriesInfoJson();
|
||||||
Chapter[] chapters = manga.Value.mangaConnector.GetNewChapters(manga.Value, this.translatedLanguage);
|
Chapter[] chapters = manga.Value.mangaConnector.GetNewChapters(manga.Value, this.translatedLanguage);
|
||||||
this.progressToken.increments = chapters.Length;
|
this.progressToken.increments = chapters.Length;
|
||||||
List<Job> jobs = new();
|
List<Job> jobs = new();
|
||||||
|
@ -140,15 +140,15 @@ public class JobBoss : GlobalBase
|
|||||||
|
|
||||||
private void LoadJobsList(HashSet<MangaConnector> connectors)
|
private void LoadJobsList(HashSet<MangaConnector> connectors)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(settings.jobsFolderPath)) //No jobs to load
|
if (!Directory.Exists(TrangaSettings.jobsFolderPath)) //No jobs to load
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(settings.jobsFolderPath);
|
Directory.CreateDirectory(TrangaSettings.jobsFolderPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Regex idRex = new (@"(.*)\.json");
|
Regex idRex = new (@"(.*)\.json");
|
||||||
|
|
||||||
//Load json-job-files
|
//Load json-job-files
|
||||||
foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name)))
|
foreach (FileInfo file in new DirectoryInfo(TrangaSettings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name)))
|
||||||
{
|
{
|
||||||
Log($"Adding {file.Name}");
|
Log($"Adding {file.Name}");
|
||||||
Job? job = JsonConvert.DeserializeObject<Job>(File.ReadAllText(file.FullName),
|
Job? job = JsonConvert.DeserializeObject<Job>(File.ReadAllText(file.FullName),
|
||||||
@ -192,17 +192,17 @@ public class JobBoss : GlobalBase
|
|||||||
foreach (string internalId in extraneousIds)
|
foreach (string internalId in extraneousIds)
|
||||||
RemoveMangaFromCache(internalId);
|
RemoveMangaFromCache(internalId);
|
||||||
|
|
||||||
string[] coverFiles = Directory.GetFiles(settings.coverImageCache);
|
string[] coverFiles = Directory.GetFiles(TrangaSettings.coverImageCache);
|
||||||
foreach(string fileName in coverFiles.Where(fileName => !GetAllCachedManga().Any(manga => manga.coverFileNameInCache == fileName)))
|
foreach(string fileName in coverFiles.Where(fileName => !GetAllCachedManga().Any(manga => manga.coverFileNameInCache == fileName)))
|
||||||
File.Delete(fileName);
|
File.Delete(fileName);
|
||||||
string[] mangaFiles = Directory.GetFiles(settings.mangaCacheFolderPath);
|
string[] mangaFiles = Directory.GetFiles(TrangaSettings.mangaCacheFolderPath);
|
||||||
foreach(string fileName in mangaFiles.Where(fileName => !GetAllCachedManga().Any(manga => fileName.Split('.')[0] == manga.internalId)))
|
foreach(string fileName in mangaFiles.Where(fileName => !GetAllCachedManga().Any(manga => fileName.Split('.')[0] == manga.internalId)))
|
||||||
File.Delete(fileName);
|
File.Delete(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void UpdateJobFile(Job job, string? oldFile = null)
|
internal void UpdateJobFile(Job job, string? oldFile = null)
|
||||||
{
|
{
|
||||||
string newJobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json");
|
string newJobFilePath = Path.Join(TrangaSettings.jobsFolderPath, $"{job.id}.json");
|
||||||
|
|
||||||
if (!this.jobs.Any(jjob => jjob.id == job.id))
|
if (!this.jobs.Any(jjob => jjob.id == job.id))
|
||||||
{
|
{
|
||||||
@ -249,7 +249,7 @@ public class JobBoss : GlobalBase
|
|||||||
|
|
||||||
//Remove files with jobs not in this.jobs-list
|
//Remove files with jobs not in this.jobs-list
|
||||||
Regex idRex = new (@"(.*)\.json");
|
Regex idRex = new (@"(.*)\.json");
|
||||||
foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles())
|
foreach (FileInfo file in new DirectoryInfo(TrangaSettings.jobsFolderPath).EnumerateFiles())
|
||||||
{
|
{
|
||||||
if (idRex.IsMatch(file.Name))
|
if (idRex.IsMatch(file.Name))
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,7 @@ public class UpdateMetadata : Job
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddMangaToCache(manga.Value.WithMetadata(updatedManga));
|
AddMangaToCache(manga.Value.WithMetadata(updatedManga));
|
||||||
this.manga.Value.SaveSeriesInfoJson(settings.downloadLocation, true);
|
this.manga.Value.SaveSeriesInfoJson(true);
|
||||||
this.mangaConnector.CopyCoverFromCacheToDownloadLocation((Manga)manga);
|
this.mangaConnector.CopyCoverFromCacheToDownloadLocation((Manga)manga);
|
||||||
this.progressToken.Complete();
|
this.progressToken.Complete();
|
||||||
}
|
}
|
||||||
|
@ -137,9 +137,9 @@ public struct Manga
|
|||||||
latestChapterDownloaded = latestChapterDownloaded < chapterNumber ? chapterNumber : latestChapterDownloaded;
|
latestChapterDownloaded = latestChapterDownloaded < chapterNumber ? chapterNumber : latestChapterDownloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveSeriesInfoJson(string downloadDirectory, bool overwrite = false)
|
public void SaveSeriesInfoJson(bool overwrite = false)
|
||||||
{
|
{
|
||||||
string publicationFolder = CreatePublicationFolder(downloadDirectory);
|
string publicationFolder = CreatePublicationFolder(TrangaSettings.downloadLocation);
|
||||||
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
||||||
if(overwrite || (!overwrite && !File.Exists(seriesInfoPath)))
|
if(overwrite || (!overwrite && !File.Exists(seriesInfoPath)))
|
||||||
File.WriteAllText(seriesInfoPath,this.GetSeriesInfoJson());
|
File.WriteAllText(seriesInfoPath,this.GetSeriesInfoJson());
|
||||||
|
@ -193,7 +193,7 @@ public class Bato : MangaConnector
|
|||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken);
|
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] ParseImageUrlsFromHtml(string mangaUrl)
|
private string[] ParseImageUrlsFromHtml(string mangaUrl)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
using PuppeteerSharp;
|
using PuppeteerSharp;
|
||||||
using PuppeteerSharp.Input;
|
|
||||||
|
|
||||||
namespace Tranga.MangaConnectors;
|
namespace Tranga.MangaConnectors;
|
||||||
|
|
||||||
@ -11,10 +11,11 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
private IBrowser browser { get; set; }
|
private IBrowser browser { get; set; }
|
||||||
private const string ChromiumVersion = "1154303";
|
private const string ChromiumVersion = "1154303";
|
||||||
private const int StartTimeoutMs = 30000;
|
private const int StartTimeoutMs = 30000;
|
||||||
|
private readonly HttpDownloadClient _httpDownloadClient;
|
||||||
|
|
||||||
private async Task<IBrowser> DownloadBrowser()
|
private async Task<IBrowser> DownloadBrowser()
|
||||||
{
|
{
|
||||||
BrowserFetcher browserFetcher = new BrowserFetcher();
|
BrowserFetcher browserFetcher = new ();
|
||||||
foreach(string rev in browserFetcher.LocalRevisions().Where(rev => rev != ChromiumVersion))
|
foreach(string rev in browserFetcher.LocalRevisions().Where(rev => rev != ChromiumVersion))
|
||||||
browserFetcher.Remove(rev);
|
browserFetcher.Remove(rev);
|
||||||
if (!browserFetcher.LocalRevisions().Contains(ChromiumVersion))
|
if (!browserFetcher.LocalRevisions().Contains(ChromiumVersion))
|
||||||
@ -58,9 +59,18 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
public ChromiumDownloadClient(GlobalBase clone) : base(clone)
|
public ChromiumDownloadClient(GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
this.browser = DownloadBrowser().Result;
|
this.browser = DownloadBrowser().Result;
|
||||||
|
_httpDownloadClient = new(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
private readonly Regex _imageUrlRex = new(@"https?:\/\/.*\.(?:p?jpe?g|gif|a?png|bmp|avif|webp)(\?.*)?");
|
||||||
|
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||||
|
{
|
||||||
|
return _imageUrlRex.IsMatch(url)
|
||||||
|
? _httpDownloadClient.MakeRequestInternal(url, referrer)
|
||||||
|
: MakeRequestBrowser(url, referrer, clickButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RequestResult MakeRequestBrowser(string url, string? referrer = null, string? clickButton = null)
|
||||||
{
|
{
|
||||||
IPage page = this.browser.NewPageAsync().Result;
|
IPage page = this.browser.NewPageAsync().Result;
|
||||||
page.DefaultTimeout = 10000;
|
page.DefaultTimeout = 10000;
|
||||||
|
@ -14,15 +14,15 @@ internal abstract class DownloadClient : GlobalBase
|
|||||||
|
|
||||||
public RequestResult MakeRequest(string url, RequestType requestType, string? referrer = null, string? clickButton = null)
|
public RequestResult MakeRequest(string url, RequestType requestType, string? referrer = null, string? clickButton = null)
|
||||||
{
|
{
|
||||||
if (!settings.requestLimits.ContainsKey(requestType))
|
if (!TrangaSettings.requestLimits.ContainsKey(requestType))
|
||||||
{
|
{
|
||||||
Log("RequestType not configured for rate-limit.");
|
Log("RequestType not configured for rate-limit.");
|
||||||
return new RequestResult(HttpStatusCode.NotAcceptable, null, Stream.Null);
|
return new RequestResult(HttpStatusCode.NotAcceptable, null, Stream.Null);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rateLimit = settings.userAgent == TrangaSettings.DefaultUserAgent
|
int rateLimit = TrangaSettings.userAgent == TrangaSettings.DefaultUserAgent
|
||||||
? TrangaSettings.DefaultRequestLimits[requestType]
|
? TrangaSettings.DefaultRequestLimits[requestType]
|
||||||
: settings.requestLimits[requestType];
|
: TrangaSettings.requestLimits[requestType];
|
||||||
|
|
||||||
TimeSpan timeBetweenRequests = TimeSpan.FromMinutes(1).Divide(rateLimit);
|
TimeSpan timeBetweenRequests = TimeSpan.FromMinutes(1).Divide(rateLimit);
|
||||||
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(timeBetweenRequests));
|
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(timeBetweenRequests));
|
||||||
@ -40,6 +40,6 @@ internal abstract class DownloadClient : GlobalBase
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null);
|
internal abstract RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null);
|
||||||
public abstract void Close();
|
public abstract void Close();
|
||||||
}
|
}
|
@ -13,10 +13,10 @@ internal class HttpDownloadClient : DownloadClient
|
|||||||
|
|
||||||
public HttpDownloadClient(GlobalBase clone) : base(clone)
|
public HttpDownloadClient(GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", settings.userAgent);
|
Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", TrangaSettings.userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||||
{
|
{
|
||||||
if(clickButton is not null)
|
if(clickButton is not null)
|
||||||
Log("Can not click button on static site.");
|
Log("Can not click button on static site.");
|
||||||
|
@ -23,7 +23,7 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
protected MangaConnector(GlobalBase clone, string name) : base(clone)
|
protected MangaConnector(GlobalBase clone, string name) : base(clone)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
Directory.CreateDirectory(settings.coverImageCache);
|
Directory.CreateDirectory(TrangaSettings.coverImageCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string name { get; } //Name of the Connector (e.g. Website)
|
public string name { get; } //Name of the Connector (e.g. Website)
|
||||||
@ -65,7 +65,7 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
Log($"Checking for duplicates {manga}");
|
Log($"Checking for duplicates {manga}");
|
||||||
List<Chapter> newChaptersList = allChapters.Where(nChapter => float.TryParse(nChapter.chapterNumber, numberFormatDecimalPoint, out float chapterNumber)
|
List<Chapter> newChaptersList = allChapters.Where(nChapter => float.TryParse(nChapter.chapterNumber, numberFormatDecimalPoint, out float chapterNumber)
|
||||||
&& chapterNumber > manga.ignoreChaptersBelow
|
&& chapterNumber > manga.ignoreChaptersBelow
|
||||||
&& !nChapter.CheckChapterIsDownloaded(settings.downloadLocation)).ToList();
|
&& !nChapter.CheckChapterIsDownloaded()).ToList();
|
||||||
Log($"{newChaptersList.Count} new chapters. {manga}");
|
Log($"{newChaptersList.Count} new chapters. {manga}");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -167,7 +167,7 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
{
|
{
|
||||||
Log($"Copy cover {manga}");
|
Log($"Copy cover {manga}");
|
||||||
//Check if Publication already has a Folder and cover
|
//Check if Publication already has a Folder and cover
|
||||||
string publicationFolder = manga.CreatePublicationFolder(settings.downloadLocation);
|
string publicationFolder = manga.CreatePublicationFolder(TrangaSettings.downloadLocation);
|
||||||
DirectoryInfo dirInfo = new (publicationFolder);
|
DirectoryInfo dirInfo = new (publicationFolder);
|
||||||
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
||||||
{
|
{
|
||||||
@ -291,7 +291,7 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
//https?:\/\/[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+)) for only second level domains
|
//https?:\/\/[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+)) for only second level domains
|
||||||
Match match = urlRex.Match(url);
|
Match match = urlRex.Match(url);
|
||||||
string filename = $"{match.Groups[1].Value}-{mangaInternalId}.{match.Groups[3].Value}";
|
string filename = $"{match.Groups[1].Value}-{mangaInternalId}.{match.Groups[3].Value}";
|
||||||
string saveImagePath = Path.Join(settings.coverImageCache, filename);
|
string saveImagePath = Path.Join(TrangaSettings.coverImageCache, filename);
|
||||||
|
|
||||||
if (File.Exists(saveImagePath))
|
if (File.Exists(saveImagePath))
|
||||||
return saveImagePath;
|
return saveImagePath;
|
||||||
@ -299,7 +299,7 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
RequestResult coverResult = downloadClient.MakeRequest(url, requestType);
|
RequestResult coverResult = downloadClient.MakeRequest(url, requestType);
|
||||||
using MemoryStream ms = new();
|
using MemoryStream ms = new();
|
||||||
coverResult.result.CopyTo(ms);
|
coverResult.result.CopyTo(ms);
|
||||||
Directory.CreateDirectory(settings.coverImageCache);
|
Directory.CreateDirectory(TrangaSettings.coverImageCache);
|
||||||
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
||||||
Log($"Saving cover to {saveImagePath}");
|
Log($"Saving cover to {saveImagePath}");
|
||||||
return saveImagePath;
|
return saveImagePath;
|
||||||
|
@ -291,6 +291,6 @@ public class MangaDex : MangaConnector
|
|||||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
//Download Chapter-Images
|
//Download Chapter-Images
|
||||||
return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -186,7 +186,7 @@ public class MangaHere : MangaConnector
|
|||||||
|
|
||||||
if (progressToken is not null)
|
if (progressToken is not null)
|
||||||
progressToken.increments = images;//we blip to normal length, in downloadchapterimages it is increasaed by the amount of urls again
|
progressToken.increments = images;//we blip to normal length, in downloadchapterimages it is increasaed by the amount of urls again
|
||||||
return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
||||||
|
@ -217,7 +217,7 @@ public class MangaKatana : MangaConnector
|
|||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken);
|
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] ParseImageUrlsFromHtml(string mangaUrl)
|
private string[] ParseImageUrlsFromHtml(string mangaUrl)
|
||||||
|
@ -194,6 +194,6 @@ public class MangaLife : MangaConnector
|
|||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -209,7 +209,7 @@ public class Manganato : MangaConnector
|
|||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, "https://chapmanganato.com/", progressToken:progressToken);
|
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, "https://chapmanganato.com/", progressToken:progressToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
||||||
|
@ -61,21 +61,27 @@ public class Mangasee : MangaConnector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly string[] _filterWords = {"a", "the", "of", "as", "to", "no", "for", "on", "with", "be", "and", "in", "wa", "at", "be", "ni"};
|
||||||
|
private string ToFilteredString(string input) => string.Join(' ', input.ToLower().Split(' ').Where(word => _filterWords.Contains(word) == false));
|
||||||
private SearchResult[] FilteredResults(string publicationTitle, SearchResult[] unfilteredSearchResults)
|
private SearchResult[] FilteredResults(string publicationTitle, SearchResult[] unfilteredSearchResults)
|
||||||
{
|
{
|
||||||
Dictionary<SearchResult, int> similarity = new();
|
Dictionary<SearchResult, int> similarity = new();
|
||||||
foreach (SearchResult sr in unfilteredSearchResults)
|
foreach (SearchResult sr in unfilteredSearchResults)
|
||||||
{
|
{
|
||||||
List<int> scores = new();
|
List<int> scores = new();
|
||||||
foreach (string se in sr.a)
|
string filteredPublicationString = ToFilteredString(publicationTitle);
|
||||||
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(se.ToLower(), publicationTitle.ToLower()));
|
string filteredSString = ToFilteredString(sr.s);
|
||||||
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(sr.s.ToLower(), publicationTitle.ToLower()));
|
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredSString, filteredPublicationString));
|
||||||
|
foreach (string srA in sr.a)
|
||||||
|
{
|
||||||
|
string filteredAString = ToFilteredString(srA);
|
||||||
|
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredAString, filteredPublicationString));
|
||||||
|
}
|
||||||
similarity.Add(sr, scores.Sum() / scores.Count);
|
similarity.Add(sr, scores.Sum() / scores.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchResult[] similarity90 = similarity.Where(s => s.Value < 10).Select(s => s.Key).ToArray();
|
List<SearchResult> ret = similarity.OrderBy(s => s.Value).Take(10).Select(s => s.Key).ToList();
|
||||||
|
return ret.ToArray();
|
||||||
return similarity90;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Manga? GetMangaFromId(string publicationId)
|
public override Manga? GetMangaFromId(string publicationId)
|
||||||
@ -218,6 +224,6 @@ public class Mangasee : MangaConnector
|
|||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -209,7 +209,7 @@ public class Mangaworld: MangaConnector
|
|||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, "https://www.mangaworld.bz/", progressToken:progressToken);
|
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, "https://www.mangaworld.bz/", progressToken:progressToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
||||||
|
@ -179,6 +179,6 @@ public class ManhuaPlus : MangaConnector
|
|||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -75,9 +75,9 @@ public partial class Server : GlobalBase, IDisposable
|
|||||||
|
|
||||||
this._parent = parent;
|
this._parent = parent;
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
this._listener.Prefixes.Add($"http://*:{settings.apiPortNumber}/");
|
this._listener.Prefixes.Add($"http://*:{TrangaSettings.apiPortNumber}/");
|
||||||
else
|
else
|
||||||
this._listener.Prefixes.Add($"http://localhost:{settings.apiPortNumber}/");
|
this._listener.Prefixes.Add($"http://localhost:{TrangaSettings.apiPortNumber}/");
|
||||||
Thread listenThread = new(Listen);
|
Thread listenThread = new(Listen);
|
||||||
listenThread.Start();
|
listenThread.Start();
|
||||||
while(_parent.keepRunning && _running)
|
while(_parent.keepRunning && _running)
|
||||||
|
@ -61,7 +61,7 @@ public partial class Server
|
|||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "'interval' Parameter missing, or is not in correct format.");
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "'interval' Parameter missing, or is not in correct format.");
|
||||||
requestParameters.TryGetValue("language", out string? language);
|
requestParameters.TryGetValue("language", out string? language);
|
||||||
if (requestParameters.TryGetValue("customFolder", out string? folder))
|
if (requestParameters.TryGetValue("customFolder", out string? folder))
|
||||||
manga.Value.MovePublicationFolder(settings.downloadLocation, folder);
|
manga.Value.MovePublicationFolder(TrangaSettings.downloadLocation, folder);
|
||||||
if (requestParameters.TryGetValue("startChapter", out string? startChapterStr) &&
|
if (requestParameters.TryGetValue("startChapter", out string? startChapterStr) &&
|
||||||
float.TryParse(startChapterStr, out float startChapter))
|
float.TryParse(startChapterStr, out float startChapter))
|
||||||
{
|
{
|
||||||
|
@ -140,7 +140,7 @@ public partial class Server
|
|||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'");
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'");
|
||||||
if(!requestParameters.TryGetValue("location", out string? newFolder))
|
if(!requestParameters.TryGetValue("location", out string? newFolder))
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.BadRequest, "Parameter 'location' missing.");
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.BadRequest, "Parameter 'location' missing.");
|
||||||
manga.Value.MovePublicationFolder(settings.downloadLocation, newFolder);
|
manga.Value.MovePublicationFolder(TrangaSettings.downloadLocation, newFolder);
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,24 +8,24 @@ public partial class Server
|
|||||||
{
|
{
|
||||||
private ValueTuple<HttpStatusCode, object?> GetV2Settings(GroupCollection groups, Dictionary<string, string> requestParameters)
|
private ValueTuple<HttpStatusCode, object?> GetV2Settings(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||||
{
|
{
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.AsJObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueTuple<HttpStatusCode, object?> GetV2SettingsUserAgent(GroupCollection groups, Dictionary<string, string> requestParameters)
|
private ValueTuple<HttpStatusCode, object?> GetV2SettingsUserAgent(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||||
{
|
{
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.userAgent);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueTuple<HttpStatusCode, object?> PostV2SettingsUserAgent(GroupCollection groups, Dictionary<string, string> requestParameters)
|
private ValueTuple<HttpStatusCode, object?> PostV2SettingsUserAgent(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||||
{
|
{
|
||||||
if (!requestParameters.TryGetValue("value", out string? userAgent))
|
if (!requestParameters.TryGetValue("value", out string? userAgent))
|
||||||
{
|
{
|
||||||
settings.UpdateUserAgent(null);
|
TrangaSettings.UpdateUserAgent(null);
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.Accepted, null);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.Accepted, null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
settings.UpdateUserAgent(userAgent);
|
TrangaSettings.UpdateUserAgent(userAgent);
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ public partial class Server
|
|||||||
|
|
||||||
private ValueTuple<HttpStatusCode, object?> GetV2SettingsRateLimit(GroupCollection groups, Dictionary<string, string> requestParameters)
|
private ValueTuple<HttpStatusCode, object?> GetV2SettingsRateLimit(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||||
{
|
{
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.requestLimits);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.requestLimits);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueTuple<HttpStatusCode, object?> PostV2SettingsRateLimit(GroupCollection groups, Dictionary<string, string> requestParameters)
|
private ValueTuple<HttpStatusCode, object?> PostV2SettingsRateLimit(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||||
@ -47,10 +47,9 @@ public partial class Server
|
|||||||
if(!Enum.TryParse(kv.Key, out RequestType requestType) ||
|
if(!Enum.TryParse(kv.Key, out RequestType requestType) ||
|
||||||
!int.TryParse(kv.Value, out int requestsPerMinute))
|
!int.TryParse(kv.Value, out int requestsPerMinute))
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, null);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, null);
|
||||||
settings.requestLimits[requestType] = requestsPerMinute;
|
TrangaSettings.UpdateRateLimit(requestType, requestsPerMinute);
|
||||||
settings.ExportSettings();
|
|
||||||
}
|
}
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.requestLimits);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.requestLimits);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueTuple<HttpStatusCode, object?> GetV2SettingsRateLimitType(GroupCollection groups, Dictionary<string, string> requestParameters)
|
private ValueTuple<HttpStatusCode, object?> GetV2SettingsRateLimitType(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||||
@ -58,7 +57,7 @@ public partial class Server
|
|||||||
if(groups.Count < 1 ||
|
if(groups.Count < 1 ||
|
||||||
!Enum.TryParse(groups[1].Value, out RequestType requestType))
|
!Enum.TryParse(groups[1].Value, out RequestType requestType))
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"RequestType {groups[1].Value}");
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"RequestType {groups[1].Value}");
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.requestLimits[requestType]);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.requestLimits[requestType]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueTuple<HttpStatusCode, object?> PostV2SettingsRateLimitType(GroupCollection groups, Dictionary<string, string> requestParameters)
|
private ValueTuple<HttpStatusCode, object?> PostV2SettingsRateLimitType(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||||
@ -69,13 +68,13 @@ public partial class Server
|
|||||||
if (!requestParameters.TryGetValue("value", out string? requestsPerMinuteStr) ||
|
if (!requestParameters.TryGetValue("value", out string? requestsPerMinuteStr) ||
|
||||||
!int.TryParse(requestsPerMinuteStr, out int requestsPerMinute))
|
!int.TryParse(requestsPerMinuteStr, out int requestsPerMinute))
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "Errors parsing requestsPerMinute");
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "Errors parsing requestsPerMinute");
|
||||||
settings.requestLimits[requestType] = requestsPerMinute;
|
TrangaSettings.UpdateRateLimit(requestType, requestsPerMinute);
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueTuple<HttpStatusCode, object?> GetV2SettingsAprilFoolsMode(GroupCollection groups, Dictionary<string, string> requestParameters)
|
private ValueTuple<HttpStatusCode, object?> GetV2SettingsAprilFoolsMode(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||||
{
|
{
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.aprilFoolsMode);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.aprilFoolsMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueTuple<HttpStatusCode, object?> PostV2SettingsAprilFoolsMode(GroupCollection groups, Dictionary<string, string> requestParameters)
|
private ValueTuple<HttpStatusCode, object?> PostV2SettingsAprilFoolsMode(GroupCollection groups, Dictionary<string, string> requestParameters)
|
||||||
@ -83,7 +82,7 @@ public partial class Server
|
|||||||
if (!requestParameters.TryGetValue("value", out string? trueFalseStr) ||
|
if (!requestParameters.TryGetValue("value", out string? trueFalseStr) ||
|
||||||
!bool.TryParse(trueFalseStr, out bool trueFalse))
|
!bool.TryParse(trueFalseStr, out bool trueFalse))
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "Errors parsing 'value'");
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "Errors parsing 'value'");
|
||||||
settings.UpdateAprilFoolsMode(trueFalse);
|
TrangaSettings.UpdateAprilFoolsMode(trueFalse);
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +97,7 @@ public partial class Server
|
|||||||
false => true,
|
false => true,
|
||||||
true => bool.Parse(moveFilesStr!)
|
true => bool.Parse(moveFilesStr!)
|
||||||
};
|
};
|
||||||
settings.UpdateDownloadLocation(folderPath, moveFiles);
|
TrangaSettings.UpdateDownloadLocation(folderPath, moveFiles);
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
||||||
}
|
}
|
||||||
catch (FormatException)
|
catch (FormatException)
|
||||||
|
@ -10,10 +10,9 @@ public partial class Tranga : GlobalBase
|
|||||||
public JobBoss jobBoss;
|
public JobBoss jobBoss;
|
||||||
private Server.Server _server;
|
private Server.Server _server;
|
||||||
|
|
||||||
public Tranga(Logger? logger, TrangaSettings settings) : base(logger, settings)
|
public Tranga(Logger? logger) : base(logger)
|
||||||
{
|
{
|
||||||
Log("\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n");
|
Log("\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n");
|
||||||
Log(settings.ToString());
|
|
||||||
keepRunning = true;
|
keepRunning = true;
|
||||||
_connectors = new HashSet<MangaConnector>()
|
_connectors = new HashSet<MangaConnector>()
|
||||||
{
|
{
|
||||||
@ -69,7 +68,7 @@ public partial class Tranga : GlobalBase
|
|||||||
{
|
{
|
||||||
while (keepRunning)
|
while (keepRunning)
|
||||||
{
|
{
|
||||||
if(!settings.aprilFoolsMode || !IsAprilFirst())
|
if(!TrangaSettings.aprilFoolsMode || !IsAprilFirst())
|
||||||
jobBoss.CheckJobs();
|
jobBoss.CheckJobs();
|
||||||
else
|
else
|
||||||
Log("April Fools Mode in Effect");
|
Log("April Fools Mode in Effect");
|
||||||
|
@ -36,34 +36,16 @@ public partial class Tranga : GlobalBase
|
|||||||
enabledLoggers.Add(Logger.LoggerType.FileLogger);
|
enabledLoggers.Add(Logger.LoggerType.FileLogger);
|
||||||
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, directoryPath);
|
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, directoryPath);
|
||||||
|
|
||||||
TrangaSettings? settings = null;
|
|
||||||
bool dlp = fetched.TryGetValue(downloadLocation, out string[]? downloadLocationPath);
|
bool dlp = fetched.TryGetValue(downloadLocation, out string[]? downloadLocationPath);
|
||||||
bool wdp = fetched.TryGetValue(workingDirectory, out string[]? workingDirectoryPath);
|
bool wdp = fetched.TryGetValue(workingDirectory, out string[]? workingDirectoryPath);
|
||||||
|
|
||||||
if (dlp && wdp)
|
if (wdp)
|
||||||
{
|
TrangaSettings.LoadFromWorkingDirectory(workingDirectoryPath![0]);
|
||||||
settings = new TrangaSettings(downloadLocationPath![0], workingDirectoryPath![0]);
|
|
||||||
}else if (dlp)
|
|
||||||
{
|
|
||||||
if (settings is null)
|
|
||||||
settings = new TrangaSettings(downloadLocation: downloadLocationPath![0]);
|
|
||||||
else
|
|
||||||
settings = new TrangaSettings(downloadLocation: downloadLocationPath![0], settings.workingDirectory);
|
|
||||||
}else if (wdp)
|
|
||||||
{
|
|
||||||
if (settings is null)
|
|
||||||
settings = new TrangaSettings(workingDirectory: workingDirectoryPath![0]);
|
|
||||||
else
|
|
||||||
settings = new TrangaSettings(settings.downloadLocation, workingDirectoryPath![0]);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
TrangaSettings.CreateOrUpdate();
|
||||||
settings = new TrangaSettings();
|
if(dlp)
|
||||||
}
|
TrangaSettings.CreateOrUpdate(downloadDirectory: downloadLocationPath![0]);
|
||||||
|
|
||||||
Directory.CreateDirectory(settings.downloadLocation);//TODO validate path
|
Tranga _ = new (logger);
|
||||||
Directory.CreateDirectory(settings.workingDirectory);//TODO validate path
|
|
||||||
|
|
||||||
Tranga _ = new (logger, settings);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.Json.Nodes;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using Tranga.LibraryConnectors;
|
using Tranga.LibraryConnectors;
|
||||||
using Tranga.MangaConnectors;
|
using Tranga.MangaConnectors;
|
||||||
using Tranga.NotificationConnectors;
|
using Tranga.NotificationConnectors;
|
||||||
@ -9,21 +8,21 @@ using static System.IO.UnixFileMode;
|
|||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
public class TrangaSettings
|
public static class TrangaSettings
|
||||||
{
|
{
|
||||||
public string downloadLocation { get; private set; }
|
|
||||||
public string workingDirectory { get; private set; }
|
|
||||||
public int apiPortNumber { get; init; }
|
|
||||||
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 mangaCacheFolderPath => Path.Join(workingDirectory, "manga");
|
|
||||||
[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; } = 2;
|
public static string downloadLocation { get; private set; } = (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(Directory.GetCurrentDirectory(), "Downloads"));
|
||||||
public bool aprilFoolsMode { get; private set; } = true;
|
public static string workingDirectory { get; private set; } = Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
|
||||||
|
public static int apiPortNumber { get; private set; } = 6531;
|
||||||
|
public static string userAgent { get; private set; } = DefaultUserAgent;
|
||||||
|
[JsonIgnore] public static string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||||
|
[JsonIgnore] public static string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
|
||||||
|
[JsonIgnore] public static string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
|
||||||
|
[JsonIgnore] public static string jobsFolderPath => Path.Join(workingDirectory, "jobs");
|
||||||
|
[JsonIgnore] public static string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||||
|
[JsonIgnore] public static string mangaCacheFolderPath => Path.Join(workingDirectory, "mangaCache");
|
||||||
|
public static ushort? version { get; } = 2;
|
||||||
|
public static 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},
|
||||||
@ -34,50 +33,35 @@ public class TrangaSettings
|
|||||||
{RequestType.Default, 60}
|
{RequestType.Default, 60}
|
||||||
};
|
};
|
||||||
|
|
||||||
public Dictionary<RequestType, int> requestLimits { get; set; } = DefaultRequestLimits;
|
public static Dictionary<RequestType, int> requestLimits { get; set; } = DefaultRequestLimits;
|
||||||
|
|
||||||
public TrangaSettings(string? downloadLocation = null, string? workingDirectory = null, int? apiPortNumber = null)
|
public static void LoadFromWorkingDirectory(string directory)
|
||||||
{
|
{
|
||||||
string wd = workingDirectory ?? Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
|
TrangaSettings.workingDirectory = directory;
|
||||||
string sfp = Path.Join(wd, "settings.json");
|
if(File.Exists(settingsFilePath))
|
||||||
|
Deserialize(File.ReadAllText(settingsFilePath));
|
||||||
|
else return;
|
||||||
|
|
||||||
string lockFilePath = $"{sfp}.lock";
|
Directory.CreateDirectory(downloadLocation);
|
||||||
if (File.Exists(sfp) && !File.Exists(lockFilePath))
|
Directory.CreateDirectory(workingDirectory);
|
||||||
{//Load from settings file
|
ExportSettings();
|
||||||
FileStream lockFile = File.Create(lockFilePath,0, FileOptions.DeleteOnClose); //lock settingsfile
|
|
||||||
string settingsStr = File.ReadAllText(sfp);
|
|
||||||
settingsStr = Regex.Replace(settingsStr, @"""MangaDexAuthor"": [0-9]+,", "");//https://github.com/C9Glax/tranga/pull/161 Remove sometime in the future :3
|
|
||||||
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(settingsStr)!;
|
|
||||||
this.requestLimits = settings.requestLimits;
|
|
||||||
this.userAgent = settings.userAgent;
|
|
||||||
this.downloadLocation = downloadLocation ?? settings.downloadLocation;
|
|
||||||
this.workingDirectory = workingDirectory ?? settings.workingDirectory;
|
|
||||||
this.apiPortNumber = apiPortNumber ?? settings.apiPortNumber;
|
|
||||||
lockFile.Close(); //unlock settingsfile
|
|
||||||
}
|
|
||||||
else if(!File.Exists(sfp))
|
|
||||||
{//No settings file exists
|
|
||||||
if (downloadLocation?.Length < 1 || workingDirectory?.Length < 1)
|
|
||||||
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
|
|
||||||
this.requestLimits = DefaultRequestLimits;
|
|
||||||
this.userAgent = DefaultUserAgent;
|
|
||||||
this.apiPortNumber = apiPortNumber ?? 6531;
|
|
||||||
this.downloadLocation = downloadLocation ?? (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(Directory.GetCurrentDirectory(), "Downloads"));
|
|
||||||
this.workingDirectory = workingDirectory ?? Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
|
|
||||||
ExportSettings();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{//Settingsfile is locked
|
|
||||||
this.requestLimits = DefaultRequestLimits;
|
|
||||||
this.userAgent = DefaultUserAgent;
|
|
||||||
this.apiPortNumber = apiPortNumber!.Value;
|
|
||||||
this.downloadLocation = downloadLocation!;
|
|
||||||
this.workingDirectory = workingDirectory!;
|
|
||||||
}
|
|
||||||
UpdateDownloadLocation(this.downloadLocation, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<LibraryConnector> LoadLibraryConnectors(GlobalBase clone)
|
public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null, int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = null)
|
||||||
|
{
|
||||||
|
if(pWorkingDirectory is null && File.Exists(settingsFilePath))
|
||||||
|
LoadFromWorkingDirectory(workingDirectory);
|
||||||
|
TrangaSettings.downloadLocation = downloadDirectory ?? TrangaSettings.downloadLocation;
|
||||||
|
TrangaSettings.workingDirectory = pWorkingDirectory ?? TrangaSettings.workingDirectory;
|
||||||
|
TrangaSettings.apiPortNumber = pApiPortNumber ?? TrangaSettings.apiPortNumber;
|
||||||
|
TrangaSettings.userAgent = pUserAgent ?? TrangaSettings.userAgent;
|
||||||
|
TrangaSettings.aprilFoolsMode = pAprilFoolsMode ?? TrangaSettings.aprilFoolsMode;
|
||||||
|
Directory.CreateDirectory(downloadLocation);
|
||||||
|
Directory.CreateDirectory(workingDirectory);
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashSet<LibraryConnector> LoadLibraryConnectors(GlobalBase clone)
|
||||||
{
|
{
|
||||||
if (!File.Exists(libraryConnectorsFilePath))
|
if (!File.Exists(libraryConnectorsFilePath))
|
||||||
return new HashSet<LibraryConnector>();
|
return new HashSet<LibraryConnector>();
|
||||||
@ -91,7 +75,7 @@ public class TrangaSettings
|
|||||||
})!;
|
})!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<NotificationConnector> LoadNotificationConnectors(GlobalBase clone)
|
public static HashSet<NotificationConnector> LoadNotificationConnectors(GlobalBase clone)
|
||||||
{
|
{
|
||||||
if (!File.Exists(notificationConnectorsFilePath))
|
if (!File.Exists(notificationConnectorsFilePath))
|
||||||
return new HashSet<NotificationConnector>();
|
return new HashSet<NotificationConnector>();
|
||||||
@ -105,13 +89,13 @@ public class TrangaSettings
|
|||||||
})!;
|
})!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateAprilFoolsMode(bool enabled)
|
public static void UpdateAprilFoolsMode(bool enabled)
|
||||||
{
|
{
|
||||||
this.aprilFoolsMode = enabled;
|
TrangaSettings.aprilFoolsMode = enabled;
|
||||||
ExportSettings();
|
ExportSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDownloadLocation(string newPath, bool moveFiles = true)
|
public static void UpdateDownloadLocation(string newPath, bool moveFiles = true)
|
||||||
{
|
{
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
Directory.CreateDirectory(newPath,
|
Directory.CreateDirectory(newPath,
|
||||||
@ -119,32 +103,44 @@ public class TrangaSettings
|
|||||||
else
|
else
|
||||||
Directory.CreateDirectory(newPath);
|
Directory.CreateDirectory(newPath);
|
||||||
|
|
||||||
if (moveFiles && Directory.Exists(this.downloadLocation))
|
if (moveFiles && Directory.Exists(TrangaSettings.downloadLocation))
|
||||||
Directory.Move(this.downloadLocation, newPath);
|
Directory.Move(TrangaSettings.downloadLocation, newPath);
|
||||||
|
|
||||||
this.downloadLocation = newPath;
|
TrangaSettings.downloadLocation = newPath;
|
||||||
ExportSettings();
|
ExportSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateWorkingDirectory(string newPath)
|
public static void UpdateWorkingDirectory(string newPath)
|
||||||
{
|
{
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
Directory.CreateDirectory(newPath,
|
Directory.CreateDirectory(newPath,
|
||||||
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||||
else
|
else
|
||||||
Directory.CreateDirectory(newPath);
|
Directory.CreateDirectory(newPath);
|
||||||
Directory.Move(this.workingDirectory, newPath);
|
Directory.Move(TrangaSettings.workingDirectory, newPath);
|
||||||
this.workingDirectory = newPath;
|
TrangaSettings.workingDirectory = newPath;
|
||||||
ExportSettings();
|
ExportSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateUserAgent(string? customUserAgent)
|
public static void UpdateUserAgent(string? customUserAgent)
|
||||||
{
|
{
|
||||||
this.userAgent = customUserAgent ?? DefaultUserAgent;
|
TrangaSettings.userAgent = customUserAgent ?? DefaultUserAgent;
|
||||||
ExportSettings();
|
ExportSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExportSettings()
|
public static void UpdateRateLimit(RequestType requestType, int newLimit)
|
||||||
|
{
|
||||||
|
TrangaSettings.requestLimits[requestType] = newLimit;
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ResetRateLimits()
|
||||||
|
{
|
||||||
|
TrangaSettings.requestLimits = DefaultRequestLimits;
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ExportSettings()
|
||||||
{
|
{
|
||||||
if (File.Exists(settingsFilePath))
|
if (File.Exists(settingsFilePath))
|
||||||
{
|
{
|
||||||
@ -153,22 +149,38 @@ public class TrangaSettings
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
Directory.CreateDirectory(new FileInfo(settingsFilePath).DirectoryName!);
|
Directory.CreateDirectory(new FileInfo(settingsFilePath).DirectoryName!);
|
||||||
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
|
File.WriteAllText(settingsFilePath, Serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetFullCoverPath(Manga manga)
|
public static JObject AsJObject()
|
||||||
{
|
{
|
||||||
return Path.Join(this.coverImageCache, manga.coverFileNameInCache);
|
JObject jobj = new JObject();
|
||||||
|
jobj.Add("downloadLocation", JToken.FromObject(TrangaSettings.downloadLocation));
|
||||||
|
jobj.Add("workingDirectory", JToken.FromObject(TrangaSettings.workingDirectory));
|
||||||
|
jobj.Add("apiPortNumber", JToken.FromObject(TrangaSettings.apiPortNumber));
|
||||||
|
jobj.Add("userAgent", JToken.FromObject(TrangaSettings.userAgent));
|
||||||
|
jobj.Add("aprilFoolsMode", JToken.FromObject(TrangaSettings.aprilFoolsMode));
|
||||||
|
jobj.Add("version", JToken.FromObject(TrangaSettings.version));
|
||||||
|
jobj.Add("requestLimits", JToken.FromObject(TrangaSettings.requestLimits));
|
||||||
|
return jobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public static string Serialize() => AsJObject().ToString();
|
||||||
|
|
||||||
|
public static void Deserialize(string serialized)
|
||||||
{
|
{
|
||||||
return $"TrangaSettings:\n" +
|
JObject jobj = JObject.Parse(serialized);
|
||||||
$"\tDownloadLocation: {downloadLocation}\n" +
|
if (jobj.TryGetValue("downloadLocation", out JToken? dl))
|
||||||
$"\tworkingDirectory: {workingDirectory}\n" +
|
TrangaSettings.downloadLocation = dl.Value<string>()!;
|
||||||
$"\tjobsFolderPath: {jobsFolderPath}\n" +
|
if (jobj.TryGetValue("workingDirectory", out JToken? wd))
|
||||||
$"\tsettingsFilePath: {settingsFilePath}\n" +
|
TrangaSettings.workingDirectory = wd.Value<string>()!;
|
||||||
$"\t\tnotificationConnectors: {notificationConnectorsFilePath}\n" +
|
if (jobj.TryGetValue("apiPortNumber", out JToken? apn))
|
||||||
$"\t\tlibraryConnectors: {libraryConnectorsFilePath}\n";
|
TrangaSettings.apiPortNumber = apn.Value<int>();
|
||||||
|
if (jobj.TryGetValue("userAgent", out JToken? ua))
|
||||||
|
TrangaSettings.userAgent = ua.Value<string>()!;
|
||||||
|
if (jobj.TryGetValue("aprilFoolsMode", out JToken? afm))
|
||||||
|
TrangaSettings.aprilFoolsMode = afm.Value<bool>()!;
|
||||||
|
if (jobj.TryGetValue("requestLimits", out JToken? rl))
|
||||||
|
TrangaSettings.requestLimits = rl.ToObject<Dictionary<RequestType, int>>()!;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user