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.
This commit is contained in:
wm4 2020-08-12 20:16:13 +02:00
parent 69c6b244a1
commit 5dcfe32ff2
1 changed files with 7 additions and 1 deletions

View File

@ -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