This commit is contained in:
2026-06-28 22:10:55 -07:00
parent d309c3da93
commit c97f3df288
3 changed files with 106 additions and 9 deletions
+51 -5
View File
@@ -4,7 +4,7 @@ local msg = require 'mp.msg'
local M = {}
local MEDEIA_LUA_VERSION = '2026-03-23.1'
local MEDEIA_LUA_VERSION = '2026-06-25.3'
-- Expose a tiny breadcrumb for debugging which script version is loaded.
pcall(mp.set_property, 'user-data/medeia-lua-version', MEDEIA_LUA_VERSION)
@@ -4164,6 +4164,10 @@ function M._build_web_ytdl_raw_options()
if not lower:find('sub%-langs=', 1) then
extra[#extra + 1] = 'sub-langs=[en.*,en,-live_chat]'
end
if not lower:find('sub%-format=', 1) then
-- Prefer chunked subtitle formats over word-by-word JSON tracks.
extra[#extra + 1] = 'sub-format=srt/vtt/best'
end
if #extra == 0 then
return raw ~= '' and raw or nil
@@ -4174,15 +4178,43 @@ function M._build_web_ytdl_raw_options()
return table.concat(extra, ',')
end
function M._apply_web_subtitle_load_defaults(reason)
local target = trim(tostring(mp.get_property('path') or mp.get_property('stream-open-filename') or ''))
if target == '' or not _is_http_url(target) then
function M._prime_web_subtitle_global_defaults(reason)
local raw = M._build_web_ytdl_raw_options()
if not raw or raw == '' then
return false
end
if not _is_ytdlp_url(target) then
pcall(mp.set_property, 'options/ytdl-raw-options', raw)
pcall(mp.set_property, 'ytdl-raw-options', raw)
_lua_log('web-subtitles: primed global ytdl defaults reason=' .. tostring(reason or 'startup'))
return true
end
function M._resolve_web_subtitle_target(preferred_target)
local explicit = trim(tostring(preferred_target or ''))
if explicit ~= '' and _is_http_url(explicit) and _is_ytdlp_url(explicit) then
return explicit
end
local path_target = trim(tostring(mp.get_property('path') or mp.get_property('stream-open-filename') or ''))
if path_target ~= '' and _is_http_url(path_target) and _is_ytdlp_url(path_target) then
return path_target
end
local current = _get_current_web_url()
if current and current ~= '' and _is_http_url(current) and _is_ytdlp_url(current) then
return current
end
return nil
end
function M._apply_web_subtitle_load_defaults(reason, preferred_target)
local target = M._resolve_web_subtitle_target(preferred_target)
if not target then
return false
end
_set_current_web_url(target)
M._prepare_ytdl_format_for_web_load(target, reason or 'on-load')
local raw = M._build_web_ytdl_raw_options()
@@ -4192,6 +4224,8 @@ function M._apply_web_subtitle_load_defaults(reason)
pcall(mp.set_property, 'file-local-options/sub-visibility', 'yes')
pcall(mp.set_property, 'file-local-options/sid', 'auto')
pcall(mp.set_property, 'file-local-options/track-auto-selection', 'yes')
-- Strip ASS positioning/styling for web subtitles to keep lines anchored naturally.
pcall(mp.set_property, 'file-local-options/sub-ass-override', 'strip')
_lua_log('web-subtitles: prepared load defaults reason=' .. tostring(reason or 'on-load') .. ' target=' .. tostring(target))
return true
end
@@ -5554,6 +5588,10 @@ local function _apply_ytdl_format_and_reload(url, fmt)
_lua_log('change-format: setting ytdl format=' .. tostring(fmt))
_skip_next_store_check_url = _normalize_url_for_store_lookup(url)
_set_current_web_url(url)
if _is_ytdlp_url(url) then
M._prime_web_subtitle_global_defaults('change-format')
M._apply_web_subtitle_load_defaults('change-format', url)
end
M._remember_ytdl_download_format(url, fmt)
pcall(mp.set_property, 'options/ytdl-format', tostring(fmt))
pcall(mp.set_property, 'file-local-options/ytdl-format', tostring(fmt))
@@ -6559,6 +6597,10 @@ mp.register_script_message('medios-load-url-event', function(json)
_log_all('INFO', 'Load URL started: ' .. url)
_lua_log('[LOAD-URL] Starting to load: ' .. url)
_set_current_web_url(url)
if _is_ytdlp_url(url) then
M._prime_web_subtitle_global_defaults('load-url')
M._apply_web_subtitle_load_defaults('load-url', url)
end
_pending_format_change = nil
pcall(mp.set_property, 'options/ytdl-format', '')
pcall(mp.set_property, 'file-local-options/ytdl-format', '')
@@ -6756,6 +6798,10 @@ end)
mp.add_timeout(0, function()
pcall(ensure_mpv_ipc_server)
pcall(_lua_log, 'medeia-lua loaded version=' .. MEDEIA_LUA_VERSION)
local ok_subtitle_defaults, subtitle_defaults_err = pcall(M._prime_web_subtitle_global_defaults, 'startup')
if not ok_subtitle_defaults then
_lua_log('web-subtitles: startup defaults failed err=' .. tostring(subtitle_defaults_err))
end
local ok_helper, helper_err = pcall(function()
attempt_start_pipeline_helper_async(function(success)