[vlc-commits] commit: LUA HTTP Interface: Implementation of missing seeking funtionality when using status. xml from the lua http interface. (GBX )

git at videolan.org git at videolan.org
Sat Oct 2 11:33:25 CEST 2010


vlc | branch: master | GBX <g.b.x at web.de> | Sat Oct  2 11:28:20 2010 +0200| [20da20364f00d55e60df831918097386ca5e9e03] | committer: Rémi Duraffort 

LUA HTTP Interface: Implementation of missing seeking funtionality when using status.xml from the lua http interface.

Seeking is now possible with relative values instead of just absolute ones.
Also the time format as mentioned in the readme file is now recognized:
[+ or -][<int><H or h>:][<int><M or m or '>:][<int><nothing or S or s or ">]

Signed-off-by: Rémi Duraffort <ivoire at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=20da20364f00d55e60df831918097386ca5e9e03
---

 share/lua/intf/modules/common.lua |   51 ++++++++++++++++++++++++++++++++++---
 1 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/share/lua/intf/modules/common.lua b/share/lua/intf/modules/common.lua
index b3fef02..a6da379 100644
--- a/share/lua/intf/modules/common.lua
+++ b/share/lua/intf/modules/common.lua
@@ -86,13 +86,56 @@ function realpath(path)
     return string.gsub(string.gsub(string.gsub(string.gsub(path,"/%.%./[^/]+","/"),"/[^/]+/%.%./","/"),"/%./","/"),"//","/")
 end
 
+-- parse the time from a string and return the seconds
+-- time format: [+ or -][<int><H or h>:][<int><M or m or '>:][<int><nothing or S or s or ">]
+function parsetime(timestring)
+    local seconds = 0
+    local hourspattern = "(%d+)[hH]"
+    local minutespattern = "(%d+)[mM']"
+    local secondspattern = "(%d+)[sS\"]?$"
+
+    local _, _, hoursmatch = string.find(timestring, hourspattern)
+    if hoursmatch ~= nil then
+        seconds = seconds + tonumber(hoursmatch) * 3600
+    end
+    local _, _, minutesmatch = string.find(timestring, minutespattern)
+    if minutesmatch ~= nil then
+        seconds = seconds + tonumber(minutesmatch) * 60
+    end
+    local _, _, secondsmatch = string.find(timestring, secondspattern)
+    if secondsmatch ~= nil then
+        seconds = seconds + tonumber(secondsmatch)
+    end
+
+    if string.sub(timestring,1,1) == "-" then
+        seconds = seconds * -1
+    end
+
+    return seconds
+end
+
 -- seek
 function seek(value)
     local input = vlc.object.input()
-    if string.sub(value,#value)=="%" then
-        vlc.var.set(input,"position",tonumber(string.sub(value,1,#value-1))/100.)
-    else
-        vlc.var.set(input,"time",tonumber(value))
+    if input ~= nil and value ~= nil then
+        if string.sub(value,-1) == "%" then
+            local number = tonumber(string.sub(value,1,-2))
+            if number ~= nil then
+                local posPercent = tonumber( string.sub(value,1,-2))/100.
+                if string.sub(value,1,1) == "+" or string.sub(value,1,1) == "-" then
+                    vlc.var.set(input,"position",vlc.var.get(input,"position") + posPercent)
+                else
+                    vlc.var.set(input,"position",posPercent)
+                end
+            end
+        else
+            local posTime = parsetime(value)
+            if string.sub(value,1,1) == "+" or string.sub(value,1,1) == "-" then
+                vlc.var.set(input,"time",vlc.var.get(input,"time") + posTime)
+            else
+                vlc.var.set(input,"time",posTime)
+            end
+        end
     end
 end
 



More information about the vlc-commits mailing list