Skip to content

Commit

Permalink
Prevent a book with no pages to be added to the library (e.g. Hitomi …
Browse files Browse the repository at this point in the history
…parser failure)
  • Loading branch information
RobbWatershed committed Oct 28, 2022
1 parent 04fb919 commit 4f77072
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ private void completeDownload(final long contentId, @NonNull final String title,
int nbImages = (int) Stream.of(images).filter(i -> !i.isCover()).count(); // Don't count the cover

boolean hasError = false;
// Set error state if no image has been detected at all
if (0 == content.getQtyPages() && 0 == nbImages) {
logErrorRecord(contentId, ErrorType.PARSING, content.getGalleryUrl(), "pages", "The book has no pages");
hasError = true;
}
// Set error state if less pages than initially detected - More than 10% difference in number of pages
if (content.getQtyPages() > 0 && nbImages < content.getQtyPages() && Math.abs(nbImages - content.getQtyPages()) > content.getQtyPages() * 0.1) {
String errorMsg = String.format("The number of images found (%s) does not match the book's number of pages (%s)", nbImages, content.getQtyPages());
Expand All @@ -688,7 +693,6 @@ private void completeDownload(final long contentId, @NonNull final String title,
// NB : this should not happen theoretically
long nbDownloadedPages = content.getNbDownloadedPages();
if (nbDownloadedPages < content.getQtyPages()) {
Timber.i(">> downloaded vs. qty KO %s vs %s", nbDownloadedPages, content.getQtyPages());
String errorMsg = String.format("The number of downloaded images (%s) does not match the book's number of pages (%s)", nbDownloadedPages, content.getQtyPages());
logErrorRecord(contentId, ErrorType.PARSING, content.getGalleryUrl(), "pages", errorMsg);
hasError = true;
Expand Down Expand Up @@ -753,7 +757,6 @@ private void completeDownload(final long contentId, @NonNull final String title,
}
}
}

applyRenamingRules(content);
} else {
content.setStatus(StatusContent.ERROR);
Expand Down

0 comments on commit 4f77072

Please sign in to comment.