From ee05804bfa7273528a739a9144eb99112b32dfe8 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Mon, 5 Aug 2024 08:40:42 +0200 Subject: [PATCH] {osc,select}.lua: show playlist entries with trailing / If a playlist entry ends with a slash these scripts only show the basename which is empty. Fix this by stripping trailing slashes so that the last directory component becomes the basename. --- player/lua/osc.lua | 5 ++++- player/lua/select.lua | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 9f54a029f5..4d4407af12 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -544,12 +544,15 @@ local function get_playlist() local message = string.format('Playlist [%d/%d]:\n', pos, count) local show = mp.get_property_native('osd-playlist-entry') + local trailing_slash_pattern = mp.get_property("platform") == "windows" + and "[/\\]+$" or "/+$" for _, v in ipairs(limlist) do local entry = v.title if not entry or show ~= 'title' then entry = v.filename if not entry:find("://") then - entry = select(2, utils.split_path(entry)) + entry = select(2, utils.split_path( + entry:gsub(trailing_slash_pattern, ""))) end end if v.title and show == 'both' then diff --git a/player/lua/select.lua b/player/lua/select.lua index 6b59bc303a..ce990513b7 100644 --- a/player/lua/select.lua +++ b/player/lua/select.lua @@ -29,13 +29,16 @@ mp.add_forced_key_binding(nil, "select-playlist", function () local playlist = {} local default_item local show = mp.get_property_native("osd-playlist-entry") + local trailing_slash_pattern = mp.get_property("platform") == "windows" + and "[/\\]+$" or "/+$" for i, entry in ipairs(mp.get_property_native("playlist")) do playlist[i] = entry.title if not playlist[i] or show ~= "title" then playlist[i] = entry.filename if not playlist[i]:find("://") then - playlist[i] = select(2, utils.split_path(playlist[i])) + playlist[i] = select(2, utils.split_path( + playlist[i]:gsub(trailing_slash_pattern, ""))) end end if entry.title and show == "both" then