Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 08-06-2021, 12:07 PM   #1
fmagin
Junior Member
fmagin began at the beginning.
 
fmagin's Avatar
 
Posts: 2
Karma: 10
Join Date: Aug 2021
Device: reMarkable 1
Question 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:
  • I have some datafiles that contain the information about what I highlighted in an epub on my device
  • I would like to import these highlights into Calibre, so they show up like any other highlight added via the epub viewer
  • in the future I would maybe integrate further external dependencies to automatically retrieve the highlight data from the Cloud API of the tablet, but for now I just have some local JSON files I need to work with.

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.
fmagin is offline   Reply With Quote
Old 08-06-2021, 11:20 PM   #2
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,866
Karma: 22666666
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
kovidgoyal is offline   Reply With Quote
Advert
Old 08-07-2021, 10:16 AM   #3
fmagin
Junior Member
fmagin began at the beginning.
 
fmagin's Avatar
 
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:
{
"end_cfi": "/2/4/56/1:250",
"highlighted_text": "frontal lobes represent about 7 per cent of the total brain volume of a relatively intelligent animal such as the dog, and take up about 17 per cent of the brain in the lesser apes, they represent as much as 35 per cent of the human brain",
"spine_index": 10,
"spine_name": "OPS/chapter_01.htm",
"start_cfi": "/2/4/56/1:12",
"style": {
"kind": "color",
"type": "builtin",
"which": "yellow"
},
"timestamp": "2021-08-06T15:39:28.644Z",
"toc_family_titles": [
"Part One The Divided Brain",
"Chapter 1 Asymmetry and the Brain"
],
"type": "highlight",
"uuid": "ffT8yQAnoxs0oSoXBXdK6w"
},


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?
fmagin is offline   Reply With Quote
Old 08-07-2021, 09:15 PM   #4
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,866
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
Old 06-01-2023, 06:41 PM   #5
Bunker D
Junior Member
Bunker D began at the beginning.
 
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.
Bunker D is offline   Reply With Quote
Advert
Old 06-01-2023, 10:41 PM   #6
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,866
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No there is no further work on this that I am aware of.
kovidgoyal is offline   Reply With Quote
Reply


Forum Jump

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


All times are GMT -4. The time now is 03:34 PM.


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