Access input file name in postadd (FileTypePlugin)?
I've noticed that with the lastest update Calibre does support attaching arbitrary data files to a book.
For my ACSM-to-EPUB plugin I was planning to add an option to add the source ACSM file as a data file to the imported book, so people can archive that file if they want to.
In order to do that, I added the "postadd" method to my plugin - and then I got stuck, because the only parameters I get there are book_id (the ID the new book entry has in the database), fmt_map (a mapping between formats and file names for the books themselves), and db (probably a reference to the Calibre database object).
In the Calibre source code I found db.add_extra_files which is the method I'd need to call to add the ACSM files to the book records, but I'm still a bit stuck.
The plugin's "run" method is too early to do that, because at that point the book is not yet added to the database and so a book ID does not exist yet.
The plugin's "postadd" method is too late - when that's executed I do know the book's book ID, but I no longer know the path to (or the contents of) the original, unmodified input file before it ran through all the FileTypePlugins.
I can't add code to the "run" method to store the original path or even the full original file, because when multiple books are being imported at the same time, how do I know which of the stored files from the "run" method corresponds to the book IDs returned in "postadd"?
Is there a way to do what I'm trying to do, or is that not supported with Calibre's current API?
|