Fetching books: Being a lazy pirate, arrh
Table of Contents
Anna's Archive is a good library, it has a paid membership, but its gratis fetch is still somewhat convenient.
However it takes some time when you're dealing with a larger amount:
- Search
.epubbooks - Enter the book page (
/md5/) - Enter the
/slow_download/page - Wait (if applicable) and copy the link to
wget. - Convert the
.epubto.orgwith a helper script.
This web flow is inefficient: Mouse clocks, redirects, downloads management…
I want to pay the membership, so I can have access to a stable JSON APIs, but…
It is much cooler to just use a little of grep.
So I made some bash scripts :b
Fetching the Book
First, the most important fetcher: You give the anti-bot walled fetching page and your WAF cookies. It gives you the file via wget:
wgetannasarchive --help
* NAME wgetannasarchive - Fetches the books from Annas Archive * SYNOPSIS wgetannasarchive <cookies-txt> <slow-download-url ...> * DESCRIPTION Scrappes the URL from bot-walled page using cookies and run ~wget~. Waits the queue if needed. ** Supported Formats - =<HOST>/slow_download/<MD5>/0/<MIRROR_NUMBER>= - =<HOST>/md5/<MD5>=
Converting .epub to .org
To read a .epub in plain text, I convert it to .org. And since epubs are
mere HTML pages compressed in a ZIP, a simple helper does the job:
epub2org --help
* NAME epub2org - Unpacks EPUB, recurse its HTML files and packs into a single Org file. * SYNOPSIS epub2org <epub-file> <out-org-file> [--no-autocleanup]
Searching the website and fetching results
Then, as last instance of convenience, this script:
- Does a search in Anna's Archive.
- Greps the results URL.
- And calls
wgetannasarchivefor each result.
annasarchivesearchdownload --help
* NAME annasarchivesearchdownload - Search Anna's Archive and fetch results * SYNOPSIS annasarchivesearchdownload <cookies-txt> <per-page-fetch-count> <search-term ...> * DESCRIPTION Multi-page iteration supported. Each page contains 50 items by default.
Final flow
Easy as below:
annasarchivesearchdownload my-cookies.txt ~/Downloads 10 'book from john doe'
epub2orgall ~/Downloads/*.epub
See sources in https://codeberg.org/thisago/smallBashScripts
Hope you have a peaceful sea, dear pirate.