Skip to content

Instantly share code, notes, and snippets.

@Woody2143
Last active February 2, 2018 14:44
Show Gist options
  • Save Woody2143/830d5eae396f5ddcae4f6b7668690659 to your computer and use it in GitHub Desktop.
Save Woody2143/830d5eae396f5ddcae4f6b7668690659 to your computer and use it in GitHub Desktop.
@graymouser (https://gist.github.com/graymouser/a33fbb75f94f08af7e36) came up with the initial bit of javascript code to paste in to a console window on the humble bundle site to download files. The resulting discussion lead to some nice code by @oxguy3 but I wanted one last addition on that. So below is my code to save the file as the title of…
/*
This no longer works. They changed how their page renders. The good news is that an alternative is in the works.
There is a single request fo their order API that gives a JSON response with all of the download links. A quick
script to parse that should generate a list of download links and files to save as. Stand-by...
*/
/* I've added MP3 below for MP3 audio books, you could also add FLAC if you wanted, but those file sizes... */
var pattern = /(MOBI|EPUB|PDF( ?\(H.\))?|CBZ|Download|MP3)$/i;
var nodes = document.getElementsByTagName('a');
var downloadCmd = '';
for (i in nodes) {
var a = nodes[i];
if (a && a.text && pattern.test(a.text.trim()) && a.attributes['data-web']) {
var name = a.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute("data-human-name");
name = name.replace(/\s+/g, '_'); /* change spaces to underscores */
name = name.replace(/'/g, ''); /* don't want single quotes */
name = name.replace(/:/g, '_-'); /* change : to _- for looks */
name = name.replace(/,/g, ''); /* don't need commas */
name = name.replace(/&/g, 'and'); /* taking out the pesky & */
name = name.replace(/!/g, ''); /* taking out the pesky ! */
var extension;
/* This isn't the best way to do this I'm sure, but my regex skills are failing me at this point, so I'm moving on */
if (/\_optimized\./.test(a.attributes['data-web'].value)) {
/* likely the below URL regex will need corrected at some point */
extension = /https:\/\/dl\.humble\.com\/.*(_optimized\..*)\?gamekey.*/.exec(a.attributes['data-web'].value);
} else {
extension = /https:\/\/dl\.humble\.com\/.*(\..*)\?gamekey.*/.exec(a.attributes['data-web'].value);
}
name += extension[1];
downloadCmd += 'wget --output-document="' + name + '" --content-disposition "' + a.attributes['data-web'].value + "\"\n";
}
}
downloadCmd += "\n";
var output = document.createElement("pre");
output.textContent = downloadCmd;
document.getElementById("papers-content").prepend(output);
@jimmckeeth
Copy link

Thanks!

@Woody2143
Copy link
Author

I do have a script started that does the bulk download; see here:
HumbleBundleDL

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