Skip to content

Commit

Permalink
feat: add check for duplicate chapters
Browse files Browse the repository at this point in the history
duplicate chapter names cause all sorts of things to fail
  • Loading branch information
potatoeggy committed Jan 12, 2025
1 parent 0341ed7 commit 02c6a5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
28 changes: 19 additions & 9 deletions mandown/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import io, sources
from .comic import BaseComic
from .convert_utils import ConvertFormats, convert_one
from .errors import ImageDownloadError
from .errors import ChapterImageCountMismatchError, ImageDownloadError
from .processor import ProcessConfig, ProcessOps, Processor


Expand Down Expand Up @@ -295,14 +295,24 @@ def download_progress(

# name them 00001.png, 00002.png, etc
# skipping ones that already exist
processed_image_urls, filestems = zip(
*(
(link, str(i).rjust(io.NUM_LEFT_PAD_DIGITS, "0"))
for i, link in enumerate(image_urls, start=1)
if i not in skip_images
),
strict=False,
)
try:
processed_image_urls, filestems = zip(
*(
(link, str(i).rjust(io.NUM_LEFT_PAD_DIGITS, "0"))
for i, link in enumerate(image_urls, start=1)
if i not in skip_images
),
strict=False,
)
except ValueError:
# ValueError is raised when `zip` is given no arguments and thus
# no images to download
processed_image_urls, filestems = [], []

raise ChapterImageCountMismatchError(
"There are more images in the filesystem than in present in the chapter index."
" You should never see this message."
) from None

chapter_path = full_path / chap.slug

Expand Down
4 changes: 4 additions & 0 deletions mandown/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ class NoImagesFoundError(MandownError):

class ImageDownloadError(MandownError):
pass


class ChapterImageCountMismatchError(MandownError):
pass

0 comments on commit 02c6a5d

Please sign in to comment.