|
@@ -28,11 +28,7 @@ class librespot(object):
|
28
|
28
|
logger.info("Starting Librespot...")
|
29
|
29
|
self.__state_callback__ = state_callback
|
30
|
30
|
self.__title_callback__ = title_callback
|
31
|
|
- self.__process__ = subprocess.Popen(["librespot", "-v", "--name", config.DEVICE_NAME],
|
32
|
|
- shell=False,
|
33
|
|
- # We pipe the output to an internal pipe
|
34
|
|
- stdout=subprocess.PIPE,
|
35
|
|
- stderr=subprocess.STDOUT)
|
|
31
|
+ self.__start_process__()
|
36
|
32
|
self.__state__ = None
|
37
|
33
|
self.__preload_state__ = False
|
38
|
34
|
self.__title__ = None
|
|
@@ -41,18 +37,27 @@ class librespot(object):
|
41
|
37
|
self.set_state(False)
|
42
|
38
|
self.set_title("")
|
43
|
39
|
|
|
40
|
+ def __start_process__(self):
|
|
41
|
+ self.__process__ = subprocess.Popen(["librespot", "-v", "--name", config.DEVICE_NAME],
|
|
42
|
+ shell=False,
|
|
43
|
+ # We pipe the output to an internal pipe
|
|
44
|
+ stdout=subprocess.PIPE,
|
|
45
|
+ stderr=subprocess.STDOUT)
|
|
46
|
+
|
44
|
47
|
def run(self):
|
45
|
48
|
while True:
|
46
|
49
|
output = self.__process__.stdout.readline()
|
47
|
50
|
# Polling returns None when the program is still running, return_code otherwise
|
48
|
51
|
return_code = self.__process__.poll()
|
49
|
52
|
if return_code is not None:
|
50
|
|
- self.__process__.close()
|
|
53
|
+ #self.__process__.close()
|
51
|
54
|
# Program ended, get exit/return code
|
52
|
|
- raise RuntimeError("Command '{}' finished with exit code {}".format(command, return_code))
|
53
|
|
-
|
|
55
|
+ #raise RuntimeError
|
|
56
|
+ logger.exception(("Command '{}' finished with exit code {}".format(command, return_code)))
|
54
|
57
|
# If the output is not empty, feed it to the function, strip the newline first
|
55
|
|
- if output:
|
|
58
|
+ self.__start_process__()
|
|
59
|
+ output = None
|
|
60
|
+ elif output:
|
56
|
61
|
out_txt = output.decode('utf-8').strip('\n').strip()
|
57
|
62
|
out_txt = out_txt[out_txt.find(']') + 2:]
|
58
|
63
|
#logger.debug("librespot output: %s", out_txt)
|