[vlc-devel] [PATCH 7/9] lua: scripts: use new playlist/player lua API

Romain Vimont rom1v at videolabs.io
Mon Mar 4 11:53:27 CET 2019


---
 share/lua/extensions/VLSub.lua              |   8 +-
 share/lua/http/js/controllers.js            |   2 +-
 share/lua/http/requests/playlist_jstree.xml |  64 ++----
 share/lua/http/requests/status.xml          |   2 +-
 share/lua/intf/cli.lua                      | 222 ++++++++++++--------
 share/lua/intf/dumpmeta.lua                 |   2 +-
 share/lua/intf/http.lua                     |   9 +-
 share/lua/intf/modules/httprequests.lua     |  76 +++----
 share/lua/modules/common.lua                |  13 +-
 9 files changed, 187 insertions(+), 211 deletions(-)

diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index ee9e5f84a9..dc896b2157 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -347,7 +347,7 @@ function activate()
         return false
   end
 
-  if vlc.input.item() then
+  if vlc.player.item() then
     openSub.getFileInfo()
     openSub.getMovieInfo()
   end
@@ -1215,7 +1215,7 @@ openSub = {
     }
   },
   getInputItem = function()
-    return vlc.item or vlc.input.item()
+    return vlc.item or vlc.player.item()
   end,
   getFileInfo = function()
   -- Get video file path, name, extension from input uri
@@ -1591,9 +1591,9 @@ function dump_zip(url, dir, subfileName)
 end
 
 function add_sub(subPath)
-  if vlc.item or vlc.input.item() then
+  if vlc.item or vlc.player.item() then
     vlc.msg.dbg("[VLsub] Adding subtitle :" .. subPath)
-    return vlc.input.add_subtitle(subPath, true)
+    return vlc.player.add_subtitle(subPath, true)
   end
   return false
 end
diff --git a/share/lua/http/js/controllers.js b/share/lua/http/js/controllers.js
index 7ae3b10b1d..bb40c17923 100644
--- a/share/lua/http/js/controllers.js
+++ b/share/lua/http/js/controllers.js
@@ -518,7 +518,7 @@ $(function () {
             $(this).addClass('ui-state-highlight');
             current_playlist_id = $(this).attr('id').substr(5);
         });
-    }).delegate("#plid_0 li.jstree-leaf a", "click", function (event, data) {
+    }).delegate("li.jstree-leaf a", "click", function (event, data) {
         event.preventDefault();
         current_playlist_id = $(this).parent().attr('id').substr(5);
         sendCommand('command=pl_play&id=' + current_playlist_id);
diff --git a/share/lua/http/requests/playlist_jstree.xml b/share/lua/http/requests/playlist_jstree.xml
index 4281117787..0cdc309f2b 100644
--- a/share/lua/http/requests/playlist_jstree.xml
+++ b/share/lua/http/requests/playlist_jstree.xml
@@ -26,62 +26,22 @@ vim:syntax=lua
 ]] ?>
 <root>
 <?vlc
---[[
-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
---]]
-
-function print_playlist(item)
-    if item.flags.disabled then return end
-    if(item.children) then
+function print_playlist()
+    local current = vlc.playlist.current()
+    local list = vlc.playlist.list()
+    for _, item in ipairs(list) do
         local name = vlc.strings.convert_xml_special_chars(item.name or "")
-        name = name or ""
-        if(name ~= "Undefined") then
-			print('<item id="plid_' ..tostring(item.id).. '" name="' ..tostring(name).. '" ro="' ..(item.flags.ro and "ro" or "rw").. '"><content><name>' ..name.. '</name></content>')
-			for _, child in ipairs(item.children) do
-				print_playlist(child)
-			end
-			print('</item>')
-		else
-			for _, child in ipairs(item.children) do
-				print_playlist(child)
-			end
-		end
-    else
-        local name, path = vlc.strings.convert_xml_special_chars(item.name or "", item.path or "")
-        name = name or ""
-        local current_item_id = vlc.playlist.current()
-        local current = ""
-        -- Is the item the one currently played
-        if(current_item_id ~= nil) then
-            if(current_item_id == item.id) then
-                current = 'current="current"'
-            end
+        local path = item.path or ""
+        print('<item id="plid_' ..tostring(item.id).. '" uri="' ..tostring(path).. '" name="' ..tostring(name).. '" duration="' ..math.floor(item.duration).. '"')
+        if current == item.id then
+            print(' current="current"')
         end
