diff --git a/spotify.py b/spotify.py index 13d2a6d..5e6fa51 100644 --- a/spotify.py +++ b/spotify.py @@ -30,8 +30,10 @@ class librespot(object): # We pipe the output to an internal pipe stderr=subprocess.PIPE) self.__state__ = None + self.__preload_state__ = False self.__title__ = None self.__spot_id__ = None + self.__spot_id_preload__ = None self.set_state(False) self.set_title("") @@ -49,29 +51,36 @@ class librespot(object): if output: out_txt = output.decode('utf-8').strip('\n').strip() out_txt = out_txt[out_txt.find(']') + 2:] - logger.debug("librespot output: %s", out_txt) + #logger.debug("librespot output: %s", out_txt) # TODO: Parse for "librespot output: Loading with Spotify URI " if out_txt.lower().startswith("loading"): - self.__spot_id__ = out_txt.split("<")[2][:-1] - logger.info("Track-ID %s identified", self.__spot_id__) - if self.__state__: - self.set_title(self.get_title_by_id()) + logger.debug("librespot: %s", out_txt) + if self.__preload_state__: + self.__spot_id_preload__ = out_txt.split("<")[2][:-1] + logger.info("Upcomming Track-ID %s identified", self.__spot_id__) else: - self.set_title("") + self.__spot_id__ = out_txt.split("<")[2][:-1] + logger.info("Current Track-ID %s identified", self.__spot_id__) if "command=" in out_txt: command = out_txt[out_txt.find('command=') + 8:].strip().lower() logger.debug("librespot command: %s", command) + if command.startswith("preload"): + self.__preload_state__ = True if command.startswith("load"): self.set_state(command.split(',')[2].strip() == 'true') + # + self.__preload_state__ = False + self.__spot_id__ = self.__spot_id_preload__ # - if command in self.ON_CMD: + elif command in self.ON_CMD: self.set_state(True) - if command in self.OFF_CMD: + elif command in self.OFF_CMD: self.set_state(False) - if self.__state__: - self.set_title(self.get_title_by_id()) - else: - self.set_title("") + if self.__state__: + self.set_title(self.get_title_by_id()) + else: + self.set_title("") + def get_title_by_id(self): if self.__spot_id__ is None: