Skip to content

[Highlight Export Plugin] Include book author name in myclippings export format for better book identification#12106

Merged
Frenzie merged 7 commits into
koreader:masterfrom
arpanghosh8453:OOM-merge-highlight-export
Jun 28, 2024
Merged

[Highlight Export Plugin] Include book author name in myclippings export format for better book identification#12106
Frenzie merged 7 commits into
koreader:masterfrom
arpanghosh8453:OOM-merge-highlight-export

Conversation

@arpanghosh8453

@arpanghosh8453 arpanghosh8453 commented Jun 27, 2024

Copy link
Copy Markdown
Contributor

Extension of #10263 by @Mochitto and @pazos

Currently there is no Author name in the exported file of myclippings. This adds the Author name (if present) which helps in better book recognition. The app is able to fetch book frontcover preview on the site (myclippings.io) if the Author name is present.

Before

False Witness
- Your highlight on page 21 | Added on Thursday, June 27, 2024 08:57:13 PM

From the kitchen, Callie heard Trevor tapping his fingers on the aquarium. Her grip tightened around the spatula she was using to mix cookie dough. He was only ten years old. She thought he was being bullied at school. His father was an asshole. He was allergic to cats and terrified of dogs. Any shrink would tell you the kid was terrorizing the poor fish in a desperate bid for attention, but Callie was barely holding on by her fingernails.
==========
The Paris Apartment
- Your highlight on page 18 | Added on Thursday, June 27, 2024 09:06:59 AM

The metal gate in front of me has a brass lion’s head knocker: the fat metal ring held between snarling teeth. Along the top of the gate, I notice, is a bristle of anti-climb spikes. And all along the high wall either side of the gate are embedded shards of glass. These security measures feel kind of at odds with the elegance of the building.
==========
  • Image thumbnails will be missing for the books

After

False Witness (Karin Slaughter)
- Your highlight on page 21 | Added on Thursday, June 27, 2024 08:57:13 PM

From the kitchen, Callie heard Trevor tapping his fingers on the aquarium. Her grip tightened around the spatula she was using to mix cookie dough. He was only ten years old. She thought he was being bullied at school. His father was an asshole. He was allergic to cats and terrified of dogs. Any shrink would tell you the kid was terrorizing the poor fish in a desperate bid for attention, but Callie was barely holding on by her fingernails.
==========
The Paris Apartment (Lucy Foley)
- Your highlight on page 18 | Added on Thursday, June 27, 2024 09:06:59 AM

The metal gate in front of me has a brass lion’s head knocker: the fat metal ring held between snarling teeth. Along the top of the gate, I notice, is a bristle of anti-climb spikes. And all along the high wall either side of the gate are embedded shards of glass. These security measures feel kind of at odds with the elegance of the building.
==========

image


This change is Reviewable

@pazos

pazos commented Jun 27, 2024

Copy link
Copy Markdown
Member

Closes #11593

@pazos pazos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

BTW, this exporter might still OOM on the whole history export. It is explained in #10745 (comment)

A fix can come later

@hius07

hius07 commented Jun 27, 2024

Copy link
Copy Markdown
Member

AFAIK, if the author is absent, Amazon writes on the home screen and in My Clippings: "Unknown".
Maybe we should do the same, for full compatibility.

@Mochitto

Mochitto commented Jun 27, 2024

Copy link
Copy Markdown
Contributor

I've solved the OOM issue; the PRs will be in conflict

And thanks for building on top of this export target; I'm happy it's being used by someone :)

@Frenzie Frenzie added this to the 2024.06 milestone Jun 27, 2024
@arpanghosh8453

arpanghosh8453 commented Jun 28, 2024

Copy link
Copy Markdown
Contributor Author

@Mochitto It's hard to merge with conflicting changes and your fix is essential for large exports. As my contribution is minor, It can be included in #12107 directly as I mentioned in my latest comment on that thread. Also I did make a change here to use Unknown when author is not present matching kindle format as mentioned by @hius07

How we go about merging both of the pull request changes without making a lot of trouble for @pazos?

@Mochitto

Copy link
Copy Markdown
Contributor

I'll wait for further indications from the maintainers regarding solving conflicts :)

You can also open a PR towards my fix branch, if they don't mind them being together in the PR; that way your name will show up in the commits so it will be easier for them to credit you when they make a release or for people to tag you in the future.

@Frenzie

Frenzie commented Jun 28, 2024

Copy link
Copy Markdown
Member

