|
|
#16 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,616
Karma: 28549044
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You read metadata from OPF files using the get_metadata() function from calibre.ebooks.metadata.opf
that will give you a Metadata object that you can apply to any book in the calibre library using the set_metadata() function of self.gui.current_db.new_api |
|
|
|
|
|
#17 | ||
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
You can also get the format_metadata using db.format_metadata(). You can get the paths using db.format_files(). There are many examples in calibre of using these methods. |
||
|
|
|
|
|
#18 |
|
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
Thank you all for your inputs.
I made it work as needed. It's nice to have a living community and a living software in constant development. I will go on this dev a little later on. Merry Xmas to all ! Long live Calibre !
|
|
|
|
|
|
#19 |
|
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
I have been able to change the book file for an exiting record in the database with :
Code:
self.gui.current_db.new_api.add_format(id, book_extension, path, True) I want to regenerate the cover after uploading the new file using default page 1 Also I read "Covers are always changed if a new cover is provided, but are never deleted" in Calibre source code. So should I remove it first, with remove_cover and then rebuild it with generate_cover ? And use something like: Code:
img = generate_cover(self.mi, prefs=prefs, as_qimage=True)
img.setDevicePixelRatio(dpr)
self.preview_label.setPixmap(QPixmap.fromImage(img))
Is it the way to go or is there a simpler way to achieve this ? |
|
|
|
|
|
#20 |
|
Plugin Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,142
Karma: 5005503
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
|
Here's the code I use to force a cover update after updating a book in FanFicFare:
First, I use db.add_format_with_hooks(book_id, options['fileform'], book['outfile'], index_is_id=True) instead of just add_format(). I believe the difference is input plugins being run. Second, I have code that takes a cover from the ebook, using the first page if there isn't an actual image: Code:
from calibre.ebooks.metadata.meta import get_metadata as calibre_get_metadata
existingepub = db.format(book_id,'EPUB',index_is_id=True, as_file=True)
epubmi = calibre_get_metadata(existingepub,'EPUB')
if epubmi.cover_data[1] is not None:
try:
db.set_cover(book_id, epubmi.cover_data[1])
except:
logger.info("Failed to set_cover, skipping")
Code:
if len(add_list):
self.gui.library_view.model().books_added(len(add_list))
self.gui.library_view.model().refresh_ids(add_ids)
if len(update_list):
self.gui.library_view.model().refresh_ids(update_ids)
current = self.gui.library_view.currentIndex()
self.gui.library_view.model().current_changed(current, self.previous)
self.gui.tags_view.recount()
if self.gui.cover_flow:
self.gui.cover_flow.dataChanged()
|
|
|
|
|
|
#21 | |
|
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
Thank you JimmXinu.
I'll give it a try. I was just wondering if there was a simpler / more recent way to do this Quote:
|
|
|
|
|
|
|
#22 | |
|
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
Hi,
I tried to adapt but unfortunately get_metadata only returns the following fields correctly: Title, Title sort, Author(s), Publisher, Tags , Series, Languages, Timestamp, Published but no cover_data Here is my code: This overwrites the ebook file and works fine Code:
self.gui.current_db.new_api.add_format(searchId, fmt, path, replace=True, run_hooks=True) But the cover is not updated from this list (default first page) Code:
mi = self.gui.current_db.new_api.format_metadata(searchId, fmt, allow_cache=True, update_db=True) OR mi = self.gui.current_db.new_api.get_metadata(searchId, get_cover=True, get_user_categories=False, cover_as_data=True) Code:
self.gui.current_db.new_api.set_cover({searchId, mi.cover_data[1]})
Quote:
I think that the cover needs to be generated before being saved in a temporary file so I can send the buffer in the metadata cover field. Unfortunately I've found no way to generate the cover at least page 1. How can I force cover generation from a given book id and format ? Thank you
|
|
|
|
|
|
|
#23 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
{ book_id: cover_data }
|
|
|
|
|
|
|
#24 |
|
Enthusiast
![]() Posts: 35
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
|
yes you are right. Thank you.
there is no error anymore now. Code:
self.gui.current_db.new_api.set_cover({searchId: mi.cover_data[1]})
|
|
|
|
![]() |
| Tags |
| plugin development |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| TOC reference in Guide section of OPF fails | Jeff L | Calibre | 0 | 10-20-2011 05:04 AM |
| Multiple reference elements with the same type in the <guide> | Valloric | ePub | 8 | 04-25-2010 12:18 PM |
| Adding a <reference> item to <guide> in OPF file | GRiker | Sigil | 2 | 04-12-2010 02:06 PM |
| Reference Guide: How to Prepare Images for EPUB (and other) Formats | Zorba | ePub | 13 | 11-22-2009 09:28 AM |
| Free PDF: Ubuntu Pocket Guide and Reference | TadW | Deals and Resources (No Self-Promotion or Affiliate Links) | 4 | 01-31-2009 12:22 AM |