@hook.command('spotify', 'sptrack')
def spotify(text):
 params = {'q': text.strip()}
 request = requests.get('http://ws.spotify.com/search/1/track.json', params=params)
 if (request.status_code != requests.codes.ok):
  return 'Could not get track information: {}'.format(request.status_code)
 data = request.json()
 try:
  (_type, _id) = data['tracks'][0]['href'].split(':')[1:]
 except IndexError:
  return 'Could not find track.'
 url = web.try_shorten(gateway.format(_type, _id))
 return '\x02{}\x02 by \x02{}\x02 - {}'.format(data['tracks'][0]['name'], data['tracks'][0]['artists'][0]['name'], url)

@ hook . command ( 'spotify' , 'sptrack' ) def spotify ( text ) : params = { 'q' : text . strip ( ) } request = requests . get ( 'http://ws.spotify.com/search/1/track.json' , params = params ) if ( request . status_code != requests . codes . ok ) : return 'Could not get track information: {}' . format ( request . status_code ) data = request . json ( ) try : ( _type , _id ) = data [ 'tracks' ] [ 0 ] [ 'href' ] . split ( ':' ) [ 1 : ] except IndexError : return 'Could not find track.' url = web . try_shorten ( gateway . format ( _type , _id ) ) return '\x02{}\x02 by \x02{}\x02 - {}' . format ( data [ 'tracks' ] [ 0 ] [ 'name' ] , data [ 'tracks' ] [ 0 ] [ 'artists' ] [ 0 ] [ 'name' ] , url )
spotify <song> -- search spotify for <song> .