Working version, if run in a dir that has <=9 mp4s

This commit is contained in:
n loewen 2024-05-06 15:40:41 -07:00
parent dd5aa34d51
commit 444cfc4a15
1 changed files with 37 additions and 61 deletions

View File

@ -1,19 +1,12 @@
--os.execute("ffplay -exitonmousedown -x 200 -left 0 -top 0 -noborder -loop 0 darren_crash.mp4 > /dev/null 2>&1 &") function exec(cmd)
--os.execute("ffplay -exitonmousedown -x 200 -left 200 -top 0 -noborder -loop 0 darren_crash.mp4 > /dev/null 2>&1 &") local handle = io.popen(cmd)
---- os.execute("osascript -e 'display dialog \"Close all videos?\" buttons {\"Close all videos\"} default button 1'") 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') function linesToTable(s)
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 = {} local t = {}
for x in string.gmatch(s, "([^%s]+)") do for x in string.gmatch(s, "([^%s]+)") do
table.insert(t, x) table.insert(t, x)
@ -21,44 +14,31 @@ function split(s)
return t return t
end end
local filetable = split(files) local cd = exec("pwd")
-- print("| "..cd.." |")
-- for i = 1, #filetable do local files = exec('stat -f "%N" *.mp4')
-- print(i) -- print("| "..files.." |")
-- end
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 if #filetable <= 9 then
cols = 3 cols = 3
rows = 3 rows = 3
end end
screen_width = 500 -- FIXME:
screen_width = 1000
aspect_ratio = 1.5 aspect_ratio = 1.5
video_width = screen_width // cols -- "floor division" returns an integer video_width = screen_width // cols -- "floor division" returns an integer
video_height = video_width * aspect_ratio video_height = video_width // aspect_ratio
window_titlebar_height = 39
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
]]
current_col = 1 current_col = 1
current_row = 1 current_row = 1
@ -66,7 +46,7 @@ for _, file in ipairs(filetable) do
print("opening "..file) print("opening "..file)
print(string.format(" col: %s, row: %s", current_col, current_row)) print(string.format(" col: %s, row: %s", current_col, current_row))
local x1 = (current_col * video_width) - video_width 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 x2 = x1 + video_width
local y2 = y1 + video_height local y2 = y1 + video_height
local bounds = string.format("{%d, %d, %d, %d}", x1, y1, x2, y2) local bounds = string.format("{%d, %d, %d, %d}", x1, y1, x2, y2)
@ -74,22 +54,18 @@ for _, file in ipairs(filetable) do
print() print()
-- os.execute(string.format("open -a 'QuickTime Player' %s", file)) -- os.execute(string.format("open -a 'QuickTime Player' %s", file))
local file = file:sub(1, #file) -- remove trailing newline os.execute(
file = cd .. "/" .. file string.format(
print("file: " .. file .. " |") [[osascript -e '
set f to POSIX file "%s"
-- os.execute( tell application "QuickTime Player"
-- string.format( set theMovie to open file f
-- [[osascript -e ' tell theMovie
-- set f to POSIX file "%s" set the looping of theMovie to true
-- tell application "QuickTime Player" play
-- set theMovie to open file f end tell
-- tell theMovie end tell'
-- set the looping of theMovie to true ]], file))
-- 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) local cmd = string.format("osascript -e 'tell application \"%s\" to set the bounds of the front window to %s'", "QuickTime Player", bounds)
print(cmd) print(cmd)