lua, osc: use properties for chapter/track lists

This commit is contained in:
wm4 2014-02-24 21:54:50 +01:00
parent 4d1575173b
commit 0797babbfa
2 changed files with 5 additions and 82 deletions

View File

@ -726,81 +726,6 @@ static int script_get_time(lua_State *L)
return 1;
}
static int script_get_chapter_list(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
mp_dispatch_lock(mpctx->dispatch);
lua_newtable(L); // list
int num = get_chapter_count(mpctx);
for (int n = 0; n < num; n++) {
double time = chapter_start_time(mpctx, n);
char *name = chapter_display_name(mpctx, n);
lua_newtable(L); // list ch
lua_pushnumber(L, time); // list ch time
lua_setfield(L, -2, "time"); // list ch
lua_pushstring(L, name); // list ch name
lua_setfield(L, -2, "name"); // list ch
lua_pushinteger(L, n + 1); // list ch n1
lua_insert(L, -2); // list n1 ch
lua_settable(L, -3); // list
talloc_free(name);
}
mp_dispatch_unlock(mpctx->dispatch);
return 1;
}
static const char *stream_type(enum stream_type t)
{
switch (t) {
case STREAM_VIDEO: return "video";
case STREAM_AUDIO: return "audio";
case STREAM_SUB: return "sub";
default: return "unknown";
}
}
static int script_get_track_list(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
mp_dispatch_lock(mpctx->dispatch);
lua_newtable(L); // list
for (int n = 0; n < mpctx->num_tracks; n++) {
struct track *track = mpctx->tracks[n];
lua_newtable(L); // list track
lua_pushstring(L, stream_type(track->type));
lua_setfield(L, -2, "type");
lua_pushinteger(L, track->user_tid);
lua_setfield(L, -2, "id");
lua_pushboolean(L, track->default_track);
lua_setfield(L, -2, "default");
lua_pushboolean(L, track->attached_picture);
lua_setfield(L, -2, "attached_picture");
if (track->lang) {
lua_pushstring(L, track->lang);
lua_setfield(L, -2, "language");
}
if (track->title) {
lua_pushstring(L, track->title);
lua_setfield(L, -2, "title");
}
lua_pushboolean(L, track->is_external);
lua_setfield(L, -2, "external");
if (track->external_filename) {
lua_pushstring(L, track->external_filename);
lua_setfield(L, -2, "external_filename");
}
lua_pushboolean(L, track->auto_loaded);
lua_setfield(L, -2, "auto_loaded");
lua_pushinteger(L, n + 1); // list track n1
lua_insert(L, -2); // list n1 track
lua_settable(L, -3); // list
}
mp_dispatch_unlock(mpctx->dispatch);
return 1;
}
static int script_input_define_section(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
@ -933,8 +858,6 @@ static struct fn_entry fn_list[] = {
FN_ENTRY(get_screen_size),
FN_ENTRY(get_mouse_pos),
FN_ENTRY(get_time),
FN_ENTRY(get_chapter_list),
FN_ENTRY(get_track_list),
FN_ENTRY(input_define_section),
FN_ENTRY(input_enable_section),
FN_ENTRY(input_disable_section),

View File

@ -251,7 +251,7 @@ local nicetypes = {video = "Video", audio = "Audio", sub = "Subtitle"}
-- updates the OSC internal playlists, should be run each time the track-layout changes
function update_tracklist()
local tracktable = mp.get_track_list()
local tracktable = mp.get_property_native("track-list", {})
-- by osc_id
tracks_osc = {}
@ -284,7 +284,7 @@ function get_tracklist(type)
for n = 1, #tracks_osc[type] do
local track = tracks_osc[type][n]
local lang, title, selected = "unkown", "", "{\\fscx" .. select_scale .. "\\fscy" .. select_scale .. "}○{\\fscx100\\fscy100}"
if not(track.language == nil) then lang = track.language end
if not(track.lang == nil) then lang = track.lang end
if not(track.title == nil) then title = track.title end
if (track.id == tonumber(mp.get_property(type))) then
selected = "{\\fscx" .. select_scale .. "\\fscy" .. select_scale .. "}●{\\fscx100\\fscy100}"
@ -318,7 +318,7 @@ function set_track(type, next)
show_message(nicetypes[type] .. " Track: none")
else
show_message(nicetypes[type] .. " Track: " .. new_track_osc .. "/" .. #tracks_osc[type]
.. " [" .. (tracks_osc[type][new_track_osc].language or "unkown") .. "] " .. (tracks_osc[type][new_track_osc].title or ""))
.. " [" .. (tracks_osc[type][new_track_osc].lang or "unkown") .. "] " .. (tracks_osc[type][new_track_osc].title or ""))
end
end
@ -804,7 +804,7 @@ function osc_init()
--chapters
-- do we have any?
local metainfo = {}
metainfo.enabled = ((#mp.get_chapter_list()) > 0)
metainfo.enabled = ((#mp.get_property_native("chapter-list", {})) > 0)
--prev
local eventresponder = {}
@ -923,7 +923,7 @@ function osc_init()
duration = tonumber(mp.get_property("length"))
end
local chapters = mp.get_chapter_list()
local chapters = mp.get_property_native("chapter-list", {})
local markers = {}
for n = 1, #chapters do
markers[n] = (chapters[n].time / duration * 100)