Last active
May 10, 2019 23:35
-
-
Save deangiberson/c9c55c6dbd368032582ea1c5ff81cf5d to your computer and use it in GitHub Desktop.
Download humble bundle contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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.*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"]; | |
command = `curl --create-dirs -o "${bundleTitle}/${bookTitle}/${filename}" "${downloadLink}"`; | |
commands.push("echo " + command); | |
commands.push(command); | |
md5Sums.push(`${md5} ${bundleTitle}/${bookTitle}/${filename}`); | |
}; | |
console.log(commands.join('\n')); | |
console.log(md5Sums.join('\n')); | |
} | |
downloadBookBundle(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment