Quote:
Originally Posted by ownedbycats
If it can be easily modified, I would find it useful for deleting ORIGINAL_EPUBS on my generate + embed cover chain. 
|
The code is below.
There is no confirmation before deleting the format. There is no check that it is not the only format. I run this module as part of a routine which always create both epub and azw3 formats. If the format to delete does not exist in some of the selected books, it is not problematic (at least as far as I could test).
You can delete another format by changing the line "fmt = 'YourFormat'"
Code:
from calibre.ebooks.metadata.meta import metadata_from_formats
from calibre_plugins.action_chains.actions.base import ChainAction
class DeleteEPUBFormat(ChainAction):
name = 'Delete EPUB format'
def run(self, gui, settings, chain):
db = gui.current_db.new_api
rows = gui.current_view().selectionModel().selectedRows()
book_ids = [ gui.library_view.model().db.id(row.row()) for row in rows ]
fmt = 'epub'
for book_id in book_ids:
gui.library_view.model().db.remove_format(book_id, fmt, index_is_id=True, notify=False)
gui.library_view.model().refresh_ids([book_id])
gui.library_view.model().current_changed(gui.library_view.currentIndex(), gui.library_view.currentIndex())
gui.tags_view.recount_with_position_based_index()
Hope it helps!