<?xml version="1.0" encoding="utf-8" standalone="yes" ?<?vlc print'>'?>
<?vlc --[[
vim:syntax=lua
<!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
<  playlist.xml: VLC media player web interface
< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
<  Copyright (C) 2005-2006 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.
< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
]] ?>

<?vlc
--[[<node id="0" name="Undefined" ro="ro">]]
function print_playlist(item)
  if item.flags.disabled then return end
  if item.children then
    local name = vlc.strings.convert_xml_special_chars(item.name)
    print("<node id=\""..tostring(item.id).."\" name=\""..name.."\" ro=\""..(item.flags.ro and "ro" or "rw").."\">")
    for _, c in ipairs(item.children) do
      print_playlist(c)
    end
    print("</node>")
  else
    local name, path = vlc.strings.convert_xml_special_chars(item.name,item.path or "")
    print("<leaf id='"..tostring(item.id).."' uri='"..path.."' name='"..name.."' ro='"..(item.flags.ro and "ro" or "rw").."' duration='"..tostring(item.duration).."'/>")
  end
end
function a(t,pre)
  local pre = pre or ""
  for k,v in pairs(t) do
    vlc.msg.err(pre..tostring(k).." : "..tostring(v))
    if type(v) == "table" then
      a(v,pre.."  ")
    end
  end
end
--[[
for cat,pl in pairs(p) do
  print("<node id=\"-1\" name=\""..cat.."\" ro=\"ro\">")
  print_playlist(pl)
  print("</node>")
end
--]]
local p
if _GET["search"] then
  if _GET["search"] ~= "" then
    _G.search_key = _GET["search"]
  else
    _G.search_key = nil
  end
  local key = vlc.strings.decode_uri(_GET["search"])
  p = vlc.playlist.search(key)
else
  p = vlc.playlist.get()
end
-- a(p) Uncomment to debug
print_playlist(p)
?>

<?vlc --[[
</node>
<node id="9" name="Nevermind" ro="rw">
<leaf id="10" current="current" uri="file:///mnt/stuff/media/Nirvana/Nevermind/01 - Smells Like Teen Spirit.mp3" name="Smells Like Teen Spirit" ro="rw" duration="-1"/>
]]?>
