1 --[[ This code is public domain (since it really isn't very interesting) ]]--
3 module("common",package.seeall)
5 -- Iterate over a table in the keys' alphabetical order
6 function pairs_sorted(t)
8 for k,_ in pairs(t) do table.insert(s,k) end
11 return function () i = i + 1; return s[i], t[s[i]] end
14 -- Return a function such as skip(foo)(a,b,c) = foo(b,c)
16 return function(discard,...) return foo(...) end
19 -- Return a function such as setarg(foo,a)(b,c) = foo(a,b,c)
20 function setarg(foo,a)
21 return function(...) return foo(a,...) end
26 local id = vlc.misc.action_id( arg )
28 vlc.var.set( vlc.object.libvlc(), "key-action", id )
35 -- Take a video snapshot
37 local vout = vlc.object.find(nil,"vout","anywhere")
38 if not vout then return end
39 vlc.var.set(vout,"video-snapshot",nil)
42 -- Naive (non recursive) table copy
43 function table_copy(t)
45 for i,v in pairs(t) do c[i]=v end
49 -- strip leading and trailing spaces
51 return string.gsub(str, "^%s*(.-)%s*$", "%1")
54 -- print a table (recursively)
55 function table_print(t,prefix)
56 local prefix = prefix or ""
58 print(prefix.."/!\\ nil")
61 for a,b in pairs_sorted(t) do
62 print(prefix..tostring(a),b)
63 if type(b)==type({}) then
64 table_print(b,prefix.."\t")
69 -- print the list of callbacks registered in lua
70 -- useful for debug purposes
71 function print_callbacks()
73 table_print(vlc.callbacks)
76 -- convert a duration (in seconds) to a string
77 function durationtostring(duration)
78 return string.format("%02d:%02d:%02d",
79 math.floor(duration/3600),
80 math.floor(duration/60)%60,
81 math.floor(duration%60))
85 function realpath(path)
86 return string.gsub(string.gsub(string.gsub(string.gsub(path,"/%.%./[^/]+","/"),"/[^/]+/%.%./","/"),"/%./","/"),"//","/")
91 local input = vlc.object.input()
92 if string.sub(value,#value)=="%" then
93 vlc.var.set(input,"position",tonumber(string.sub(value,1,#value-1))/100.)
95 vlc.var.set(input,"time",tonumber(value))
99 function volume(value)
100 if type(value)=="string" and string.sub(value,1,1) == "+" or string.sub(value,1,1) == "-" then
101 vlc.volume.set(vlc.volume.get()+tonumber(value))
103 vlc.volume.set(tostring(value))