From b20f1d3fd7b81639a17e3c380f607496a4f43216 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 14 Oct 2019 09:34:58 +0530 Subject: [PATCH] Viewer: Treat the first image in comics as the cover --- src/calibre/ebooks/conversion/plugins/comic_input.py | 9 +++++++-- src/calibre/srv/render_book.py | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/comic_input.py b/src/calibre/ebooks/conversion/plugins/comic_input.py index ed252b2922..079e12b569 100644 --- a/src/calibre/ebooks/conversion/plugins/comic_input.py +++ b/src/calibre/ebooks/conversion/plugins/comic_input.py @@ -204,10 +204,13 @@ class ComicInput(InputFormatPlugin): return os.path.basename(x) return '/'.join(x.split(os.sep)[-2:]) + cover_href = None for comic in comics: pages, wrappers = comic[1:] - entries += [(w, None) for w in map(href, wrappers)] + \ - [(x, None) for x in map(href, pages)] + page_entries = [(x, None) for x in map(href, pages)] + entries += [(w, None) for w in map(href, wrappers)] + page_entries + if cover_href is None and page_entries: + cover_href = page_entries[0][0] opf.create_manifest(entries) spine = [] for comic in comics: @@ -216,6 +219,8 @@ class ComicInput(InputFormatPlugin): for comic in comics: self._images.extend(comic[1]) opf.create_spine(spine) + if self.for_viewer and cover_href: + opf.guide.set_cover(cover_href) toc = TOC() if len(comics) == 1: wrappers = comics[0][2] diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index 6d530dc347..6989231d7d 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -17,6 +17,7 @@ from css_parser import replaceUrls from css_parser.css import CSSRule from calibre import force_unicode, prepare_string_for_xml +from calibre.customize.ui import plugin_for_input_format from calibre.ebooks import parse_css_length from calibre.ebooks.css_transform_rules import StyleDeclaration from calibre.ebooks.oeb.base import ( @@ -335,6 +336,9 @@ class Container(ContainerBase): raster_cover_name = self.href_to_name(item.get('href'), self.opf_name) with self.open(raster_cover_name, 'wb') as dest: dest.write(generic_cover()) + input_plugin = plugin_for_input_format(input_fmt) + if getattr(input_plugin, 'is_image_collection', False): + return raster_cover_name, None item = self.generate_item(name='titlepage.html', id_prefix='titlepage') titlepage_name = self.href_to_name(item.get('href'), self.opf_name) raw = templ % prepare_string_for_xml(self.name_to_href(raster_cover_name, titlepage_name), True)