Introduction
Humble Book Bundle [1] has often very cool books about IT, hacking, security, programming, Linux, Unix, science and other geeky stuff. Sadly there is no reliable way to download all books. This post shows how you can download all books in a quick and reliable way using a bookmarklet.
Precondition
Of course, first you need to buy the Humble Book Bundle.
For this example, I use the “Secure Your Stuff by Apress” Humble Book Bundle:
The Goal
I want to download all the books in a simple and reliable way.
The Problem
There are two problems:
- Clicking on all PDF and EPUB buttons takes too much time and is annoying.
- The “Bulk Download” button does not work in a reliable way. Often, downloads are missed and it has to be clicked several times until all books are downloaded. This is the same behavior for direct links and the BitTorrent links.
The Solution
A bookmarklet [2] can be used to extract all direct download links from the website. This list can then be used to download all books.
Create a new bookmark:
Paste the following code into the Location field:
Update 2024-10-09: The bookmarklet did not work anymore. I updated it to make it work again.
javascript:(function() {
var url = window.location;
var title = document.title.split(":")[1].split("(")[0].trim();
var date = new Date();
var year = date.getFullYear();
var month = ('0' + (date.getMonth() + 1)).slice(-2);
var dir = 'Humble Book Bundle - ' + year + '-' + month + ' - ' + title;
var links = document.querySelectorAll('a[href*=".epub"], a[href*=".pdf"], a[href*=".mobi"], a[href*=".torrent"], a[href*=".zip"]');
var linklist = '';
links.forEach(function(link) {
linklist += link.href + '\n';
});
document.documentElement.innerHTML = `<pre>`
+ `mkdir "${dir}"<br>`
+ `cd "${dir}"<br>`
+ `echo "${url}" > 00_bundle_downloadpage.txt<br>`
+ `cat << EOI > 00_bundle_links.txt<br>`
+ `${linklist}<br>EOI<br>`
+ `<br>`
+ `xargs -P 15 -n 1 curl -JLO < 00_bundle_links.txt<br>`
+ `</pre>`;
})();
This code gets some information about the bundle and loops through all displayed download links on the page (*.epub
, *.mobi
, *.pdf
, *.torrent
and *.zip
). Then, commands are printed to create a new directory, save the information and links into files and download the books using 15 parallel curl
processes.
Execute these commands in a bash shell and it will automatically create a new directory containing all the ebooks!
Now you just need some time to read all these books ;-)
Other Bookmarklets
Some other other bookmarklets I wrote are available in a GitHub repo: https://github.com/emanuelduss/Configs/blob/master/bookmarklets/README.md