Ignore duplicated chapters for download limits
In case the next 5 chapters should get downloaded and they are all the same chapter from different scanlators, then the download actually only included 1 chapter. To fix this duplicated chapters are counted as 1 chapter
This commit is contained in:
@@ -305,6 +305,18 @@ export class Chapters {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provided "uniqueChapters" plus their duplicates found in "allChapters"
|
||||
*/
|
||||
static addDuplicates<T extends ChapterScanlatorInfo & ChapterNumberInfo>(
|
||||
uniqueChapters: T[],
|
||||
allChapters: T[],
|
||||
): T[] {
|
||||
const chapterNumberToChapters = Object.groupBy(allChapters, ({ chapterNumber }) => chapterNumber);
|
||||
|
||||
return uniqueChapters.map(({ chapterNumber }) => chapterNumberToChapters[chapterNumber]!).flat();
|
||||
}
|
||||
|
||||
static removeDuplicates<T extends ChapterScanlatorInfo & ChapterNumberInfo>(currentChapter: T, chapters: T[]): T[] {
|
||||
const chapterNumberToChapters = Object.groupBy(chapters, ({ chapterNumber }) => chapterNumber);
|
||||
|
||||
|
||||
@@ -280,7 +280,23 @@ export class Mangas {
|
||||
) satisfies MangaIdToDownloadSize[];
|
||||
|
||||
const chapterIdsToDownload = mangaIdToActualDownloadSize
|
||||
.map(([mangaId, actualSize]) => mangaIdToChaptersToConsider[Number(mangaId)]!.slice(0, actualSize))
|
||||
.map(([mangaId, actualSize]) => {
|
||||
const mangaChapters = mangaIdToChaptersToConsider[Number(mangaId)]!;
|
||||
|
||||
if (!mangaChapters.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const shouldDownloadAll = actualSize === undefined;
|
||||
if (shouldDownloadAll) {
|
||||
return mangaChapters;
|
||||
}
|
||||
|
||||
const uniqueMangaChapters = Chapters.removeDuplicates(mangaChapters[0], mangaChapters);
|
||||
const uniqueMangaChaptersToDownload = uniqueMangaChapters.slice(0, actualSize);
|
||||
|
||||
return Chapters.addDuplicates(uniqueMangaChaptersToDownload, mangaChapters);
|
||||
})
|
||||
.flat();
|
||||
|
||||
if (!chapterIdsToDownload.length) {
|
||||
|
||||
Reference in New Issue
Block a user