Added support for spotify:type:id links, added album to track info
This commit is contained in:
parent
9185e7c8d5
commit
1f774a72d1
1 changed files with 12 additions and 11 deletions
|
@ -1,23 +1,24 @@
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
import spotimeta
|
import spotimeta
|
||||||
|
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
|
||||||
gateway = 'http://open.spotify.com/{}/{}' # http spotify gw address
|
gateway = 'http://open.spotify.com/{}/{}' # http spotify gw address
|
||||||
spotify_re = (r'(open\.spotify\.com\/(track|album|artist|user)\/'
|
|
||||||
|
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)
|
'([a-zA-Z0-9]+))', re.I)
|
||||||
|
|
||||||
|
@hook.regex(*http_re)
|
||||||
@hook.regex(*spotify_re)
|
@hook.regex(*spotify_re)
|
||||||
def spotify_url(match):
|
def spotify_url(match):
|
||||||
spotify_type = match.group(2)
|
type = match.group(2)
|
||||||
print spotify_type
|
|
||||||
spotify_id = match.group(3)
|
spotify_id = match.group(3)
|
||||||
url = gateway.format(spotify_type, spotify_id)
|
url = gateway.format(type, spotify_id)
|
||||||
data = spotimeta.lookup(url)
|
data = spotimeta.lookup(url)
|
||||||
if spotify_type == "track":
|
if type == "track":
|
||||||
return "Spotify Track: {} - {}".format(data["result"]["artist"]["name"], data["result"]["name"])
|
return u"Spotify Track: {} by {} from the album {}".format(data["result"]["name"], data["result"]["artist"]["name"], data["result"]["album"]["name"])
|
||||||
elif spotify_type == "artist":
|
elif type == "artist":
|
||||||
return "Spotify Artist: {}".format(data["result"]["name"])
|
return u"Spotify Artist: {}".format(data["result"]["name"])
|
||||||
elif spotify_type == "album":
|
elif type == "album":
|
||||||
return "Spotify Album: {} - {}".format(data["result"]["artist"]["name"], data["result"]["name"])
|
return u"Spotify Album: {} - {}".format(data["result"]["artist"]["name"], data["result"]["name"])
|
Reference in a new issue