diff --git a/syncplay/players/mplayer.py b/syncplay/players/mplayer.py index 69fa0d2..b1baa6b 100755 --- a/syncplay/players/mplayer.py +++ b/syncplay/players/mplayer.py @@ -1,4 +1,5 @@ # coding:utf8 +import ast import os import re import subprocess @@ -10,7 +11,7 @@ import time from syncplay import constants, utils from syncplay.players.basePlayer import BasePlayer from syncplay.messages import getMessage -from syncplay.utils import isWindows +from syncplay.utils import isMacOS, isWindows class MplayerPlayer(BasePlayer): @@ -338,6 +339,20 @@ class MplayerPlayer(BasePlayer): env = os.environ.copy() if 'TERM' in env: del env['TERM'] + # On macOS, youtube-dl requires system python to run. Set the environment + # to allow that version of python to be executed in the mpv subprocess. + if isMacOS(): + try: + pythonLibs = subprocess.check_output(['/usr/bin/python', '-E', '-c', + 'import sys; print(sys.path)'], + text=True, env=dict()) + pythonLibs = ast.literal_eval(pythonLibs) + pythonPath = ':'.join(pythonLibs[1:]) + except: + pythonPath = None + if pythonPath is not None: + env['PATH'] = '/usr/bin:/usr/local/bin' + env['PYTHONPATH'] = pythonPath if filePath: self.__process = subprocess.Popen( call, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT,