Title message improved - preload
This commit is contained in:
parent
3137bbf930
commit
e023c4a06a
33
spotify.py
33
spotify.py
@ -30,8 +30,10 @@ class librespot(object):
|
|||||||
# We pipe the output to an internal pipe
|
# We pipe the output to an internal pipe
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
self.__state__ = None
|
self.__state__ = None
|
||||||
|
self.__preload_state__ = False
|
||||||
self.__title__ = None
|
self.__title__ = None
|
||||||
self.__spot_id__ = None
|
self.__spot_id__ = None
|
||||||
|
self.__spot_id_preload__ = None
|
||||||
self.set_state(False)
|
self.set_state(False)
|
||||||
self.set_title("")
|
self.set_title("")
|
||||||
|
|
||||||
@ -49,29 +51,36 @@ class librespot(object):
|
|||||||
if output:
|
if output:
|
||||||
out_txt = output.decode('utf-8').strip('\n').strip()
|
out_txt = output.decode('utf-8').strip('\n').strip()
|
||||||
out_txt = out_txt[out_txt.find(']') + 2:]
|
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 <Here Ever After> with Spotify URI <spotify:track:0zckHMfaB6vT5o23ZVBLHJ>"
|
# TODO: Parse for "librespot output: Loading <Here Ever After> with Spotify URI <spotify:track:0zckHMfaB6vT5o23ZVBLHJ>"
|
||||||
if out_txt.lower().startswith("loading"):
|
if out_txt.lower().startswith("loading"):
|
||||||
self.__spot_id__ = out_txt.split("<")[2][:-1]
|
logger.debug("librespot: %s", out_txt)
|
||||||
logger.info("Track-ID %s identified", self.__spot_id__)
|
if self.__preload_state__:
|
||||||
if self.__state__:
|
self.__spot_id_preload__ = out_txt.split("<")[2][:-1]
|
||||||
self.set_title(self.get_title_by_id())
|
logger.info("Upcomming Track-ID %s identified", self.__spot_id__)
|
||||||
else:
|
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:
|
if "command=" in out_txt:
|
||||||
command = out_txt[out_txt.find('command=') + 8:].strip().lower()
|
command = out_txt[out_txt.find('command=') + 8:].strip().lower()
|
||||||
logger.debug("librespot command: %s", command)
|
logger.debug("librespot command: %s", command)
|
||||||
|
if command.startswith("preload"):
|
||||||
|
self.__preload_state__ = True
|
||||||
if command.startswith("load"):
|
if command.startswith("load"):
|
||||||
self.set_state(command.split(',')[2].strip() == 'true')
|
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)
|
self.set_state(True)
|
||||||
if command in self.OFF_CMD:
|
elif command in self.OFF_CMD:
|
||||||
self.set_state(False)
|
self.set_state(False)
|
||||||
if self.__state__:
|
if self.__state__:
|
||||||
self.set_title(self.get_title_by_id())
|
self.set_title(self.get_title_by_id())
|
||||||
else:
|
else:
|
||||||
self.set_title("")
|
self.set_title("")
|
||||||
|
|
||||||
|
|
||||||
def get_title_by_id(self):
|
def get_title_by_id(self):
|
||||||
if self.__spot_id__ is None:
|
if self.__spot_id__ is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user