Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader > Kobo Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 05-25-2022, 09:04 PM   #1
qkqw
Connoisseur
qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.
 
Posts: 58
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
NickelMenu script for fixing Pocket images

As you may know, the current Pocket implementation in Kobo readers struggles with images other than JPEG. JPEGs will be displayed fine, but all other image types, like PNG, SVG or GIF simply won't be displayed.

As I grew tired of seeing the "image not found" icon - too many articles using png files and the like - I wrote a small script for NickelMenu to convert these images to JPEG on the fly.

Add a line like this one to your NickelMenu config:

Code:
menu_item  :library  :Fix Pocket Images  :cmd_spawn  :quiet:/bin/sh /mnt/onboard/.adds/pocket/fix.sh
  chain_success  :dbg_toast  :Done
Then extract pocket.zip to /mnt/onboard/.adds/pocket.

The script currently supports the following formats: GIF, PNG, SVG, WEBP.

Ps. You might need to reboot your Kobo if the article already was cached.

Changelog:

2022-05-28:
  • Initial release

2022-06-08:
  • Add ImageMagick timeout flags
  • Only move files if ImageMagick was successful
  • Added toast message to NickelMenu config

2022-06-08:
  • Switch to ImageMagick 7
  • Add support for GIF, SVG, WEBP
  • Add support for SVG with embedded text using a default font

Attached Files
File Type: zip pocket-20220526.zip (3.85 MB, 132 views)
File Type: zip pocket-20220608.zip (3.85 MB, 145 views)
File Type: zip pocket-20220706.zip (3.19 MB, 338 views)

Last edited by qkqw; 07-06-2022 at 05:11 PM.
qkqw is offline   Reply With Quote
Old 05-30-2022, 11:11 PM   #2
xyclonei
Connoisseur
xyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watch
 
xyclonei's Avatar
 
Posts: 92
Karma: 10988
Join Date: Dec 2018
Device: Kobo Clara HD
Hi there! Thank you for this excellent add on! Any reason why it's png only for now?

Can it be expanded to other file formats?
xyclonei is offline   Reply With Quote
Advert
Old 05-31-2022, 04:34 AM   #3
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,983
Karma: 128903378
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
But how does the website code know to pick up the converted images given that they will now have a different file extension?
JSWolf is offline   Reply With Quote
Old 05-31-2022, 05:04 AM   #4
xyclonei
Connoisseur
xyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watch
 
xyclonei's Avatar
 
Posts: 92
Karma: 10988
Join Date: Dec 2018
Device: Kobo Clara HD
Quote:
Originally Posted by JSWolf View Post
But how does the website code know to pick up the converted images given that they will now have a different file extension?
This is my assumption on how it works.

If you have a look at .kobo/articles directory, you can see that the images are stored as a UID filename with no extension. The article file (index.html) makes a call to the filename only. If it's JPG encoded, it displays, else it fails.

What this script does is to make an in-place replacement of the PNG file with a JPG one. Since the filename remains, the call to the image should still be valid and will display correctly.

What I want to check though is whether this can be used as a catch-all for any image type.
xyclonei is offline   Reply With Quote
Old 05-31-2022, 06:46 AM   #5
qkqw
Connoisseur
qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.
 
Posts: 58
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
Quote:
Originally Posted by xyclonei View Post
Hi there! Thank you for this excellent add on! Any reason why it's png only for now?

Can it be expanded to other file formats?
Sure, that would be quite easy to do. However I could only find Jpg and Png files so far. If you happen to find any other format, I'd gladly amend the script. Let me know!

Also, @NiLuJe's ImageMagick only seems to support Jpg, Jfif and Png at this time, but I could cross compile a version with support for more file types if needed.
qkqw is offline   Reply With Quote
Advert
Old 05-31-2022, 06:49 AM   #6
qkqw
Connoisseur
qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.
 
Posts: 58
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
Quote:
Originally Posted by xyclonei View Post
This is my assumption on how it works.

