diff options
| author | 2016-04-06 13:56:12 +0100 | |
|---|---|---|
| committer | 2016-04-06 13:56:12 +0100 | |
| commit | 7f7a1f6d55cedf587b2070044cd39b858145bc15 (patch) | |
| tree | af455ee43c0341be5651aebec6b4a8d6d2e2f0cc /modules/soundcloud.py | |
| parent | added usage help to a lot of modules, added a verbose option to karma.py. (diff) | |
added spotify.py and soundcloud.py, updated bot.json.example.
Diffstat (limited to 'modules/soundcloud.py')
| -rw-r--r-- | modules/soundcloud.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/modules/soundcloud.py b/modules/soundcloud.py new file mode 100644 index 00000000..9aa15508 --- /dev/null +++ b/modules/soundcloud.py @@ -0,0 +1,34 @@ +#--require-config soundcloud-api-key + +import json, time +import Utils + +URL_SOUNDCLOUD = "http://api.soundcloud.com/tracks" + +class Module(object): + _name = "SoundCloud" + def __init__(self, bot): + self.bot = bot + bot.events.on("received").on("command").on("soundcloud", "sc" + ).hook(self.soundcloud, min_args=1, help="Search SoundCloud") + + def soundcloud(self, event): + page = Utils.get_url(URL_SOUNDCLOUD, get_params={ + "client_id": self.bot.config["soundcloud-api-key"], + "limit": 1, "q": event["args"]}, json=True) + if page: + if page: + page = page[0] + title = page["title"] + user = page["user"]["username"] + duration = time.strftime("%H:%M:%S", time.gmtime(page[ + "duration"]/1000)) + if duration.startswith("00:"): + duration = duration[3:] + link = page["permalink_url"] + event["stdout"].write("%s [%s] (posted by %s) %s" % (title, + duration, user, link)) + else: + event["stderr"].write("No results found") + else: + event["stderr"].write("Failed to load results") |
