Skip to content

Instantly share code, notes, and snippets.

@pedrocatre
Last active December 24, 2020 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrocatre/7af4acac0da7bb144b8ced87ddeec5e7 to your computer and use it in GitHub Desktop.
Save pedrocatre/7af4acac0da7bb144b8ced87ddeec5e7 to your computer and use it in GitHub Desktop.
download audio content on https://markmanson.net/audio, requires a premium account
// wait function taken from https://stackoverflow.com/a/33414145
function wait(ms) {
var start = new Date().getTime();
var end = start;
while (end < start + ms) {
end = new Date().getTime();
}
}
let count = 0;
function downloadAudio(downloadClass) {
jQuery(downloadClass).each(function (index) {
count++;
if (count > 10) { // wait every few downloads because we have a limit of simultaneous downloads
console.log('paused before ' + index);
wait(60000); // wait Y milliseconds to make sure the previous downloads finished in the meantime
console.log('paused after' + index);
count = 0;
}
let $downloadElement = jQuery(this);
// Add attribute download to make the file auto downloadable, and put the name of the file as the URL
$downloadElement.attr("download", $downloadElement.attr("href"));
// the reason why get(0) is needed and you can't simply trigger click on the jQuery element is explained here https://stackoverflow.com/a/25507433
$downloadElement.get(0).click();
});
}
downloadAudio('.audio-member__download-article');
downloadAudio('.audio-member__download-commentary');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment