First commit

This commit is contained in:
n loewen 2024-05-06 15:10:55 -07:00
commit dd5aa34d51
1 changed files with 102 additions and 0 deletions

102
mosaic.lua Normal file
View File

@ -0,0 +1,102 @@
--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'")
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={}
for x in string.gmatch(s, "([^%s]+)") do
table.insert(t, x)
end
return t
end
local filetable = split(files)
-- for i = 1, #filetable do
-- print(i)
-- end
if #filetable <= 9 then
cols = 3
rows = 3
end
screen_width = 500
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
]]
current_col = 1
current_row = 1
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 x2 = x1 + video_width
local y2 = y1 + video_height
local bounds = string.format("{%d, %d, %d, %d}", x1, y1, x2, y2)
print(" "..bounds)
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))
local cmd = string.format("osascript -e 'tell application \"%s\" to set the bounds of the front window to %s'", "QuickTime Player", bounds)
print(cmd)
os.execute(cmd)
current_col = current_col + 1
if current_col > cols then
current_col = 1
current_row = current_row + 1
end
end