View Single Post
Old 07-10-2025, 05:53 PM   #27
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
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))
chaley is offline   Reply With Quote