Last active
July 31, 2016 22:45
-
-
Save porterjamesj/a1f866c060babb25b0236571cd4b9d51 to your computer and use it in GitHub Desktop.
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
var system = require('system'); | |
var fs = require("fs"); | |
function scroller(eofSelector, cb, wait) { | |
var done = page.evaluate(function (s) { | |
return document.querySelector(s); | |
}, eofSelector); | |
if(done === null) { | |
page.evaluate(function() { | |
window.scroll(0, document.body.scrollHeight); | |
}); | |
window.setTimeout(function() { scroller(eofSelector, cb, wait); }, wait); | |
} | |
else { | |
window.setTimeout(cb, wait); | |
} | |
} | |
function scrollToBottom(eofSelector, cb, wait) { | |
window.setTimeout(function () { scroller(eofSelector, cb, wait); }, wait); | |
} | |
var page = require('webpage').create(); | |
page.onResourceReceived = function(resp) { | |
if (resp.url.contains("cf-media.sndcdn.com") && | |
resp.contentType === "audio/mpeg") { | |
console.log(resp.url); | |
// console.log('Request ' + JSON.stringify(request, undefined, 4)); | |
} | |
}; | |
var soundcloudUrl = "https://soundcloud.com/" + system.args[1]; | |
page.open(soundcloudUrl, function (status) { | |
scrollToBottom("div.paging-eof", function () { | |
page.evaluate(function () { | |
var songs = document.querySelectorAll("div.trackItem__content.sc-truncate"); | |
function clickEachWithDelay(elems) { | |
if (elems.length === 0) { | |
return; | |
} else { | |
elems[0].click(); | |
window.setTimeout(function () { | |
clickEachWithDelay(elems.slice(1)); | |
}, 1000); | |
} | |
} | |
clickEachWithDelay(Array.prototype.slice.call(songs)); | |
}); | |
}, 2000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment