@@ -42,14 +42,15 @@ class WindowsSocket(threading.Thread):
42
42
Data is automatically encoded and decoded as JSON. The callback
43
43
function will be called for each inbound message.
44
44
"""
45
- def __init__ (self , ipc_socket , callback = None ):
45
+ def __init__ (self , ipc_socket , callback = None , quit_callback = None ):
46
46
"""Create the wrapper.
47
47
48
48
*ipc_socket* is the pipe name. (Not including \\ \\ .\\ pipe\\ )
49
49
*callback(json_data)* is the function for recieving events.
50
50
"""
51
51
ipc_socket = "\\ \\ .\\ pipe\\ " + ipc_socket
52
52
self .callback = callback
53
+ self .quit_callback = quit_callback
53
54
54
55
access = _winapi .GENERIC_READ | _winapi .GENERIC_WRITE
55
56
limit = 5 # Connection may fail at first. Try 5 times.
@@ -102,7 +103,8 @@ def run(self):
102
103
self .callback (json_data )
103
104
data = b''
104
105
except EOFError :
105
- pass
106
+ if self .quit_callback :
107
+ self .quit_callback ()
106
108
107
109
class UnixSocket (threading .Thread ):
108
110
"""
@@ -111,14 +113,15 @@ class UnixSocket(threading.Thread):
111
113
Data is automatically encoded and decoded as JSON. The callback
112
114
function will be called for each inbound message.
113
115
"""
114
- def __init__ (self , ipc_socket , callback = None ):
116
+ def __init__ (self , ipc_socket , callback = None , quit_callback = None ):
115
117
"""Create the wrapper.
116
118
117
119
*ipc_socket* is the path to the socket.
118
120
*callback(json_data)* is the function for recieving events.
119
121
"""
120
122
self .ipc_socket = ipc_socket
121
123
self .callback = callback
124
+ self .quit_callback = quit_callback
122
125
self .socket = socket .socket (socket .AF_UNIX )
123
126
self .socket .connect (self .ipc_socket )
124
127
@@ -157,6 +160,8 @@ def run(self):
157
160
json_data = json .loads (item )
158
161
self .callback (json_data )
159
162
data = b''
163
+ if self .quit_callback :
164
+ self .quit_callback ()
160
165
161
166
class MPVProcess :
162
167
"""
@@ -236,7 +241,7 @@ class MPVInter:
236
241
"""
237
242
Low-level interface to MPV. Does NOT manage an mpv process. (Internal)
238
243
"""
239
- def __init__ (self , ipc_socket , callback = None ):
244
+ def __init__ (self , ipc_socket , callback = None , quit_callback = None ):
240
245
"""Create the wrapper.
241
246
242
247
*ipc_socket* is the path to the Unix/Linux socket or name of the Windows pipe.
@@ -247,10 +252,11 @@ def __init__(self, ipc_socket, callback=None):
247
252
Socket = WindowsSocket
248
253
249
254
self .callback = callback
255
+ self .quit_callback = quit_callback
250
256
if self .callback is None :
251
257
self .callback = lambda event , data : None
252
258
253
- self .socket = Socket (ipc_socket , self .event_callback )
259
+ self .socket = Socket (ipc_socket , self .event_callback , self . quit_callback )
254
260
self .socket .start ()
255
261
self .command_id = 1
256
262
self .rid_lock = threading .Lock ()
@@ -352,7 +358,8 @@ class MPV:
352
358
Please note that if you are using a really old MPV version, a fallback command
353
359
list is used. Not all commands may actually work when this fallback is used.
354
360
"""
355
- def __init__ (self , start_mpv = True , ipc_socket = None , mpv_location = None , log_handler = None , loglevel = None , ** kwargs ):
361
+ def __init__ (self , start_mpv = True , ipc_socket = None , mpv_location = None ,
362
+ log_handler = None , loglevel = None , quit_callback = None , ** kwargs ):
356
363
"""
357
364
Create the interface to MPV and process instance.
358
365
@@ -391,7 +398,7 @@ def __init__(self, start_mpv=True, ipc_socket=None, mpv_location=None, log_handl
391
398
else :
392
399
raise MPVError ("MPV process retry limit reached." )
393
400
394
- self .mpv_inter = MPVInter (ipc_socket , self ._callback )
401
+ self .mpv_inter = MPVInter (ipc_socket , self ._callback , quit_callback )
395
402
self .properties = set (x .replace ("-" , "_" ) for x in self .command ("get_property" , "property-list" ))
396
403
try :
397
404
command_list = [x ["name" ] for x in self .command ("get_property" , "command-list" )]
0 commit comments