ソースを参照

Title message improved - preload

master
Dirk Alders 2年前
コミット
e023c4a06a
1個のファイルの変更21行の追加12行の削除
  1. 21
    12
      spotify.py

+ 21
- 12
spotify.py ファイルの表示

@@ -30,8 +30,10 @@ class librespot(object):
30 30
                                # We pipe the output to an internal pipe
31 31
                                stderr=subprocess.PIPE)
32 32
         self.__state__ = None
33
+        self.__preload_state__ = False
33 34
         self.__title__ = None
34 35
         self.__spot_id__ = None
36
+        self.__spot_id_preload__ = None
35 37
         self.set_state(False)
36 38
         self.set_title("")
37 39
 
@@ -49,29 +51,36 @@ class librespot(object):
49 51
             if output:
50 52
                 out_txt = output.decode('utf-8').strip('\n').strip()
51 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 55
                 # TODO: Parse for "librespot output: Loading <Here Ever After> with Spotify URI <spotify:track:0zckHMfaB6vT5o23ZVBLHJ>"
54 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 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 64
                 if "command=" in out_txt:
62 65
                     command = out_txt[out_txt.find('command=') + 8:].strip().lower()
63 66
                     logger.debug("librespot command: %s", command)
67
+                    if command.startswith("preload"):
68
+                        self.__preload_state__ = True
64 69
                     if command.startswith("load"):
65 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 76
                         self.set_state(True)
69
-                    if command in self.OFF_CMD:
77
+                    elif command in self.OFF_CMD:
70 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 85
     def get_title_by_id(self):
77 86
         if self.__spot_id__ is None:

読み込み中…
キャンセル
保存