namespace Tranga.TrangaTasks; public class DownloadNewChaptersTask : TrangaTask { public DownloadNewChaptersTask(Task task, string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(task, connectorName, publication, reoccurrence, language) { } public override void Execute(TaskManager taskManager) { Publication pub = (Publication)this.publication!; Connector connector = taskManager.GetConnector(this.connectorName); //Check if Publication already has a Folder string publicationFolder = Path.Join(connector.downloadLocation, pub.folderName); if(!Directory.Exists(publicationFolder)) Directory.CreateDirectory(publicationFolder); List newChapters = UpdateChapters(connector, pub, language!, ref taskManager._chapterCollection); connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings); pub.SaveSeriesInfoJson(connector.downloadLocation); foreach(Chapter newChapter in newChapters) connector.DownloadChapter(pub, newChapter); } /// /// 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 private static List UpdateChapters(Connector connector, Publication publication, string language, ref Dictionary> chapterCollection) { List newChaptersList = new(); chapterCollection.TryAdd(publication, newChaptersList); //To ensure publication is actually in collection Chapter[] newChapters = connector.GetChapters(publication, language); newChaptersList = newChapters.Where(nChapter => !connector.CheckChapterIsDownloaded(publication, nChapter)).ToList(); return newChaptersList; } }