If you have a look at .kobo/articles directory, you can see that the images are stored as a UID filename with no extension. The article file (index.html) makes a call to the filename only. If it's JPG encoded, it displays, else it fails.

What this script does is to make an in-place replacement of the PNG file with a JPG one. Since the filename remains, the call to the image should still be valid and will display correctly.

What I want to check though is whether this can be used as a catch-all for any image type.
That is absolutely correct. The heavy lifting is done by Pocket, which already seems to convert images. Unfortunately their API is not public, so I haven't had the chance to see what they do exactly.

To use a catch-all, you'd just need to change this line

Code:
  if [ "$FORMAT" == "PNG" ]; then

to this

Code:
  if [ "$FORMAT" != "JPG" ]; then
Obviously we'd need an ImageMagick with support for more formats
qkqw is offline   Reply With Quote
Old 06-05-2022, 06:08 AM   #7
xyclonei
Connoisseur
xyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watch
 
xyclonei's Avatar
 
Posts: 92
Karma: 10988
Join Date: Dec 2018
Device: Kobo Clara HD
Just thinking out loud, but is there a timeout for this?

Is there a possibility that it might get hung up on an image and keep eating battery?
xyclonei is offline   Reply With Quote
Old 06-06-2022, 05:50 PM   #8
qkqw
Connoisseur
qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.
 
Posts: 58
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
Quote:
Originally Posted by xyclonei View Post
Just thinking out loud, but is there a timeout for this?

Is there a possibility that it might get hung up on an image and keep eating battery?
Currently there is no timeout: ImageMagick will either suceed or fail transforming the images, but it won't get stuck.
qkqw is offline   Reply With Quote
Old 06-07-2022, 06:07 PM   #9
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,477
Karma: 26012494
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
IM has a builtin fairly complex limits framework that can be set up to avoid issues in degenerate use-cases (because you can't be 100% sure one weird bug on specific input wouldn't cause a long busy loop).

(at a minima, passing something like -limit time 60 might not be entirely stupid).
NiLuJe is offline   Reply With Quote
Old 06-08-2022, 02:51 AM   #10
xyclonei
Connoisseur
xyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watch
 
xyclonei's Avatar
 
Posts: 92
Karma: 10988
Join Date: Dec 2018
Device: Kobo Clara HD
Thank you, @NiLuJe! That's the fringe case example I was thinking of.

@qkqw, will adding -limit time 60 to the variables CONVERT & IDENTIFY work?

Code:
#!/bin/sh

ARTICLES="/mnt/onboard/.kobo/articles"
CONVERT="/mnt/onboard/.adds/pocket/convert -limit time 60"
IDENTIFY="/mnt/onboard/.adds/pocket/identify -quiet -limit time 60"

LD_LIBRARY_PATH="/mnt/onboard/.adds/pocket/lib:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH

for i in $(find $ARTICLES -type f -not -iname "*.html"); do
  FORMAT=$($IDENTIFY -format "%m" "$i")
  if [ "$FORMAT" == "PNG" ]; then
    $CONVERT "$i" "$i.jpg"
    mv "$i.jpg" "${i%.jpg}"
  fi
done
xyclonei is offline   Reply With Quote
Old 06-08-2022, 12:18 PM   #11
qkqw
Connoisseur
qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.
 
Posts: 58
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
Quote:
Originally Posted by xyclonei View Post
@qkqw, will adding -limit time 60 to the variables CONVERT & IDENTIFY work?
Yes, I've added this and a few more improvements to the original script.

@NiLuJe thanks for the assist!
qkqw is offline   Reply With Quote
Old 06-08-2022, 03:46 PM   #12
xyclonei
Connoisseur
xyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watch
 
xyclonei's Avatar
 
Posts: 92
Karma: 10988
Join Date: Dec 2018
Device: Kobo Clara HD
Quote:
Originally Posted by qkqw View Post
Yes, I've added this and a few more improvements to the original script.

@NiLuJe thanks for the assist!
Thank you very much for the update!
xyclonei is offline   Reply With Quote
Old 06-12-2022, 02:37 AM   #13
xyclonei
Connoisseur
xyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watch
 
