|
|
@ -18,10 +18,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import division, print_function, unicode_literals
|
|
|
|
from __future__ import division, print_function, unicode_literals
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
import io
|
|
|
|
|
|
|
|
|
|
|
|
from . import logger, isoLanguages
|
|
|
|
from . import logger, isoLanguages
|
|
|
|
from .constants import BookMeta
|
|
|
|
from .constants import BookMeta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
from PIL import Image as PILImage
|
|
|
|
|
|
|
|
use_PIL = True
|
|
|
|
|
|
|
|
except ImportError as e:
|
|
|
|
|
|
|
|
use_PIL = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log = logger.create()
|
|
|
|
log = logger.create()
|
|
|
|
|
|
|
|
|
|
|
@ -41,6 +48,27 @@ except ImportError as e:
|
|
|
|
use_rarfile = False
|
|
|
|
use_rarfile = False
|
|
|
|
use_comic_meta = False
|
|
|
|
use_comic_meta = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cover_processing(tmp_file_name, img, extension):
|
|
|
|
|
|
|
|
if use_PIL:
|
|
|
|
|
|
|
|
# convert to jpg because calibre only supports jpg
|
|
|
|
|
|
|
|
if extension in ('.png', '.webp'):
|
|
|
|
|
|
|
|
imgc = PILImage.open(io.BytesIO(img))
|
|
|
|
|
|
|
|
im = imgc.convert('RGB')
|
|
|
|
|
|
|
|
tmp_bytesio = io.BytesIO()
|
|
|
|
|
|
|
|
im.save(tmp_bytesio, format='JPEG')
|
|
|
|
|
|
|
|
img = tmp_bytesio.getvalue()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prefix = os.path.dirname(tmp_file_name)
|
|
|
|
|
|
|
|
if img:
|
|
|
|
|
|
|
|
tmp_cover_name = prefix + '/cover.jpg'
|
|
|
|
|
|
|
|
image = open(tmp_cover_name, 'wb')
|
|
|
|
|
|
|
|
image.write(img)
|
|
|
|
|
|
|
|
image.close()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
tmp_cover_name = None
|
|
|
|
|
|
|
|
return tmp_cover_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
|
|
|
|
def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
|
|
|
|
cover_data = extension = None
|
|
|
|
cover_data = extension = None
|
|
|
@ -50,7 +78,7 @@ def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
|
|
|
|
ext = os.path.splitext(name)
|
|
|
|
ext = os.path.splitext(name)
|
|
|
|
if len(ext) > 1:
|
|
|
|
if len(ext) > 1:
|
|
|
|
extension = ext[1].lower()
|
|
|
|
extension = ext[1].lower()
|
|
|
|
if extension == '.jpg' or extension == '.jpeg':
|
|
|
|
if extension in ('.jpg', '.jpeg', '.png', '.webp'):
|
|
|
|
cover_data = archive.getPage(index)
|
|
|
|
cover_data = archive.getPage(index)
|
|
|
|
break
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -60,7 +88,7 @@ def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
|
|
|
|
ext = os.path.splitext(name)
|
|
|
|
ext = os.path.splitext(name)
|
|
|
|
if len(ext) > 1:
|
|
|
|
if len(ext) > 1:
|
|
|
|
extension = ext[1].lower()
|
|
|
|
extension = ext[1].lower()
|
|
|
|
if extension == '.jpg' or extension == '.jpeg':
|
|
|
|
if extension in ('.jpg', '.jpeg', '.png', '.webp'):
|
|
|
|
cover_data = cf.read(name)
|
|
|
|
cover_data = cf.read(name)
|
|
|
|
break
|
|
|
|
break
|
|
|
|
elif original_file_extension.upper() == '.CBT':
|
|
|
|
elif original_file_extension.upper() == '.CBT':
|
|
|
@ -69,7 +97,7 @@ def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
|
|
|
|
ext = os.path.splitext(name)
|
|
|
|
ext = os.path.splitext(name)
|
|
|
|
if len(ext) > 1:
|
|
|
|
if len(ext) > 1:
|
|
|
|
extension = ext[1].lower()
|
|
|
|
extension = ext[1].lower()
|
|
|
|
if extension == '.jpg' or extension == '.jpeg':
|
|
|
|
if extension in ('.jpg', '.jpeg', '.png', '.webp'):
|
|
|
|
cover_data = cf.extractfile(name).read()
|
|
|
|
cover_data = cf.extractfile(name).read()
|
|
|
|
break
|
|
|
|
break
|
|
|
|
elif original_file_extension.upper() == '.CBR' and use_rarfile:
|
|
|
|
elif original_file_extension.upper() == '.CBR' and use_rarfile:
|
|
|
@ -80,21 +108,12 @@ def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
|
|
|
|
ext = os.path.splitext(name)
|
|
|
|
ext = os.path.splitext(name)
|
|
|
|
if len(ext) > 1:
|
|
|
|
if len(ext) > 1:
|
|
|
|
extension = ext[1].lower()
|
|
|
|
extension = ext[1].lower()
|
|
|
|
if extension == '.jpg' or extension == '.jpeg':
|
|
|
|
if extension in ('.jpg', '.jpeg', '.png', '.webp'):
|
|
|
|
cover_data = cf.read(name)
|
|
|
|
cover_data = cf.read(name)
|
|
|
|
break
|
|
|
|
break
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
log.debug('Rarfile failed with error: %s', e)
|
|
|
|
log.debug('Rarfile failed with error: %s', e)
|
|
|
|
|
|
|
|
return _cover_processing(tmp_file_name, cover_data, extension)
|
|
|
|
prefix = os.path.dirname(tmp_file_name)
|
|
|
|
|
|
|
|
if cover_data:
|
|
|
|
|
|
|
|
tmp_cover_name = prefix + '/cover' + extension
|
|
|
|
|
|
|
|
image = open(tmp_cover_name, 'wb')
|
|
|
|
|
|
|
|
image.write(cover_data)
|
|
|
|
|
|
|
|
image.close()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
tmp_cover_name = None
|
|
|
|
|
|
|
|
return tmp_cover_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_comic_info(tmp_file_path, original_file_name, original_file_extension, rarExceutable):
|
|
|
|
def get_comic_info(tmp_file_path, original_file_name, original_file_extension, rarExceutable):
|
|
|
|