Moved GetPublicationsFromConnector to connector.
Moved GetNewChaptersList to Connector. Removed knownPublications file Renamed chapterCollection to collection and only contains Publications
This commit is contained in:
parent
e70a14ca56
commit
41b6bb77b6
@ -276,7 +276,7 @@ public class RequestHandler
|
|||||||
return null;
|
return null;
|
||||||
if(title.Length < 4)
|
if(title.Length < 4)
|
||||||
return null;
|
return null;
|
||||||
return _taskManager.GetPublicationsFromConnector(connector1, title);
|
return connector1.GetPublications(title);
|
||||||
case "/Publications/Chapters":
|
case "/Publications/Chapters":
|
||||||
string[] yes = { "true", "yes", "1", "y" };
|
string[] yes = { "true", "yes", "1", "y" };
|
||||||
variables.TryGetValue("connectorName", out string? connectorName2);
|
variables.TryGetValue("connectorName", out string? connectorName2);
|
||||||
@ -297,7 +297,7 @@ public class RequestHandler
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
if(newOnly)
|
if(newOnly)
|
||||||
return _taskManager.GetNewChaptersList(connector2, (Publication)publication, language??"en").ToArray();
|
return connector2.GetNewChaptersList((Publication)publication, language??"en", ref _taskManager.collection).ToArray();
|
||||||
else if (existingOnly)
|
else if (existingOnly)
|
||||||
return _taskManager.GetExistingChaptersList(connector2, (Publication)publication, language ?? "en").ToArray();
|
return _taskManager.GetExistingChaptersList(connector2, (Publication)publication, language ?? "en").ToArray();
|
||||||
else
|
else
|
||||||
|
@ -565,7 +565,7 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine("Publication search query (leave empty for all):");
|
Console.WriteLine("Publication search query (leave empty for all):");
|
||||||
string? query = Console.ReadLine();
|
string? query = Console.ReadLine();
|
||||||
|
|
||||||
Publication[] publications = taskManager.GetPublicationsFromConnector(connector, query ?? "");
|
Publication[] publications = connector.GetPublications(query ?? "");
|
||||||
|
|
||||||
if (publications.Length < 1)
|
if (publications.Length < 1)
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml.Linq;
|
|
||||||
using Logging;
|
using Logging;
|
||||||
using Tranga.TrangaTasks;
|
using Tranga.TrangaTasks;
|
||||||
using static System.IO.UnixFileMode;
|
using static System.IO.UnixFileMode;
|
||||||
@ -48,6 +47,24 @@ public abstract class Connector
|
|||||||
/// <returns>Array of Chapters matching Publication and Language</returns>
|
/// <returns>Array of Chapters matching Publication and Language</returns>
|
||||||
public abstract Chapter[] GetChapters(Publication publication, string language = "");
|
public abstract Chapter[] GetChapters(Publication publication, string language = "");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the available Chapters of a Publication
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="publication">Publication to check</param>
|
||||||
|
/// <param name="language">Language to receive chapters for</param>
|
||||||
|
/// <param name="collection"></param>
|
||||||
|
/// <returns>List of Chapters that were previously not in collection</returns>
|
||||||
|
public List<Chapter> GetNewChaptersList(Publication publication, string language, ref HashSet<Publication> collection)
|
||||||
|
{
|
||||||
|
Chapter[] newChapters = this.GetChapters(publication, language);
|
||||||
|
collection.Add(publication);
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), "Checking for duplicates");
|
||||||
|
List<Chapter> newChaptersList = newChapters.Where(nChapter => !nChapter.CheckChapterIsDownloaded(settings.downloadLocation)).ToList();
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"{newChaptersList.Count} new chapters.");
|
||||||
|
|
||||||
|
return newChaptersList;
|
||||||
|
}
|
||||||
|
|
||||||
public Chapter[] SelectChapters(Publication publication, string searchTerm, string? language = null)
|
public Chapter[] SelectChapters(Publication publication, string searchTerm, string? language = null)
|
||||||
{
|
{
|
||||||
Chapter[] availableChapters = this.GetChapters(publication, language??"en");
|
Chapter[] availableChapters = this.GetChapters(publication, language??"en");
|
||||||
|
@ -11,7 +11,7 @@ namespace Tranga;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TaskManager
|
public class TaskManager
|
||||||
{
|
{
|
||||||
public Dictionary<Publication, List<Chapter>> chapterCollection = new();
|
public HashSet<Publication> collection = new();
|
||||||
private HashSet<TrangaTask> _allTasks = new();
|
private HashSet<TrangaTask> _allTasks = new();
|
||||||
private readonly Dictionary<TrangaTask, CancellationTokenSource> _runningTasks = new ();
|
private readonly Dictionary<TrangaTask, CancellationTokenSource> _runningTasks = new ();
|
||||||
private bool _continueRunning = true;
|
private bool _continueRunning = true;
|
||||||
@ -266,40 +266,10 @@ public class TaskManager
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Publication[] GetPublicationsFromConnector(Connector connector, string? title = null)
|
|
||||||
{
|
|
||||||
Publication[] ret = connector.GetPublications(title ?? "");
|
|
||||||
foreach (Publication publication in ret)
|
|
||||||
{
|
|
||||||
if(chapterCollection.All(pub => pub.Key.internalId != publication.internalId))
|
|
||||||
this.chapterCollection.TryAdd(publication, new List<Chapter>());
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <returns>All added Publications</returns>
|
/// <returns>All added Publications</returns>
|
||||||
public Publication[] GetAllPublications()
|
public Publication[] GetAllPublications()
|
||||||
{
|
{
|
||||||
return this.chapterCollection.Keys.ToArray();
|
return this.collection.ToArray();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates the available Chapters of a Publication
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="connector">Connector to use</param>
|
|
||||||
/// <param name="publication">Publication to check</param>
|
|
||||||
/// <param name="language">Language to receive chapters for</param>
|
|
||||||
/// <returns>List of Chapters that were previously not in collection</returns>
|
|
||||||
public List<Chapter> GetNewChaptersList(Connector connector, Publication publication, string language)
|
|
||||||
{
|
|
||||||
List<Chapter> newChaptersList = new();
|
|
||||||
chapterCollection.TryAdd(publication, newChaptersList); //To ensure publication is actually in collection
|
|
||||||
|
|
||||||
Chapter[] newChapters = connector.GetChapters(publication, language);
|
|
||||||
newChaptersList = newChapters.Where(nChapter => !nChapter.CheckChapterIsDownloaded(settings.downloadLocation)).ToList();
|
|
||||||
|
|
||||||
return newChaptersList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Chapter> GetExistingChaptersList(Connector connector, Publication publication, string language)
|
public List<Chapter> GetExistingChaptersList(Connector connector, Publication publication, string language)
|
||||||
@ -363,15 +333,6 @@ public class TaskManager
|
|||||||
parentTask.lastExecuted = DateTime.UnixEpoch;
|
parentTask.lastExecuted = DateTime.UnixEpoch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists(settings.knownPublicationsPath))
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Importing known publications from {settings.knownPublicationsPath}");
|
|
||||||
buffer = File.ReadAllText(settings.knownPublicationsPath);
|
|
||||||
Publication[] publications = JsonConvert.DeserializeObject<Publication[]>(buffer)!;
|
|
||||||
foreach (Publication publication in publications)
|
|
||||||
this.chapterCollection.TryAdd(publication, new List<Chapter>());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -386,11 +347,6 @@ public class TaskManager
|
|||||||
while(IsFileInUse(settings.tasksFilePath))
|
while(IsFileInUse(settings.tasksFilePath))
|
||||||
Thread.Sleep(50);
|
Thread.Sleep(50);
|
||||||
File.WriteAllText(settings.tasksFilePath, JsonConvert.SerializeObject(this._allTasks));
|
File.WriteAllText(settings.tasksFilePath, JsonConvert.SerializeObject(this._allTasks));
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Exporting known publications to {settings.knownPublicationsPath}");
|
|
||||||
while(IsFileInUse(settings.knownPublicationsPath))
|
|
||||||
Thread.Sleep(50);
|
|
||||||
File.WriteAllText(settings.knownPublicationsPath, JsonConvert.SerializeObject(this.chapterCollection.Keys.ToArray()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsFileInUse(string path)
|
private bool IsFileInUse(string path)
|
||||||
|
@ -12,7 +12,6 @@ public class TrangaSettings
|
|||||||
public string workingDirectory { get; set; }
|
public string workingDirectory { get; set; }
|
||||||
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||||
[JsonIgnore] public string tasksFilePath => Path.Join(workingDirectory, "tasks.json");
|
[JsonIgnore] public string tasksFilePath => Path.Join(workingDirectory, "tasks.json");
|
||||||
[JsonIgnore] public string knownPublicationsPath => Path.Join(workingDirectory, "knownPublications.json");
|
|
||||||
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||||
public HashSet<LibraryManager> libraryManagers { get; }
|
public HashSet<LibraryManager> libraryManagers { get; }
|
||||||
public HashSet<NotificationManager> notificationManagers { get; }
|
public HashSet<NotificationManager> notificationManagers { get; }
|
||||||
|
@ -23,7 +23,7 @@ public class MonitorPublicationTask : TrangaTask
|
|||||||
|
|
||||||
//Check if Publication already has a Folder
|
//Check if Publication already has a Folder
|
||||||
publication.CreatePublicationFolder(taskManager.settings.downloadLocation);
|
publication.CreatePublicationFolder(taskManager.settings.downloadLocation);
|
||||||
List<Chapter> newChapters = taskManager.GetNewChaptersList(connector, publication, language);
|
List<Chapter> newChapters = connector.GetNewChaptersList(publication, language, ref taskManager.collection);
|
||||||
|
|
||||||
connector.CopyCoverFromCacheToDownloadLocation(publication, taskManager.settings);
|
connector.CopyCoverFromCacheToDownloadLocation(publication, taskManager.settings);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user