View Single Post
Old 07-10-2025, 10:39 PM   #30
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
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'
chaley is offline   Reply With Quote