Merge pull request #400 from Syncplay/update-mpv-jsonipc-vendor-code-2

Update mpv json ipc vendor code
This commit is contained in:
Daniel Wróbel 2021-03-19 08:36:05 +01:00 committed by GitHub
commit 77ce05d02d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 33 deletions

View File

@ -112,6 +112,10 @@ class WindowsSocket(threading.Thread):
except EOFError:
if self.quit_callback:
self.quit_callback()
except Exception as ex:
log.error("Pipe connection died.", exc_info=1)
if self.quit_callback:
self.quit_callback()
class UnixSocket(threading.Thread):
"""
@ -159,22 +163,25 @@ class UnixSocket(threading.Thread):
def run(self):
"""Process socket events. Do not run this directly. Use *start*."""
data = b''
while True:
current_data = self.socket.recv(1024)
if current_data == b'':
break
try:
while True:
current_data = self.socket.recv(1024)
if current_data == b'':
break
data += current_data
if data[-1] != 10:
continue
data = data.decode('utf-8', 'ignore').encode('utf-8')
for item in data.split(b'\n'):
if item == b'':
data += current_data
if data[-1] != 10:
continue
json_data = json.loads(item)
self.callback(json_data)
data = b''
data = data.decode('utf-8', 'ignore').encode('utf-8')
for item in data.split(b'\n'):
if item == b'':
continue
json_data = json.loads(item)
self.callback(json_data)
data = b''
except Exception as ex:
log.error("Socket connection died.", exc_info=1)
if self.quit_callback:
self.quit_callback()

View File

@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
setup(
name='python-mpv-jsonipc',
version='1.1.11',
version='1.1.13',
author="Ian Walton",
author_email="iwalton3@gmail.com",
description="Python API to MPV using JSON IPC",