From 106ae904c30f7359d16db0d1e1cdd4e1d1e28937 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 1 Feb 2019 18:27:58 +0530 Subject: [PATCH] cbr/cbz cleanups --- oml/media/cbr.py | 12 ++++++++++-- oml/media/cbz.py | 5 +++-- oml/utils.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/oml/media/cbr.py b/oml/media/cbr.py index 0c29fe2..a1840a3 100644 --- a/oml/media/cbr.py +++ b/oml/media/cbr.py @@ -1,9 +1,16 @@ # -*- coding: utf-8 -*- - - +import logging import os + import ox +logger = logging.getLogger(__name__) + +IMAGE_EXTENSIONS = ['.jpg', '.png', '.gif'] + +def filter_images(files): + return [f for f in files if os.path.splitext(f)[-1] in IMAGE_EXTENSION] + def cover(path): data = None #open rar file and extract first page here @@ -11,6 +18,7 @@ def cover(path): from unrar import rarfile rar = rarfile.RarFile(path) files = rar.namelist() + files = filter_images(files) if files: cover = ox.sorted_strings(files)[0] data = rar.read(cover) diff --git a/oml/media/cbz.py b/oml/media/cbz.py index a4bcb5b..0e71475 100644 --- a/oml/media/cbz.py +++ b/oml/media/cbz.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- +import logging import os import zipfile -import logging import ox +from .cbr import filter_images logger = logging.getLogger(__name__) - def cover(path): data = None logger.debug('cover %s', path) @@ -19,6 +19,7 @@ def cover(path): logger.debug('invalid zbc file %s', path) return data files = [f.filename for f in z.filelist] + files = filter_images(files) if files: cover = ox.sorted_strings(files)[0] try: diff --git a/oml/utils.py b/oml/utils.py index c080426..ad2b65a 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -424,7 +424,7 @@ def ctl_output(*args): p = subprocess.Popen([os.path.join(settings.base_dir, 'ctl')] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() - logger.debug('ctl_output%s -> %s [%s]', args, stdout, stderr) + #logger.debug('ctl_output%s -> %s [%s]', args, stdout, stderr) return stdout.decode('utf-8').strip() def user_sort_key(u):