Commit 32d59336 authored by Rob Jonson's avatar Rob Jonson Committed by Francois Cartegnie

lua http: update browse command in lua http interface.

Refactor browse command to draw data from central model in httprequests.lua
add proper URI created by VLC's make_uri command to attributes in the browse data.
(this means that clients can simply use the correct URI for browse,open,enqueue commands,
rather than trying to convert paths to URI) accept file uri as input for browse command
(so that clients can completely ignore the path attribute) browse.xml displays data from
the model (fully backward compatible) browse.json provides alternative view of the same data
parent 32a7f895
...@@ -25,24 +25,32 @@ vim:syntax=lua ...@@ -25,24 +25,32 @@ vim:syntax=lua
< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> < - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
]] ?> ]] ?>
<root>
<?vlc <?vlc
local dir = _GET["dir"]
if dir then --package.loaded.httprequests = nil --uncomment to debug changes
if dir == "~" then dir = vlc.misc.homedir() end require "httprequests"
dir = common.realpath(dir.."/")
local d = vlc.net.opendir(dir) httprequests.processcommands()
table.sort(d)
for _,f in pairs(d) do local browseTable=httprequests.getbrowsetable()
if f == ".." or not string.match(f,"^%.") then
local df = common.realpath(dir..f) print('<root>\n')
local s = vlc.net.stat(df)
local path, name = vlc.strings.convert_xml_special_chars( df, f ) --httprequests.printTableAsJson(browseTable.element._array,0)
print("<element")
for k,v in pairs(s) do print(" "..k.."='"..v.."'") end
print(" path='"..path.."' name='"..name.."'/>\n") for i,e in ipairs(browseTable.element._array) do
end print('<element ')
end
for k,v in pairs(e) do
print(" "..k.."='"..v.."'")
end
print('/>')
end end
print('</root>')
?> ?>
</root>
...@@ -354,6 +354,63 @@ playlisttable = function () ...@@ -354,6 +354,63 @@ playlisttable = function ()
return parseplaylist(basePlaylist) return parseplaylist(basePlaylist)
end end
getbrowsetable = function ()
local dir = _GET["dir"]
if dir == nil then dir = "" end
--allow browse to deal with file-style URI's as well as paths
local start=string.sub(dir,0,8)
if start=="file:///" then
dir= string.sub(dir,9)
end
local result={}
result.element={}
result.element._array={}
if dir then
if dir == "~" then dir = vlc.misc.homedir() end
dir = common.realpath(dir.."/")
local d = vlc.net.opendir(dir)
table.sort(d)
--paths are returned as an array of elements
for _,f in pairs(d) do
if f == ".." or not string.match(f,"^%.") then
local df = common.realpath(dir..f)
local s = vlc.net.stat(df)
local path, name = vlc.strings.convert_xml_special_chars( df, f )
local element={}
for k,v in pairs(s) do
element[k]=v
end
element["path"]=path
element["name"]=name
local uri=vlc.strings.make_uri(path)
--windows paths are returned with / separators, but make_uri expects \ for windows and returns nil
if not uri then
--convert failed path to windows format and try again
path=string.gsub(path,"/","\\")
uri=vlc.strings.make_uri(path)
end
element["uri"]=uri
table.insert(result.element._array,element)
end
end
end
return result;
end
getstatus = function (includecategories) getstatus = function (includecategories)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment