From 2dbe0416ded4159044f4c5fd9ef0d576ad7a3ea2 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Mon, 10 Feb 2020 12:19:45 +0000 Subject: [PATCH] Work with cbz files with subdirectories --- backend.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend.py b/backend.py index d1c1835..943bfa3 100644 --- a/backend.py +++ b/backend.py @@ -29,6 +29,10 @@ def dict_factory(cursor, row): return d +def filter_zip_filelist(filelist): + return [file for file in filelist if not file.is_dir()] + + class BaseDB: def __init__(self, webp_quality, webp_method, webp_size): # lossy: 0-100 (used as quality) @@ -251,7 +255,8 @@ class CalibreDB(BaseDB): def get_volume_page_number(self, volume_id): path = self.get_volume_filepath(volume_id) with ZipFile(path, 'r') as volume: - return len(volume.filelist) + filelist = filter_zip_filelist(volume.filelist) + return len(filelist) def get_volume_page(self, volume_id, page_number, original=False): if page_number < 1: @@ -259,7 +264,8 @@ class CalibreDB(BaseDB): path = self.get_volume_filepath(volume_id) with ZipFile(path, 'r') as volume: try: - zip_info = volume.filelist[page_number - 1] + filelist = filter_zip_filelist(volume.filelist) + zip_info = filelist[page_number - 1] except IndexError: raise exceptions.NotFound() return None