From 42d1f7f7d6877cd1aabc10fa13ce3b4aae65c855 Mon Sep 17 00:00:00 2001 From: sudacode Date: Sun, 8 Sep 2024 22:12:53 -0700 Subject: [PATCH] fix load_queue command - fix parsing/conversion to table from json list --- mpv-youtube-queue.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mpv-youtube-queue.lua b/mpv-youtube-queue.lua index c5ce052..5ac5ad7 100644 --- a/mpv-youtube-queue.lua +++ b/mpv-youtube-queue.lua @@ -315,7 +315,20 @@ function YouTubeQueue.load_queue() style.error) return false else - for i in result do YouTubeQueue.add_to_queue(i) end + if result.status == 0 then + -- split urls based on commas + local urls = {} + -- Remove the brackets from json list + local l = result.stdout:sub(2, -3) + local item + for turl in l:gmatch('[^,]+') do + item = turl:match("^%s*(.-)%s*$"):gsub('"', "'") + table.insert(urls, item) + end + for _, turl in ipairs(urls) do + YouTubeQueue.add_to_queue(turl) + end + end end end) end