This one's just a couple of lines, so easy to update.

@Frenzie Frenzie added the Plugin label Jun 28, 2024
@hius07

hius07 commented Jun 28, 2024

Copy link
Copy Markdown
Member

just a couple of lines

One line
content = content .. booknotes.title .. " (" .. (booknotes.author or "Unknown") .. ")" .. "\n"

@hius07

hius07 commented Jun 28, 2024

Copy link
Copy Markdown
Member

I've checked other interface languages in my Kindle, the "Unknown" string is not translatable.

@hius07

hius07 commented Jun 28, 2024

Copy link
Copy Markdown
Member

It looks like the title string is the same for highlights and notes, it can be reused.

Comment thread plugins/exporter.koplugin/target/my_clippings.lua Outdated
Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>
@hius07

hius07 commented Jun 28, 2024

Copy link
Copy Markdown
Member

Can you optimize

diff --git "a/my_clippings.lua" "b/my_clippings.lua"
index 0e2ee9b..3c0d63d 100644
--- "a/my_clippings.lua"
+++ "b/my_clippings.lua"
@@ -16,11 +16,8 @@ local function format(booknotes)
     for ___, entry in ipairs(booknotes) do
         for ____, clipping in ipairs(entry) do
             if booknotes.title and clipping.text then
-                if booknotes.author then
-                    table.insert(tbl, booknotes.title .. " (" .. booknotes.author .. ")" )
-                else
-                    table.insert(tbl, booknotes.title .. " (Unknown)" )
-                end
+                local title_str = booknotes.title .. " (" .. (booknotes.author or "Unknown") .. ")"
+                table.insert(tbl, title_str)
 
                 local header = T(_("- Your highlight on page %1 | Added on %2"), clipping.page,
                     os.date("%A, %B %d, %Y %I:%M:%S %p", clipping.time))
@@ -31,11 +28,7 @@ local function format(booknotes)
                 table.insert(tbl, "==========")
 
                 if clipping.note then
-                    if booknotes.author then
-                        table.insert(tbl, booknotes.title .. " (" .. booknotes.author .. ")" )
-                    else
-                        table.insert(tbl, booknotes.title .. " (Unknown)" )
-                    end
+                    table.insert(tbl, title_str)
 
                     header = T(_("- Your note on page %1 | Added on %2"), clipping.page,
                         os.date("%A, %B %d, %Y %I:%M:%S %p", clipping.time))

@arpanghosh8453

Copy link
Copy Markdown
Contributor Author

Can you optimize

diff --git "a/my_clippings.lua" "b/my_clippings.lua"
index 0e2ee9b..3c0d63d 100644
--- "a/my_clippings.lua"
+++ "b/my_clippings.lua"
@@ -16,11 +16,8 @@ local function format(booknotes)
     for ___, entry in ipairs(booknotes) do
         for ____, clipping in ipairs(entry) do
             if booknotes.title and clipping.text then
-                if booknotes.author then
-                    table.insert(tbl, booknotes.title .. " (" .. booknotes.author .. ")" )
-                else
-                    table.insert(tbl, booknotes.title .. " (Unknown)" )
-                end
+                local title_str = booknotes.title .. " (" .. (booknotes.author or "Unknown") .. ")"
+                table.insert(tbl, title_str)
 
                 local header = T(_("- Your highlight on page %1 | Added on %2"), clipping.page,
                     os.date("%A, %B %d, %Y %I:%M:%S %p", clipping.time))
@@ -31,11 +28,7 @@ local function format(booknotes)
                 table.insert(tbl, "==========")
 
                 if clipping.note then
-                    if booknotes.author then
-                        table.insert(tbl, booknotes.title .. " (" .. booknotes.author .. ")" )
-                    else
-                        table.insert(tbl, booknotes.title .. " (Unknown)" )
-                    end
+                    table.insert(tbl, title_str)
 
                     header = T(_("- Your note on page %1 | Added on %2"), clipping.page,
                         os.date("%A, %B %d, %Y %I:%M:%S %p", clipping.time))

Thank you. Done. I think it's ready to merge :)

@arpanghosh8453

Copy link
Copy Markdown
Contributor Author

Thank you @pazos and @hius07 for approvals. Will this be merged in v2024.06 before it ships?

@Frenzie Frenzie merged commit e88bfbe into koreader:master Jun 28, 2024
Commodore64user pushed a commit to Commodore64user/KOReader_fork that referenced this pull request Aug 2, 2024
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants