Browse Source

Title message improved - preload

master
Dirk Alders 2 years ago
parent
commit
e023c4a06a
1 changed files with 21 additions and 12 deletions
  1. 21
    12
      spotify.py

+ 21
- 12
spotify.py View File

30
                                # We pipe the output to an internal pipe
30
                                # We pipe the output to an internal pipe
31
                                stderr=subprocess.PIPE)
31
                                stderr=subprocess.PIPE)
32
         self.__state__ = None
32
         self.__state__ = None
33
+        self.__preload_state__ = False
33
         self.__title__ = None
34
         self.__title__ = None
34
         self.__spot_id__ = None
35
         self.__spot_id__ = None
36
+        self.__spot_id_preload__ = None
35
         self.set_state(False)
37
         self.set_state(False)
36
         self.set_title("")
38
         self.set_title("")
37
 
39
 
49
             if output:
51
             if output:
50
                 out_txt = output.decode('utf-8').strip('\n').strip()
52
                 out_txt = output.decode('utf-8').strip('\n').strip()
51
                 out_txt = out_txt[out_txt.find(']') + 2:]
53
                 out_txt = out_txt[out_txt.find(']') + 2:]
52
-                logger.debug("librespot output: %s", out_txt)
54
+                #logger.debug("librespot output: %s", out_txt)
53
                 # TODO: Parse for "librespot output: Loading <Here Ever After> with Spotify URI <spotify:track:0zckHMfaB6vT5o23ZVBLHJ>"
55
                 # TODO: Parse for "librespot output: Loading <Here Ever After> with Spotify URI <spotify:track:0zckHMfaB6vT5o23ZVBLHJ>"
54
                 if out_txt.lower().startswith("loading"):
56
                 if out_txt.lower().startswith("loading"):
55
-                    self.__spot_id__ = out_txt.split("<")[2][:-1]
56
-                    logger.info("Track-ID %s identified", self.__spot_id__)
57
-                    if self.__state__:
58
-                        self.set_title(self.get_title_by_id())
57
+                    logger.debug("librespot: %s", out_txt)
58
+                    if self.__preload_state__:
59
+                        self.__spot_id_preload__ = out_txt.split("<")[2][:-1]
60
+                        logger.info("Upcomming Track-ID %s identified", self.__spot_id__)
59
                     else:
61
                     else:
60
-                        self.set_title("")
62
+                        self.__spot_id__ = out_txt.split("<")[2][:-1]
63
+                        logger.info("Current Track-ID %s identified", self.__spot_id__)
61
                 if "command=" in out_txt:
64
                 if "command=" in out_txt:
62
                     command = out_txt[out_txt.find('command=') + 8:].strip().lower()
65
                     command = out_txt[out_txt.find('command=') + 8:].strip().lower()
63
                     logger.debug("librespot command: %s", command)
66
                     logger.debug("librespot command: %s", command)
67
+                    if command.startswith("preload"):
68
+                        self.__preload_state__ = True
64
                     if command.startswith("load"):
69
                     if command.startswith("load"):
65
                         self.set_state(command.split(',')[2].strip() == 'true')
70
                         self.set_state(command.split(',')[2].strip() == 'true')
71
+                        #
72
+                        self.__preload_state__ = False
73
+                        self.__spot_id__ = self.__spot_id_preload__
66
                     #
74
                     #
67
-                    if command in self.ON_CMD:
75
+                    elif command in self.ON_CMD:
68
                         self.set_state(True)
76
                         self.set_state(True)
69
-                    if command in self.OFF_CMD:
77
+                    elif command in self.OFF_CMD:
70
                         self.set_state(False)
78
                         self.set_state(False)
71
-                    if self.__state__:
72
-                        self.set_title(self.get_title_by_id())
73
-                    else:
74
-                        self.set_title("")
79
+                if self.__state__:
80
+                    self.set_title(self.get_title_by_id())
81
+                else:
82
+                    self.set_title("")
83
+
75
 
84
 
76
     def get_title_by_id(self):
85
     def get_title_by_id(self):
77
         if self.__spot_id__ is None:
86
         if self.__spot_id__ is None:

Loading…
Cancel
Save