diff --git a/README.md b/README.md index 33b6061..8c7a0ee 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,6 @@ You may also, of course, just `cat` the files together yourself. See the [`cat_o #### Footnotes -1You _may_ need to add `mpv[.exe]` to your `PATH` (and _will_ have to add `ffmpeg[.exe]` if you want faster generation). +1You _may_ need to add `mpv[.exe]` to your `PATH` (and _will_ have to add `ffmpeg[.exe]` if you want faster generation). Manual lookup of these binaries is attempted on macOS since GUI apps do not inherit user `PATH` on that OS. -2Tested on Linux (Arch), but it _should_ work on Windows/Mac and whatnot as well, if 1 has been taken care of. +2Tested on Linux (Arch, Ubuntu) and macOS, but it _should_ work on Windows and whatnot as well, if 1 has been taken care of. diff --git a/lib/helpers.lua b/lib/helpers.lua index 7645014..349dff4 100644 --- a/lib/helpers.lua +++ b/lib/helpers.lua @@ -119,6 +119,15 @@ function create_directories(path) utils.subprocess(cmd) end +function find_on_paths(name, paths) + for _, path in ipairs(paths) do + if file_exists(path .. name) then + return path .. name + end + end + return nil +end + -- Find an executable in PATH or CWD with the given name function find_executable(name) local delim = ON_WINDOWS and ";" or ":" diff --git a/src/thumbnailer_server.lua b/src/thumbnailer_server.lua index 5b35772..8cb2a81 100644 --- a/src/thumbnailer_server.lua +++ b/src/thumbnailer_server.lua @@ -26,7 +26,13 @@ function create_thumbnail_mpv(file_path, timestamp, size, output_path, options) local log_arg = "--log-file=" .. output_path .. ".log" - local mpv_path = ON_MAC and "/opt/homebrew/bin/mpv" or "mpv" + local mpv_path = nil + if ON_MAC then + local applications_path = "Applications/mpv.app/Contents/MacOS/" + mpv_path = find_on_paths("mpv", { applications_path, os.getenv("HOME") .. applications_path }) + else mpv_path = "mpv" + end + local mpv_command = skip_nil({ mpv_path, @@ -73,7 +79,12 @@ end function create_thumbnail_ffmpeg(file_path, timestamp, size, output_path, options) options = options or {} - local ffmpeg_path = ON_MAC and "/opt/homebrew/bin/ffmpeg" or "ffmpeg" + local ffmpeg_path = nil + if ON_MAC then + ffmpeg_path = find_on_paths("ffmpeg", { "/opt/homebrew/bin/", "/usr/local/bin/", os.getenv("HOME") .. "bin/" }) + else ffmpeg_path = "mpv" + end + local ffmpeg_command = { ffmpeg_path,