]> git.sesse.net Git - vlc/blob - share/lua/http/requests/vlm.xml
Mozilla : use \n
[vlc] / share / lua / http / requests / vlm.xml
1 <?xml version="1.0" encoding="utf-8" standalone="yes" ?<?vlc print '>'
2 --[[
3 vim:syntax=lua
4 <!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
5 <  vlm.xml: VLC media player web interface
6 < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
7 <  Copyright (C) 2005-2006 the VideoLAN team
8 <  $Id$
9
10 <  Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
11
12 <  This program is free software; you can redistribute it and/or modify
13 <  it under the terms of the GNU General Public License as published by
14 <  the Free Software Foundation; either version 2 of the License, or
15 <  (at your option) any later version.
16
17 <  This program is distributed in the hope that it will be useful,
18 <  but WITHOUT ANY WARRANTY; without even the implied warranty of
19 <  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 <  GNU General Public License for more details.
21
22 <  You should have received a copy of the GNU General Public License
23 <  along with this program; if not, write to the Free Software
24 <  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
26 ]]
27
28 local function insert_children(c,t)
29   print(c.children)
30     if c.children then
31       for _, d in ipairs(c.children) do
32         table.insert(t,d.value or d.name)
33         if d.value then
34         print("V"..d.value.."|")
35         end
36         if d.name then
37         print("N"..d.name.."|")
38         end
39       end
40     end
41 end
42 local function print_table(name,t)
43   print("<"..name.."s>")
44   if #t ~= 0 then
45     for _,v in ipairs(t) do
46       print("<"..name..">")
47         print(v)
48       print("</"..name..">")
49     end
50   end
51   print("</"..name.."s>")
52 end
53 local function print_media(m)
54   local name = m.name
55   local type_, enabled, loop, output
56   local inputs = {}
57   local options = {}
58   local instances = {}
59   for _,c in ipairs(m.children) do
60     if c.name=="type" then
61       type_ = c.value
62     elseif c.name=="enabled" then
63       enabled = c.value
64     elseif c.name=="loop" then
65       loop = c.value
66     elseif c.name=="output" then
67       output = c.value
68     elseif c.name=="inputs" then
69       insert_children(c,inputs)
70     elseif c.name=="options" then
71       insert_children(c,options)
72     elseif c.name=="instances" then
73       if c.children then
74         for _, d in ipairs(c.children) do
75           local instance = "<instance "
76           for _,e in ipairs(d.children) do
77             instance = instance .. e.name .. "=\"" .. e.value .. "\" "
78           end
79           instance = instance .. "/>"
80           table.insert(instances,instance)
81         end
82       end
83     end
84   end
85   print("<"..type_.." name=\""..name.."\" enabled=\""..enabled.."\" loop=\""..loop.."\">\n")
86   print("<output>"..output.."</output>\n")
87   print_table("input",inputs)
88   print_table("option",options)
89   print "<instances>\n"
90   if #instances ~= 0 then
91     print(table.concat(instances))
92   end
93   print "</instances>\n"
94   print("</"..type_..">\n")
95 end
96
97 local function print_schedule(m)
98   local name = m.name
99   local enabled, date, period, repeat_ = "", "", "", ""
100   local commands = {}
101   for _,c in ipairs(m.children) do
102     if c.name=="enabled" then
103       enabled = c.value
104     elseif c.name=="date" then
105       date = c.value
106     elseif c.name=="period" then
107       period = c.value
108     elseif c.name=="repeat" then
109       repeat_ = c.value
110     elseif c.name=="commands" then
111       insert_children(c,commands)
112     end
113   end
114   print("<schedule name=\""..name.."\" enabled=\""..enabled.."\" period=\""..period.."\" repeat=\""..repeat_.."\">\n")
115   print_table("command",commands)
116   print("</schedule>\n")
117 end
118
119 local function print_xml(m)
120   print "<vlm>"
121   if m then
122     for _, c in ipairs(m.children) do
123       if c.name=="media" and c.children then
124         for _, d in ipairs(c.children) do
125           print_media(d)
126         end
127       elseif c.name=="schedule" and c.children then
128         for _, d in ipairs(c.children) do
129           print_schedule(d)
130         end
131       end
132     end
133   else
134     print "oops"
135   end
136   print "</vlm>"
137 end
138
139 local function print_msg(m)
140   if not m then return end
141   print("<"..m.name..">\n")
142   if m.children then
143     for _, child in ipairs(m.children) do
144       print_msg(child)
145     end
146   elseif m.value then
147     print(m.value)
148   end
149   print("</"..m.name..">\n")
150 end
151
152 local msg = vlc.vlm.execute_command(vlm,"show")
153 print_xml(msg)
154 --print_msg(msg)
155
156 ?>