08-07-2017, 04:25 PM | #1 |
Junior Member
Posts: 2
Karma: 10
Join Date: Aug 2017
Location: Uganda
Device: none
|
Help Writing a Plugin for File Checksums
Hello. I'm trying to write a Calibre plugin that will compute MD5 checksums of ebooks and store them in a custom column. I tried writing one following the examples in the manual (attached) but I clearly don't know what I'm doing as the code does nothing. I'd appreciate if anyone with some Python would give a few pointers regarding what I'm not doing right. Thank you.
|
08-07-2017, 05:21 PM | #2 |
null operator
Posts: 20,414
Karma: 25894272
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Moderator Notice
@lucask - I moved your thread to the Development sub-forum. If you read the PLEASE READ BEFORE ... sticky you'll understand why BR |
08-07-2017, 11:01 PM | #3 |
creator of calibre
Posts: 43,739
Karma: 22446736
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The indentation of the run method is incorrect. And for metadatawriter plugins you need to implement the set_metadata method, not the run method.
Also I'm not sure what you are expecting to do here. If you want to add metadata based on newly added book files to the calibre databse you need to create a filetype plugin not a metadatawriter plugin. Create a filetype plugin and implement either the postimport() or postadd() methods in it. |
08-24-2017, 01:02 AM | #4 |
Junior Member
Posts: 2
Karma: 10
Join Date: Aug 2017
Location: Uganda
Device: none
|
Thank you for responding. I have been trying for an embarrassingly long time to understand and implement your suggestion and had the following questions.
1. I intend to apply this plugin to an existing library, not to newly imported books. Should I still try to write postadd() and/or postimport() methods? 2. I have not yet had a successful test, so I don't know if the way I attempt to write to a user-defined column is right. In the GUI these columns are preceded by pound signs (as in #genre). When writing such plugins, is it, for instance 'mi.genre = ((some_code))' or 'mi.#genre = ((some_code))? Thank you for your time. |
08-24-2017, 01:24 AM | #5 |
creator of calibre
Posts: 43,739
Karma: 22446736
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
If you want to apply it to an existing library you will need to create a user interface plugin. I suggest simply adapting an existing plugin such as the Word Count plugin.
|
08-24-2017, 02:37 AM | #6 |
Grand Sorcerer
Posts: 24,908
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Yes, the Count Pages plugin would be a good example for this. It already iterates over the selected books, does some processing on them in a background and then passes the result back to the foreground for updating into a column.
But, I don't know what the point of calculating a checksum for the books in the library is. There are plenty of things you can do that will change the files in a way to invalidate the checksum (edit, convert, polish, update metadata). And if you send the book outside the library calibre updates the metadata, including the cover, and that won't match the checksum. |
08-24-2017, 06:16 AM | #7 |
The Grand Mouse 高貴的老鼠
Posts: 71,366
Karma: 305065800
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Perhaps a checksum of the contents of the HTML/CSS/Images, and not of the metadata?
|
10-07-2017, 06:31 PM | #8 |
Enthusiast
Posts: 43
Karma: 70238
Join Date: Jun 2014
Device: none
|
I think having the checksum for the file as it was when it was first imported can still be really useful. I had some plans for something like this for myself.
The context is the key. I regularly grab free books off amazon. When I do, it's not rare that I grab a whole bunch of them in one sitting. That collection of books has gotten pretty big over time. After downloading the books and importing them to calibre, I clean up the tiles, the authors, do the cover thing... basically I work so much on them that on the next batch import, I end up with with duplicates. Having the original checksum (to prevent reimporting books I already imported) would be great in this case and an up-to-date checksum would be useless. |
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Writing a plugin and my method isn't being called | plugin_dev | Development | 8 | 09-20-2014 09:02 AM |
Writing a first plugin | Agama | Development | 50 | 07-07-2012 04:06 PM |
Calibre checksums? | Suffolk Punch | Calibre | 6 | 05-14-2011 11:49 PM |
Help with plugin writing | meme | Plugins | 2 | 01-21-2011 01:57 PM |
Writing an interface action plugin | kiwidude | Plugins | 21 | 11-11-2010 04:11 PM |