31 lines
928 B
Lua
31 lines
928 B
Lua
|
require "lfs"
|
||
|
|
||
|
local open = io.open
|
||
|
|
||
|
local function read_file(path)
|
||
|
local file = open(path, "rb") -- r read mode and b binary mode
|
||
|
if not file then return nil end
|
||
|
local content = file:read "*a" -- *a or *all reads the whole file
|
||
|
file:close()
|
||
|
return content
|
||
|
end
|
||
|
|
||
|
function string.ends(String,End)
|
||
|
return End=='' or string.sub(String,-string.len(End))==End
|
||
|
end
|
||
|
|
||
|
function find_songs(dir)
|
||
|
for file in lfs.dir(dir) do
|
||
|
if string.ends(file, ".ly") then
|
||
|
local ly_content = read_file(dir .. '/' .. file)
|
||
|
local ly_title = string.match(ly_content, 'title = "(.-)"')
|
||
|
|
||
|
tex.sprint('\\unchapter{' .. ly_title .. '}')
|
||
|
tex.sprint('\\includely[staffsize=14]{' .. dir .. '/' .. file .. '}')
|
||
|
tex.sprint('~\\\\')
|
||
|
tex.sprint('~\\\\')
|
||
|
tex.sprint('\\input{' .. dir .. '/' .. file:gsub("%.ly", ".tex") .. '}')
|
||
|
end
|
||
|
end
|
||
|
end
|