04-23-2024, 09:30 AM | #1321 |
Wizard
Posts: 1,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
Try this:
Code:
id_path_map = {} for row in rows: book_id = self.gui.library_view.model().id(row) id_path_map[book_id] = dpath self.gui.current_db.new_api.set_field('#custompath', id_path_map) |
04-23-2024, 01:01 PM | #1322 |
Enthusiast
Posts: 29
Karma: 10
Join Date: Mar 2017
Device: Kindle Paperwhite
|
Works fine, thanks
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 Last edited by Dzib; 04-24-2024 at 02:01 AM. |
Advert | |
|
04-24-2024, 02:48 AM | #1323 | |
Wizard
Posts: 1,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
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)
Quote:
Last edited by capink; 04-24-2024 at 06:22 AM. |
|
04-24-2024, 04:16 AM | #1324 |
Wizard
Posts: 1,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
Another way to do this without having to hard code the custom column name, is to append this instead to the run() method:
Code:
db = gui.current_db 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()}')) chain.set_book_var(book_id, 'save_to_disk_path', ','.join(fmt_paths)) Code:
program: book_vars('save_to_disk_path') Last edited by capink; 05-08-2024 at 08:24 AM. |
04-24-2024, 06:39 AM | #1325 | |
Grand Sorcerer
Posts: 11,950
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The only way I know to get the "real" path is to include the calibre ID somewhere in the path, walk the resulting book folders to generate the full path to a book, then use the ID to insert that path into the book's metadata. |
|
Advert | |
|
04-24-2024, 07:45 AM | #1326 | |
Wizard
Posts: 1,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
Quote:
One other way is to follow calibre's own way of sanitizing and shortening paths. Something like this: Code:
from calibre.library.save_to_disk import sanitize_args, get_path_components db = gui.current_db for book_id in chain.scope().get_book_ids(): fmt_paths = [] root, opts, length = sanitize_args(path, opts) mi = db.get_metadata(book_id, index_is_id=True) components = get_path_components(opts, mi, book_id, length) extensionless_path = os.path.sep.join(components) if single_dir: extensionless_path = components[-1] 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(root, f'{extensionless_path}.{fmt.lower()}')) chain.set_book_vars(book_id, 'save_to_disk_path', ','.join(fmt_paths)) Last edited by capink; 05-08-2024 at 08:23 AM. |
|
04-25-2024, 02:36 AM | #1327 |
Enthusiast
Posts: 29
Karma: 10
Join Date: Mar 2017
Device: Kindle Paperwhite
|
Woaw, your code works perfect !
Many thanks to you & to chaley Last edited by Dzib; 04-25-2024 at 06:39 AM. |
04-28-2024, 12:20 PM | #1328 |
Junior Member
Posts: 8
Karma: 10
Join Date: Jul 2020
Device: Kobo Clara HD
|
Hello, I am trying to run 2 different types of Add Book actions, where one handles the metadata with the name, and the other with the content of the ebook (i go more in details here) https://www.mobileread.com/forums/sh...15&postcount=1
I tried the Add Book action but it seems to not have the metadata handling part that Calibre has. Is it possible adding it? It could fix the issue I have currently as I need to have metadata handled differently for 2 types of books (2 different folders). Thanks for your work ! |
04-28-2024, 07:49 PM | #1329 |
Custom User Title
Posts: 9,338
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Is there an action that can select the first item in the book list? This would be for use after refreshing the book sort, which depending on book can sometimes send me a few hundred books down.
Last edited by ownedbycats; 04-28-2024 at 07:53 PM. |
04-29-2024, 03:12 AM | #1330 | |
Wizard
Posts: 1,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
Quote:
What you can do, is use the GetFileName plugin, which stores the filename in custom column. With this you can use Action Chains to add the book and apply the metadata from the GetFileName column. Action allows you to use Calibre Template language to write data to column using regex. |
|
04-29-2024, 03:15 AM | #1331 |
Wizard
Posts: 1,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
|
05-12-2024, 02:47 AM | #1332 |
Enthusiast
Posts: 25
Karma: 10
Join Date: Nov 2023
Device: Kindle Oasis
|
Hi, i don't know what i'm doing. i use "Event Manager" to show me the books i'm currently reading every time i change library, all good But now I want it to show me my TBR in case I don't have books in Currently Reading, and i don't know how |
05-12-2024, 05:48 AM | #1333 |
Wizard
Posts: 1,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
To be able to offer specific help, I need more details regarding how you keep track of currently reading and TBR. I need the custom column names and the datatype of these custom columns.
Last edited by capink; 05-12-2024 at 06:02 AM. |
05-12-2024, 08:00 PM | #1334 |
Enthusiast
Posts: 25
Karma: 10
Join Date: Nov 2023
Device: Kindle Oasis
|
this is what i have
Last edited by correoparaappzz; 05-12-2024 at 11:11 PM. |
05-13-2024, 02:53 AM | #1335 |
Wizard
Posts: 1,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
|
There are two solutions:
Edit: The two template functions from_search() and from_selection() are only available in Action Chains plugin. @chaley has since introduced a template function called book_values() that can replace from_search(). Last edited by capink; 05-13-2024 at 05:00 AM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Editor Plugin] Editor Chains | capink | Plugins | 94 | 07-03-2024 07:26 PM |
Action Chains Resources | capink | Plugins | 65 | 07-01-2024 03:12 PM |
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB | lrpirlet | Plugins | 2 | 08-18-2022 03:15 PM |
[GUI Plugin] Save Virtual Libraries To Column (GUI) | chaley | Plugins | 14 | 04-04-2021 05:25 AM |