Steven Smith revised this gist . Go to revision
1 file changed, 31 insertions
scloud_get.js(file created)
| @@ -0,0 +1,31 @@ | |||
| 1 | + | // Soundcloud stream thingy. For playlist, opens a prompt with the urls for the tracks | |
| 2 | + | // in the playlist spearated by spaces. For songs, opens a prompt with the stream url. | |
| 3 | + | // Create an applicaiton at soundcloud.com and chuck your client id in there. | |
| 4 | + | ||
| 5 | + | var cid = ""; | |
| 6 | + | var xmlhttp = new XMLHttpRequest(); | |
| 7 | + | xmlhttp.onreadystatechange = function() { | |
| 8 | + | if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { | |
| 9 | + | var data = JSON.parse(xmlhttp.responseText); | |
| 10 | + | if (data.kind == "track") { | |
| 11 | + | prompt("Track url:", data.stream_url + "?client_id=" + cid) | |
| 12 | + | } else if (data.kind == "playlist") { | |
| 13 | + | var out = []; | |
| 14 | + | data.tracks.forEach(function(v) { | |
| 15 | + | out.push(v.permalink_url); | |
| 16 | + | }); | |
| 17 | + | prompt("Playlist track urls:", out.join(" ")); | |
| 18 | + | } | |
| 19 | + | } | |
| 20 | + | }; | |
| 21 | + | if (window.location.href.indexOf("?") != -1) { | |
| 22 | + | var url = window.location.href.slice(0, window.location.href.indexOf("?")); | |
| 23 | + | } else { | |
| 24 | + | var url = window.location.href; | |
| 25 | + | } | |
| 26 | + | ||
| 27 | + | xmlhttp.open("GET", "https://api.soundcloud.com/resolve?url=" + url + "&client_id=" + cid, true); | |
| 28 | + | xmlhttp.send(); | |
| 29 | + | ||
| 30 | + | // bookmarklet | |
| 31 | + | javascript:var cid="a5711d1dc681e9114660bbc0603eecaa",xmlhttp=new XMLHttpRequest;if(xmlhttp.onreadystatechange=function(){if(4==xmlhttp.readyState&&200==xmlhttp.status){var t=JSON.parse(xmlhttp.responseText);if("track"==t.kind)prompt("Track url:",t.stream_url+"?client_id="+cid);else if("playlist"==t.kind){var e=[];t.tracks.forEach(function(t){e.push(t.permalink_url)}),prompt("Playlist track urls:",e.join(" "))}}},-1!=window.location.href.indexOf("?"))var url=window.location.href.slice(0,window.location.href.indexOf("?"));else var url=window.location.href;xmlhttp.open("GET","https://api.soundcloud.com/resolve?url="+url+"&client_id="+cid,!0),xmlhttp.send(); | |
Newer
Older