Created
March 10, 2011 13:48
-
-
Save TheLinx/864114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lua | |
-- prints the collected duration of all files listed on the command line or stdin | |
-- get filenames | |
if select("#", ...) == 0 then -- nothing on commandline, assume stdin | |
files = {} | |
while true do | |
local s = io.stdin:read("*l") | |
if not s or #s < 0 then break end -- read until ctrl+d or empty line | |
table.insert(files, s) | |
end | |
else | |
files = {...} | |
end | |
local total = 0 | |
for n=1,#files do | |
local fname = files[n] | |
if io.open(fname, "r") then -- if file exists | |
local h, m, s = io.popen(("ffprobe %q 2>&1"):format(fname)):read("*a"):match("Duration: (%d%d):(%d%d):(%d%d)") -- disregard milliseconds | |
total = total + h * 3600 + m * 60 + s | |
end | |
end | |
h = math.floor(total / 3600) | |
m = math.floor((total - h * 3600) / 60) | |
s = total - h * 3600 - m * 60 | |
io.stdout:write(("%02d:%02d:%02d"):format(h, m, s)) -- os.date was working with timezones and shit so I made my own shit for this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment