dotfiles2/base/bin/ff2mpv
2022-08-05 22:16:17 -07:00

32 lines
1.1 KiB
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
# Modified from original ff2mpv to use floaty-mpv instead of
# standard mpv.
require "json"
len = $stdin.read(4).unpack1("L")
data = JSON.parse($stdin.read(len))
url = data["url"]
args = %w[--no-terminal]
# HACK(ww): On macOS, graphical applications inherit their path from `launchd`
# rather than the default path list in `/etc/paths`. `launchd` doesn't include
# `/usr/local/bin` 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"] = "/usr/local/bin:#{ENV['PATH']}" if RUBY_PLATFORM =~ /darwin/
pid = nil
if (/darwin/ =~ RUBY_PLATFORM) != nil then
pid = spawn "/Users/flurry/bin/iinado", url, in: :close, out: :close, err: :close
else
pid = spawn "/home/flurry/bin/floaty-mpv", url, in: :close, out: "/dev/null", err: "/home/flurry/.tmp/fmpv.log"
end
Process.detach pid