-
-
Save duncanbeevers/2157987 to your computer and use it in GitHub Desktop.
(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); |
(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); |
Thanks @haroldSanchezb, I'll keep that in mind an retest. Cheers!
@GustavoHahn is possible, simply set up your context menu that captures the link by pressing right click, and send that url to a script that makes the function of generating the link to download.
Greetings!
It seems that this works, although the filenames are just a string of letters and numbers with 128 at the end showing their bit rate. Any reason why I am running into this issue?
Doesn't work in Safari with newest SoundCloud
This doesn't work on chrome. I guess soundcloud are changing their protection mechanisms.
'require' is a missing reference. Perhaps SC is not using requireJS anymore?
Yup, broken now. Is there a quick fix?
Ok, i will check tonight
Anything to report?
Time to give this an update?
Hello, Anyone know how I can use your code and put it in a contextmenu of chrome?