Skip to content

Instantly share code, notes, and snippets.

@fsteffek
Forked from graymouser/hb_all_books_dl.js
Last active April 24, 2022 20:47
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save fsteffek/bf4ac1e3d2601629a6c9cca94b5649f6 to your computer and use it in GitHub Desktop.
Save fsteffek/bf4ac1e3d2601629a6c9cca94b5649f6 to your computer and use it in GitHub Desktop.
Humble bundle book bundles - download all books and md5sums
/*
After purchasing a humble book bundle, go to your download page for that bundle.
Open a console window for the page and paste in the below javascript
*/
function getTitle() {
var re = /^Humble\ Book\ Bundle\:\ (.*)\ \(/g;
return re.exec(document.title)[1];
}
function showHashes() {
document.querySelectorAll('.dlmd5').forEach(md5 => {
if (md5.innerText.trim() == 'md5') {
md5.click();
}
});
}
function gatherInfo() {
const data = [];
const bundleTitle = getTitle();
showHashes();
document.querySelectorAll('.row').forEach(row => {
const bookTitle = row.dataset.humanName;
[...row.querySelectorAll('.downloads .download')].forEach(dl => {
const downloadLink = dl.querySelector('.flexbtn a').href;
const filename = /\.com\/([^?]+)/.exec(downloadLink)[1];
const md5 = dl.querySelector('a.dlmd5').innerText.trim();
data.push({
"bundleTitle": bundleTitle,
"bookTitle": bookTitle,
"filename": filename,
"downloadLink": downloadLink,
"md5": md5
});
});
});
return data;
}
function downloadBookBundle() {
const commands = []
const md5Sums = [];
const info = gatherInfo();
for (var i in info) {
bundleTitle = info[i]["bundleTitle"];
bookTitle = info[i]["bookTitle"];
filename = info[i]["filename"];
downloadLink = info[i]["downloadLink"];
md5 = info[i]["md5"];
commands.push(`curl --create-dirs -o "${bundleTitle}/${bookTitle}/${filename}" "${downloadLink}"`);
md5Sums.push(`${md5} ${bundleTitle}/${bookTitle}/${filename}`);
};
console.log(commands.join(' && '));
console.log(md5Sums.join('\n'));
}
downloadBookBundle();
@mfurquimdev
Copy link

I wanted to download and organize the e-books by directories. It was a pain to do it by hand. Then I thought: "Hey, I bet someone else had the same idea". And then I found a bunch of scripts which does that. Thank you so much for sharing it!

@mfurquimdev
Copy link

After having a few difficulties downloading all my eBooks from purchases, I found the humblebundle-downloader python program, if anyone is interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment