View Single Post
Old 04-24-2024, 02:48 AM   #1323
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,106
Karma: 1954138
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by Dzib View Post
Works fine, thanks
Append the following code under the run() method:

Code:
        col_name = '#custompath'
        db = gui.current_db
        id_path_map = {}
        for book_id in chain.scope().get_book_ids():
            fmt_paths = []
            fname = chain.evaluate_template(opts.template, book_id)
            if single_dir:
                fname = os.path.basename(fname)
            if opts.formats == 'all':
                formats = db.formats(book_id, index_is_id=True)
            else:
                formats = settings['formats']
            for fmt in [fmt.strip().lower() for fmt in formats.split(',')]:
                fmt_paths.append(os.path.join(path, f'{fname}.{fmt.lower()}'))
            id_path_map[book_id] = ','.join(fmt_paths)
        db.new_api.set_field(col_name, id_path_map)
Note: If you save more than one format per book, the above code will add them all to the custom column as comma separated list.

Quote:
Originally Posted by Dzib View Post
Another question, not related : if I make a new chain with open with action, how to use the serie in the template but only if it's not null ?
I've tried with an if else statement but it's not working
Consult the template language manual under the "Conditionally including text" section.

Last edited by capink; 04-24-2024 at 06:22 AM.
capink is offline   Reply With Quote