def updateSongData(self, callback=None):
windowText = GetWindowText(self.windowHandle)
## Don't just endlessly loop if the window handle stops working
## (usually because the window was closed).
if(not windowText):
self.stopScraping()
self.windowHandle = None
raise RuntimeError("No valid " + SPOTIFY + " windows available. Was it closed recently?")
songMatch = SONG_DATA_RE.match(windowText)
## Check to see that the 'Artist - Song' string is in the window's title.
if(songMatch):
song = songMatch.group(1)
artist = songMatch.group(2)
## Check to make sure that the song data is for a new song.
if(self.song != song or self.artist != artist):
self.song = song
self.artist = artist
if(self.shouldGetArt):
self.art = self.captureAlbumArt()
## Callback only when the song has been updated.
if(callback):
if(self._callbackArgCount == 0):
callback()
elif(self._callbackArgCount == 1):
callback(self.getSongDataDict())
else:
self.stopScraping()
alert = "The callback function '{0}' should take 0 or 1 arguments. It current takes {1} arguments."
RuntimeError(alert.format(callback.__name__, self._callbackArgCount))
评论列表
文章目录