diff --git a/API/RequestHandler.cs b/API/RequestHandler.cs
index 625da3d..4360f30 100644
--- a/API/RequestHandler.cs
+++ b/API/RequestHandler.cs
@@ -276,7 +276,7 @@ public class RequestHandler
return null;
if(title.Length < 4)
return null;
- return _taskManager.GetPublicationsFromConnector(connector1, title);
+ return connector1.GetPublications(title);
case "/Publications/Chapters":
string[] yes = { "true", "yes", "1", "y" };
variables.TryGetValue("connectorName", out string? connectorName2);
@@ -297,7 +297,7 @@ public class RequestHandler
return null;
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)
return _taskManager.GetExistingChaptersList(connector2, (Publication)publication, language ?? "en").ToArray();
else
diff --git a/Tranga-CLI/Tranga_Cli.cs b/Tranga-CLI/Tranga_Cli.cs
index d2a279e..083f36d 100644
--- a/Tranga-CLI/Tranga_Cli.cs
+++ b/Tranga-CLI/Tranga_Cli.cs
@@ -565,7 +565,7 @@ public static class Tranga_Cli
Console.WriteLine("Publication search query (leave empty for all):");
string? query = Console.ReadLine();
- Publication[] publications = taskManager.GetPublicationsFromConnector(connector, query ?? "");
+ Publication[] publications = connector.GetPublications(query ?? "");
if (publications.Length < 1)
{
diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs
index 257976f..f5bb4cd 100644
--- a/Tranga/Connector.cs
+++ b/Tranga/Connector.cs
@@ -2,7 +2,6 @@
using System.Net;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
-using System.Xml.Linq;
using Logging;
using Tranga.TrangaTasks;
using static System.IO.UnixFileMode;
@@ -48,6 +47,24 @@ public abstract class Connector
/// Array of Chapters matching Publication and Language
public abstract Chapter[] GetChapters(Publication publication, string language = "");
+ ///
+ /// Updates the available Chapters of a Publication
+ ///
+ /// Publication to check
+ /// Language to receive chapters for
+ ///
+ /// List of Chapters that were previously not in collection
+ public List GetNewChaptersList(Publication publication, string language, ref HashSet collection)
+ {
+ Chapter[] newChapters = this.GetChapters(publication, language);
+ collection.Add(publication);
+ logger?.WriteLine(this.GetType().ToString(), "Checking for duplicates");
+ List 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)
{
Chapter[] availableChapters = this.GetChapters(publication, language??"en");
diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs
index 64b2c37..717aa58 100644
--- a/Tranga/TaskManager.cs
+++ b/Tranga/TaskManager.cs
@@ -11,7 +11,7 @@ namespace Tranga;
///
public class TaskManager
{
- public Dictionary> chapterCollection = new();
+ public HashSet collection = new();
private HashSet _allTasks = new();
private readonly Dictionary _runningTasks = new ();
private bool _continueRunning = true;
@@ -265,41 +265,11 @@ public class TaskManager
_allTasks.CopyTo(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());
- }
- return ret;
- }
/// All added Publications
public Publication[] GetAllPublications()
{
- return this.chapterCollection.Keys.ToArray();
- }
-
-
- ///
- /// Updates the available Chapters of a Publication
- ///
- /// Connector to use
- /// Publication to check
- /// Language to receive chapters for
- /// List of Chapters that were previously not in collection
- public List GetNewChaptersList(Connector connector, Publication publication, string language)
- {
- List 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;
+ return this.collection.ToArray();
}
public List GetExistingChaptersList(Connector connector, Publication publication, string language)
@@ -363,15 +333,6 @@ public class TaskManager
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(buffer)!;
- foreach (Publication publication in publications)
- this.chapterCollection.TryAdd(publication, new List());
- }
}
///
@@ -386,11 +347,6 @@ public class TaskManager
while(IsFileInUse(settings.tasksFilePath))
Thread.Sleep(50);
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)
diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs
index 0c817fc..e26218c 100644
--- a/Tranga/TrangaSettings.cs
+++ b/Tranga/TrangaSettings.cs
@@ -12,7 +12,6 @@ public class TrangaSettings
public string workingDirectory { get; set; }
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.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");
public HashSet libraryManagers { get; }
public HashSet notificationManagers { get; }
diff --git a/Tranga/TrangaTasks/MonitorPublicationTask.cs b/Tranga/TrangaTasks/MonitorPublicationTask.cs
index df84e08..2b93f7c 100644
--- a/Tranga/TrangaTasks/MonitorPublicationTask.cs
+++ b/Tranga/TrangaTasks/MonitorPublicationTask.cs
@@ -23,7 +23,7 @@ public class MonitorPublicationTask : TrangaTask
//Check if Publication already has a Folder
publication.CreatePublicationFolder(taskManager.settings.downloadLocation);
- List newChapters = taskManager.GetNewChaptersList(connector, publication, language);
+ List newChapters = connector.GetNewChaptersList(publication, language, ref taskManager.collection);
connector.CopyCoverFromCacheToDownloadLocation(publication, taskManager.settings);