summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-08-12 20:16:13 +0200
committerwm4 <wm4@nowhere>2020-08-12 20:16:13 +0200
commit5dcfe32ff21bf560a27db3a75f773f73afdf6dcf (patch)
tree9134ba3d784014e829bddddfaf846647b5d54022
parent69c6b244a10283f717f9d6d7e3ba8b5a91889015 (diff)
downloadmpv-5dcfe32ff21bf560a27db3a75f773f73afdf6dcf.tar.bz2
mpv-5dcfe32ff21bf560a27db3a75f773f73afdf6dcf.tar.xz
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.
-rw-r--r--player/lua/ytdl_hook.lua8
1 files changed, 7 insertions, 1 deletions
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