From 291bff50daa8e2aa6e76ab396ffbaedae8775f50 Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 9 Jul 2013 19:17:48 +0000 Subject: [PATCH] soundcloud module [#524] --- modules/soundcloud/config.json | 5 ++++ modules/soundcloud/soundcloud.js | 41 ++++++++++++++++++++++++++++++++ modules/soundcloud/strings.json | 5 ++++ 3 files changed, 51 insertions(+) create mode 100644 modules/soundcloud/config.json create mode 100644 modules/soundcloud/soundcloud.js create mode 100644 modules/soundcloud/strings.json diff --git a/modules/soundcloud/config.json b/modules/soundcloud/config.json new file mode 100644 index 0000000..50a1537 --- /dev/null +++ b/modules/soundcloud/config.json @@ -0,0 +1,5 @@ +{ + "client_id": "391bcf67b5ad70fd64c6a4f79374f2f4", + "outputPrefix": "\u000307soundcloud\u000f", + "dependencies": [ "link" ] +} diff --git a/modules/soundcloud/soundcloud.js b/modules/soundcloud/soundcloud.js new file mode 100644 index 0000000..97aab8c --- /dev/null +++ b/modules/soundcloud/soundcloud.js @@ -0,0 +1,41 @@ +/** + * Module Name: soundcloud + * Description: Various SoundCloud functionality + */ +var _ = require('underscore')._, + request = require('request'); + +var soundcloud = function(dbot) { + this.ApiRoot = 'http://api.soundcloud.com'; + + this.onLoad = function() { + dbot.api.link.addHandler(this.name, + /https?:\/\/(www\.)?soundcloud\.com\//, + function(event, match, name) { + var url = match.input; + request.get(this.ApiRoot + '/resolve.json', { + 'qs': { + 'client_id': this.config.client_id, + 'url': url + }, + 'json': true + }, function(error, response, body) { + if(response.statusCode == 200) { + if(body.kind == 'track') { + event.reply(dbot.t('sc_track', { + 'title': body.title, + 'artist': body.user.username, + 'genre': body.genre.trim(), + 'plays': body.playback_count, + 'favs': body.favoritings_count + })); + } + } + }); + }.bind(this)); + }.bind(this); +}; + +exports.fetch = function(dbot) { + return new soundcloud(dbot); +}; diff --git a/modules/soundcloud/strings.json b/modules/soundcloud/strings.json new file mode 100644 index 0000000..59c21d1 --- /dev/null +++ b/modules/soundcloud/strings.json @@ -0,0 +1,5 @@ +{ + "sc_track": { + "en": "[{title} by {artist} — {genre} — \u000312▶\u000f{plays} \u000304♥\u000f{favs}]" + } +}