mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-15 22:34:56 +00:00
feat: use single uploaded image as cover
This commit is contained in:
parent
83c8bdba6c
commit
5ce595c179
@ -143,7 +143,8 @@ del env_CALIBRE_PORT
|
|||||||
|
|
||||||
|
|
||||||
EXTENSIONS_AUDIO = {'mp3', 'ogg', 'opus', 'wav', 'flac', 'm4a', 'm4b'}
|
EXTENSIONS_AUDIO = {'mp3', 'ogg', 'opus', 'wav', 'flac', 'm4a', 'm4b'}
|
||||||
EXTENSIONS_VIDEO = {'mp4', 'avi', 'mkv', 'webm', 'm4v', 'mov', 'wmv', 'mpg', 'mpeg', 'flv', '3gp', '3g2', 'ogv'}
|
EXTENSIONS_VIDEO = {'mp4', 'avi', 'mkv', 'webm', 'm4v', 'mov', 'wmv', 'mpg', 'mpeg', 'flv', '3gp', '3g2', 'ogv'}
|
||||||
|
EXTENSIONS_IMAGE = {'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'tif', 'svg', 'ico', 'webp'}
|
||||||
EXTENSIONS_CONVERT_FROM = ['pdf', 'epub', 'mobi', 'azw3', 'docx', 'rtf', 'fb2', 'lit', 'lrf',
|
EXTENSIONS_CONVERT_FROM = ['pdf', 'epub', 'mobi', 'azw3', 'docx', 'rtf', 'fb2', 'lit', 'lrf',
|
||||||
'txt', 'htmlz', 'rtf', 'odt', 'cbz', 'cbr']
|
'txt', 'htmlz', 'rtf', 'odt', 'cbz', 'cbr']
|
||||||
EXTENSIONS_CONVERT_TO = ['pdf', 'epub', 'mobi', 'azw3', 'docx', 'rtf', 'fb2',
|
EXTENSIONS_CONVERT_TO = ['pdf', 'epub', 'mobi', 'azw3', 'docx', 'rtf', 'fb2',
|
||||||
|
@ -753,10 +753,11 @@ def move_coverfile(meta, db_book):
|
|||||||
cover_file = os.path.join(constants.STATIC_DIR, 'generic_cover.jpg')
|
cover_file = os.path.join(constants.STATIC_DIR, 'generic_cover.jpg')
|
||||||
new_cover_path = os.path.join(config.config_calibre_dir, db_book.path)
|
new_cover_path = os.path.join(config.config_calibre_dir, db_book.path)
|
||||||
try:
|
try:
|
||||||
os.makedirs(new_cover_path, exist_ok=True)
|
if cover_file != "img":
|
||||||
copyfile(cover_file, os.path.join(new_cover_path, "cover.jpg"))
|
os.makedirs(new_cover_path, exist_ok=True)
|
||||||
if meta.cover:
|
copyfile(cover_file, os.path.join(new_cover_path, "cover.jpg"))
|
||||||
os.unlink(meta.cover)
|
if meta.cover:
|
||||||
|
os.unlink(meta.cover)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
log.error("Failed to move cover file %s: %s", new_cover_path, e)
|
log.error("Failed to move cover file %s: %s", new_cover_path, e)
|
||||||
flash(_("Failed to Move Cover File %(file)s: %(error)s", file=new_cover_path,
|
flash(_("Failed to Move Cover File %(file)s: %(error)s", file=new_cover_path,
|
||||||
|
@ -54,7 +54,7 @@ from . import calibre_db, cli_param
|
|||||||
from .tasks.convert import TaskConvert
|
from .tasks.convert import TaskConvert
|
||||||
from . import logger, config, db, ub, fs
|
from . import logger, config, db, ub, fs
|
||||||
from . import gdriveutils as gd
|
from . import gdriveutils as gd
|
||||||
from .constants import STATIC_DIR as _STATIC_DIR, CACHE_TYPE_THUMBNAILS, THUMBNAIL_TYPE_COVER, THUMBNAIL_TYPE_SERIES
|
from .constants import STATIC_DIR as _STATIC_DIR, CACHE_TYPE_THUMBNAILS, THUMBNAIL_TYPE_COVER, THUMBNAIL_TYPE_SERIES, EXTENSIONS_IMAGE
|
||||||
from .subproc_wrapper import process_wait
|
from .subproc_wrapper import process_wait
|
||||||
from .services.worker import WorkerThread
|
from .services.worker import WorkerThread
|
||||||
from .tasks.mail import TaskEmail
|
from .tasks.mail import TaskEmail
|
||||||
@ -783,7 +783,11 @@ def get_book_cover_internal(book, use_generic_cover_on_failure, resolution=None)
|
|||||||
# Send the book cover from the Calibre directory
|
# Send the book cover from the Calibre directory
|
||||||
else:
|
else:
|
||||||
cover_file_path = os.path.join(config.config_calibre_dir, book.path)
|
cover_file_path = os.path.join(config.config_calibre_dir, book.path)
|
||||||
if os.path.isfile(os.path.join(cover_file_path, "cover.jpg")):
|
image_files = [f for f in os.listdir(cover_file_path) if os.path.isfile(os.path.join(cover_file_path, f)) and
|
||||||
|
f.lower().endswith(EXTENSIONS_IMAGE)]
|
||||||
|
if len(image_files) == 1:
|
||||||
|
return send_from_directory(cover_file_path, image_files[0])
|
||||||
|
elif len(image_files) > 1 or os.path.isfile(os.path.join(cover_file_path, "cover.jpg")):
|
||||||
return send_from_directory(cover_file_path, "cover.jpg")
|
return send_from_directory(cover_file_path, "cover.jpg")
|
||||||
else:
|
else:
|
||||||
return get_cover_on_failure(use_generic_cover_on_failure)
|
return get_cover_on_failure(use_generic_cover_on_failure)
|
||||||
|
@ -147,7 +147,34 @@
|
|||||||
<a target="_blank" href="{{ url_for('web.read_book', book_id=entry.id, book_format=entry.video_entries[0]) }}" id="listenbtn" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-film"></span> {{ _('Watch in Browser') }} - {{ entry.video_entries[0] }}</a>
|
<a target="_blank" href="{{ url_for('web.read_book', book_id=entry.id, book_format=entry.video_entries[0]) }}" id="listenbtn" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-film"></span> {{ _('Watch in Browser') }} - {{ entry.video_entries[0] }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% elif entry.image_entries|length > 0 and current_user.role_viewer() %}
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
{% if entry.image_entries|length > 1 %}
|
||||||
|
<button id="listen-in-browser" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
<span class="glyphicon glyphicon-picture"></span> {{ _('View in Browser') }}
|
||||||
|
<span class="caret"></span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="listen-in-browser">
|
||||||
|
{% for format in entry.reader_list %}
|
||||||
|
<li><a target="_blank" href="{{ url_for('web.read_book', book_id=entry.id, book_format=format) }}">{{ format }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="listen-in-browser">
|
||||||
|
|
||||||
|
{% for format in entry.data %}
|
||||||
|
{% if format.format|lower in entry.image_entries %}
|
||||||
|
<li><a target="_blank"
|
||||||
|
href="{{ url_for('web.read_book', book_id=entry.id, book_format=format.format|lower) }}">{{ format.format|lower }}</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<a target="_blank" href="{{ url_for('web.read_book', book_id=entry.id, book_format=entry.image_entries[0]) }}" id="listenbtn" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-picture"></span> {{ _('View in Browser') }} - {{ entry.image_entries[0] }}</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h2 id="title">{{ entry.title }}</h2>
|
<h2 id="title">{{ entry.title }}</h2>
|
||||||
|
@ -23,7 +23,7 @@ from tempfile import gettempdir
|
|||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
|
|
||||||
from . import logger, comic, isoLanguages
|
from . import logger, comic, isoLanguages
|
||||||
from .constants import BookMeta
|
from .constants import BookMeta, EXTENSIONS_IMAGE, EXTENSIONS_VIDEO
|
||||||
from .helper import split_authors
|
from .helper import split_authors
|
||||||
|
|
||||||
log = logger.create()
|
log = logger.create()
|
||||||
@ -85,8 +85,10 @@ def process(tmp_file_path, original_file_name, original_file_extension, rarExecu
|
|||||||
original_file_name,
|
original_file_name,
|
||||||
original_file_extension,
|
original_file_extension,
|
||||||
rarExecutable)
|
rarExecutable)
|
||||||
elif ".WEBM" == extension_upper or ".MP4" == extension_upper:
|
elif extension_upper in EXTENSIONS_VIDEO:
|
||||||
meta = video_metadata(tmp_file_path, original_file_name, original_file_extension)
|
meta = video_metadata(tmp_file_path, original_file_name, original_file_extension)
|
||||||
|
elif extension_upper in EXTENSIONS_IMAGE:
|
||||||
|
meta = image_metadata(tmp_file_path, original_file_name, original_file_extension)
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log.warning('cannot parse metadata, using default: %s', ex)
|
log.warning('cannot parse metadata, using default: %s', ex)
|
||||||
@ -270,8 +272,26 @@ def video_cover(tmp_file_path):
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log.warning('Cannot extract cover image, using default: %s', ex)
|
log.warning('Cannot extract cover image, using default: %s', ex)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def image_metadata(tmp_file_path, original_file_name, original_file_extension):
|
||||||
|
meta = BookMeta(
|
||||||
|
file_path=tmp_file_path,
|
||||||
|
extension=original_file_extension,
|
||||||
|
title=original_file_name,
|
||||||
|
author='Unknown',
|
||||||
|
cover='img'
|
||||||
|
description='',
|
||||||
|
tags='',
|
||||||
|
series="",
|
||||||
|
series_id="",
|
||||||
|
languages="",
|
||||||
|
publisher="",
|
||||||
|
pubdate="",
|
||||||
|
identifiers=[])
|
||||||
|
return meta
|
||||||
|
|
||||||
|
|
||||||
def get_magick_version():
|
def get_magick_version():
|
||||||
ret = dict()
|
ret = dict()
|
||||||
if not use_generic_pdf_cover:
|
if not use_generic_pdf_cover:
|
||||||
|
@ -1551,7 +1551,7 @@ def read_book(book_id, book_format):
|
|||||||
log.debug("Start mp3 listening for %d", book_id)
|
log.debug("Start mp3 listening for %d", book_id)
|
||||||
return render_title_template('listenmp3.html', mp3file=book_id, audioformat=book_format.lower(),
|
return render_title_template('listenmp3.html', mp3file=book_id, audioformat=book_format.lower(),
|
||||||
entry=entries, bookmark=bookmark)
|
entry=entries, bookmark=bookmark)
|
||||||
for fileExt in constants.EXTENSIONS_VIDEO:
|
for fileExt in constants.EXTENSIONS_VIDEO + constants.EXTENSIONS_IMAGE:
|
||||||
if book_format.lower() == fileExt:
|
if book_format.lower() == fileExt:
|
||||||
entries = calibre_db.get_filtered_book(book_id)
|
entries = calibre_db.get_filtered_book(book_id)
|
||||||
log.debug("Start video watching for %d", book_id)
|
log.debug("Start video watching for %d", book_id)
|
||||||
@ -1601,11 +1601,14 @@ def show_book(book_id):
|
|||||||
|
|
||||||
entry.audio_entries = []
|
entry.audio_entries = []
|
||||||
entry.video_entries = []
|
entry.video_entries = []
|
||||||
|
entry.image_entries = []
|
||||||
for media_format in entry.data:
|
for media_format in entry.data:
|
||||||
if media_format.format.lower() in constants.EXTENSIONS_AUDIO:
|
if media_format.format.lower() in constants.EXTENSIONS_AUDIO:
|
||||||
entry.audio_entries.append(media_format.format.lower())
|
entry.audio_entries.append(media_format.format.lower())
|
||||||
if media_format.format.lower() in constants.EXTENSIONS_VIDEO:
|
if media_format.format.lower() in constants.EXTENSIONS_VIDEO:
|
||||||
entry.video_entries.append(media_format.format.lower())
|
entry.video_entries.append(media_format.format.lower())
|
||||||
|
if media_format.format.lower() in constants.EXTENSIONS_IMAGE:
|
||||||
|
entry.image_entries.append(media_format.format.lower())
|
||||||
|
|
||||||
return render_title_template('detail.html',
|
return render_title_template('detail.html',
|
||||||
entry=entry,
|
entry=entry,
|
||||||
|
Loading…
Reference in New Issue
Block a user