View Single Post
Old 07-12-2025, 02:00 PM   #45
edojan
Connoisseur
edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.
 
Posts: 68
Karma: 11226
Join Date: Mar 2022
Device: Kobo Libra 2, Aura H2O
@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'])

Last edited by edojan; 07-12-2025 at 02:13 PM.
edojan is offline   Reply With Quote