View Single Post
Old 08-17-2022, 08:49 PM   #8
lizzie1170
Member
lizzie1170 began at the beginning.
 
lizzie1170's Avatar
 
Posts: 12
Karma: 10
Join Date: Jul 2022
Device: none
Quote:
Originally Posted by capink View Post
As David points out, you can run your code through the Action Chains plugin to process multiple books. There is an action called "Run Python Code" that allows you to do just that:
  • Create a chain that contains a single "Run Python Code" action.
  • Click the settings button next to the action, a window will pop up where you can copy the following code:
    Code:
    def tags_from_epub(path_to_epub):
       # the code you posted in your post should go
       # here. The run() function below will pass
       # path_to_epub, so modify it use this instead
       # of the hardcoded epub path
    
    def run(gui, settings, chain):
        db = gui.current_db
        for book_id in chain.scope().get_book_ids():
            fmts = [ fmt.strip() for fmt in db.formats(book_id, index_is_id=True).split(',') ]
            if 'EPUB' in fmts:
                path_to_epub = db.format_abspath(book_id, 'EPUB', index_is_id=True)
                tags_from_epub(path_to_epub)
    As you can see, you have to include your code in the the first function and modify it to use path_to_epub
  • Now, you should find a menu entry with the name of your chain in the Action Chains menu. You can even bind it to a keyboard shortcut if you want.

Edit: The chain you created will only act on books selected in the list view.
I followed the recommendations but I'm having trouble reading the content of epubs.
Attached Thumbnails
Click image for larger version

Name:	Error_module.PNG
Views:	96
Size:	58.9 KB
ID:	195943  
lizzie1170 is offline   Reply With Quote