Quote:
Originally Posted by chaley
That error is harmless, caused by the template dialog not having a real book to work with. It will work when it us run "for real" -- when sending to the device.
This version removes the error.
Code:
python:
def evaluate(book, context):
import os
from calibre.library import current_library_path
fmt_metadata = book.get('format_metadata')
if fmt_metadata:
for v in fmt_metadata.values():
# A calibre format name is roughly "author/title (id)/title - author.extension"
# We want to return the last segment, stripping off the author and title
# directory names and the extension, leaving just the basename of the book file
f = v['path']
return f[f.rfind(os.sep)+1:f.rfind('.')]
else:
return 'title - author'
|
This code is still not accepted by the template editor - please see the screenshot