-        print('<item id="plid_' ..tostring(item.id).. '" uri="' ..tostring(path).. '" name="' ..name.. '" ro="' ..(item.flags.ro and "ro" or "rw").. '" duration ="' ..math.floor(item.duration).. '" ' ..current.. ' ><content><name>' ..name.. '</name></content></item>')
+        print('>')
+        print('  <content><name>' ..name.. '</name></content>')
+        print('</item>')
     end
 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)
+print_playlist()
 ?>
 </root>
diff --git a/share/lua/http/requests/status.xml b/share/lua/http/requests/status.xml
index d3e468d798..2d76b6a556 100644
--- a/share/lua/http/requests/status.xml
+++ b/share/lua/http/requests/status.xml
@@ -38,7 +38,7 @@ local statusTable=httprequests.getstatus(false)
 print('<root>\n')
 httprequests.printTableAsXml(statusTable,0)
 
-local item = vlc.input.item()
+local item = vlc.player.item()
 
 --data in the information section is presented in a non-standard way to keep compatibility.
 
diff --git a/share/lua/intf/cli.lua b/share/lua/intf/cli.lua
index 3d85e2601a..58501d10d5 100644
--- a/share/lua/intf/cli.lua
+++ b/share/lua/intf/cli.lua
@@ -211,48 +211,32 @@ function playlist_is_tree( client )
     end
 end
 
+function format_item(item, is_current)
+    local marker = ( item.id == current ) and "*" or " "
+    local str = "|"..marker..tostring(item.id).." - "..
+                    ( item.name or item.path )
+    if item.duration > 0 then
+        str = str.." ("..common.durationtostring(item.duration)..")"
+    end
+    return str
+end
+
 function playlist(name,client,arg)
     local current = vlc.playlist.current()
-    function playlist0(item,prefix)
-        local prefix = prefix or ""
-        if not item.flags.disabled then
-            local marker = ( item.id == current ) and "*" or " "
-            local str = "|"..prefix..marker..tostring(item.id).." - "..
-                            ( item.name or item.path )
-            if item.duration > 0 then
-                str = str.." ("..common.durationtostring(item.duration)..")"
-            end
-            if item.nb_played > 0 then
-                str = str.." [played "..tostring(item.nb_played).." time"
-                if item.nb_played > 1 then
-                    str = str .. "s"
-                end
-                str = str .. "]"
-            end
-            client:append(str)
-        end
-        if item.children then
-            for _, c in ipairs(item.children) do
-                playlist0(c,prefix.."  ")
-            end
-        end
-    end
-    local playlist
-    local tree = playlist_is_tree(client)
-    if tonumber(arg) then
-        playlist = vlc.playlist.get(tonumber(arg), tree)
-    elseif arg then
-        playlist = vlc.playlist.get(arg, tree)
-    else
-        playlist = vlc.playlist.get(nil, tree)
-    end
     client:append("+----[ Playlist - "..name.." ]")
-    if playlist.children then
-        for _, item in ipairs(playlist.children) do
-            playlist0(item)
+    if arg == nil then
+        -- print the whole playlist
+        local list = vlc.playlist.list()
+        for _, item in ipairs(list) do
+            client:append(format_item(item, item.id == current))
         end
     else
-        playlist0(playlist)
+        -- print the requested item (if it exists)
+        local id = tonumber(arg)
+        local item = vlc.playlist.get(id)
+        if item ~= nil then
+            client:append(format_item(item, false))
+        end
     end
     client:append("+----[ End of playlist ]")
 end
@@ -339,12 +323,19 @@ function help(name,client,arg)
 end
 
 function input_info(name,client,id)
-    local item = nil;
+    local pl_item;
 
