08-06-2021, 12:07 PM | #1 |
Junior Member
Posts: 2
Karma: 10
Join Date: Aug 2021
Device: reMarkable 1
|
Plugin to import Highlight information from external source
I am using a reMarkable Tablet which added support for highlights that are aligned with the text. The tablet specific details aren't really relevant for my question though, the abstract situation is:
My core question is: What are the appropriate APIs to add an highlights/annotations to an existing book? Are there existing examples for this API, ideally as a headless script that doesn't require adding GUI actions? In case there are any existing plugins/tools/ideas for something like this, or completely different ways to approach this I am also curious to hear about them. |
08-06-2021, 11:20 PM | #2 |
creator of calibre
Posts: 44,422
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
look in db/cache.py at functions with *annotations* in their name. Annotations in calibre are simple JSON objects that store highlighted text and start and end positions as EPUB CFI paths, alongwith colors/styles. Just creating a few different annotations with the calibre viewer and examining the resulting obets will do the trick.
You can get the db/cache.py object like this: from calibre.library import db cache = db('/path/to/library/folder').new_api this is from a standalone script run via calibre-debug if you are in a gui plugin then you get it as: from calibre.gui2.ui import get_gui() cache = get_gui().current_db.new_api |
08-07-2021, 10:16 AM | #3 | |
Junior Member
Posts: 2
Karma: 10
Join Date: Aug 2021
Device: reMarkable 1
|
Thanks, this covers the initial problem!
The hurdle I am encountering now is properly getting the exact location as Calibre expects it. E.g. in Calibre the JSON annotation data looks like this: Quote:
I need to somehow get the location info from just the text "frontal lobes [...] of the human brain" or ideally a regex, like the epub viewer allows via the search function + highlight creation. Is there some API to achieve this without a GUI, or is this too deeply intertwined with the GUI code? |
|
08-07-2021, 09:15 PM | #4 |
creator of calibre
Posts: 44,422
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
This happens via Javascript that runs in either a browser or Qt WebEngine. Qt WebEngine can run headlessly but it wont be an easy task. In the long term you are better off writing python code to parse html, do the search and convert its matches into CFI paths. Sadly this wont be an easy task either.
|
06-01-2023, 06:41 PM | #5 |
Junior Member
Posts: 3
Karma: 10
Join Date: Jan 2022
Device: Onyx Boox Nova 2
|
Are there any advancement on this topic? From what I get, the “Annotations” plug-in becomes quite outdated, isn't integrated with Calibre native annotation system, and is on it's way to depreciation.
I might help developing something, but at this point I don't even know where to start, and wouldn't like to do work that has already been done. |
06-01-2023, 10:41 PM | #6 |
creator of calibre
Posts: 44,422
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
No there is no further work on this that I am aware of.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Metadata Source Plugin] Empty Plugin? (Fake Identifier) | mneimeyer | Plugins | 3 | 11-11-2019 08:07 PM |
Calibre no longer able to import from external hdd | PandathePanda | Calibre | 4 | 10-12-2019 12:29 AM |
Import book information by ISBN in a different language | dma_k | Library Management | 6 | 09-11-2016 10:15 AM |
Series information is lost during the import | Tomita | Library Management | 5 | 12-16-2013 09:23 AM |
Import external OPDS catalog | titimoby | Calibre | 2 | 11-05-2010 05:57 AM |