From 444cfc4a15b1212865050405fa70dec79757277b Mon Sep 17 00:00:00 2001 From: n loewen Date: Mon, 6 May 2024 15:40:41 -0700 Subject: [PATCH] Working version, if run in a dir that has <=9 mp4s --- mosaic.lua | 98 +++++++++++++++++++++--------------------------------- 1 file changed, 37 insertions(+), 61 deletions(-) diff --git a/mosaic.lua b/mosaic.lua index 62e74a8..ebeb40b 100644 --- a/mosaic.lua +++ b/mosaic.lua @@ -1,64 +1,44 @@ ---os.execute("ffplay -exitonmousedown -x 200 -left 0 -top 0 -noborder -loop 0 darren_crash.mp4 > /dev/null 2>&1 &") ---os.execute("ffplay -exitonmousedown -x 200 -left 200 -top 0 -noborder -loop 0 darren_crash.mp4 > /dev/null 2>&1 &") ----- os.execute("osascript -e 'display dialog \"Close all videos?\" buttons {\"Close all videos\"} default button 1'") +function exec(cmd) + local handle = io.popen(cmd) + local result = handle:read("*a") + handle:close() + result = result:sub(1, #result - 1) -- remove trailing newline + return result +end -local cd_handle = io.popen('pwd') -local cd = cd_handle:read("*a") -cd_handle:close() -print(cd) - -local stat_handle = io.popen('stat -f "%N" *.mp4') -local files = stat_handle:read("*a") -stat_handle:close() -files = string.sub(files, 1, string.len(files) - 1) -- remove trailing newline -print(files) - -function split(s) - local t={} +function linesToTable(s) + local t = {} for x in string.gmatch(s, "([^%s]+)") do table.insert(t, x) end return t end -local filetable = split(files) +local cd = exec("pwd") +-- print("| "..cd.." |") --- for i = 1, #filetable do --- print(i) --- end +local files = exec('stat -f "%N" *.mp4') +-- print("| "..files.." |") +local filetable = linesToTable(files) +for k, file in ipairs(filetable) do + print("k "..k.." v "..file) + filetable[k] = cd.."/"..file + print(filetable[k]) +end +-- FIXME: if #filetable <= 9 then cols = 3 rows = 3 end -screen_width = 500 +-- FIXME: +screen_width = 1000 aspect_ratio = 1.5 video_width = screen_width // cols -- "floor division" returns an integer -video_height = video_width * aspect_ratio - -print() - ---[[ -for row = 1, rows do - io.write("row " .. row .." ") - for col = 1, cols do - io.write(" | col: " .. col .. " ") - x = (col * video_width) - video_width - io.write("x pos: " .. x .. " ") - y = (row * video_height) - video_height - print( col - 1 ) - file = filetable[1] - -- os.execute(string.format("ffplay -exitonmousedown -x %d -left %d -top %d -noborder -loop 0 %s &", video_width, x, y, file)) - -- os.execute(string.format("open -a 'QuickTime Player' %s", "/Users/n/Downloads/vlc-mosaic/darren_crash.mp4")) - print("opening "..file) - os.execute(string.format("open -a 'QuickTime Player' %s", file)) - os.execute(string.format("osascript -e 'tell application \"%s\" to set the bounds of the front window to {24, 96, 524, 396}'", "QuickTime Player")) - end - io.write("\n") -end -]] +video_height = video_width // aspect_ratio +window_titlebar_height = 39 current_col = 1 current_row = 1 @@ -66,7 +46,7 @@ for _, file in ipairs(filetable) do print("opening "..file) print(string.format(" col: %s, row: %s", current_col, current_row)) local x1 = (current_col * video_width) - video_width - local y1 = (current_row * video_height) - video_height + local y1 = (current_row * video_height) - video_height + (current_row * window_titlebar_height) - window_titlebar_height local x2 = x1 + video_width local y2 = y1 + video_height local bounds = string.format("{%d, %d, %d, %d}", x1, y1, x2, y2) @@ -74,22 +54,18 @@ for _, file in ipairs(filetable) do print() -- os.execute(string.format("open -a 'QuickTime Player' %s", file)) - local file = file:sub(1, #file) -- remove trailing newline - file = cd .. "/" .. file - print("file: " .. file .. " |") - --- os.execute( --- string.format( --- [[osascript -e ' --- set f to POSIX file "%s" --- tell application "QuickTime Player" --- set theMovie to open file f --- tell theMovie --- set the looping of theMovie to true --- play --- end tell --- end tell' --- ]], file)) + os.execute( + string.format( + [[osascript -e ' + set f to POSIX file "%s" + tell application "QuickTime Player" + set theMovie to open file f + tell theMovie + set the looping of theMovie to true + play + end tell + end tell' + ]], file)) local cmd = string.format("osascript -e 'tell application \"%s\" to set the bounds of the front window to %s'", "QuickTime Player", bounds) print(cmd)