cbr/cbz cleanups

This commit is contained in:
j 2019-02-01 18:27:58 +05:30
parent 3b438010d6
commit 106ae904c3
3 changed files with 14 additions and 5 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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):