From 746c148997ea53cc3b5434df0eed9ac328f26f7a Mon Sep 17 00:00:00 2001 From: GRiker Date: Tue, 7 Aug 2012 07:01:38 -0600 Subject: [PATCH] Generate default cover if no existing cover found, other bug fixes --- src/calibre/gui2/catalog/catalog_epub_mobi.py | 6 ++--- src/calibre/library/catalogs/epub_mobi.py | 23 ++++++++++++++++++- .../library/catalogs/epub_mobi_builder.py | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.py b/src/calibre/gui2/catalog/catalog_epub_mobi.py index 72363046d7..da9139a25e 100644 --- a/src/calibre/gui2/catalog/catalog_epub_mobi.py +++ b/src/calibre/gui2/catalog/catalog_epub_mobi.py @@ -402,7 +402,6 @@ class PluginWidget(QWidget,Ui_Form): self.exclude_genre.setText(default[1]) break - class CheckableTableWidgetItem(QTableWidgetItem): ''' Borrowed from kiwidude @@ -637,8 +636,9 @@ class GenericRulesTable(QTableWidget): pass def resize_name(self, scale): - current_width = self.columnWidth(1) - self.setColumnWidth(1, min(225,int(current_width * scale))) + #current_width = self.columnWidth(1) + #self.setColumnWidth(1, min(225,int(current_width * scale))) + self.setColumnWidth(1, 225) def rule_name_edited(self): current_row = self.currentRow() diff --git a/src/calibre/library/catalogs/epub_mobi.py b/src/calibre/library/catalogs/epub_mobi.py index 6f4d7d4821..0787d149ca 100644 --- a/src/calibre/library/catalogs/epub_mobi.py +++ b/src/calibre/library/catalogs/epub_mobi.py @@ -13,6 +13,9 @@ from collections import namedtuple from calibre import strftime from calibre.customize import CatalogPlugin from calibre.customize.conversion import OptionRecommendation, DummyReporter +from calibre.ebooks import calibre_cover +from calibre.ptempfile import PersistentTemporaryFile +from calibre.utils.magick.draw import save_cover_data_to Option = namedtuple('Option', 'option, default, dest, action, help') @@ -338,7 +341,7 @@ class EPUB_MOBI(CatalogPlugin): OptionRecommendation.HIGH)) recommendations.append(('comments', '', OptionRecommendation.HIGH)) - # Use to debug generated catalog code before conversion + # >>> Use to debug generated catalog code before conversion <<< #setattr(opts,'debug_pipeline',os.path.expanduser("~/Desktop/Catalog debug")) dp = getattr(opts, 'debug_pipeline', None) @@ -356,6 +359,7 @@ class EPUB_MOBI(CatalogPlugin): # If cover exists, use it cpath = None + generate_new_cover = False try: search_text = 'title:"%s" author:%s' % ( opts.catalog_title.replace('"', '\\"'), 'calibre') @@ -365,9 +369,26 @@ class EPUB_MOBI(CatalogPlugin): if cpath and os.path.exists(cpath): recommendations.append(('cover', cpath, OptionRecommendation.HIGH)) + log.info("using existing cover") + else: + log.info("no existing cover, generating new cover") + generate_new_cover = True + else: + log.info("no existing cover, generating new cover") + generate_new_cover = True except: pass + if generate_new_cover: + new_cover_path = PersistentTemporaryFile(suffix='.jpg') + new_cover_path.close() + new_cover = calibre_cover(opts.catalog_title.replace('"', '\\"'), 'calibre') + save_cover_data_to(new_cover,new_cover_path.name) + recommendations.append(('cover', new_cover_path.name, OptionRecommendation.HIGH)) + + if opts.verbose: + log.info("Invoking Plumber with recommendations:\n %s" % recommendations) + # Run ebook-convert from calibre.ebooks.conversion.plumber import Plumber plumber = Plumber(os.path.join(catalog.catalogPath, diff --git a/src/calibre/library/catalogs/epub_mobi_builder.py b/src/calibre/library/catalogs/epub_mobi_builder.py index 91856600d8..1c79901037 100644 --- a/src/calibre/library/catalogs/epub_mobi_builder.py +++ b/src/calibre/library/catalogs/epub_mobi_builder.py @@ -1126,7 +1126,7 @@ Author '{0}': aTag = Tag(soup, "a") current_letter = self.letter_or_symbol(book['author_sort'][0].upper()) if current_letter == self.SYMBOLS: - aTag['id'] = self.SYMBOLS + aTag['id'] = self.SYMBOLS + '_authors' else: aTag['id'] = "%s_authors" % self.generateUnicodeName(current_letter) pIndexTag.insert(0,aTag)