From d96c632028a180c729a2cb3fbb232446b0f042c2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 26 Feb 2015 12:18:32 +0530 Subject: [PATCH] Add API to get absolute path to cover --- src/calibre/db/backend.py | 6 ++++++ src/calibre/db/cache.py | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 0df7e939c8..1f25eae6b1 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1230,6 +1230,12 @@ class DB(object): shutil.copyfile(candidates[0], fmt_path) return fmt_path + def cover_abspath(self, book_id, path): + path = os.path.join(self.library_path, path) + fmt_path = os.path.join(path, 'cover.jpg') + if os.path.exists(fmt_path): + return fmt_path + def apply_to_format(self, book_id, path, fname, fmt, func, missing_value=None): path = self.format_abspath(book_id, fmt, fname, path) if path is None: diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index bffb792bfe..d665534715 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -708,20 +708,27 @@ class Cache(object): Instead use, :meth:`copy_format_to`. Currently used only in calibredb list, the viewer, edit book, - compare_format to original format and the catalogs (via + compare_format to original format, open with and the catalogs (via get_data_as_dict()). - Apart from the viewer and edit book, I don't believe any of the others - do any file write I/O with the results of this call. + Apart from the viewer, open with and edit book, I don't believe any of + the others do any file write I/O with the results of this call. ''' fmt = (fmt or '').upper() try: - name = self.fields['formats'].format_fname(book_id, fmt) path = self._field_for('path', book_id).replace('/', os.sep) except: return None - if name and path: - return self.backend.format_abspath(book_id, fmt, name, path) + if path: + if fmt == '__COVER_INTERNAL__': + return self.backend.cover_abspath(book_id, path) + else: + try: + name = self.fields['formats'].format_fname(book_id, fmt) + except: + return None + if name: + return self.backend.format_abspath(book_id, fmt, name, path) @read_api def has_format(self, book_id, fmt):