-    if id then item = (vlc.playlist.get(id) or {})["item"]
-    else       item = vlc.input.item() end
+    if id then
+        pl_item = vlc.playlist.get(id)
+    else
+        pl_item = vlc.playlist.current_item()
+    end
 
-    if(item == nil) then return end
+    if pl_item == nil then
+        return
+    end
+
+    local item = pl_item.item
     local infos = item:info()
     infos["Meta data"] = item:metas()
 
@@ -367,7 +358,7 @@ function input_info(name,client,id)
 end
 
 function stats(name,client)
-    local item = vlc.input.item()
+    local item = vlc.player.item()
     if(item == nil) then return end
     local stats_tab = item:stats()
 
@@ -393,7 +384,7 @@ function stats(name,client)
 end
 
 function playlist_status(name,client)
-    local item = vlc.input.item()
+    local item = vlc.player.item()
     if(item ~= nil) then
         client:append( "( new input: " .. vlc.strings.decode_uri(item:uri()) .. " )" )
     end
@@ -402,11 +393,11 @@ function playlist_status(name,client)
 end
 
 function is_playing(name,client)
-    if vlc.input.is_playing() then client:append "1" else client:append "0" end
+    if vlc.player.is_playing() then client:append "1" else client:append "0" end
 end
 
 function get_title(name,client)
-    local item = vlc.input.item()
+    local item = vlc.player.item()
     if item then
         client:append(item:name())
     else
@@ -415,7 +406,7 @@ function get_title(name,client)
 end
 
 function get_length(name,client)
-    local item = vlc.input.item()
+    local item = vlc.player.item()
     if item then
         client:append(math.floor(item:duration()))
     else
@@ -429,48 +420,46 @@ function ret_print(foo,start,stop)
     return function(discard,client,...) client:append(start..tostring(foo(...))..stop) end
 end
 
-function get_time(var)
-    return function(name,client)
-        local input = vlc.object.input()
-	if input then
-	    client:append(math.floor(vlc.var.get( input, var ) / 1000000))
-	else
-	    client:append("")
-	end
+function get_time(name,client)
+    if vlc.player.is_playing() then
+        client:append(math.floor(vlc.player.get_time() / 1000000))
+    else
+        client:append("")
     end
 end
 
-function titlechap(name,client,value)
-    local input = vlc.object.input()
-    local var = string.gsub( name, "_.*$", "" )
+function title(name,client,value)
     if value then
-        vlc.var.set( input, var, value )
+        vlc.player.title_goto(value)
     else
-        local item = vlc.var.get( input, var )
-        -- Todo: add item name conversion
-        client:append(item)
+        local idx = vlc.player.get_title_index()
+        client:append(idx)
     end
 end
 
-function titlechap_offset(var,offset)
-    local input = vlc.object.input()
-    vlc.var.set( input, var, vlc.var.get( input, var ) + offset )
-end
-
 function title_next(name,client,value)
-    titlechap_offset('title', 1)
+    vlc.player.title_next()
 end
 
 function title_previous(name,client,value)
-    titlechap_offset('title', -1)
+    vlc.player.title_prev()
+end
+
+function chapter(name,client,value)
+    if value then
+        vlc.player.chapter_goto(value)
+    else
+        local idx = vlc.player.get_chapter_index()
+        client:append(idx)
+    end
 end
 
 function chapter_next(name,client,value)
-    titlechap_offset('chapter', 1)
+    vlc.player.chapter_next()
 end
 
 function chapter_previous(name,client,value)
-    titlechap_offset('chapter', -1)
+    vlc.player.chapter_prev()
 end
 
 function seek(name,client,value)
@@ -485,30 +474,35 @@ function volume(name,client,value)
     end
 end
 
-function rate(name,client,value)
-    local input = vlc.object.input()
-    if name == "rate" then
-        vlc.var.set(input, "rate", common.us_tonumber(value))
-    elseif name == "normal" then
-        vlc.var.set(input,"rate",1)
-    end
+function rate_normal(name, client)
+    vlc.player.set_rate(1)
+end
+
+function rate_faster(name, client)
+    vlc.player.increment_rate()
 end
 
