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 -*- # -*- coding: utf-8 -*-
import logging
import os import os
import ox 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): def cover(path):
data = None data = None
#open rar file and extract first page here #open rar file and extract first page here
@ -11,6 +18,7 @@ def cover(path):
from unrar import rarfile from unrar import rarfile
rar = rarfile.RarFile(path) rar = rarfile.RarFile(path)
files = rar.namelist() files = rar.namelist()
files = filter_images(files)
if files: if files:
cover = ox.sorted_strings(files)[0] cover = ox.sorted_strings(files)[0]
data = rar.read(cover) data = rar.read(cover)

View file

@ -1,14 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging
import os import os
import zipfile import zipfile
import logging
import ox import ox
from .cbr import filter_images
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def cover(path): def cover(path):
data = None data = None
logger.debug('cover %s', path) logger.debug('cover %s', path)
@ -19,6 +19,7 @@ def cover(path):
logger.debug('invalid zbc file %s', path) logger.debug('invalid zbc file %s', path)
return data return data
files = [f.filename for f in z.filelist] files = [f.filename for f in z.filelist]
files = filter_images(files)
if files: if files:
cover = ox.sorted_strings(files)[0] cover = ox.sorted_strings(files)[0]
try: try:

View file

@ -424,7 +424,7 @@ def ctl_output(*args):
p = subprocess.Popen([os.path.join(settings.base_dir, 'ctl')] + list(args), p = subprocess.Popen([os.path.join(settings.base_dir, 'ctl')] + list(args),
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate() 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() return stdout.decode('utf-8').strip()
def user_sort_key(u): def user_sort_key(u):