Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 12-20-2020, 02:55 PM   #1
patricorgi
Member
patricorgi began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Apr 2020
Device: iPad Pro 2018
How to use python/shell scripts to edit the metadata of selected book(s) in calibre?

It seems to me calibre has made good use of python for many purposes. So I'm wondering it there is a way to edit the metadata, e.g. adding tags, of selected book(s) in calibre window using python script?

I know I can simply click "Edit Metadata" and use the interface to edit metadata but I'm here looking for a way of automation. (I'm using calibre on macOS and with applications like Keyboard Maestro or Alfred I can set a bunch of keyboard shortcuts to automate this process.)

Any help will be appreciated!
patricorgi is offline   Reply With Quote
Old 12-20-2020, 04:17 PM   #2
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,171
Karma: 73448616
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
See if https://manual.calibre-ebook.com/gen...cli-index.html gives you ideas
PeterT is offline   Reply With Quote
Old 12-20-2020, 04:52 PM   #3
latepaul
Wizard
latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.latepaul ought to be getting tired of karma fortunes by now.
 
latepaul's Avatar
 
Posts: 1,264
Karma: 10203040
Join Date: Dec 2011
Device: a variety (mostly kindles and kobos)
Can you elaborate on what type of edits you want to automate?

I have a couple of shell scripts I use but they are interactive - they prompt for values to put in certain fields.

I mostly use calibredb set_metadata or calibredb set_custom.

If you want to call your script from the calibre window though that implies writing a plugin I think. Unless Keyboard Maestro or Alfred can do screen scraping as well as provide hot keys. Because you would need a way to "read" the values associated with the current book and act upon it.
latepaul is offline   Reply With Quote
Old 12-20-2020, 05:35 PM   #4
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,092
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
Have a look at the Action Chains plugin and see whether it fulfills your needs. It also enables you to write python scripts by using the plugin's module editor to create custom actions. The advantage to this approach to the usual calibre-debug pyhton scripts is that it can read selections from gui and act on them.

For more on using python for calibre development, see the documentation here.
capink is online now   Reply With Quote
Old 12-20-2020, 06:18 PM   #5
patricorgi
Member
patricorgi began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Apr 2020
Device: iPad Pro 2018
I'd like to perform the following actions:

1. Changing the Rating of currently selected book(s) with a hotkey, such as ⌘+1/2/3/4/5 for corresponding ratings.
2. Adding or switching between "Unread/Read/Reading" tags to currently selected book(s).
3. Obtaining the book name or author name and search it with a search engine. Now I have to click on the author name, copy it and paste on Google search bar. I want to use a python/shell script to automate this procedure.
4. ...

I can give more examples here but the fundamental idea is to manipulate the metadata (both original columns or custom columns) without using the Edit Metadata interface but with a python/shell script which is capable of reading/writing the metadata of CURRENTLY SELECTED book(s).
patricorgi is offline   Reply With Quote
Old 12-20-2020, 06:49 PM   #6
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 8,644
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
1 be done from the book list with relatively few keystrokes. See the doubleclick_on_library_view tweak for more information.

2 can be action chained pretty easily. I have a 'mark as read' that sets #read:true, #percentread:100, #lastread: current time and pops up the rating dialog.

For 3 there's a plugin called Search the Internet though I don't remember if that can be hotkeyed.
ownedbycats is offline   Reply With Quote
Old 12-20-2020, 07:02 PM   #7
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,092
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
1 be done from the book list with relatively few keystrokes. See the doubleclick_on_library_view tweak for more information.
No. 1 also can be done in Action Chains by making 5 different chains and assigning each one to keyboard shortcut. Each chain contains one action that changes the rating to a predefined value (Single Field Edit Action). You can even supplement —if you want— with other actions like automatically adding timestamps to a custom #last_rated date column.

No. 3 can be done by writing An action chains custom action, if you know python.
capink is online now   Reply With Quote
Old 12-20-2020, 09:17 PM   #8
patricorgi
Member
patricorgi began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Apr 2020
Device: iPad Pro 2018
Quote:
Originally Posted by capink View Post
No. 1 also can be done in Action Chains by making 5 different chains and assigning each one to keyboard shortcut. Each chain contains one action that changes the rating to a predefined value (Single Field Edit Action). You can even supplement —if you want— with other actions like automatically adding timestamps to a custom #last_rated date column.

No. 3 can be done by writing An action chains custom action, if you know python.
This plugin is exactly what I need. Thank you so much!
patricorgi is offline   Reply With Quote
Old 12-20-2020, 09:19 PM   #9
patricorgi
Member
patricorgi began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Apr 2020
Device: iPad Pro 2018
Quote:
Originally Posted by ownedbycats View Post
1 be done from the book list with relatively few keystrokes. See the doubleclick_on_library_view tweak for more information.

2 can be action chained pretty easily. I have a 'mark as read' that sets #read:true, #percentread:100, #lastread: current time and pops up the rating dialog.

For 3 there's a plugin called Search the Internet though I don't remember if that can be hotkeyed.
Yes, this plugin is the perfect solution for my needs. Thank you very much!
patricorgi is offline   Reply With Quote
Reply

Tags
automation, python


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calibre:Book Cover size in Book Details side pane & Edit Metadata Individually window Volfer Calibre 3 01-05-2016 01:56 PM
Selected a couple of Authors/Series but Calibre not showing the books selected lizzyong Library Management 3 04-16-2015 07:47 PM
Quick util to wait for press (in shell or python) krcrouse Kindle Developer's Corner 3 01-21-2014 01:02 AM
The Idiot's Guide to running Igorsk's Python Scripts Nate the great Workshop 9 05-22-2010 12:17 PM
GUI Frontend for python scripts [windows] - seeking mod input first sherman Workshop 7 04-27-2009 01:04 AM


All times are GMT -4. The time now is 02:14 AM.


MobileRead.com is a privately owned, operated and funded community.