Skip to content

Commit

Permalink
Run mpv subprocess with a system PYTHONPATH env on macOS.
Browse files Browse the repository at this point in the history
youtube-dl relies on system python to run on macOS, but system
python cannot be executed in a subprocess created from the frozen
python3 executable. This makes youtube-dl unusable from frozen
versions of Syncplay on macOS. So, the environment of the mpv
subprocess is modified with system PYTHONPATH, allowing the
execution of /usr/bin/python (and hence, of youtube-dl)
from within the subprocess in frozen executables.

Fixes: Syncplay#228
  • Loading branch information
albertosottile committed Mar 14, 2019
1 parent 22eec11 commit 0b8a8a0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion syncplay/players/mplayer.py
@@ -1,4 +1,5 @@
# coding:utf8
import ast
import os
import re
import subprocess
Expand All @@ -10,7 +11,7 @@
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):
Expand Down Expand Up @@ -338,6 +339,20 @@ def __init__(self, playerController, playerPath, filePath, args):
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,
Expand Down

0 comments on commit 0b8a8a0

Please sign in to comment.