mirror of
https://github.com/janeczku/calibre-web
synced 2024-10-31 15:16:20 +00:00
Fix #985 (png and webp are extracted as cover files from comic files)
This commit is contained in:
parent
64bebaa1d1
commit
fcefd8031a
47
cps/comic.py
47
cps/comic.py
@ -18,10 +18,17 @@
|
||||
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
import os
|
||||
import io
|
||||
|
||||
from . import logger, isoLanguages
|
||||
from .constants import BookMeta
|
||||
|
||||
try:
|
||||
from PIL import Image as PILImage
|
||||
use_PIL = True
|
||||
except ImportError as e:
|
||||
use_PIL = False
|
||||
|
||||
|
||||
log = logger.create()
|
||||
|
||||
@ -41,6 +48,27 @@ except ImportError as e:
|
||||
use_rarfile = 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):
|
||||
cover_data = extension = None
|
||||
@ -50,7 +78,7 @@ def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
|
||||
ext = os.path.splitext(name)
|
||||
if len(ext) > 1:
|
||||
extension = ext[1].lower()
|
||||
if extension == '.jpg' or extension == '.jpeg':
|
||||
if extension in ('.jpg', '.jpeg', '.png', '.webp'):
|
||||
cover_data = archive.getPage(index)
|
||||
break
|
||||
else:
|
||||
@ -60,7 +88,7 @@ def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
|
||||
ext = os.path.splitext(name)
|
||||
if len(ext) > 1:
|
||||
extension = ext[1].lower()
|
||||
if extension == '.jpg' or extension == '.jpeg':
|
||||
if extension in ('.jpg', '.jpeg', '.png', '.webp'):
|
||||
cover_data = cf.read(name)
|
||||
break
|
||||
elif original_file_extension.upper() == '.CBT':
|
||||
@ -69,7 +97,7 @@ def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
|
||||
ext = os.path.splitext(name)
|
||||
if len(ext) > 1:
|
||||
extension = ext[1].lower()
|
||||
if extension == '.jpg' or extension == '.jpeg':
|
||||
if extension in ('.jpg', '.jpeg', '.png', '.webp'):
|
||||
cover_data = cf.extractfile(name).read()
|
||||
break
|
||||
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)
|
||||
if len(ext) > 1:
|
||||
extension = ext[1].lower()
|
||||
if extension == '.jpg' or extension == '.jpeg':
|
||||
if extension in ('.jpg', '.jpeg', '.png', '.webp'):
|
||||
cover_data = cf.read(name)
|
||||
break
|
||||
except Exception as e:
|
||||
log.debug('Rarfile failed with error: %s', e)
|
||||
|
||||
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
|
||||
return _cover_processing(tmp_file_name, cover_data, extension)
|
||||
|
||||
|
||||
def get_comic_info(tmp_file_path, original_file_name, original_file_extension, rarExceutable):
|
||||
|
@ -112,7 +112,7 @@ class _Settings(_Base):
|
||||
config_converterpath = Column(String)
|
||||
config_calibre = Column(String)
|
||||
config_rarfile_location = Column(String)
|
||||
config_upload_formats = Column(String, default=constants.EXTENSIONS_UPLOAD)
|
||||
config_upload_formats = Column(String, default=','.join(constants.EXTENSIONS_UPLOAD))
|
||||
|
||||
config_updatechannel = Column(Integer, default=constants.UPDATE_STABLE)
|
||||
|
||||
|
@ -411,6 +411,19 @@ bitjs.archive = bitjs.archive || {};
|
||||
return "unrar.js";
|
||||
};
|
||||
|
||||
/**
|
||||
* Unrarrer5
|
||||
* @extends {bitjs.archive.Unarchiver}
|
||||
* @constructor
|
||||
*/
|
||||
bitjs.archive.Unrarrer5 = function(arrayBuffer, optPathToBitJS) {
|
||||
bitjs.base(this, arrayBuffer, optPathToBitJS);
|
||||
};
|
||||
bitjs.inherits(bitjs.archive.Unrarrer5, bitjs.archive.Unarchiver);
|
||||
bitjs.archive.Unrarrer5.prototype.getScriptFileName = function() {
|
||||
return "unrar5.js";
|
||||
};
|
||||
|
||||
/**
|
||||
* Untarrer
|
||||
* @extends {bitjs.archive.Unarchiver}
|
||||
|
@ -73,8 +73,6 @@ except ImportError as e:
|
||||
log.debug('cannot import Pillow, using png and webp images as cover will not work: %s', e)
|
||||
use_PIL = False
|
||||
|
||||
__author__ = 'lemmsh'
|
||||
|
||||
|
||||
def process(tmp_file_path, original_file_name, original_file_extension, rarExcecutable):
|
||||
meta = None
|
||||
|
Loading…
Reference in New Issue
Block a user