36
37
self.last_read = []
37
38
self.art_regex = re.compile('src=["\'](.*?)["\'].*alt="Product Details"')
38
39
self.file = "%s/Documents/Grooveshark/currentSong.txt" % os.path.expanduser("~")
40
self.last_content = []
41
self.last_mtime = os.stat(self.file)[ST_MTIME]
43
last_mtime = os.stat(self.file)[ST_MTIME]
46
Main loop that calls check_updates and waits for a
53
except KeyboardInterrupt:
46
mtime = os.stat(self.file)[ST_MTIME]
47
if last_mtime < mtime:
49
content = fh.read().split("\t")
51
if last_content != content and len(content) >= 3:
52
last_content = content
53
art = self.get_artwork('"%s" "%s"' % (content[0], content[2]))
54
notify("Now Playing", "%s\nBy %s" % (content[0], content[2]), art)
56
except KeyboardInterrupt:
59
def check_update(self):
61
Checks currentSong.txt for changes, and uses the content to
62
display a play notification.
64
mtime = os.stat(self.file)[ST_MTIME]
65
if self.last_mtime < mtime:
67
content = fh.read().split("\t")
70
# Ignore the status field
71
if len(content) >= 3 and self.last_content[0:3] != content[0:3]:
72
self.last_content = content
73
art = self.get_artwork('"%s" "%s"' % (content[1], content[2]))
74
notify("Now Playing", "%s\nBy %s" % (content[0], content[2]), art)
63
76
def get_artwork(self, query):
78
Attempts to retrieve album artwork based on passed query.
64
80
response = urlopen("http://www.amazon.com/s/ref=nb_ss?url=search-alias=aps&field-keywords=%s" % (quote_plus(query)))
65
81
content = response.read()
66
82
matches = self.art_regex.findall(content)