Added two new commands, removed spotimeta

This commit is contained in:
blha303 2013-05-18 21:27:12 +08:00
parent c4e5e91c14
commit 81ccdd2849
3 changed files with 22 additions and 466 deletions

View file

@ -9,6 +9,7 @@ spotify_re = (r'(spotify:(track|album|artist|user):([a-zA-Z0-9]+))', re.I)
http_re = (r'(open\.spotify\.com\/(track|album|artist|user)\/'
'([a-zA-Z0-9]+))', re.I)
@hook.command('sptrack')
@hook.command
def spotify(inp):
"spotify <song> -- Search Spotify for <song>"
@ -20,6 +21,27 @@ def spotify(inp):
url = gateway.format(type, id)
return u"{} by {} - {}".format(data["tracks"][0]["name"], data["tracks"][0]["artists"][0]["name"], url)
@hook.command
def spalbum(inp):
"spalbum <album> -- Search Spotify for <album>"
data = http.get_json("http://ws.spotify.com/search/1/album.json", q=inp.strip())
try:
type, id = data["albums"][0]["href"].split(":")[1:]
except IndexError:
return "Could not find album."
url = gateway.format(type, id)
return u"{} by {} - {}".format(data["albums"][0]["name"], data["albums"][0]["artists"][0]["name"], url)
@hook.command
def spartist(inp):
"spartist <artist> -- Search Spotify for <artist>"
data = http.get_json("http://ws.spotify.com/search/1/artist.json", q=inp.strip())
try:
type, id = data["artists"][0]["href"].split(":")[1:]
except IndexError:
return "Could not find artist."
url = gateway.format(type, id)
return u"{} - {}".format(data["artists"][0]["name"], url)
@hook.regex(*http_re)
@hook.regex(*spotify_re)