Wow, fist written (not dictated) post in a long time. Let's see if I can finish it.

Given the fact that Amazon is shutting down downloading your purchased ebooks, I decided to download
them all before the cut in a couple of days. To me, the definitve gide comes in this toot:

[rem@front-end.social, Feb 18](https://front-end.social/@rem/114026180468002581)

The first link is a tool that will automatically download the books for you; otherwise, you have to
download them by hand/clickops. If your collection is big that can be tedious. The first problem is that 
that tool is developed in a obscure programming language called `bun`[^1], which of course gets installed
by the classic `curl | bash` method which... _sigh_. Let's just say it's not the ideal. At least the 
options they use in `curl` are not bad, but it would be nice if they used the `--long-options` so I
don't have to peruse `curl`'s man page to see if they're not doing anything even more crappy, like
ignoring bad SSL certs or something  worse.

So instead of blindly doing that, I open the script and start reading. The usual crap, but it includes 
this gem:

    install_env=BUN_INSTALL
    bin_env=\$$install_env/bin

    install_dir=${!install_env:-$HOME/.bun}
    bin_dir=$install_dir/bin
    exe=$bin_dir/bun

In a roundabout way, it's saying that it will honor the `BUN_INSTALL` envvar as the root of the 
installation, defaulting to `$HOME/.bun`, which is what I was looking for; I don't want more trash in 
my home directory. I also run the script with tracing to make sure it doesn't do anything ugly.

    mdione@ioniq:~/src/system/fsck-amazon$ BUN_INSTALL=$(pwd) bash -x ./install 

I should have read it more. The bloody thing helpfully adds these lines you the `.bashrc`:

    # bun
    export BUN_INSTALL="$HOME/src/system/fsck-amazon"
    export PATH="$BUN_INSTALL/bin:$PATH"

_sigh_ So I undo that and only set the envvars on the shell I run for all this.

Ok, now to follow the bulkk tool's install instructions. The step that most time takes is:

    🚚 typescript... 

_sigh_. To be slightly fair, my internet has been crappy for a while now. I blame the PLC network 
between my ISP router and my home made AP.

So far only (!!!) 121MiB have been used. _sigh_ Let's see how much will it be at the end, because the 
next step is:

    bunx puppeteer browsers install chrome
    
See that last one? This is because the ony things that can use the web lately are only full fledged
browsers that include a fsck-ton amount of technologies, so this thing is going to drive Amazon's
site with a full fledged Chrome browser. And of course it escapes my feeble attempt to give it a jail:

    mdione@ioniq:~/src/system/fsck-amazon/amazon-kindle-bulk-downloader$ bunx puppeteer browsers install chrome
    chrome@133.0.6943.98 /home/mdione/.cache/puppeteer/chrome/linux-133.0.6943.98/chrome-linux64/chrome

_sigh_

    mdione@ioniq:~/src/system/fuck-amazon/amazon-kindle-bulk-downloader$ du -sm /home/mdione/.cache/puppeteer/
    585     /home/mdione/.cache/puppeteer/

So 706MiB so far.

_eyeroll_

To not write the auth on the disk in plain text, I just run the system with manual auth:

    mdione@ioniq:~/src/system/fsck-amazon/amazon-kindle-bulk-downloader$ bun run start --manualAuth
    $ bun run src/index.ts --manualAuth
    ✔ Enter the Amazon base URL … https://www.amazon.com/
    ✔ Press enter once you've logged in … yes
    Got auth
    [...]
    Downloading complete. You can find your books in the 'downloads' folder.

An that's it. After this I cleaned up the two diredtories, making sure not to delete the `downloads`
the tool created.

Next step is to download the Calibre plugin (I already have Calibre via the OS packages) and 
[follow the install instructions](https://github.com/noDRM/DeDRM_tools/blob/master/CALIBRE_CLI_INSTRUCTIONS.md).
One of the step is to write a list of serials for the ebooks you have. I my case, it was on 
drop-from-the-top menu -> All Settings -> Device Options -> Device Info -> Serial Number; it's a
4 groups of 4 characters string, `WWWW XXXX YYYY ZZZZ`. Also in my case, the config files was
`~/.config/calibre/plugins/dedrm.json`. You can write it by hand or use the GUI to add new serials.
For the latter, it's Calibre -> Preferences -> Plugins -> File type -> DeDRM -> Customize plugin ->
Kindle eInk ebooks -> + (add serial). Just notice it wants the serial as a single 16 char string.

Last step: convert them all:

    mdione@ioniq:~/src/system/fuck-amazon$ for file in downloads/; do calibredb add $file --with-library=library; done

Notice two things: when I said "making sure not to delete the `downloads` the tool created", I meant
moving that directory into this root and deleting everything else. Second, this just DeDRMs the files,
and leaves them in a different directory (`library`), but Calibre won't see them until you really 
add them.

[^1]: Oh, fscking hell: "Bun is a fast JavaScript all-in-one toolkit". _sigh_
