Skip to content

Instantly share code, notes, and snippets.

@shrwnsan
Forked from duncanbeevers/sc-dl-min.js
Last active August 29, 2015 13:55
Show Gist options
  • Save shrwnsan/8787871 to your computer and use it in GitHub Desktop.
Save shrwnsan/8787871 to your computer and use it in GitHub Desktop.
Bookmarklet which creates download links on *any* Soundcloud page. Full credit goes to @duncanbeevers, with contributions from @markpiro and @haroldSanchezb -- Last tested on Soundcloud site: 4 Feb 2013 Successful :-)
!function(a){var b,c,d,e=$(".sound"),f=require("config").get("client_id");require("lib/connect").getAuthToken();var i,j,k,l,m,h=require("lib/helpers/conversion-helper");for(b=e.length-1;b>=0;b--){c=$(e[b]);var n="https://soundcloud.com"+(c.find(".soundTitle__title").attr("href")||a.location.pathname);k={url:n,client_id:f},m=function(a){return function(b){var c={client_id:f};l=require("lib/url").stringify({query:c},b.stream_url+".mp3"),d=$(a.find(".sound__soundActions .sc-button-group")[0]),j=d.find(".sc-button:first")[0].className.match(/sc-button-((?:small)|(?:medium))/)[1],i=$('<a class="sc-button sc-button-download sc-button-icon sc-button-responsive">Download</a>').attr({title:"Download this sound ("+h.bytesToMB(b.original_content_size)+")",href:l,download:a.find(".soundTitle__title").first().text()+".mp3"}).addClass("sc-button-"+j),0==a.find(".sc-button-download").length&&d.append(i)}}(c),$.getJSON("http://api.soundcloud.com/resolve.json",k).success(m)}}(window);
(function(window) {
var i, $sound, $buttonGroup;
var $sounds = $(".sound");
var clientId = require("config").get("client_id");
var oauthToken = require("lib/connect").getAuthToken();
var conversionHelper = require("lib/helpers/conversion-helper");
var $downloadButton, size;
var params, downloadUrl, onSuccess;
for (i = $sounds.length - 1; i >= 0; i--) {
$sound = $($sounds[i]);
var soundcloudUrl = "https://soundcloud.com" + ($sound.find(".soundTitle__title").attr("href") || window.location.pathname);
params = {
url: soundcloudUrl,
client_id: clientId
};
onSuccess = (function($sound) {
return function(data) {
var params = {
client_id: clientId
};
downloadUrl = require("lib/url").stringify({ query: params }, data.stream_url + ".mp3");
$buttonGroup = $($sound.find(".sound__soundActions .sc-button-group")[0]);
size = ($buttonGroup.find(".sc-button:first")[0].className).match(/sc-button-((?:small)|(?:medium))/)[1];
$downloadButton = $('<a class="sc-button sc-button-download sc-button-icon sc-button-responsive">Download</a>').attr({
title: "Download this sound (" + conversionHelper.bytesToMB(data.original_content_size) + ")",
href: downloadUrl,
download: $sound.find(".soundTitle__title").first().text()+'.mp3'
}).addClass("sc-button-" + size);
if (0 == $sound.find(".sc-button-download").length) {
$buttonGroup.append($downloadButton);
}
};
})($sound);
$.getJSON("http://api.soundcloud.com/resolve.json", params).success(onSuccess);
}
})(window);
@uniZero
Copy link

uniZero commented Jun 14, 2014

Nice! This works great, but I can only use it via console.
It is too long for Chrome's bookmark URL field (including the minified version).

@uniZero
Copy link

uniZero commented Jun 14, 2014

༼ つ ◕◡◕ ༽つ

javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://rawgit.com/stechico/8787871/raw/20005a85d9b57b0e6de90c2032e5358ce939db0a/sc-dl-min.js';})();javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://rawgit.com/stechico/8787871/raw/20005a85d9b57b0e6de90c2032e5358ce939db0a/sc-dl-min.js';})();

@ http://stackoverflow.com/questions/106425/load-external-js-from-bookmarklet

@juxtaposse
Copy link

and how to process the "secret" files with no toolbar? like this one:
https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/161976651%3Fsecret_token%3Ds-TFivq

@markpalantoni
Copy link

does this still work? I've tried on Chrome and Safari, disabled my pop-up blocker, and enabled JS on Safari and couldn't get it to work.

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