Created
March 6, 2016 20:58
-
-
Save blha303/470a692f79cad0143595 to your computer and use it in GitHub Desktop.
A soundcloud track getter thingy
This file contains hidden or 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
// Soundcloud stream thingy. For playlist, opens a prompt with the urls for the tracks | |
// in the playlist spearated by spaces. For songs, opens a prompt with the stream url. | |
// Create an applicaiton at soundcloud.com and chuck your client id in there. | |
var cid = ""; | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { | |
var data = JSON.parse(xmlhttp.responseText); | |
if (data.kind == "track") { | |
prompt("Track url:", data.stream_url + "?client_id=" + cid) | |
} else if (data.kind == "playlist") { | |
var out = []; | |
data.tracks.forEach(function(v) { | |
out.push(v.permalink_url); | |
}); | |
prompt("Playlist track urls:", out.join(" ")); | |
} | |
} | |
}; | |
if (window.location.href.indexOf("?") != -1) { | |
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, true); | |
xmlhttp.send(); | |
// bookmarklet | |
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment