From 5dcfe32ff21bf560a27db3a75f773f73afdf6dcf Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 12 Aug 2020 20:16:13 +0200 Subject: ytdl_hook: sort subtitle list by language The subtitle list is returned in randomized order, because a table (i.e. JSON object) is used. To make the order stable across repeated invocations, sort it by language. --- player/lua/ytdl_hook.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 7ee1dc3145..929e379a89 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -577,7 +577,13 @@ local function add_single_video(json) -- add subtitles if not (json.requested_subtitles == nil) then - for lang, sub_info in pairs(json.requested_subtitles) do + local subs = {} + for lang, info in pairs(json.requested_subtitles) do + subs[#subs + 1] = {lang = lang or "-", info = info} + end + table.sort(subs, function(a, b) return a.lang < b.lang end) + for _, e in ipairs(subs) do + local lang, sub_info = e.lang, e.info msg.verbose("adding subtitle ["..lang.."]") local sub = nil -- cgit v1.2.3