[vlc-commits] lua http: update browse command in lua http interface.
Rob Jonson
git at videolan.org
Sun Sep 25 00:15:36 CEST 2011
vlc | branch: master | Rob Jonson <rob at hobbyistsoftware.com> | Mon Sep 19 15:37:58 2011 +0100| [32d59336f5e76ab6cafdf83c087a26a74e78a23f] | committer: 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
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=32d59336f5e76ab6cafdf83c087a26a74e78a23f
---
share/lua/http/requests/browse.xml | 44 ++++++++++++++----------
share/lua/intf/modules/httprequests.lua | 57 +++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 18 deletions(-)
diff --git a/share/lua/http/requests/browse.xml b/share/lua/http/requests/browse.xml
index a192546..b65d2b2 100644
--- a/share/lua/http/requests/browse.xml
+++ b/share/lua/http/requests/browse.xml
@@ -25,24 +25,32 @@ vim:syntax=lua
< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
]] ?>
-<root>
<?vlc
-local dir = _GET["dir"]
-if dir then
- if dir == "~" then dir = vlc.misc.homedir() end
- dir = common.realpath(dir.."/")
- local d = vlc.net.opendir(dir)
- table.sort(d)
- 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 )
- print("<element")
- for k,v in pairs(s) do print(" "..k.."='"..v.."'") end
- print(" path='"..path.."' name='"..name.."'/>\n")
- end
- end
+
+--package.loaded.httprequests = nil --uncomment to debug changes
+require "httprequests"
+
+httprequests.processcommands()
+
+local browseTable=httprequests.getbrowsetable()
+
+print('<root>\n')
+
+--httprequests.printTableAsJson(browseTable.element._array,0)
+
+
+for i,e in ipairs(browseTable.element._array) do
+ print('<element ')
+
+ for k,v in pairs(e) do
+ print(" "..k.."='"..v.."'")
+ end
+
+ print('/>')
end
+
+
+print('</root>')
+
?>
-</root>
+
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index 2054c8e..131f164 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -354,6 +354,63 @@ playlisttable = function ()
return parseplaylist(basePlaylist)
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)
More information about the vlc-commits
mailing list