Skip to content

Commit

Permalink
Re-enable youtube-dl on macOS plus mpv and IINA (#381)
Browse files Browse the repository at this point in the history
* Determine correct PYTHONPATH for youtube-dl and pass it to mpv subprocess (follows c07206c)
* Homebrew on arm64 has a different prefix
  • Loading branch information
albertosottile committed Jan 23, 2021
1 parent f791fac commit 03cde67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions syncplay/players/mpv.py
Expand Up @@ -590,15 +590,25 @@ def __init__(self, playerController, playerIPCHandler, playerPath, filePath, arg
# 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',
env['PATH'] = '/opt/homebrew/bin:/usr/local/bin:/usr/bin'
ytdl_path = subprocess.check_output(['which', 'youtube-dl'], text=True, env=env).rstrip('\n')
with open(ytdl_path, 'rb') as f:
ytdl_shebang = f.readline()
ytdl_python = ytdl_shebang.decode('utf-8').lstrip('!#').rstrip('\n')
if '/usr/bin/env' in ytdl_python:
python_name = ytdl_python.split(' ')[1]
python_executable = subprocess.check_output(['which', python_name], text=True, env=env).rstrip('\n')
else:
python_executable = ytdl_python
pythonLibs = subprocess.check_output([python_executable, '-E', '-c',
'import sys; print(sys.path)'],
text=True, env=dict())
pythonLibs = ast.literal_eval(pythonLibs)
pythonPath = ':'.join(pythonLibs[1:])
except:
except Exception as e:
pythonPath = None
if pythonPath is not None:
env['PATH'] = '/usr/bin:/usr/local/bin'
env['PATH'] = python_executable + ':' + env['PATH']
env['PYTHONPATH'] = pythonPath
try:
socket = self.mpv_arguments.get('input-ipc-server')
Expand Down
2 changes: 1 addition & 1 deletion syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py
Expand Up @@ -211,7 +211,7 @@ def __init__(self, ipc_socket, mpv_location=None, env=None, **kwargs):
self._start_process(ipc_socket, args, env=env)

def _start_process(self, ipc_socket, args, env):
self.process = subprocess.Popen(args)
self.process = subprocess.Popen(args, env=env)
ipc_exists = False
for _ in range(100): # Give MPV 10 seconds to start.
time.sleep(0.1)
Expand Down

0 comments on commit 03cde67

Please sign in to comment.