From 148b41087fcff4097c7e3ee38a8c3de8ce41e260 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 1 Feb 2019 19:24:34 +0530 Subject: [PATCH] extract pages from cbr/cbz --- oml/media/cbr.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/oml/media/cbr.py b/oml/media/cbr.py index 244ee67..0735d32 100644 --- a/oml/media/cbr.py +++ b/oml/media/cbr.py @@ -66,10 +66,30 @@ def cover_cbz(path): data = None return data +def get_pages(path): + files = [] + format = detect_format(path) + if format == 'cbz': + try: + z = zipfile.ZipFile(path) + except zipfile.BadZipFile: + logger.debug('invalid cbz file %s', path) + return data + files = [f.filename for f in z.filelist] + elif format == 'cbr': + try: + from unrar import rarfile + rar = rarfile.RarFile(path) + files = rar.namelist() + except: + pass + files = filter_images(files) + return len(files) + def info(path): data = {} data['title'] = os.path.splitext(os.path.basename(path))[0] - #data['pages'] = fixme read rar to count pages + data['pages'] = get_pages(path) return data