From 3d78028b43c57c63e494cc97c4150ea32665e165 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Fri, 19 Jul 2013 17:17:08 +0800 Subject: [PATCH 1/3] Add soundcloud autoresponse plugin. Currently supports tracks/playlists and users. The /resolve endpoint doesn't send any kind of information about what the item is, except missing items in the response (like .title, which is only in track and playlist responses). So I catch the AttributeError there and switch to returning username instead. --- plugins/soundc.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 plugins/soundc.py diff --git a/plugins/soundc.py b/plugins/soundc.py new file mode 100644 index 0000000..36b6607 --- /dev/null +++ b/plugins/soundc.py @@ -0,0 +1,18 @@ +from util import hook, http, web +import soundcloud +import re + +sc_re = (r'(.*:)//(www.)?(soundcloud.com)(.*)', re.I) + +@hook.regex(*sc_re) +def soundcloud_url(match, bot=None): + api_key = bot.config.get("api_keys", {}).get("soundcloud") + if not api_key: + return "Error: no api key set" + url = match.group(1).split(' ')[-1] + "//" + (match.group(2) if match.group(2) else "") + match.group(3) + match.group(4).split(' ')[0] + client = soundcloud.Client(client_id=api_key) + track = client.get('/resolve', url=url) + try: + return "SoundCloud track: \x02%s\x02 by \x02%s\x02 - \x02%s\x02" % (track.title, track.user['username'], web.isgd(track.permalink_url)) + except: + return "SoundCloud user: \x02%s\x02 - \x02%s\x02" % (track.username, web.isgd(track.permalink_url)) From ff5769d773bdca66c22342efc59a5e5d24d8980a Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Fri, 19 Jul 2013 17:18:09 +0800 Subject: [PATCH 2/3] Update requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9cda528..67fd59c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ BeautifulSoup==3.2.1 lxml==3.1beta1 pyenchant==1.6.5 pydns>=2.3.6 -BeautifulSoup4 \ No newline at end of file +BeautifulSoup4 +soundcloud==0.3.6 From ea3462558eda5cbd5c15a24e3f12a13ef0569446 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Fri, 19 Jul 2013 17:22:06 +0800 Subject: [PATCH 3/3] Update config.py --- core/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/config.py b/core/config.py index e03babe..76884a4 100755 --- a/core/config.py +++ b/core/config.py @@ -34,6 +34,7 @@ if not os.path.exists('config'): "wolframalpha": "", "lastfm": "", "rottentomatoes": "", + "soundcloud": "", "twitter_consumer_key": "", "twitter_consumer_secret": "", "twitter_access_token": "",