Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 12-29-2018, 10: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, 11: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: 22,489
Karma: 22514864
Join Date: Aug 2009
Location: (The original) Silicon Valley, USA
Device: K4NT, Galaxy Tab A, Kobo Aura2
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
Advert
Old 12-29-2018, 12:03 PM   #3
jhowell
Wizard
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: 2,532
Karma: 25145447
Join Date: Nov 2011
Location: Florida
Device: Oasis 2, Fire, iPad Air 2, Nexus 7
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 online now   Reply With Quote
Old 12-29-2018, 02: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, 04: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: 22,489
Karma: 22514864
Join Date: Aug 2009
Location: (The original) Silicon Valley, USA
Device: K4NT, Galaxy Tab A, Kobo Aura2
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
Advert
Old 12-29-2018, 04: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, 05:37 PM   #7
BetterRed
null operator
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: 11,853
Karma: 10633600
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, 06: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, 06:13 PM   #9
BetterRed
null operator
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: 11,853
Karma: 10633600
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, 10: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: 33,916
Karma: 10254168
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, 09: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

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 09:29 PM.


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