From 6538541ec791d7f80f559bdfc1bff0fc9595c79c Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Wed, 6 Feb 2013 19:16:13 +1300 Subject: [PATCH] Got the Spotify plugin working \o/ --- plugins/spotify.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/plugins/spotify.py b/plugins/spotify.py index 7212e51..33bf83f 100644 --- a/plugins/spotify.py +++ b/plugins/spotify.py @@ -4,23 +4,14 @@ import spotimeta from util import hook, http -spotify_re = (r'(open\.spotify\.com/(track|album|artist|user)' - '([a-zA-Z0-9]+{22})', re.I) - -gateway = 'http://ws.spotify.com/lookup/1/' # http spotify gw address - -spotify_track_res = ( re.compile(r'spotify:(?P\w+):(?P\w{22})'), - re.compile(r'http://open.spotify.com/(?P\w+)/(?P\w{22})') ) - -def get_spotify_ids(s): - for r in spotify_track_res: - for type, track in r.findall(s): - yield type, track +gateway = 'http://open.spotify.com/{}/{}' # http spotify gw address +spotify_re = (r'(open\.spotify\.com\/(track|album|artist|user)\/' + '([a-zA-Z0-9]+))', re.I) @hook.regex(*spotify_re) def spotify_url(match): - for type, spotify_id in get_spotify_ids(match): - url = '%s?uri=spotify:%s:%s' %(gateway, type, spotify_id) + spotify_type = match.group(2) + spotify_id = match.group(3) + url = gateway.format(spotify_type, spotify_id) track = spotimeta.lookup(url) - out = track["result"]["artist"]["name"], "-", track["result"]["name"] - return out + return "{} - {}".format(track["result"]["artist"]["name"], track["result"]["name"]) \ No newline at end of file