⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc.lua

📁 VLC Player Source Code
💻 LUA
📖 第 1 页 / 共 2 页
字号:
--[==========================================================================[ rc.lua: remote control module for VLC--[==========================================================================[ Copyright (C) 2007 the VideoLAN team $Id$ Authors: Antoine Cellerier <dionoea at videolan dot org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.--]==========================================================================]description=[============================================================================[ Remote control interface for VLC This is a modules/control/rc.c look alike (with a bunch of new features)  Use on local term:    vlc -I luarc Use on tcp connection:    vlc -I luarc --lua-config "rc={host='localhost:4212'}" Use on multiple hosts (term + 2 tcp ports):    vlc -I luarc --lua-config "rc={hosts={'*console','localhost:4212','localhost:5678'}}"  Note:    -I luarc is an alias for -I lua --lua-intf rc Configuration options setable throught the --lua-config option are:    * hosts: A list of hosts to listen on.    * host: A host to listen on. (won't be used if `hosts' is set) The following can be set using the --lua-config option or in the interface itself using the `set' command:    * prompt: The prompt.    * welcome: The welcome message.    * width: The default terminal width (used to format text).    * autocompletion: When issuing an unknown command, print a list of                      possible commands to autocomplete with. (0 to disable,                      1 to enable).    * autoalias: If autocompletion returns only one possibility, use it                 (0 to disable, 1 to enable).    * flatplaylist: 0 to disable, 1 to enable.]============================================================================]require("common")skip = common.skipskip2 = function(foo) return skip(skip(foo)) endsetarg = common.setargstrip = common.strip--[[ Setup default environement ]]env = { prompt = "> ";        width = 70;        autocompletion = 1;        autoalias = 1;        welcome = "Remote control interface initialized. Type `help' for help.";        flatplaylist = 0;      }--[[ Import custom environement variables from the command line config (if possible) ]]for k,v in pairs(env) do    if config[k] then        if type(env[k]) == type(config[k]) then            env[k] = config[k]            vlc.msg.dbg("set environement variable `"..k.."' to "..tonumber(env[k]))        else            vlc.msg.err("environement variable `"..k.."' should be of type "..type(env[k])..". config value will be discarded.")        end    endend--[[ Command functions ]]function set_env(name,client,value)    if value then        local var,val = split_input(value)        if val then            s = string.gsub(val,"\"(.*)\"","%1")            if type(client.env[var])==type(1) then                client.env[var] = tonumber(s)            else                client.env[var] = s            end        else            client:append( tostring(client.env[var]) )        end    else        for e,v in common.pairs_sorted(client.env) do            client:append(e.."="..v)        end    endendfunction save_env(name,client,value)    env = common.table_copy(client.env)endfunction alias(client,value)    if value then        local var,val = split_input(value)        if commands[var] and type(commands[var]) ~= type("") then            client:append("Error: cannot use a primary command as an alias name")        else            if commands[val] then                commands[var]=val            else                client:append("Error: unknown primary command `"..val.."'.")            end        end    else        for c,v in common.pairs_sorted(commands) do            if type(v)==type("") then                client:append(c.."="..v)            end        end    endendfunction fixme(name,client)    client:append( "FIXME: unimplemented command `"..name.."'." )endfunction logout(name,client)    if client.type == host.client_type.net then        client:send("Bye-bye!")        client:del()    else        client:append("Error: Can't logout of stdin/stdout. Use quit or shutdown to close VLC.")    endendfunction shutdown(name,client)    client:append("Bye-bye!")    h:broadcast("Shutting down.")    vlc.msg.info("Requested shutdown.")    vlc.misc.quit()endfunction quit(name,client)    if client.type == host.client_type.net then        logout(name,client)    else        shutdown(name,client)    endendfunction add(name,client,arg)    -- TODO: parse (and use) options    local f    if name == "enqueue" then        f = vlc.playlist.enqueue    else        f = vlc.playlist.add    end    f({{path=arg}})endfunction playlist_is_tree( client )    if client.env.flatplaylist == 0 then        return true    else        return false    endendfunction playlist(name,client,arg)    function playlist0(item,prefix)        local prefix = prefix or ""        if not item.flags.disabled then            local str = "| "..prefix..tostring(item.id).." - "..item.name            if item.duration > 0 then                str = str.." ("..common.durationtostring(item.duration)..")"            end            if item.nb_played > 0 then                str = str.." [played "..tostring(item.nb_played).." time"                if item.nb_played > 1 then                    str = str .. "s"                end                str = str .. "]"            end            client:append(str)        end        if item.children then            for _, c in ipairs(item.children) do                playlist0(c,prefix.."  ")            end        end    end    local playlist    local tree = playlist_is_tree(client)    if name == "search" then        playlist = vlc.playlist.search(arg or "", tree)    else        if tonumber(arg) then            playlist = vlc.playlist.get(tonumber(arg), tree)        elseif arg then            playlist = vlc.playlist.get(arg, tree)        else            playlist = vlc.playlist.get(nil, tree)        end    end    if name == "search" then        client:append("+----[ Search - "..(arg or "`reset'").." ]")    else        client:append("+----[ Playlist - "..playlist.name.." ]")    end    if playlist.children then        for _, item in ipairs(playlist.children) do            playlist0(item)        end    else        playlist0(playlist)    end    if name == "search" then        client:append("+----[ End of search - Use `search' to reset ]")    else        client:append("+----[ End of playlist ]")    endendfunction playlist_sort(name,client,arg)    if not arg then        client:append("Valid sort keys are: id, title, artist, genre, random, duration, album.")    else        local tree = playlist_is_tree(client)        vlc.playlist.sort(arg,false,tree)    endendfunction services_discovery(name,client,arg)    if arg then        if vlc.sd.is_loaded(arg) then            vlc.sd.remove(arg)            client:append(arg.." disabled.")        else            vlc.sd.add(arg)            client:append(arg.." enabled.")        end    else        local sd = vlc.sd.get_services_names()        client:append("+----[ Services discovery ]")        for n,ln in pairs(sd) do            local status            if vlc.sd.is_loaded(n) then                status = "enabled"            else                status = "disabled"            end            client:append("| "..n..": " .. ln .. " (" .. status .. ")")        end        client:append("+----[ End of services discovery ]")    endendfunction print_text(label,text)    return function(name,client)        client:append("+----[ "..label.." ]")        client:append "|"        for line in string.gmatch(text,".-\r?\n") do            client:append("| "..string.gsub(line,"\r?\n",""))        end        client:append "|"        client:append("+----[ End of "..string.lower(label).." ]")    endendfunction help(name,client,arg)    local width = client.env.width    local long = (name == "longhelp")    local extra = ""    if arg then extra = "matching `" .. arg .. "' " end    client:append("+----[ Remote control commands "..extra.."]")    for i, cmd in ipairs(commands_ordered) do        if (cmd == "" or not commands[cmd].adv or long)        and (not arg or string.match(cmd,arg)) then            local str = "| " .. cmd            if cmd ~= "" then                local val = commands[cmd]                if val.aliases then                    for _,a in ipairs(val.aliases) do                        str = str .. ", " .. a                    end                end                if val.args then str = str .. " " .. val.args end                if #str%2 == 1 then str = str .. " " end                str = str .. string.rep(" .",(width-(#str+#val.help)-1)/2)                str = str .. string.rep(" ",width-#str-#val.help) .. val.help            end            client:append(str)        end    end    client:append("+----[ end of help ]")endfunction input_info(name,client)    local categories = vlc.input_info()    for cat, infos in pairs(categories) do        client:append("+----[ "..cat.." ]")        client:append("|")        for name, value in pairs(infos) do            client:append("| "..name..": "..value)        end        client:append("|")    end    client:append("+----[ end of stream info ]")endfunction playlist_status(name,client)    local a,b,c = vlc.playlist.status()    client:append( "( new input: " .. tostring(a) .. " )" )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -