summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-15 18:28:13 +0100
committerwm4 <wm4@nowhere>2020-02-15 18:30:42 +0100
commit29e15e62487b81b79e6fd0b9ff0710dea35f443e (patch)
tree5a0e4be5dd5d620eee5a2f9df8601f71f1f75d6e /player/lua
parente54ebaec5229f9f82bc6b77cef5c5b75b7577487 (diff)
downloadmpv-29e15e62487b81b79e6fd0b9ff0710dea35f443e.tar.bz2
mpv-29e15e62487b81b79e6fd0b9ff0710dea35f443e.tar.xz
ytdl_hook.lua: delay load subtitles
Uses the infrastructure added in the previous commits. This is admittedly a bit weird (constructing EDL URLs and such). But on the other hand, adding this as "first class" mechanism directly to the sub-add command or so would increase weirdness and unexpected behavior in other places, or at least that's what I think. To reduce confusion, this goes through the effort of mapping the webvtt codec, so it's shown "properly" in the codec list. Without this it would show "null", but still work. In particular, any non-webvtt codecs should still work if libavcodec supports it. Not sure if I should remove the --all-subs hack from the code. But I guess it does no harm.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/ytdl_hook.lua14
1 files changed, 12 insertions, 2 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua
index 7e77eb01ba..8822299671 100644
--- a/player/lua/ytdl_hook.lua
+++ b/player/lua/ytdl_hook.lua
@@ -29,6 +29,11 @@ local safe_protos = Set {
"data"
}
+-- Codec name as reported by youtube-dl mapped to mpv internal codec names.
+local map_codec_to_mpv = {
+ ["vtt"] = "webvtt",
+}
+
local function exec(args)
local ret = mp.command_native({name = "subprocess",
args = args,
@@ -386,8 +391,13 @@ local function add_single_video(json)
end
if not (sub == nil) then
- mp.commandv("sub-add", sub,
- "auto", sub_info.ext, lang)
+ local edl = "edl://!no_clip;!delay_open,media_type=sub"
+ local codec = map_codec_to_mpv[sub_info.ext]
+ if codec then
+ edl = edl .. ",codec=" .. codec
+ end
+ edl = edl .. ";" .. edl_escape(sub)
+ mp.commandv("sub-add", edl, "auto", sub_info.ext, lang)
else
msg.verbose("No subtitle data/url for ["..lang.."]")
end