Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into Server-V2
# Conflicts: # Tranga/Jobs/JobBoss.cs
This commit is contained in:
commit
3e581e2ddb
@ -89,13 +89,15 @@ public readonly struct Chapter : IComparable
|
|||||||
return false;
|
return false;
|
||||||
FileInfo? mangaArchive = null;
|
FileInfo? mangaArchive = null;
|
||||||
string markerPath = Path.Join(mangaDirectory, $".{id}");
|
string markerPath = Path.Join(mangaDirectory, $".{id}");
|
||||||
if (this.id is not null
|
if (this.id is not null && File.Exists(markerPath))
|
||||||
&& File.Exists(markerPath)
|
|
||||||
&& File.Exists(File.ReadAllText(markerPath)))
|
|
||||||
{
|
{
|
||||||
mangaArchive = new FileInfo(File.ReadAllText(markerPath));
|
if(File.Exists(File.ReadAllText(markerPath)))
|
||||||
|
mangaArchive = new FileInfo(File.ReadAllText(markerPath));
|
||||||
|
else
|
||||||
|
File.Delete(markerPath);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if(mangaArchive is null)
|
||||||
{
|
{
|
||||||
FileInfo[] archives = new DirectoryInfo(mangaDirectory).GetFiles("*.cbz");
|
FileInfo[] archives = new DirectoryInfo(mangaDirectory).GetFiles("*.cbz");
|
||||||
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]+)*)");
|
||||||
@ -110,6 +112,7 @@ public readonly struct Chapter : IComparable
|
|||||||
return m.Groups[2].Value == t.chapterNumber;
|
return m.Groups[2].Value == t.chapterNumber;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
string correctPath = GetArchiveFilePath();
|
string correctPath = GetArchiveFilePath();
|
||||||
if(mangaArchive is not null && mangaArchive.FullName != correctPath)
|
if(mangaArchive is not null && mangaArchive.FullName != correctPath)
|
||||||
mangaArchive.MoveTo(correctPath, true);
|
mangaArchive.MoveTo(correctPath, true);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Tranga.MangaConnectors;
|
using Tranga.MangaConnectors;
|
||||||
|
using static System.IO.UnixFileMode;
|
||||||
|
|
||||||
namespace Tranga.Jobs;
|
namespace Tranga.Jobs;
|
||||||
|
|
||||||
@ -17,7 +19,7 @@ public class JobBoss : GlobalBase
|
|||||||
Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}");
|
Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddJob(Job job)
|
public bool AddJob(Job job, string? jobFile = null)
|
||||||
{
|
{
|
||||||
if (ContainsJobLike(job))
|
if (ContainsJobLike(job))
|
||||||
{
|
{
|
||||||
@ -27,10 +29,11 @@ public class JobBoss : GlobalBase
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log($"Added {job}");
|
Log($"Added {job}");
|
||||||
this.jobs.Add(job);
|
if (!this.jobs.Add(job))
|
||||||
UpdateJobFile(job);
|
return false;
|
||||||
return true;
|
UpdateJobFile(job, jobFile);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddJobs(IEnumerable<Job> jobsToAdd)
|
public void AddJobs(IEnumerable<Job> jobsToAdd)
|
||||||
@ -140,18 +143,18 @@ public class JobBoss : GlobalBase
|
|||||||
|
|
||||||
private void LoadJobsList(HashSet<MangaConnector> connectors)
|
private void LoadJobsList(HashSet<MangaConnector> connectors)
|
||||||
{
|
{
|
||||||
|
Directory.CreateDirectory(TrangaSettings.jobsFolderPath);
|
||||||
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(TrangaSettings.jobsFolderPath, UserRead | UserWrite | UserExecute | GroupRead | OtherRead);
|
||||||
if (!Directory.Exists(TrangaSettings.jobsFolderPath)) //No jobs to load
|
if (!Directory.Exists(TrangaSettings.jobsFolderPath)) //No jobs to load
|
||||||
{
|
|
||||||
Directory.CreateDirectory(TrangaSettings.jobsFolderPath);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
Regex idRex = new (@"(.*)\.json");
|
Regex idRex = new (@"(.*)\.json");
|
||||||
|
|
||||||
//Load Manga-Files
|
//Load Manga-Files
|
||||||
ImportManga();
|
ImportManga();
|
||||||
|
|
||||||
//Load json-job-files
|
//Load json-job-files
|
||||||
foreach (FileInfo file in new DirectoryInfo(TrangaSettings.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),
|
||||||
@ -165,8 +168,8 @@ public class JobBoss : GlobalBase
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log($"Adding Job {job}");
|
Log($"Adding Job {job}");
|
||||||
this.jobs.Add(job);
|
if(!AddJob(job, file.Name)) //If we detect a duplicate, delete the file.
|
||||||
UpdateJobFile(job, file.Name);
|
file.Delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +221,8 @@ public class JobBoss : GlobalBase
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log(e.ToString());
|
Log($"Error deleting {oldFilePath} job {job.id}\n{e}");
|
||||||
|
return; //Don't export a new file when we haven't actually deleted the old one
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,6 +234,8 @@ public class JobBoss : GlobalBase
|
|||||||
while(IsFileInUse(newJobFilePath))
|
while(IsFileInUse(newJobFilePath))
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
File.WriteAllText(newJobFilePath, jobStr);
|
File.WriteAllText(newJobFilePath, jobStr);
|
||||||
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(newJobFilePath, UserRead | UserWrite | GroupRead | OtherRead);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,9 +108,10 @@ public class ManhuaPlus : MangaConnector
|
|||||||
Log("No genres found");
|
Log("No genres found");
|
||||||
}
|
}
|
||||||
|
|
||||||
string yearNodeStr = document.DocumentNode
|
Regex yearRex = new(@"(?:[0-9]{1,2}\/){2}([0-9]{2,4}) [0-9]{1,2}:[0-9]{1,2}");
|
||||||
.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-clock ')]/../span").InnerText.Replace("\n", "");
|
HtmlNode yearNode = document.DocumentNode.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-clock ')]/../span");
|
||||||
int year = int.Parse(yearNodeStr.Split(' ')[0].Split('/')[^1]);
|
Match match = yearRex.Match(yearNode.InnerText);
|
||||||
|
int year = match.Success && match.Groups[1].Success ? int.Parse(match.Groups[1].Value) : 1960;
|
||||||
|
|
||||||
status = document.DocumentNode.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-rss ')]/../span").InnerText.Replace("\n", "");
|
status = document.DocumentNode.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-rss ')]/../span").InnerText.Replace("\n", "");
|
||||||
switch (status.ToLower())
|
switch (status.ToLower())
|
||||||
|
Loading…
Reference in New Issue
Block a user