[vlc-devel] [PATCH] Added delete and move function in playlist for command line interfaces
Tomas Krotil
krotitom at fel.cvut.cz
Tue Apr 30 22:53:32 CEST 2013
From: Tomas Krotil <Tomas Krotil krotitom at fel.cvut.cz>
As in ticket #7699 added functionality for telnet and other terminal
interfaces for deleting and moving items in playlist.
---
modules/lua/libs/playlist.c | 31 ++++++++++++++++++++++++++++++-
share/lua/intf/cli.lua | 16 ++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/modules/lua/libs/playlist.c b/modules/lua/libs/playlist.c
index e9dbfc9..29f5e4b 100644
--- a/modules/lua/libs/playlist.c
+++ b/modules/lua/libs/playlist.c
@@ -141,7 +141,35 @@ static int vlclua_playlist_delete( lua_State * L )
int i_id = luaL_checkint( L, 1 );
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
PL_LOCK;
- int i_ret = playlist_DeleteFromInput(p_playlist, playlist_ItemGetById( p_playlist, i_id ) -> p_input, true );
+ playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
+ if( !p_item )
+ {
+ PL_UNLOCK;
+ return vlclua_push_ret( L, -1 );
+ }
+ int i_ret = playlist_DeleteFromInput( p_playlist, p_item -> p_input, true );
+ PL_UNLOCK;
+ return vlclua_push_ret( L, i_ret );
+}
+
+static int vlclua_playlist_move( lua_State * L )
+{
+ int i_item = luaL_checkint( L, 1 );
+ int i_target = luaL_checkint( L, 2 );
+ playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+ PL_LOCK;
+ playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_item );
+ playlist_item_t *p_target = playlist_ItemGetById( p_playlist, i_target );
+ if( !p_item || !p_target )
+ {
+ PL_UNLOCK;
+ return vlclua_push_ret( L, -1 );
+ }
+ int i_ret;
+ if( p_target->i_children != -1 )
+ i_ret = playlist_TreeMove( p_playlist, p_item, p_target, 0 );
+ else
+ i_ret = playlist_TreeMove( p_playlist, p_item, p_target->p_parent, p_target->i_id - p_target->p_parent->pp_children[0]->i_id + 1 );
PL_UNLOCK;
return vlclua_push_ret( L, i_ret );
}
@@ -389,6 +417,7 @@ static const luaL_Reg vlclua_playlist_reg[] = {
{ "sort", vlclua_playlist_sort },
{ "status", vlclua_playlist_status },
{ "delete", vlclua_playlist_delete },
+ { "move", vlclua_playlist_move },
{ NULL, NULL }
};
diff --git a/share/lua/intf/cli.lua b/share/lua/intf/cli.lua
index 72c971f..27e7efa 100644
--- a/share/lua/intf/cli.lua
+++ b/share/lua/intf/cli.lua
@@ -186,6 +186,20 @@ function add(name,client,arg)
f({{path=uri,options=options}})
end
+function move(name,client,arg)
+ local x,y
+ local tbl = {}
+ for token in string.gmatch(arg, "[^%s]+") do
+ table.insert(tbl,token)
+ end
+ x = tonumber(tbl[1])
+ y = tonumber(tbl[2])
+ local res = vlc.playlist.move(x,y)
+ if res == (-1) then
+ client:append("You should choose valid id.")
+ end
+end
+
function playlist_is_tree( client )
if client.env.flatplaylist == 0 then
return true
@@ -524,6 +538,8 @@ commands_ordered = {
{ "enqueue"; { func = add; args = "XYZ"; help = "queue XYZ to playlist" } };
{ "playlist"; { func = playlist; help = "show items currently in playlist" } };
{ "search"; { func = playlist; args = "[string]"; help = "search for items in playlist (or reset search)" } };
+ { "delete"; { func = skip2(vlc.playlist.delete); args = "[X]"; help = "delete item X in playlist" } };
+ { "move"; { func = move; args = "[X][Y]"; help = "move item X in playlist after Y" } };
{ "sort"; { func = playlist_sort; args = "key"; help = "sort the playlist" } };
{ "sd"; { func = services_discovery; args = "[sd]"; help = "show services discovery or toggle" } };
{ "play"; { func = skip2(vlc.playlist.play); help = "play stream" } };
--
1.7.10.4
More information about the vlc-devel
mailing list