09-05-2010, 10:34 AM | #1 |
Addict
Posts: 305
Karma: 78651
Join Date: May 2010
Location: New Brunswick, Canada
Device: Kobo, Kobo Wifi, Kobo Touch
|
Manage Collections
I am trying to figure out how to add collections support to the Kobo.
What is it that the manage collections action from the device popup menu does? I assume that it would add the currently selected collection to the currently selected book. Is that correct? I will probably have other questions as I work on this... Tim |
09-05-2010, 11:07 AM | #2 | |
Grand Sorcerer
Posts: 12,029
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
From the point of view of a device driver, collection management is currently arranged in the class CollectionsBookList. There is one interface method, rebuild_collections, and one utility method, get_collections. Both of these interact with the Metadata Management setting in preferences -> add/save -> send to device. When a device is plugged in: if a device supports collections, then the 'books' interface method *must* ensure that the book.device_collections contains a list of the collections of which the book is a member. If it does not, and if metadata management is set to manual, then the collections will be lost. In addition, the GUI will not be able to display the information. If Metadata management is manual, then the user can add and remove collections on the device view. After editing, calibre modifies book.device_collections and calls rebuild_collections with that book (or books). Rebuild_collections must do whatever is necessary to make the device's collections match the contents of the 'device_collections' attribute. It is not necessary (nor desirable) to call booklist.get_collections Devices that support collections should call booklist.get_collections whenever metadata is changed, i.e. when sync_booklists is called. Get_collections returns a dictionary {collection:[list of books], c:[bl], ...}. The list of books is in the order that they should appear on the device. The device driver's job is to ensure that collections on the device match what is in the dict, deleting and adding as needed. Get_collections uses the Metadata management setting, the new_book flag, and the book's device_collections attribute to build the dict. If metadata management is set to either automatic or on_send, then collections are built exclusively from the calibre attributes specified in the device customization. Custom field attributes are being added real-soon-now. The user cannot add or remove collections on the device view. The Sony drivers are a good but complicated example of how collection management works. It is very possible that some sony-only stuff has crept into the general code. Don't hesitate to point that out. It would be best to try to avoid creating another collection management structure. |
|
Advert | |
|
09-05-2010, 11:03 PM | #3 | |||||
Addict
Posts: 305
Karma: 78651
Join Date: May 2010
Location: New Brunswick, Canada
Device: Kobo, Kobo Wifi, Kobo Touch
|
Quote:
[snip] Quote:
Quote:
Quote:
Quote:
Tim |
|||||
09-06-2010, 05:16 AM | #4 | |||
Grand Sorcerer
Posts: 12,029
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
1) Be sure that you set the booklist_class variable to CollectionsBookList. If you don't, then calibre thinks that the device cannot support collections. 2) Don't hack too much on the current driver. Kovid and I are in process of changing how book metadata is stored on devices, which includes how json is handled. The kobo driver will need changes (I did some so it will compile). My guess is that you will be able to get hold of the new stuff within a week or so. Is ReadStatus a boolean? If so, then you can store it in device_collections as a single value. Something like if ReadStatus == True: device_collections = ['Reading'] else: device_collections = [] The other way would work something like if 'Reading' in device_collections: ReadStatus = True else: ReadStatus = False Of course, you can map a tag to ReadStatus, but you will still need to set device_collections. Quote:
Quote:
|
|||
09-06-2010, 10:11 AM | #5 | ||||||
Addict
Posts: 305
Karma: 78651
Join Date: May 2010
Location: New Brunswick, Canada
Device: Kobo, Kobo Wifi, Kobo Touch
|
Quote:
Quote:
Quote:
if readstatus == 1: if lpath not in playlist_map: playlist_map[lpath] = [] playlist_map[lpath].append("I\'m Reading") and later: book.device_collections = playlist_map.get(book.lpath, []) That does display "I'm Reading" in the correct books in the gui. Quote:
Quote:
Quote:
Tim |
||||||
Advert | |
|
09-06-2010, 10:51 AM | #6 | |||
Grand Sorcerer
Posts: 12,029
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
CAN_SET_METADATA = True in your driver. Try putting it after line 29 FORMATS = ['epub', 'pdf'] Quote:
Quote:
You have already shown that you can create a collection from the Kobo's I'm_Reading flag, and that the user can see this collection on the device view. Once you add the CAN_SET_METADATA, the user will be able to change that field. The question is 'what is supposed to happen'? For example, what if the user adds 'Foobar' to the collection list? What is the Kobo supposed to do with that? What if the user adds 'I'm Reading'? Is the Kobo supposed to set the bit in the database? If the user sets a tag 'Reading' (or some such), is the Kobo driver supposed to turn the bit on? Is it possible to use the Kobo to turn the bit off? If so, what is calibre supposed to do? My guess is that as a first iteration, you should report the I'm Reading status back to the user in a collection. Second iteration: allow the user to edit a book's collections, either adding or removing I'm Reading, than having the Kobo driver either set or clear the bit. We might want to add another interface method so that the GUI can enquire of the driver whether the collection list is valid for the device, to handle the Foobar case. Third iteration: associate a tag with I'm Reading. If the tag is present, then set the Kobo's bit. If the tag is absent, then clear the Kobo's bit. You may want to require that Manage Metadata be set to Automatic, so that editing the collections on the device view is prohibited. Otherwise there will be unpleasant interactions between the processing of the tag and the user's manual changes. Just random thoughts... |
|||
09-06-2010, 11:07 AM | #7 |
Grand Sorcerer
Posts: 12,029
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
By the way, if you set CAN_SET_METADATA = True, then the user will be able to change author and title on the device view. Can the Kobo cope with that? Are author and title stored in the DB, independently from the book file?
|
09-06-2010, 01:05 PM | #8 | |||
Addict
Posts: 305
Karma: 78651
Join Date: May 2010
Location: New Brunswick, Canada
Device: Kobo, Kobo Wifi, Kobo Touch
|
Quote:
Quote:
The kobo is locked while connected to the computer (at present). The kobo clears the I'm reading flag when a book is finished. My plan is that calibre will read the flag from the database when it is connected so the collection will always be whatever the kobo says at initial connection. Then calibre will set the flag depending on the users settings I guess. On auto I assume it would rebuild the device collections based on the tagged files. I will need to think on it because I don't really want to overwrite someones leading list if they don't want it overwritten. Quote:
Tim |
|||
09-06-2010, 01:07 PM | #9 |
Addict
Posts: 305
Karma: 78651
Join Date: May 2010
Location: New Brunswick, Canada
Device: Kobo, Kobo Wifi, Kobo Touch
|
Those fields are all stored in the database separate from the pubs. There is no reason it could not be supported if I have enough time/Interest...
|
09-08-2010, 06:44 PM | #10 |
Addict
Posts: 305
Karma: 78651
Join Date: May 2010
Location: New Brunswick, Canada
Device: Kobo, Kobo Wifi, Kobo Touch
|
I have managed to add simple support for device collections which seems to work okay for manual editing. It still needs some work and I will probably wait till you merge the new metadata/json code and rework it then.
I did notice a couple of things: It seems that device_collections needs to be added to the JSON_ATTRIBUTES in usbms/books.py or the collection is not written to metadata.calibre There maybe a bug in the current driver that will cause a failure if a new Kobo is used with Calibre (I need to retest to be sure). rebuild_collections receives the entire booklist when a device collection is changed. In the case of the Kobo, that leads me to reset and recreate the the I'm Reading list everytime one collection is changed. It does not take long and I may be able to query the device for the collections and only reset the ones that are no longer on the list but that may well be slower. I have not looked at the on send setting and automatic settings. Do they still call rebuild_collections? Tim |
09-08-2010, 08:21 PM | #11 |
Addict
Posts: 305
Karma: 78651
Join Date: May 2010
Location: New Brunswick, Canada
Device: Kobo, Kobo Wifi, Kobo Touch
|
|
09-09-2010, 12:17 AM | #12 |
Addict
Posts: 305
Karma: 78651
Join Date: May 2010
Location: New Brunswick, Canada
Device: Kobo, Kobo Wifi, Kobo Touch
|
I have a very rough version of the driver that can both manually manage the I'm Reading list and do it automatically on connecting the device. There is still a fair amount of work and some functionality (like manual management) may be dropped.
I do like plugging it into Calibre and getting the Reading List overwritten by any books tagged with "I'm Reading". However, getting a book that you are currently reading on the device removed from the reading list (because its not in the Library or tagged) may be less than ideal. What is Calibre's preferred method? Should I overwrite or merge the reading list. Tim |
09-09-2010, 12:55 AM | #13 |
creator of calibre
Posts: 44,542
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
the metadaa management options are for that. Manual means dont overwrite device collections. Automatic means overwrite device collections.
|
09-09-2010, 06:12 AM | #14 | ||||||
Grand Sorcerer
Posts: 12,029
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
You have several questions in this and later posts. I will try to deal with them all here.
Quote:
Quote:
Quote:
Quote:
Manual: sync_booklists is called only when a book is added or removed. Get_collections will compute collections only for books with 'new_book == True'. On_send: sync_booklists is called only when a book is added or removed. Get_collections will recompute all the collections for all books on the device. Automatic: sync_booklists is called on every connect. Get_collections will recompute all the collections for all books on the device. Quote:
On the Sony, title & author & author_sort are updated for each book every time sync_booklists is called. This is done because the Sony can decide to reset the author value to what is in the book, undoing the user's request to use author_sort for the author. It can also undo setting the titleSorter field. For the Kobo, you could choose to use the _new_book flag and the setting of Metadata Management to decide whether or not to update authors etc. Rebuild_collections is called only when collections are edited on the device view. It should not touch any other metadata. This differs from sync_booklists, which has a free hand to change any metadata as needed. Quote:
If it is manual, then you do a merge. Never delete a value. Get_collections respects this rule. If it is on_send or automatic, then calibre's metadata wins. No merging is done. The user must ensure that the tag (or what-have-you) is correct. One of the differences between on_send and automatic can be seen here. Since on_send does not change the metadata on connect, the user can see the current values in 'Device Collections'. That information can be used to by the user to do a manual merge, setting/clearing the tag as desired. When a book is sent, the tag will win. On 'automatic', the device is asked to change the values on connect, so the existing values will be overwritten. Calibre's data wins. |
||||||
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Manage "Collections" in Kindle 3 | captaindonut | Devices | 4 | 03-01-2011 12:23 PM |
Neo How to manage ebooks? | ivanm | BeBook | 11 | 08-19-2010 12:01 PM |
manage annotations | ebooker | Reading and Management | 1 | 07-06-2010 09:57 PM |
How many actually use an SD card and how do you manage your books? | Dr. Drib | Sony Reader | 41 | 11-14-2009 05:11 AM |
I don't manage to listen music :( | Snas | iRex | 6 | 05-29-2007 10:28 AM |