02-13-2023, 03:33 PM | #1 |
Developer
Posts: 155
Karma: 280
Join Date: Nov 2010
Device: Kindle 3 (Keyboard) 3G / iPad 9 WiFi / Google Pixel 6a (Android)
|
FileTypePlugin postimport() not called after conversion?
Hi,
I want to write a plugin based on FileTypePlugin which implements postimport(), but I noticed that the method is only executed if I add a new ebook to Calibre (i.e. drag and drop a file), but not when I convert an existing ebook into a new format. Is there any way to have Calibre run the method also in this case? |
02-13-2023, 11:50 PM | #2 |
creator of calibre
Posts: 44,017
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
No conversion is not considered an import. If you can tell us a bit more about your actual use case, what you want your plugin to do I might be able to suggest a solution.
|
02-14-2023, 03:03 PM | #3 |
Developer
Posts: 155
Karma: 280
Join Date: Nov 2010
Device: Kindle 3 (Keyboard) 3G / iPad 9 WiFi / Google Pixel 6a (Android)
|
When I manage my ebooks in calibre, I want to keep track which files/formats are the original files I added to calibre and which ones are converted by calibre from the original file, to ensure that I never lose my original files.
I can recognize a book created by calibre from the creator metadata, so I want to automatically create a tag "Converted EPUB" if a .epub file created by calibre is added to my library/created by conversion (and similar tags for the other formats). I also need a way to automatically remove the "Converted <format>" tag if the corresponding format is deleted from the database. |
02-14-2023, 04:54 PM | #4 |
null operator (he/him)
Posts: 20,677
Karma: 26966376
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
|
02-14-2023, 05:03 PM | #5 |
Developer
Posts: 155
Karma: 280
Join Date: Nov 2010
Device: Kindle 3 (Keyboard) 3G / iPad 9 WiFi / Google Pixel 6a (Android)
|
No, I haven't. It seems to be a rather complex plugin, and I can't really figure out from the description how I could achieve my goal with it. Could you be more specific how to actually use it for my purpose?
|
02-14-2023, 06:17 PM | #6 | |
null operator (he/him)
Posts: 20,677
Karma: 26966376
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Quote:
The AC plugin didn't exist when I started using calibre, when I could have used it for a high volume proof of concept project. But my usage of calibre today is low volume so I have no need for it. I wouldn't spend more an hour a month on managing my calibre libraries. BR |
|
02-14-2023, 09:34 PM | #7 |
creator of calibre
Posts: 44,017
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You will never lose source format with default calibre settings since doing an epub to epub conversion will preserve the original as original_epub. So what is it you are actually trying to guard against?
|
02-15-2023, 12:50 PM | #8 |
Developer
Posts: 155
Karma: 280
Join Date: Nov 2010
Device: Kindle 3 (Keyboard) 3G / iPad 9 WiFi / Google Pixel 6a (Android)
|
It's not about converting one format to itself, it's about converting between formats.
I usually have my ebooks stored in Calibre as epub and mobi. Most of my ebooks I got as original epub and converted them to mobi, but some I got as original mobi and converted these to epub, and some other ebooks were originally available both as epub and mobi, so no conversion was needed at all in this case. I have no problems to delete and convert again formats which were created in the past by converting, but I don't want to lose my original formats. These automatically created and deleted tags allow me to easily distinguish the original files from the converted ones. I already use this scheme successfully for years, but it's rather annoying to maintain my necessary patches to Calibre every time I upgrade Calibre and as a result I do upgrades very seldom. I would like to achieve the same result via a plugin, so I can use an unmodified Calibre and update more easily/more often. From my perspective, all I would need are two small additions to the FileTypePlugin interface: an additional variable which lets postimport() be executed also after a conversion and a new method (e.g. postdelete()) with the same signature as postimport(), which is executed when a format is deleted. |
02-15-2023, 09:31 PM | #9 |
creator of calibre
Posts: 44,017
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You are welcome to send a PR to add on_postconvert and on_postdelete event types to the filetype plugin.
|
02-16-2023, 03:50 AM | #10 | |
Developer
Posts: 155
Karma: 280
Join Date: Nov 2010
Device: Kindle 3 (Keyboard) 3G / iPad 9 WiFi / Google Pixel 6a (Android)
|
Quote:
Can you give me some hints where these new methods need to be called and where postimport() is currently called in calibre for reference? |
|
02-16-2023, 05:23 AM | #11 |
creator of calibre
Posts: 44,017
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
see customize/ui.py and db/cache.py
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cancel book import from inside a FileTypePlugin | Leseratte_10 | Development | 2 | 09-04-2021 10:10 PM |
Error question from conversion formatter called epub bugs? | yourvirtualwizar | Writers' Corner | 15 | 03-24-2015 11:57 AM |
FileTypePlugin, config_widget, JSONConfig and Cancel | Apprentice Alf | Development | 3 | 02-28-2013 12:41 PM |
What is it called? | Crusader | Writers' Corner | 18 | 07-25-2011 04:04 AM |
What is it called? | crutledge | Workshop | 3 | 05-04-2009 02:12 PM |