43
calibre User Manual, Release 2.57.1
postimport(book_id,book_format, db)
Called post import,i.e., after the book file has been added to the database. Note that this is different from
postadd()(page195)whichiscalledwhenthebookrecordiscreatedforthefirsttime.Thismethodis
called whenever a new file is added to a book record. It is useful for modifying the book record based on
the contents of the newly added file.
Parameters
• book_id – Database id ofthe added book.
• book_format – The file type of the book that was added.
• db – Library database.
postadd(book_id,fmt_map, db)
Called postadd,i.e. afterabookhasbeenaddedtothedb. Notethatthis is differentfrompostimport()
(page 194), whichis called aftera single book file has been addedto a book. postadd() is called onlywhen
an entire book record with possibly more than one book file has been created for the first time. This is
useful if you wish to modify the book record in the database when the book is first added to calibre.
Parameters
• book_id – Database id ofthe added book.
• fmt_map – Map of file format to path from which the file format was added. Note that
this might or might not point to an actual existing file, as sometimes files are added as
streams. In which case it might be a dummy value or an on-existent path.
• db – Library database
Metadata plugins
class calibre.customize.MetadataReaderPlugin(*args, **kwargs)
Bases:calibre.customize.Plugin (page 192)
Aplugin that implements reading metadata from a set of file types.
file_types = set([])
Setoffiletypes for whichthis pluginshould berun Forexample: set([’lit’, ’mobi’, ’prc’])
get_metadata(stream, type)
Returnmetadata for the filerepresented by stream(a file like object that supports reading). Raisean excep-
tion when there is an error with the input data. :param type: The type of file. Guaranteed to be one of the
entries infile_types (page 195). :return: A calibre.ebooks.metadata.book.Metadata
object
class calibre.customize.MetadataWriterPlugin(*args, **kwargs)
Bases:calibre.customize.Plugin (page 192)
Aplugin that implements reading metadata from a set of file types.
file_types = set([])
Setoffiletypes for whichthis pluginshould berun Forexample: set([’lit’, ’mobi’, ’prc’])
set_metadata(stream, mi, type)
Setmetadata for the file representedby stream(a file like object that supports reading). Raise an exception
whenthereis anerrorwiththeinputdata. :param type: Thetype offile. Guaranteedtobe one of the entries
infile_types (page 195). :parammi: Acalibre.ebooks.metadata.book.Metadata object
1.10. Customizing calibre
195