aboutsummaryrefslogtreecommitdiff
path: root/modules/spotify.py
diff options
context:
space:
mode:
authorGravatar jesopo2016-04-06 13:56:12 +0100
committerGravatar jesopo2016-04-06 13:56:12 +0100
commit7f7a1f6d55cedf587b2070044cd39b858145bc15 (patch)
treeaf455ee43c0341be5651aebec6b4a8d6d2e2f0cc /modules/spotify.py
parentadded 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/spotify.py')
-rw-r--r--modules/spotify.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/spotify.py b/modules/spotify.py
new file mode 100644
index 00000000..64ba2c2f
--- /dev/null
+++ b/modules/spotify.py
@@ -0,0 +1,26 @@
+import json
+import Utils
+
+URL_SPOTIFY = "https://api.spotify.com/v1/search"
+
+class Module(object):
+ def __init__(self, bot):
+ bot.events.on("received").on("command").on("spotify").hook(
+ self.spotify, help="Search for a track on spotify",
+ min_args=1)
+
+ def spotify(self, event):
+ page = Utils.get_url(URL_SPOTIFY, get_params={"type": "track",
+ "limit": 1, "q": event["args"]}, json=True)
+ if page:
+ if len(page["tracks"]["items"]):
+ item = page["tracks"]["items"][0]
+ title = item["name"]
+ artist_name = item["artists"][0]["name"]
+ url = item["external_urls"]["spotify"]
+ event["stdout"].write("%s (by %s) %s" % (title, artist_name,
+ url))
+ else:
+ event["stderr"].write("No results found")
+ else:
+ event["stderr"].write("Failed to load results")