]> git.sesse.net Git - vlc/commitdiff
lua http: update browse command in lua http interface.
authorRob Jonson <rob@hobbyistsoftware.com>
Mon, 19 Sep 2011 14:37:58 +0000 (15:37 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Sat, 24 Sep 2011 22:14:47 +0000 (00:14 +0200)
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

share/lua/http/requests/browse.xml
share/lua/intf/modules/httprequests.lua

index a192546c03f2915e8997cc0f3b70333688d24b8f..b65d2b283598ae12b5ca803a0b5a0df1b9547119 100644 (file)
@@ -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>
+
index 2054c8e370c65badef92013dfb691a3e00520ef9..131f164db100f7a9587744bbe0526007a9666d37 100644 (file)
@@ -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)