Got the Spotify plugin working \o/
This commit is contained in:
parent
ee405a9a4d
commit
6538541ec7
1 changed files with 7 additions and 16 deletions
|
@ -4,23 +4,14 @@ import spotimeta
|
||||||
|
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
|
||||||
spotify_re = (r'(open\.spotify\.com/(track|album|artist|user)'
|
gateway = 'http://open.spotify.com/{}/{}' # http spotify gw address
|
||||||
'([a-zA-Z0-9]+{22})', re.I)
|
spotify_re = (r'(open\.spotify\.com\/(track|album|artist|user)\/'
|
||||||
|
'([a-zA-Z0-9]+))', re.I)
|
||||||
gateway = 'http://ws.spotify.com/lookup/1/' # http spotify gw address
|
|
||||||
|
|
||||||
spotify_track_res = ( re.compile(r'spotify:(?P<type>\w+):(?P<track_id>\w{22})'),
|
|
||||||
re.compile(r'http://open.spotify.com/(?P<type>\w+)/(?P<track_id>\w{22})') )
|
|
||||||
|
|
||||||
def get_spotify_ids(s):
|
|
||||||
for r in spotify_track_res:
|
|
||||||
for type, track in r.findall(s):
|
|
||||||
yield type, track
|
|
||||||
|
|
||||||
@hook.regex(*spotify_re)
|
@hook.regex(*spotify_re)
|
||||||
def spotify_url(match):
|
def spotify_url(match):
|
||||||
for type, spotify_id in get_spotify_ids(match):
|
spotify_type = match.group(2)
|
||||||
url = '%s?uri=spotify:%s:%s' %(gateway, type, spotify_id)
|
spotify_id = match.group(3)
|
||||||
|
url = gateway.format(spotify_type, spotify_id)
|
||||||
track = spotimeta.lookup(url)
|
track = spotimeta.lookup(url)
|
||||||
out = track["result"]["artist"]["name"], "-", track["result"]["name"]
|
return "{} - {}".format(track["result"]["artist"]["name"], track["result"]["name"])
|
||||||
return out
|
|
Reference in a new issue