spotify_scraper.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:spotify-scraper 作者: naschorr 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号