Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 12-29-2018, 09:22 AM   #1
jmoore914
Junior Member
jmoore914 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Dec 2018
Device: Kindle
Deleting book from database

Hi all,

I'm trying to write a plugin and could use a bit of help. Given a path for an ebook, I would like to delete that book from the database. I can delete the file from my computer using normal python methods but I can't seem to find a way to remove it from calibre.

Apologies if this is super obvious. I searched through the API docs and was only able to find functions to remove a book from a device.

Bonus question: Is there any way to automatically trigger a plug in to run whenever the metadata for a book is changed?

Thanks so much in advance!
jmoore914 is offline   Reply With Quote
Old 12-29-2018, 10:14 AM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,807
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Look at the commandline interface section of the users guide

https://manual.calibre-ebook.com/gen...db.html#remove

BTW NEVER make changes to the filesystem using anything other than Calibre (tools), you will break things BAD
theducks is offline   Reply With Quote
Old 12-29-2018, 11:03 AM   #3
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 6,497
Karma: 84420419
Join Date: Nov 2011
Location: Tampa Bay, Florida
Device: Kindles
The database API documentation is here. See remove_books if you want to remove a book record entirely or remove_formats if you want to eliminate just the e-book content.
jhowell is offline   Reply With Quote
Old 12-29-2018, 01:04 PM   #4
jmoore914
Junior Member
jmoore914 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Dec 2018
Device: Kindle
Thanks for the help!

remove_formats is working for the most part. The only issue I'm having is that it is successfully deleting the ebook from the filesystem but the deleted format is still listed as available in the Calibre interface. Is there some command I need to run in order to have this change reflected in the Calibre interface?

Thanks again
jmoore914 is offline   Reply With Quote
Old 12-29-2018, 03:27 PM   #5
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,807
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by jmoore914 View Post
Thanks for the help!

remove_formats is working for the most part. The only issue I'm having is that it is successfully deleting the ebook from the filesystem but the deleted format is still listed as available in the Calibre interface. Is there some command I need to run in order to have this change reflected in the Calibre interface?

Thanks again
Yes
You are using the wrong call.
Remove, does EVERYTING
theducks is offline   Reply With Quote
Old 12-29-2018, 03:44 PM   #6
jmoore914
Junior Member
jmoore914 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Dec 2018
Device: Kindle
Quote:
Originally Posted by theducks View Post
Yes
You are using the wrong call.
Remove, does EVERYTING
Hi theducks,

I am only trying to remove certain formats which is why I was using the remove_formats API call. I'm guessing the command line call would have the same result but I can give it a try I guess.
jmoore914 is offline   Reply With Quote
Old 12-29-2018, 04:37 PM   #7
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,572
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by jmoore914 View Post
Thanks for the help!

remove_formats is working for the most part. The only issue I'm having is that it is successfully deleting the ebook from the filesystem but the deleted format is still listed as available in the Calibre interface. Is there some command I need to run in order to have this change reflected in the Calibre interface?

Thanks again
remove_formats should only remove the nominated format file (e.g. EPUB, TXT etc) from the library, and it should remove the corresponding link in database.

If you restart calibre after running your plugin, is the removed format still showing in Book Details. If not, that would indicate you need to refresh the Book Details panel after doing the remove_formats. If it is -

BR
BetterRed is offline   Reply With Quote
Old 12-29-2018, 05:05 PM   #8
jmoore914
Junior Member
jmoore914 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Dec 2018
Device: Kindle
Quote:
Originally Posted by BetterRed View Post

If you restart calibre after running your plugin, is the removed format still showing in Book Details. If not, that would indicate you need to refresh the Book Details panel after doing the remove_formats. If it is -

BR
Bingo! I just need to refresh the panel. Can I force a refresh or does the program need to be restarted?
jmoore914 is offline   Reply With Quote
Old 12-29-2018, 05:13 PM   #9
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,572
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
dunno - I am a logician not a coder. I would be very surprised if there's not a refresh function available, but I've no idea where it is.

BR
BetterRed is offline   Reply With Quote
Old 12-29-2018, 09:18 PM   #10
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
If you are doing this in a GUI plugin then dont use the db API directly, instead use the existing remove books action which will take care of refreshing the GUI for you automatically. Something like:


Code:
self.gui.iactions['Remove Books'].remove_format_by_id(book_id, fmt)
Note however, that this function will ask the user for confirmation. If you want to avoid that, then look at its code and re-implement it yourself, you will find it in actions/delete.py
kovidgoyal is offline   Reply With Quote
Old 12-30-2018, 08:25 AM   #11
jmoore914
Junior Member
jmoore914 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Dec 2018
Device: Kindle
Quote:
Originally Posted by kovidgoyal View Post
If you are doing this in a GUI plugin then dont use the db API directly, instead use the existing remove books action which will take care of refreshing the GUI for you automatically. Something like:


Code:
self.gui.iactions['Remove Books'].remove_format_by_id(book_id, fmt)
Note however, that this function will ask the user for confirmation. If you want to avoid that, then look at its code and re-implement it yourself, you will find it in actions/delete.py
Hi Kovid,

I was not planning on making this a GUI plugin so I will look into re-implementing the function myself. Thanks for the suggestion and for making such an amazing program!
jmoore914 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting book filipexim Development 6 05-27-2012 12:36 PM
deleting a book StickMaker Amazon Kindle 9 09-18-2011 03:40 PM
Deleting book from sig joycedb Feedback 19 09-12-2011 09:47 AM
Deleting a Book..?? Cpl Punishment Nook Color & Nook Tablet 2 01-30-2011 08:48 PM
Deleting books from a database candide Calibre 6 10-26-2010 03:04 PM


All times are GMT -4. The time now is 06:05 PM.


MobileRead.com is a privately owned, operated and funded community.