Merge pull request #76 from blha303/patch-6

Add soundcloud autoresponse plugin.
This commit is contained in:
Luke Rogers 2013-07-19 03:49:27 -07:00
commit a8b830af4f
3 changed files with 21 additions and 1 deletions

View file

@ -34,6 +34,7 @@ if not os.path.exists('config'):
"wolframalpha": "",
"lastfm": "",
"rottentomatoes": "",
"soundcloud": "",
"twitter_consumer_key": "",
"twitter_consumer_secret": "",
"twitter_access_token": "",

18
plugins/soundc.py Normal file
View file

@ -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))

View file

@ -2,4 +2,5 @@ BeautifulSoup==3.2.1
lxml==3.1beta1
pyenchant==1.6.5
pydns>=2.3.6
BeautifulSoup4
BeautifulSoup4
soundcloud==0.3.6