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 01-15-2021, 11:29 AM   #1
jtgrenz
Junior Member
jtgrenz began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jan 2021
Device: Kobo LibraH2O
Question Need help cross-compiling jq lib for kobo

Oh hello MobileReaders, long time reader, first time poster

I noticed the other day that the KoboCloud plugin seems to have stopped working for me. It only syncs files up to a certain number and then just stops.

So, I started poking around the source code and thought to myself, wouldn't this be better if we use the dropbox api instead of relying on a parsing urls from a shared folder url?

Couple hours of playing around with the dropbox api and I had something that seemed pretty usable and also supported subfolders. Popped it over to my kobo and no dice. I totally forgot that the Kobo runs arm and one of the dependencies I added was jq, a unix json parser. I added the linux_x86_32 version of the binary to the kobo which wont work and there isn't an official arm binary available currently.

I'm a bit clueless when it comes to compiled languages and doubly so when dealing with a limited niche environment like the kobo. Would anyone be able to lend a hand in cross-compiling the Jq library over to work with the kobo? Also open to other ways to deal with JSON from the shell on the kobo.

If anyone wanted to see the rough hacky code I was working on, thats in the spoiler below. Basically I hooked into how kobo_cloud works but when it reaches a "url" of `dropbox_token:<some_token>` it runs the dropbox script below. The idea here being you have a dropbox app and all the contents of that app's dropbox folder being synced.

Spoiler:


$CURL is the path to the included kobo_cloud curl binary
$JQ is the path to the included jq binary (which alas doesn't yet work)
$AllowDropboxDelete is false by default.

Code:
#!/bin/sh
token=${1#"dropbox_token:"}

#load config
. $(dirname $0)/config.sh

response=$($CURL -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer $token" \
    --header "Content-Type: application/json" \
    --silent \
    --data "{
      \"path\": \"\",
      \"recursive\": true,
      \"limit\": 2000,
      \"include_non_downloadable_files\": false,
      \"include_deleted\": $AllowDropboxDelete
    }"
)

download() {
  $CURL -X POST https://content.dropboxapi.com/2/files/download \
  --header "Authorization: Bearer $token" \
  --header "Dropbox-API-Arg: {\"path\":\"$1\"}" \
  --silent \
  --output "$Lib$1"
}

process_entry() {
  local name=$(echo $1 | $JQ -r '.name' )
  local url="$(echo $1 | $JQ -r '.path_display')"
  local full_path="$Lib$url"
  local tag=$(echo $1| $JQ -r '.[".tag"]')
  local content_hash=$(echo $1 | $JQ -r '.content_hash')

  case "$tag" in
    "file")
      if [ ! -f "$full_path" ]; then
        echo "$(date): [Downloading] $full_path"
        download $url $name
      else
        echo "$(date): [Skip::Downloaded] $full_path"
      fi
      ;;

    "folder")
      if [ -d "$full_path" ]; then
        echo "$(date): [Directory::Found] $full_path"
      else
        echo "$(date): [Directory::NotFound] Creating $full_path"
        mkdir "$full_path"
      fi
      ;;

    "deleted")
       if [ -d "$full_path" ] || [ -f "$full_path" ]; then
       if [ "$AllowDropboxDelete" = "true" ]; then
          echo "$(date): [Delete] Removing $full_path"
          rm -rf "$full_path"
        fi
      fi
      ;;

    *)
      echo "$(date): [Error] Unknown tag: $tag"
      ;;
  esac
}

echo $response | $JQ -c '.entries[]' | while read el
do
  process_entry $el
done

Last edited by jtgrenz; 01-15-2021 at 11:33 AM.
jtgrenz is offline   Reply With Quote
Old 01-15-2021, 11:45 AM   #2
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: 26012492
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
jq is bundled in KoboStuff.

I don't recall anything heinous about the compilation process, either for jq itself or oniguruma (the RE lib), it's pretty much smooth sailing via autotools.
NiLuJe is offline   Reply With Quote
Advert
Old 01-15-2021, 08:38 PM   #3
jtgrenz
Junior Member
jtgrenz began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jan 2021
Device: Kobo LibraH2O
Oh brilliant! Thanks so much. I just copied the jq binary over and it works like a charm. I'll keep poking around and maybe try to upstream my changes.
jtgrenz is offline   Reply With Quote
Old 02-24-2021, 12:03 PM   #4
dokidoki
Junior Member
dokidoki began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Feb 2021
Device: Kobo Aura
Hi there!

I spent some time trying to make a CozyCloud connector for KoboCloud, thinking it would take me a few hours to modify the Drobpox script. Looong story short, it was way more difficult that I would expect, as I'm a real newbie as a kobo developer.

I eventually managed to get a token from a shell script, getting complex a JSON book list, which led me to the same realization (I need jq on my kobo) and to your post.

Could you maybe detail a little more where did you find the jq binary and how you installed it?

I'd be glad to know if you managed to get your script working.

Thanks!
dokidoki is offline   Reply With Quote
Old 02-24-2021, 12:17 PM   #5
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: 26012492
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
Have you, err, read my answer above? (Hint: there's a link in it).
NiLuJe is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling C++ on the Kobo Glo fat265 Kobo Developer's Corner 16 11-22-2016 08:51 AM
Help with cross-compiling tools? brianinmaine Kindle Developer's Corner 50 10-02-2013 09:42 AM
Cross compiling for the Kindle - wrong glibc version ninjageckoattack Kindle Developer's Corner 14 02-25-2012 04:44 PM
cross compiling links dent Kindle Developer's Corner 1 02-07-2011 08:42 AM
cross-compiling gstreamer for the kindle3 dent Kindle Developer's Corner 9 02-04-2011 08:39 AM


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


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