Created Method to check wether file is already downloaded.

Using this method when running TaskExecutor.UpdateChapters to get a list of all chapters that have not yet been downloaded.
This commit is contained in:
glax 2023-05-20 01:30:23 +02:00
parent 08e0fe7c71
commit 9d583b284a
3 changed files with 12 additions and 4 deletions

View File

@ -78,6 +78,16 @@ public abstract class Connector
return comicInfo.ToString(); return comicInfo.ToString();
} }
public bool ChapterIsDownloaded(Publication publication, Chapter chapter)
{
return File.Exists(CreateFullFilepath(publication, chapter));
}
protected string CreateFullFilepath(Publication publication, Chapter chapter)
{
return Path.Join(downloadLocation, publication.folderName, chapter.fileName);
}
/// <summary> /// <summary>
/// Downloads Image from URL and saves it to the given path(incl. fileName) /// Downloads Image from URL and saves it to the given path(incl. fileName)
/// </summary> /// </summary>

View File

@ -201,7 +201,7 @@ public class MangaDex : Connector
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter)); File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter));
//Download Chapter-Images //Download Chapter-Images
DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this.downloadClient, comicInfoPath); DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, comicInfoPath);
} }
public override void DownloadCover(Publication publication) public override void DownloadCover(Publication publication)

View File

@ -96,11 +96,9 @@ public static class TaskExecutor
if (!chapterCollection.ContainsKey(publication)) if (!chapterCollection.ContainsKey(publication))
return newChaptersList; return newChaptersList;
List<Chapter> currentChapters = chapterCollection[publication];
Chapter[] newChapters = connector.GetChapters(publication, language); Chapter[] newChapters = connector.GetChapters(publication, language);
newChaptersList = newChapters.Where(nChapter => !connector.ChapterIsDownloaded(publication, nChapter)).ToList();
newChaptersList = newChapters.ToList()
.ExceptBy(currentChapters.Select(cChapter => cChapter.url), nChapter => nChapter.url).ToList();
return newChaptersList; return newChaptersList;
} }
} }