Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 03-06-2023, 02:02 PM   #1
charlweed
Enthusiast
charlweed began at the beginning.
 
Posts: 27
Karma: 30
Join Date: Jul 2011
Device: none
How can I use the database API to get a collection of all known series?

I'm writing a plugin, and I'd like to obtain a list of all the series in all the books. I'll use the list to answer questions like "Is there a series with this name 'SomeName'" and "Which series have a name that starts with the string 'SomePrefix'"
I've tried various approaches including:
Code:
series_fields = self.db_cache_api.fields['series']
for val, book_ids in series_fields.iter_searchable_values(
    self.db_cache_api.get_metadata,
    self.db_cache_api.all_book_ids()
):
    print("val=\"%s\"" % val)
But the results are always empty.

Thanks for any help!
charlweed is offline   Reply With Quote
Old 03-06-2023, 03:17 PM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
I don't know where the attribute 'cache_api" is defined. Is it something you made?

In any event, here is a calibre python template that returns all the current series names.
Code:
python:
python:
def evaluate(book, context):
	series_names = context.db.new_api.all_field_names('series')
	return ', '.join(series_names)
Going from your example, I would use
Code:
	series_names = self.db.new_api.all_field_names('series')
But if you are looking for all the books for a given series then
Code:
	series_id = context.db.new_api.get_item_id('series', 'Bah')
	# should check for None
	series_books = context.db.new_api.books_for_field('series', series_id)
chaley is offline   Reply With Quote
Advert
Old 03-06-2023, 04:44 PM   #3
charlweed
Enthusiast
charlweed began at the beginning.
 
Posts: 27
Karma: 30
Join Date: Jul 2011
Device: none
Thanks! This works for me so far. I just want the series names.
`self.db_cache_api`is just an instance field where I keep the results of `db.new_api` after the current class was constructed.
charlweed is offline   Reply With Quote
Reply

Tags
api, database, plug-ins


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Series and Collection guidoexge Library Management 1 08-23-2019 09:43 AM
Problems using Calibre 3.15.0 Database API einnordlicht Development 2 01-06-2018 09:28 PM
Accessing Series and Metadata with the "new api" hakan42 Development 3 10-03-2013 04:57 AM
Author and Series database huon Calibre 5 03-31-2012 07:45 PM
Series/Collection sikm Calibre 7 10-28-2011 03:44 PM


All times are GMT -4. The time now is 09:37 AM.


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