The formats_path() function has problems if authors contain a comma. I need to fix this in base calibre.
In the meantime, this python template returns the basename of the book file
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:
raise ValueError('Book "{}" has no formats'.format(book.title))