Add API to get absolute path to cover

This commit is contained in:
Kovid Goyal 2015-02-26 12:18:32 +05:30
parent d30f65b88a
commit d96c632028
2 changed files with 19 additions and 6 deletions

View File

@ -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:

View File

@ -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):