-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotifylistener.py
33 lines (28 loc) · 963 Bytes
/
spotifylistener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import functions
import BeautifulSoup
class SpotifyListener:
def call(self, message):
words = message.message.split(":")
if words[0] == "spotify":
message.done = True
return self.spotify_uri(words[1::])
def spotify_uri(self, uri, isHttp=False):
xml = functions.get_markup('http://ws.spotify.com/lookup/1/?uri=spotify:' + ':'.join(uri))
name = xml.findAll('name')
if not isHttp:
http = '\nhttp://open.spotify.com/' + uri[0] + '/' + uri[1]
else:
http = ""
if uri[0] == "track":
artist = name[1].string
title = name[0].string
album = name[2].string
return artist + " - " + title + " (" + album + ")" + http
if uri[0] == "album":
artist = 'Artist: ' + name[1].string + '\n'
album = 'Album: ' + name[0].string + '\n'
released = xml.findAll('released')[0].string + '\n'
return artist + album + released + http
if uri[0] == "artist":
artist = 'Artist: ' + name[0].string + '\n'
return artist + http