View Single Post
Old 04-05-2023, 02:29 AM   #11
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,197
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
For books that have a supplementary material, I use the Action Chains plugin to handle and open the folder/file as follows:
  • Tag the books with a tag e.g. supplement
  • I add the supplementary material inside a folder named after the book id. This folder resides in a parent folder called calibre_supplements

    Code:
    /home/user_name/calibre_supplements/book_id
  • In Action Chains plugin, I create a chain the contains an Open With action. In the action settings, I choose my favorite file manager in the binary box, and choose the template option for the file path with the following template:
    Code:
    program:
        parent_dir = '/home/user_name/calibre_supplements';
        if 'supplement' inlist $tags then
            strcat(parent_dir, '/', $id)
        fi
    I also set the following condition so that the chain runs only if one book is selected, and the book must be tagged as "supplement"

    Code:
    program:
        if selection_count() == 1 && 'supplement' inlist $tags then
            'true'
        fi

    in the condition's datatype choose "text", and in the value box the value must be "true"

Notes:
  • To know the book id go to preferences > book details > displayed metadata > tick the box for "id". Now you can see the book id in the book details.

    If you don't want to bother with that, you can create a chain to automatically create the directory with the book id for you. Simply create a chain with a Chain Variables action that contains the following template:
    Code:
    python:
    def evaluate(book, context):
        import os
        parent_dir = '/home/user_name/calibre_supplements'
        target_dir = os.path.join(parent_dir, str(book.id))
        try:
            os.makedirs(target_dir)
        except FileExistsError:
            pass
        return ''
  • You can combine the two chains above into one chain that creates the supplement folder (if it is not already created), then open it.
  • You can get creative with the template to make it look inside the folder and open specific filetype(s) with your program of choice.
  • Action Chains allows you to bind the chain to keyboard shortcut, so you can easily open the folder/file with one click.

Edit: I have never gone through a restore process. My presupposition here is that it restores the ids of the books as well. (seeing that the book folders have the book is in the folder name)

So, before others adopt a system like that, it is worth knowing what happens with books ids and how to make this compatible with calibre restore

Last edited by capink; 04-05-2023 at 04:21 AM.
capink is offline   Reply With Quote