How to get a SoundCloud thumbnail using the API?

+7
soundcloud
source share
5 answers

You can use the endpoint /tracks and read the artwork_url property from the returned JSON. More details: http://developers.soundcloud.com/docs/api/tracks

+7
source share

I know this is pretty old, but I stumbled upon this question while looking for something else, and I would like to give two cents.

These are all possible sizes (source API Link ):

  * t500x500: 500×500 * crop: 400×400 * t300x300: 300×300 * large: 100×100 (default) * t67x67: 67×67 (only on artworks) * badge: 47×47 * small: 32×32 * tiny: 20×20 (on artworks) * tiny: 18×18 (on avatars) * mini: 16×16 * original: (originally uploaded image) 
+22
source share

Also, if you replace "-more" in the url string "-t300x300" or "-t500x500", you will get access to larger formats.

+9
source share

what you want to do is use the Soundclouds API, for example:

 SC.get(PATH, function (track, err){ IMG_URL = track.artwork; }); 

here you can see an example: http://runnable.com/UuiMCfATvMMkAAAS/get-a-tracks-artwork-on-soundcloud-in-javascript#

PATH to the track can be obtained in various ways
1. If you know the image identifier, you can capture it as if var PATH = "/tracks" + id;
2. if you know the name and user of the track
var PATH = "/users/dj-faze/tracks/phase-shift-360-019-degrees"
3. you can also get the id with other soundcloud APIs

NOTE. Make sure that the image of the track you are trying to get is public. If this is confidential, you will need to log in using the soundcloud authorization API.

+2
source share

I tried using this answer , but unfortunately SoundCloud does not seem to guarantee that t500x500 , original or other sizes will exist.

So, I resorted to writing an express application that redirects to the largest available image on their CDN, given artwork_url .

https://gist.github.com/gaearon/717ed6d6c7771f95d50d

He uses his naming scheme and lists the sizes one by one until some image returns a status of 200.

A source:

 'use strict'; var express = require('express'), app = express(); require('./config/development')(app, express); require('./config/production')(app, express); var redis = require('redis'), request = require('request'), Promise = require('bluebird'); Promise.promisifyAll(redis.RedisClient.prototype); var redisSettings = app.set('redis'), redisClient = redis.createClient(redisSettings.port, redisSettings.host, redisSettings.options); app.configure(function () { app.use(express.bodyParser()); app.use(app.router); }); function sendError(res, status, error) { if (!(error instanceof Error)) { error = new Error(JSON.stringify(error)); } return res .status(status || 500) .end(error && error.message || 'Internal Server Error'); } function generateCacheHeaders() { var maxAge = 3600 * 24 * 365; return { 'Cache-Control': 'public,max-age=' + maxAge, 'Expires': new Date(Date.now() + (maxAge * 1000)).toUTCString() }; } function getCacheKey(url) { return 'soundcloud-thumbnail-proxy:' + url; } app.get('/*', function (req, res) { var originalUrl = req.params[0], cacheKey = getCacheKey(originalUrl), urls; // https://developers.soundcloud.com/docs/api/reference#artwork_url // This is a ridiculous naming scheme, by the way. urls = [ originalUrl, originalUrl.replace('-large', '-t500x500'), originalUrl.replace('-large', '-crop'), // 400x400 originalUrl.replace('-large', '-t300x300'), originalUrl.replace('-large', '-large') // 100x100 ]; return redisClient.getAsync(cacheKey).then(function (cachedUrl) { if (cachedUrl) { return cachedUrl; } return Promise.reduce(urls, function (resolvedUrl, url) { if (resolvedUrl) { return resolvedUrl; } return new Promise(function (resolve) { request.head(url, function (err, response) { if (!err && response.statusCode === 200) { resolve(url); } else { resolve(null); } }); }); }, null); }).then(function (url) { if (!url) { throw new Error('File not found'); } var headers = generateCacheHeaders(); for (var key in headers) { if (headers.hasOwnProperty(key)) { res.setHeader(key, headers[key]); } } res.redirect(url); redisClient.set(cacheKey, url); redisClient.expire(cacheKey, 60 * 60 * 24 * 30); }).catch(function (err) { sendError(res, 404, err); }); }); app.get('/crossdomain.xml', function (req, res) { req.setEncoding('utf8'); res.writeHead(200, { 'Content-Type': 'text/xml' }); res.end('<?xml version="1.0" ?><cross-domain-policy><allow-access-from domain="*" /></cross-domain-policy>'); }); redisClient.on('ready', function () { app.listen(app.set('port')); }); redisClient.on('error', function () { throw new Error('Could not connect to Redis'); }); module.exports = app; 
+2
source share

All Articles