-function rate_var(name,client,value)
-    local playlist = vlc.object.playlist()
-    vlc.var.trigger_callback(playlist,"rate-"..name)
+function rate_slower(name, client)
+    vlc.player.decrement_rate()
+end
+
+function rate(name, client, value)
+    if value then
+        local rate = common.us_tonumber(value)
+        vlc.player.set_rate(rate)
+    else
+        client:append(vlc.player.get_rate())
+    end
 end
 
 function frame(name,client)
-    vlc.var.trigger_callback(vlc.object.input(),"frame-next");
+    vlc.player.next_video_frame()
 end
 
 function listvalue(obj,var)
     return function(client,value)
         local o
-        if obj == "input" then
-            o = vlc.object.input()
-        elseif obj == "aout" then
+        if obj == "aout" then
             o = vlc.object.aout()
         elseif obj == "vout" then
             o = vlc.object.vout()
@@ -529,6 +523,48 @@ function listvalue(obj,var)
     end
 end
 
+function vtrack(name, client, value)
+    if value then
+        vlc.player.toggle_video_track(value)
+    else
+        client:append("+----[ video tracks ]")
+        local tracks = vlc.player.get_video_tracks()
+        for _, track in ipairs(tracks) do
+            local mark = track.selected and "*" or " "
+            client:append("|"..mark..tostring(track.id).." - "..track.name)
+        end
+        client:append("+----[ end of video tracks ]")
+    end
+end
+
+function atrack(name, client, value)
+    if value then
+        vlc.player.toggle_audio_track(value)
+    else
+        client:append("+----[ audio tracks ]")
+        local tracks = vlc.player.get_audio_tracks()
+        for _, track in ipairs(tracks) do
+            local mark = track.selected and "*" or " "
+            client:append("|"..mark..tostring(track.id).." - "..track.name)
+        end
+        client:append("+----[ end of audio tracks ]")
+    end
+end
+
+function strack(name, client, value)
+    if value then
+        vlc.player.toggle_spu_track(value)
+    else
+        client:append("+----[ spu tracks ]")
+        local tracks = vlc.player.get_spu_tracks()
+        for _, track in ipairs(tracks) do
+            local mark = track.selected and "*" or " "
+            client:append("|"..mark..tostring(track.id).." - "..track.name)
+        end
+        client:append("+----[ end of spu tracks ]")
+    end
+end
+
 function hotkey(name, client, value)
     if not value then
         client:append("Please specify a hotkey (ie key-quit or quit)")
