From 99ad7feeb036710c9e174cf79944971a7f55ef8c Mon Sep 17 00:00:00 2001 From: Rick Ucker Date: Tue, 4 Apr 2023 19:18:37 -0400 Subject: [PATCH 1/3] Locate mpv, ffmpeg binaries on macOS. --- src/thumbnailer_server.lua | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/thumbnailer_server.lua b/src/thumbnailer_server.lua index 5b35772..ec37e6f 100644 --- a/src/thumbnailer_server.lua +++ b/src/thumbnailer_server.lua @@ -26,7 +26,18 @@ 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 system_app_dir_mpv = "/Applications/mpv.app/Contents/MacOS/mpv" + local user_app_dir_mpv = os.getenv("HOME") .. "/Applications/mpv.app/Contents/MacOS/mpv" + if file_exists(system_app_dir_mpv) then + mpv_path = system_app_dir_mpv + elseif file_exists(user_app_dir_mpv) then + mpv_path = user_app_dir_mpv + end + else mpv_path = "mpv" + end + local mpv_command = skip_nil({ mpv_path, @@ -73,7 +84,18 @@ 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 + local apple_silicon_homebrew_ffmpeg = "/opt/homebrew/bin/mpv" + local intel_homebrew_ffmpeg = "/usr/local/bin/mpv" + if file_exists(apple_silicon_homebrew_ffmpeg) then + ffmpeg_path = apple_silicon_homebrew_mpv + elseif file_exists(intel_homebrew_ffmpeg) then + ffmpeg_path = intel_homebrew_mpv + end + else ffmpeg_path = "mpv" + end + local ffmpeg_command = { ffmpeg_path, From 9216bb543defc493b74de5de1caa71462d95cc5c Mon Sep 17 00:00:00 2001 From: Rick Ucker Date: Fri, 14 Apr 2023 20:25:17 -0400 Subject: [PATCH 2/3] Use helper function to find binaries on macOS. --- lib/helpers.lua | 9 +++++++++ src/thumbnailer_server.lua | 17 +++-------------- 2 files changed, 12 insertions(+), 14 deletions(-) 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 ec37e6f..8cb2a81 100644 --- a/src/thumbnailer_server.lua +++ b/src/thumbnailer_server.lua @@ -28,13 +28,8 @@ function create_thumbnail_mpv(file_path, timestamp, size, output_path, options) local mpv_path = nil if ON_MAC then - local system_app_dir_mpv = "/Applications/mpv.app/Contents/MacOS/mpv" - local user_app_dir_mpv = os.getenv("HOME") .. "/Applications/mpv.app/Contents/MacOS/mpv" - if file_exists(system_app_dir_mpv) then - mpv_path = system_app_dir_mpv - elseif file_exists(user_app_dir_mpv) then - mpv_path = user_app_dir_mpv - end + 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 @@ -86,13 +81,7 @@ function create_thumbnail_ffmpeg(file_path, timestamp, size, output_path, option local ffmpeg_path = nil if ON_MAC then - local apple_silicon_homebrew_ffmpeg = "/opt/homebrew/bin/mpv" - local intel_homebrew_ffmpeg = "/usr/local/bin/mpv" - if file_exists(apple_silicon_homebrew_ffmpeg) then - ffmpeg_path = apple_silicon_homebrew_mpv - elseif file_exists(intel_homebrew_ffmpeg) then - ffmpeg_path = intel_homebrew_mpv - end + ffmpeg_path = find_on_paths("ffmpeg", { "/opt/homebrew/bin/", "/usr/local/bin/", os.getenv("HOME") .. "bin/" }) else ffmpeg_path = "mpv" end From f6c7d9e18024e7edd3f1ba765dfbfc78e8676640 Mon Sep 17 00:00:00 2001 From: Rick Ucker Date: Sat, 22 Apr 2023 16:08:31 -0400 Subject: [PATCH 3/3] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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.