spotify_scraper.py 文件源码

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

项目:spotify-scraper 作者: naschorr 项目源码 文件源码
def updateWindowHandle(self, callback=None):
        def getSpotifyWindowHandle(handle, extra):
            pid = GetWindowThreadProcessId(handle)[1]
            processName = psutil.Process(pid).name().lower()
            songMatch = SONG_DATA_RE.match(GetWindowText(handle))
            if(SPOTIFY in processName and songMatch):
                self.windowHandle = handle
                ## Should really be a return False here to kill off the 
                ##  enumeration when a suitable handle is found, but that
                ##  produces a weird 'Things have gone VERY wrong' error.
                ##  See: http://docs.activestate.com/activepython/3.1/pywin32/win32gui__EnumWindows_meth.html

        EnumWindows(getSpotifyWindowHandle, None)

        ## Can't know which window will display the currently playing song
        ##  information unless it's playing music.
        if(not self.windowHandle):
            self._findWindowHandleAttempts += 1
            if(self._findWindowHandleAttempts > ATTEMPT_LIMIT):
                self.stopScraping()
                raise RuntimeError("No valid " + SPOTIFY + " windows available. Is it currently open and running (and not playing any ads)?")
            self.playSong()
            time.sleep(WAIT_TIME)   ## Give Spotify a moment to start playing.
            self.updateWindowHandle()

        if(callback):
            callback()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号