-
Notifications
You must be signed in to change notification settings - Fork 51
/
ff2mpv
executable file
·25 lines (19 loc) · 893 Bytes
/
ff2mpv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env ruby
# frozen_string_literal: true
require "json"
len = $stdin.read(4).unpack1("L")
data = JSON.parse($stdin.read(len))
url = data["url"]
options = data["options"] || []
args = %w[--no-terminal]
args.push(*options)
# HACK(ww): On macOS, graphical applications inherit their path from `launchd`
# rather than the default path list in `/etc/paths`. `launchd` doesn't include
# Homebrew in its default list, which means that any installations
# of MPV and/or youtube-dl under that prefix aren't visible when spawning
# from, say, Firefox. The real fix is to modify `launchd.conf`, but that's
# invasive and maybe not what users want in the general case.
# Hence this nasty hack.
ENV["PATH"] = "/opt/homebrew/bin:/usr/local/bin:#{ENV['PATH']}" if RUBY_PLATFORM =~ /darwin/
pid = spawn "mpv", *args, "--", url, in: :close, out: "/dev/null", err: "/dev/null"
Process.detach pid