@chaley Thank you! I kept struggling with the double extension issue. While adding the author directory to the destination was not difficult, for whatever reason I had to try several things to address the double extension thing. In the end the only solution which worked was to remove the extension from the filename before returning it, letting Calibre add it back during the transfer process. Here is the code which finally worked for me:
Code:
Python:
def evaluate(book, context):
import os
fmt_metadata = book.get('format_metadata')
# Get main author safely, fallback 'Unknown Author', and sanitize for filesystem
author = book.get('authors', ['Unknown Author'])[0].replace('/', '_').replace('\\', '_')
if fmt_metadata:
for v in fmt_metadata.values():
# Extract only the filename with extension
f = v['path']
filename = os.path.basename(f)
# **FIX**: Remove the extension since Calibre will add it automatically
filename_without_ext = os.path.splitext(filename)[0]
# Compose path as: {Author}/{filename (WITHOUT extension)}
return '/'.join([author, filename_without_ext])
else:
# For fallback, also remove extension since Calibre will add it
return '/'.join([author, 'title - author'])