explictly use utf8 when talking to mplayer

universal_newlines uses system locale which is ascii on osx unless
LC_CTYPE/LANG is set to utf8, so we need to be explicit about the
encoding we want instead

we also lose line buffering, so we have to explicitly flush
This commit is contained in:
Damien Elmes 2016-07-12 16:55:10 +10:00
parent 8fdda2bb9c
commit 5655448919

View File

@ -94,6 +94,7 @@ class MplayerMonitor(threading.Thread):
if mplayerClear and self.mplayer: if mplayerClear and self.mplayer:
try: try:
self.mplayer.stdin.write("stop\n") self.mplayer.stdin.write("stop\n")
self.mplayer.stdin.flush()
except: except:
# mplayer quit by user (likely video) # mplayer quit by user (likely video)
self.deadPlayers.append(self.mplayer) self.deadPlayers.append(self.mplayer)
@ -111,18 +112,20 @@ class MplayerMonitor(threading.Thread):
continue continue
if mplayerClear: if mplayerClear:
mplayerClear = False mplayerClear = False
extra = "" extra = b""
else: else:
extra = " 1" extra = b" 1"
cmd = 'loadfile "%s"%s\n' % (item, extra) cmd = b'loadfile "%s"%s\n' % (item.encode("utf8"), extra)
try: try:
self.mplayer.stdin.write(cmd) self.mplayer.stdin.write(cmd)
self.mplayer.stdin.flush()
except: except:
# mplayer has quit and needs restarting # mplayer has quit and needs restarting
self.deadPlayers.append(self.mplayer) self.deadPlayers.append(self.mplayer)
self.mplayer = None self.mplayer = None
self.startProcess() self.startProcess()
self.mplayer.stdin.write(cmd) self.mplayer.stdin.write(cmd)
self.mplayer.stdin.flush()
# if we feed mplayer too fast it loses files # if we feed mplayer too fast it loses files
time.sleep(1) time.sleep(1)
# wait() on finished processes. we don't want to block on the # wait() on finished processes. we don't want to block on the
@ -140,6 +143,7 @@ class MplayerMonitor(threading.Thread):
return return
try: try:
self.mplayer.stdin.write("quit\n") self.mplayer.stdin.write("quit\n")
self.mplayer.stdin.flush()
self.deadPlayers.append(self.mplayer) self.deadPlayers.append(self.mplayer)
except: except:
pass pass
@ -154,7 +158,7 @@ class MplayerMonitor(threading.Thread):
self.mplayer = subprocess.Popen( self.mplayer = subprocess.Popen(
cmd, startupinfo=si, stdin=subprocess.PIPE, cmd, startupinfo=si, stdin=subprocess.PIPE,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
universal_newlines=True, bufsize=1, env=env) env=env)
except OSError: except OSError:
mplayerEvt.clear() mplayerEvt.clear()
raise Exception("Did you install mplayer?") raise Exception("Did you install mplayer?")