2
0

Compare commits

...

3 Commits

Author SHA1 Message Date
621468f498 Added InvalidFileNameCharacters to list of replaced Characters in folder-names 2023-05-20 01:31:06 +02:00
2c8e647a04 Simplification 2023-05-20 01:30:34 +02:00
9d583b284a 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.
2023-05-20 01:30:23 +02:00
4 changed files with 14 additions and 7 deletions

View File

@ -77,6 +77,16 @@ public abstract class Connector
);
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>
/// Downloads Image from URL and saves it to the given path(incl. fileName)

View File

@ -201,7 +201,7 @@ public class MangaDex : Connector
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter));
//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)

View File

@ -33,7 +33,7 @@ public readonly struct Publication
this.originalLanguage = originalLanguage;
this.status = status;
this.downloadUrl = downloadUrl;
this.folderName = string.Concat(sortName.Split(Path.GetInvalidPathChars()));
this.folderName = string.Concat(sortName.Split(Path.GetInvalidPathChars().Concat(Path.GetInvalidFileNameChars()).ToArray()));
}
/// <summary>

View File

@ -93,14 +93,11 @@ public static class TaskExecutor
private static List<Chapter> UpdateChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
{
List<Chapter> newChaptersList = new();
if (!chapterCollection.ContainsKey(publication))
return newChaptersList;
chapterCollection.TryAdd(publication, newChaptersList); //To ensure publication is actually in collection
List<Chapter> currentChapters = chapterCollection[publication];
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;
}
}