@@ -562,10 +598,10 @@ commands_ordered = {
     { "random"; { func = skip2(vlc.playlist.random); args = "[on|off]"; help = "toggle playlist random" } };
     { "clear"; { func = skip2(vlc.playlist.clear); help = "clear the playlist" } };
     { "status"; { func = playlist_status; help = "current playlist status" } };
-    { "title"; { func = titlechap; args = "[X]"; help = "set/get title in current item" } };
+    { "title"; { func = title; args = "[X]"; help = "set/get title in current item" } };
     { "title_n"; { func = title_next; help = "next title in current item" } };
     { "title_p"; { func = title_previous; help = "previous title in current item" } };
-    { "chapter"; { func = titlechap; args = "[X]"; help = "set/get chapter in current item" } };
+    { "chapter"; { func = chapter; args = "[X]"; help = "set/get chapter in current item" } };
     { "chapter_n"; { func = chapter_next; help = "next chapter in current item" } };
     { "chapter_p"; { func = chapter_previous; help = "previous chapter in current item" } };
     { "" };
@@ -573,15 +609,15 @@ commands_ordered = {
     { "pause"; { func = skip2(vlc.playlist.pause); help = "toggle pause" } };
     { "fastforward"; { func = setarg(common.hotkey,"key-jump+extrashort"); help = "set to maximum rate" } };
     { "rewind"; { func = setarg(common.hotkey,"key-jump-extrashort"); help = "set to minimum rate" } };
-    { "faster"; { func = rate_var; help = "faster playing of stream" } };
-    { "slower"; { func = rate_var; help = "slower playing of stream" } };
-    { "normal"; { func = rate; help = "normal playing of stream" } };
+    { "faster"; { func = rate_faster; help = "faster playing of stream" } };
+    { "slower"; { func = rate_slower; help = "slower playing of stream" } };
+    { "normal"; { func = rate_normal; help = "normal playing of stream" } };
     { "rate"; { func = rate; args = "[playback rate]"; help = "set playback rate to value" } };
     { "frame"; { func = frame; help = "play frame by frame" } };
     { "fullscreen"; { func = skip2(vlc.video.fullscreen); args = "[on|off]"; help = "toggle fullscreen"; aliases = { "f", "F" } } };
     { "info"; { func = input_info; args= "[X]"; help = "information about the current stream (or specified id)" } };
     { "stats"; { func = stats; help = "show statistical information" } };
-    { "get_time"; { func = get_time("time"); help = "seconds elapsed since stream's beginning" } };
+    { "get_time"; { func = get_time; help = "seconds elapsed since stream's beginning" } };
     { "is_playing"; { func = is_playing; help = "1 if a stream plays, 0 otherwise" } };
     { "get_title"; { func = get_title; help = "the title of the current stream" } };
     { "get_length"; { func = get_length; help = "the length of the current stream" } };
@@ -591,15 +627,15 @@ commands_ordered = {
     { "voldown"; { func = ret_print(vlc.volume.down,"( audio volume: "," )"); args = "[X]"; help = "lower audio volume X steps" } };
     -- { "adev"; { func = skip(listvalue("aout","audio-device")); args = "[X]"; help = "set/get audio device" } };
     { "achan"; { func = skip(listvalue("aout","stereo-mode")); args = "[X]"; help = "set/get stereo audio output mode" } };
-    { "atrack"; { func = skip(listvalue("input","audio-es")); args = "[X]"; help = "set/get audio track" } };
-    { "vtrack"; { func = skip(listvalue("input","video-es")); args = "[X]"; help = "set/get video track" } };
+    { "atrack"; { func = atrack; args = "[X]"; help = "set/get audio track" } };
+    { "vtrack"; { func = vtrack; args = "[X]"; help = "set/get video track" } };
     { "vratio"; { func = skip(listvalue("vout","aspect-ratio")); args = "[X]"; help = "set/get video aspect ratio" } };
     { "vcrop"; { func = skip(listvalue("vout","crop")); args = "[X]"; help = "set/get video crop"; aliases = { "crop" } } };
     { "vzoom"; { func = skip(listvalue("vout","zoom")); args = "[X]"; help = "set/get video zoom"; aliases = { "zoom" } } };
     { "vdeinterlace"; { func = skip(listvalue("vout","deinterlace")); args = "[X]"; help = "set/get video deinterlace" } };
     { "vdeinterlace_mode"; { func = skip(listvalue("vout","deinterlace-mode")); args = "[X]"; help = "set/get video deinterlace mode" } };
     { "snapshot"; { func = common.snapshot; help = "take video snapshot" } };
-    { "strack"; { func = skip(listvalue("input","spu-es")); args = "[X]"; help = "set/get subtitle track" } };
+    { "strack"; { func = strack; args = "[X]"; help = "set/get subtitle track" } };
     { "hotkey"; { func = hotkey; args = "[hotkey name]"; help = "simulate hotkey press"; adv = true; aliases = { "key" } } };
     { "" };
     { "vlm"; { func = load_vlm; help = "load the VLM" } };
diff --git a/share/lua/intf/dumpmeta.lua b/share/lua/intf/dumpmeta.lua
index 8bada445cc..0d6fd0c67f 100644
--- a/share/lua/intf/dumpmeta.lua
+++ b/share/lua/intf/dumpmeta.lua
@@ -29,7 +29,7 @@ dumpmeta.lua: dump a file's meta data on stdout/stderr
 
 local item
 repeat
-    item = vlc.input.item()
+    item = vlc.player.item()
 until (item and item:is_preparsed())
 
 -- preparsing doesn't always provide all the information we want (like duration)
diff --git a/share/lua/intf/http.lua b/share/lua/intf/http.lua
index 5367ea08c1..fc6d1a3156 100644
--- a/share/lua/intf/http.lua
+++ b/share/lua/intf/http.lua
@@ -156,12 +156,13 @@ function callback_art(data, request, args)
                 num = num()
             end
         end
-        local item
-        if num == nil then
-            item = vlc.input.item()
+        local pl_item
+        if num then
+            pl_item = vlc.playlist.get(num)
         else
-            item = vlc.playlist.get(num).item
+            pl_item = vlc.playlist.current_item()
         end
+        local item = pl_item.item
         local metas = item:metas()
         local filename = vlc.strings.decode_uri(string.gsub(metas["artwork_url"],"file://",""))
         local windowsdrive = string.match(filename, "^/%a:/.+$")  --match windows drive letter
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index ca6716354e..66e0e278ae 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -91,7 +91,7 @@ processcommands = function ()
         --]]
         vlc.playlist.add({{path=vlc.strings.make_uri(input),options=options,name=name,duration=duration}})
     elseif command == "addsubtitle" then
-        vlc.input.add_subtitle (val)
+        vlc.player.add_subtitle(val)
     elseif command == "in_enqueue" then
         vlc.playlist.enqueue({{path=vlc.strings.make_uri(input),options=options,name=name,duration=duration}})
     elseif command == "pl_play" then
@@ -133,15 +133,9 @@ processcommands = function ()
     elseif command == "pl_random" then
         vlc.playlist.random()
     elseif command == "pl_loop" then
-        --if loop is set true, then repeat needs to be set false
-        if vlc.playlist.loop() then
-            vlc.playlist.repeat_("off")
-        end
+        vlc.playlist.loop()
     elseif command == "pl_repeat" then
-        --if repeat is set true, then loop needs to be set false
-        if vlc.playlist.repeat_() then
-            vlc.playlist.loop("off")
-        end
+        vlc.playlist.repeat_()
     elseif command == "pl_sd_add" then
         vlc.sd.add(val)
     elseif command == "pl_sd_remove" then
@@ -159,20 +153,16 @@ processcommands = function ()
     elseif command == "key" then
         common.hotkey("key-"..val)
     elseif command == "audiodelay" then
-        if vlc.object.input() and val then
-            val = common.us_tonumber(val)
-            vlc.var.set(vlc.object.input(),"audio-delay",val * 1000000)
-        end
+        val = common.us_tonumber(val)
+        vlc.player.set_audio_delay(val)
     elseif command == "rate" then
         val = common.us_tonumber(val)
-        if vlc.object.input() and val >= 0 then
-            vlc.var.set(vlc.object.input(),"rate",val)
+        if val >= 0 then
+            vlc.player.set_rate(val)
         end
     elseif command == "subdelay" then
-        if vlc.object.input() then
-            val = common.us_tonumber(val)
-            vlc.var.set(vlc.object.input(),"spu-delay",val * 1000000)
-        end
+        val = common.us_tonumber(val)
+        vlc.player.set_subtitle_delay(val)
     elseif command == "aspectratio" then
         if vlc.object.vout() then
             vlc.var.set(vlc.object.vout(),"aspect-ratio",val)
@@ -188,15 +178,15 @@ processcommands = function ()
     elseif command == "setpreset" then
         vlc.equalizer.setpreset(val)
     elseif command == "title" then
-        vlc.var.set(vlc.object.input(), "title", val)
+        vlc.player.title_goto(val)
     elseif command == "chapter" then
-        vlc.var.set(vlc.object.input(), "chapter", val)
+        vlc.player.chapter_goto(val)
     elseif command == "audio_track" then
-        vlc.var.set(vlc.object.input(), "audio-es", val)
+        vlc.player.toggle_audio_track(val)
     elseif command == "video_track" then
-        vlc.var.set(vlc.object.input(), "video-es", val)
+        vlc.player.toggle_video_track(val)
     elseif command == "subtitle_track" then
-        vlc.var.set(vlc.object.input(), "spu-es", val)
+        vlc.player.toggle_spu_track(val)
     end
 
     local input = nil
@@ -440,8 +430,7 @@ end
 getstatus = function (includecategories)
 
 
-    local input = vlc.object.input()
-    local item = vlc.input.item()
+    local item = vlc.player.item()
     local playlist = vlc.object.playlist()
     local vout = vlc.object.vout()
     local aout = vlc.object.aout()
@@ -453,21 +442,12 @@ getstatus = function (includecategories)
     s.version=vlc.misc.version()
     s.volume=vlc.volume.get()
 
-    if input then
-        s.time=math.floor(vlc.var.get(input,"time") / 1000000)
-        s.position=vlc.var.get(input,"position")
-        s.currentplid=vlc.playlist.current()
-        s.audiodelay=vlc.var.get(input,"audio-delay") / 1000000
-        s.rate=vlc.var.get(input,"rate")
-        s.subtitledelay=vlc.var.get(input,"spu-delay") / 1000000
-    else
-        s.time=0
-        s.position=0
-        s.currentplid=-1
-        s.audiodelay=0
-        s.rate=1
-        s.subtitledelay=0
-    end
+    s.time = vlc.player.get_time() / 1000000
+    s.position = vlc.player.get_position()
+    s.currentplid = vlc.playlist.current()
+    s.audiodelay = vlc.player.get_audio_delay()
+    s.rate = vlc.player.get_rate()
+    s.subtitledelay = vlc.player.get_subtitle_delay()
 
     if item then
         s.length=math.floor(item:duration())
@@ -502,9 +482,9 @@ getstatus = function (includecategories)
     s.videoeffects.gamma=round(vlc.config.get("gamma"),2)
 
     s.state=vlc.playlist.status()
-    s.random=vlc.var.get(playlist,"random")
-    s.loop=vlc.var.get(playlist,"loop")
-    s["repeat"]=vlc.var.get(playlist,"repeat")
+    s.random = vlc.playlist.get_random()
+    s.loop = vlc.playlist.get_loop()
+    s["repeat"] = vlc.playlist.get_repeat()
 
     s.equalizer={}
     s.equalizer.preamp=round(vlc.equalizer.preampget(),2)
@@ -538,11 +518,11 @@ getstatus = function (includecategories)
             s.stats[tag]=v
         end
 
-        s.information.chapter=vlc.var.get(input, "chapter")
-        s.information.title=vlc.var.get(input, "title")
+        s.information.chapter = vlc.player.get_chapter_index()
+        s.information.title = vlc.player.get_title_index()
 
-        s.information.chapters=vlc.var.get_list(input, "chapter")
-        s.information.titles=vlc.var.get_list(input, "title")
+        s.information.chapters_count = vlc.player.get_chapters_count()
+        s.information.titles_count = vlc.player.get_titles_count()
 
     end
     return s
diff --git a/share/lua/modules/common.lua b/share/lua/modules/common.lua
index 8c49c713e5..06db2463b9 100644
--- a/share/lua/modules/common.lua
+++ b/share/lua/modules/common.lua
@@ -145,24 +145,23 @@ end
 
 -- seek
 function seek(value)
-    local input = vlc.object.input()
-    if input ~= nil and value ~= nil then
+    if value ~= nil then
         if string.sub(value,-1) == "%" then
             local number = us_tonumber(string.sub(value,1,-2))
             if number ~= nil then
                 local posPercent = number/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)
+                    vlc.player.seek_by_pos_relative(posPercent);
                 else
-                    vlc.var.set(input,"position",posPercent)
+                    vlc.player.seek_by_pos_absolute(posPercent);
                 end
             end
         else
-            local posTime = parsetime(value)
+            local posTime = parsetime(value) * 1000000 -- secs to usecs
             if string.sub(value,1,1) == "+" or string.sub(value,1,1) == "-" then
-                vlc.var.set(input,"time",vlc.var.get(input,"time") + (posTime * 1000000))
+                vlc.player.seek_by_time_relative(posTime)
             else
-                vlc.var.set(input,"time",posTime * 1000000)
+                vlc.player.seek_by_time_absolute(posTime)
             end
         end
     end
-- 
2.20.1



More information about the vlc-devel mailing list