xyclonei's Avatar
 
Posts: 92
Karma: 10988
Join Date: Dec 2018
Device: Kobo Clara HD
I've been scratching my head over this.

The below NM config displays Done when the script process is spawned and not when the Pocket image conversions are done.

Code:
menu_item:library:Fix Pocket Images:cmd_spawn:quiet:/bin/sh /mnt/onboard/.adds/pocket/fix.sh
  chain_success:dbg_toast:Done
I thought using cmd_output instead of cmd_spawn so that the script has a chance to indicate when it is done might sort it out:

Code:
menu_item:library:Fix Pocket Images:cmd_output:500:/bin/sh /mnt/onboard/.adds/pocket/fix.sh
  chain_success:dbg_toast:Done
But this would mean that the script would need to provide some sort of output that it was done. So I modified it to the below (apologies for the amateur code):

Code:
#!/bin/sh

ARTICLES="/mnt/onboard/.kobo/articles"
CONVERT="/mnt/onboard/.adds/pocket/convert -limit time 60"
IDENTIFY="/mnt/onboard/.adds/pocket/identify -limit time 60 -quiet"

PROCESSED="0"

LD_LIBRARY_PATH="/mnt/onboard/.adds/pocket/lib:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH

for i in $(find $ARTICLES -type f -not -iname "*.html"); do
  FORMAT=$($IDENTIFY -format "%m" "$i")
  if [ "$FORMAT" == "PNG" ]; then
    $CONVERT "$i" "$i.jpg"
    if [ $? -eq 0 ]; then
      mv "$i.jpg" "${i%.jpg}"
      (($PROCESSED)) || PROCESSED="1";
    fi
  fi
done

if [ "$PROCESSED" == "1" ]; then
	echo "DONE: Pocket articles optimised";
else echo "NOTE: Pocket articles not/already optimised";
fi
However, cmd_output message box pops up an error stating that there was a timeout.

Any idea what I'm doing wrong?
xyclonei is offline   Reply With Quote
Old 06-12-2022, 06:03 AM   #14
sherman
Guru
sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.
 
Posts: 856
Karma: 2676800
Join Date: Aug 2008
Location: Taranaki - NZ
Device: Kobo Aura H2O, Kobo Forma
Quote:
Originally Posted by xyclonei View Post
However, cmd_output message box pops up an error stating that there was a timeout.

Any idea what I'm doing wrong?
Yeah,
Code:
cmd_output
has a configurable timeout setting that you can set from 0-10 seconds (provided in milliseconds). (
Code:
:cmd_output         :500:command
). It has such a strict limit because your kobo will essentially be frozen until the command completes.

A better option would be to use a program such as FBInk to output messages to the screen. You may have to hunt for precompiled binaries, though it is available in NiLuJe's stuff pack.

Alternatively, another way to output messages is my own NickelDBus.

Of the two, FBInk isn't as intrusive, as it doesn't hook itself into the Kobo software in any manner.
sherman is offline   Reply With Quote
Old 06-12-2022, 12:55 PM   #15
xyclonei
Connoisseur
xyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watchxyclonei is clearly one to watch
 
xyclonei's Avatar
 
Posts: 92
Karma: 10988
Join Date: Dec 2018
Device: Kobo Clara HD
Thank you for the feedback, @sherman!

Seems like this might be more than I can chew with very little pay-off.

I'll look into both FBInk & NickelDBus to see if I can make sense of them.
xyclonei is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
fixing images? PandathePanda Workshop 8 11-15-2017 03:49 AM
Script to resize images to 2 Million Pixels shorshe ePub 14 06-28-2013 12:35 PM
Creation of Complex Script E-Book Using Images for Every Word? sungkhum Conversion 8 10-26-2011 04:20 PM
Script for fixing covers on B&N Nook Color jmricker Devices 0 06-28-2011 01:45 PM
Linux script for images to Kindle Screensaver soymicmic Kindle Developer's Corner 4 01-28-2011 11:20 AM


All times are GMT -4. The time now is 06:44 PM.


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