📄 rc.lua
字号:
client:append( "( audio volume: " .. tostring(b) .. " )") client:append( "( state " .. tostring(c) .. " )")endfunction is_playing(name,client) if vlc.input.is_playing() then client:append "1" else client:append "0" endendfunction ret_print(foo,start,stop) local start = start or "" local stop = stop or "" return function(discard,client,...) client:append(start..tostring(foo(...))..stop) endendfunction get_time(var,client) return function() local input = vlc.object.input() client:append(math.floor(vlc.var.get( input, var ))) endendfunction titlechap(name,client,value) local input = vlc.object.input() local var = string.gsub( name, "_.*$", "" ) if value then vlc.var.set( input, var, value ) else local item = vlc.var.get( input, var ) -- Todo: add item name conversion client:apped(item) endendfunction titlechap_offset(client,offset) return function(name,value) local input = vlc.object.input() local var = string.gsub( name, "_.*$", "" ) vlc.var.set( input, var, vlc.var.get( input, var )+offset ) endendfunction seek(name,client,value) common.seek(value)endfunction volume(name,client,value) if value then vlc.volume.set(value) else client:append(tostring(vlc.volume.get())) endendfunction rate(name,client) local input = vlc.object.input() if name == "normal" then vlc.var.set(input,"rate",1000) -- FIXME: INPUT_RATE_DEFAULT else vlc.var.set(input,"rate-"..name,nil) endendfunction listvalue(obj,var) return function(client,value) local o = vlc.object.find(nil,obj,"anywhere") if not o then return end if value then vlc.var.set( o, var, value ) else local c = vlc.var.get( o, var ) local v, l = vlc.var.get_list( o, var ) client:append("+----[ "..var.." ]") for i,val in ipairs(v) do local mark = (val==c)and " *" or "" client:append("| "..tostring(val).." - "..tostring(l[i])..mark) end client:append("+----[ end of "..var.." ]") end endendfunction eval(client,val) client:append(loadstring("return "..val)())end--[[ Declare commands, register their callback functions and provide help strings here. Syntax is: "<command name>"; { func = <function>; [ args = "<str>"; ] help = "<str>"; [ adv = <bool>; ] [ aliases = { ["<str>";]* }; ] } ]]commands_ordered = { { "add"; { func = add; args = "XYZ"; help = "add XYZ to playlist" } }; { "enqueue"; { func = add; args = "XYZ"; help = "queue XYZ to playlist" } }; { "playlist"; { func = playlist; help = "show items currently in playlist" } }; { "search"; { func = playlist; args = "[string]"; help = "search for items in playlist (or reset search)" } }; { "sort"; { func = playlist_sort; args = "key"; help = "sort the playlist" } }; { "sd"; { func = services_discovery; args = "[sd]"; help = "show services discovery or toggle" } }; { "play"; { func = skip2(vlc.playlist.play); help = "play stream" } }; { "stop"; { func = skip2(vlc.playlist.stop); help = "stop stream" } }; { "next"; { func = skip2(vlc.playlist.next); help = "next playlist item" } }; { "prev"; { func = skip2(vlc.playlist.prev); help = "previous playlist item" } }; { "goto"; { func = skip2(vlc.playlist.goto); help = "goto item at index" } }; { "repeat"; { func = skip2(vlc.playlist.repeat_); args = "[on|off]"; help = "toggle playlist repeat" } }; { "loop"; { func = skip2(vlc.playlist.loop); args = "[on|off]"; help = "toggle playlist loop" } }; { "random"; { func = skip2(vlc.playlist.random); args = "[on|off]"; help = "toggle playlist random" } }; { "clear"; { func = skip2(vlc.playlist.clear); help = "clear the playlist" } }; { "status"; { func = playlist_status; help = "current playlist status" } }; { "title"; { func = titlechap; args = "[X]"; help = "set/get title in current item" } }; { "title_n"; { func = titlechap_offset(1); help = "next title in current item" } }; { "title_p"; { func = titlechap_offset(-1); help = "previous title in current item" } }; { "chapter"; { func = titlechap; args = "[X]"; help = "set/get chapter in current item" } }; { "chapter_n"; { func = titlechap_offset(1); help = "next chapter in current item" } }; { "chapter_p"; { func = titlechap_offset(-1); help = "previous chapter in current item" } }; { "" }; { "seek"; { func = seek; args = "X"; help = "seek in seconds, for instance `seek 12'" } }; { "pause"; { func = setarg(common.hotkey,"key-play-pause"); help = "toggle pause" } }; { "fastforward"; { func = setarg(common.hotkey,"key-jump+extrashort"); help = "set to maximum rate" } }; { "rewind"; { func = setarg(common.hotkey,"key-jump-extrashort"); help = "set to minimum rate" } }; { "faster"; { func = rate; help = "faster playing of stream" } }; { "slower"; { func = rate; help = "slower playing of stream" } }; { "normal"; { func = rate; help = "normal playing of stream" } }; { "fullscreen"; { func = skip2(vlc.video.fullscreen); args = "[on|off]"; help = "toggle fullscreen"; aliases = { "f", "F" } } }; { "info"; { func = input_info; help = "information about the current stream" } }; { "get_time"; { func = get_time("time"); help = "seconds elapsed since stream's beginning" } }; { "is_playing"; { func = is_playing; help = "1 if a stream plays, 0 otherwise" } }; { "get_title"; { func = ret_print(vlc.input.get_title); help = "the title of the current stream" } }; { "get_length"; { func = get_time("length"); help = "the length of the current stream" } }; { "" }; { "volume"; { func = volume; args = "[X]"; help = "set/get audio volume" } }; { "volup"; { func = ret_print(vlc.volume.up,"( audio volume: "," )"); args = "[X]"; help = "raise audio volume X steps" } }; { "voldown"; { func = ret_print(vlc.volume.down,"( audio volume: "," )"); args = "[X]"; help = "lower audio volume X steps" } }; { "adev"; { func = skip(listvalue("aout","audio-device")); args = "[X]"; help = "set/get audio device" } }; { "achan"; { func = skip(listvalue("aout","audio-channels")); args = "[X]"; help = "set/get audio channels" } }; { "atrack"; { func = skip(listvalue("input","audio-es")); args = "[X]"; help = "set/get audio track" } }; { "vtrack"; { func = skip(listvalue("input","video-es")); args = "[X]"; help = "set/get video track" } }; { "vratio"; { func = skip(listvalue("vout","aspect-ratio")); args = "[X]"; help = "set/get video aspect ratio" } }; { "vcrop"; { func = skip(listvalue("vout","crop")); args = "[X]"; help = "set/get video crop"; aliases = { "crop" } } }; { "vzoom"; { func = skip(listvalue("vout","zoom")); args = "[X]"; help = "set/get video zoom"; aliases = { "zoom" } } }; { "snapshot"; { func = common.snapshot; help = "take video snapshot" } }; { "strack"; { func = skip(listvalue("input","spu-es")); args = "[X]"; help = "set/get subtitles track" } }; { "hotkey"; { func = skip(common.hotkey); args = "[hotkey name]"; help = "simulate hotkey press"; adv = true; aliases = { "key" } } }; { "menu"; { func = fixme; args = "[on|off|up|down|left|right|select]"; help = "use menu"; adv = true } }; { "" }; { "set"; { func = set_env; args = "[var [value]]"; help = "set/get env var"; adv = true } }; { "save_env"; { func = save_env; help = "save env vars (for future clients)"; adv = true } }; { "alias"; { func = skip(alias); args = "[cmd]"; help = "set/get command aliases"; adv = true } }; { "eval"; { func = skip(eval); help = "eval some lua (*debug*)"; adv =true } }; -- FIXME: comment out if you're not debugging { "description"; { func = print_text("Description",description); help = "describe this module" } }; { "license"; { func = print_text("License message",vlc.misc.license()); help = "print VLC's license message"; adv = true } }; { "help"; { func = help; args = "[pattern]"; help = "a help message"; aliases = { "?" } } }; { "longhelp"; { func = help; args = "[pattern]"; help = "a longer help message" } }; { "logout"; { func = logout; help = "exit (if in a socket connection)" } }; { "quit"; { func = quit; help = "quit VLC (or logout if in a socket connection)" } }; { "shutdown"; { func = shutdown; help = "shutdown VLC" } }; }commands = {}for i, cmd in ipairs( commands_ordered ) do if #cmd == 2 then commands[cmd[1]]=cmd[2] if cmd[2].aliases then for _,a in ipairs(cmd[2].aliases) do commands[a]=cmd[1] end end end commands_ordered[i]=cmd[1]end--[[ From now on commands_ordered is a list of the different command names and commands is a associative array indexed by the command name. ]]-- Compute the column width used when printing a the autocompletion listenv.colwidth = 0for c,_ in pairs(commands) do if #c > env.colwidth then env.colwidth = #c endendenv.coldwidth = env.colwidth + 1-- Count unimplemented functionsdo local count = 0 local list = "(" for c,v in pairs(commands) do if v.func == fixme then count = count + 1 if count ~= 1 then list = list.."," end list = list..c end end list = list..")" if count ~= 0 then env.welcome = env.welcome .. "\r\nWarning: "..count.." functions are still unimplemented "..list.."." endend--[[ Utils ]]function split_input(input) local input = strip(input) local s = string.find(input," ") if s then return string.sub(input,0,s-1), strip(string.sub(input,s)) else return input endendfunction call_command(cmd,client,arg) if type(commands[cmd]) == type("") then cmd = commands[cmd] end local ok, msg if arg ~= nil then ok, msg = pcall( commands[cmd].func, cmd, client, arg ) else ok, msg = pcall( commands[cmd].func, cmd, client ) end if not ok then local a = arg or "" if a ~= "" then a = " " .. a end client:append("Error in `"..cmd..a.."' ".. msg) endendfunction call_libvlc_command(cmd,client,arg) local ok, vlcerr, vlcmsg = pcall( vlc.var.libvlc_command, cmd, arg ) if not ok then local a = arg or "" if a ~= "" then a = " " .. a end client:append("Error in `"..cmd..a.."' ".. vlcerr) -- when pcall fails, the 2nd arg is the error message. end return vlcerrend--[[ Setup host ]]require("host")h = host.host()-- No authh.status_callbacks[host.status.password] = function(client) client.env = common.table_copy( env ) client:send( client.env.welcome .. "\r\n") client:switch_status(host.status.read)end-- Print prompt when switching a client's status to `read'h.status_callbacks[host.status.read] = function(client) client:send( client.env.prompt )endh:listen( config.hosts or config.host or "*console" )--[[ The main loop ]]while not vlc.misc.should_die() do h:accept() local write, read = h:select(0.1) for _, client in pairs(write) do local len = client:send() client.buffer = string.sub(client.buffer,len+1) if client.buffer == "" then client:switch_status(host.status.read) end end for _, client in pairs(read) do local input = client:recv(1000) local done = false if string.match(input,"\n$") then client.buffer = string.gsub(client.buffer..input,"\r?\n$","") done = true elseif client.buffer == "" and ((client.type == host.client_type.stdio and input == "") or (client.type == host.client_type.net and input == "\004")) then -- Caught a ^D client.buffer = "quit" done = true else client.buffer = client.buffer .. input end if done then local cmd,arg = split_input(client.buffer) client.buffer = "" client:switch_status(host.status.write) if commands[cmd] then call_command(cmd,client,arg) else if client.type == host.client_type.stdio and call_libvlc_command(cmd,client,arg) == 0 then else local choices = {} if client.env.autocompletion ~= 0 then for v,_ in common.pairs_sorted(commands) do if string.sub(v,0,#cmd)==cmd then table.insert(choices, v) end end end if #choices == 1 and client.env.autoalias ~= 0 then -- client:append("Aliasing to \""..choices[1].."\".") cmd = choices[1] call_command(cmd,client,arg) else client:append("Unknown command `"..cmd.."'. Type `help' for help.") if #choices ~= 0 then client:append("Possible choices are:") local cols = math.floor(client.env.width/(client.env.colwidth+1)) local fmt = "%-"..client.env.colwidth.."s" for i = 1, #choices do choices[i] = string.format(fmt,choices[i]) end for i = 1, #choices, cols do local j = i + cols - 1 if j > #choices then j = #choices end client:append(" "..table.concat(choices," ",i,j)) end end end end end end endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -