Enhance Load URL diagnostics with comprehensive logging
- Add [LOAD-URL] prefix to all handler logs for easy filtering - Log each stage of URL processing: parse, validate, direct-load, pipeline - Add close_menu diagnostic logging - Create test_load_url.py script for manual testing - Improve error messages and status feedback This will make it much easier to diagnose why Load URL isn't working.
This commit is contained in:
@@ -2751,57 +2751,66 @@ mp.register_script_message('medios-start-helper', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
mp.register_script_message('medios-load-url-event', function(json)
|
mp.register_script_message('medios-load-url-event', function(json)
|
||||||
_lua_log('Load URL event handler called with: ' .. tostring(json or ''))
|
_lua_log('[LOAD-URL] Event handler called with: ' .. tostring(json or 'nil'))
|
||||||
local ok, event = pcall(utils.parse_json, json)
|
local ok, event = pcall(utils.parse_json, json)
|
||||||
if not ok or type(event) ~= 'table' then
|
if not ok or type(event) ~= 'table' then
|
||||||
_lua_log('Load URL: failed to parse JSON: ' .. tostring(json))
|
_lua_log('[LOAD-URL] Failed to parse JSON: ' .. tostring(json))
|
||||||
mp.osd_message('Failed to parse URL', 2)
|
mp.osd_message('Failed to parse URL', 2)
|
||||||
if ensure_uosc_loaded() then
|
if ensure_uosc_loaded() then
|
||||||
|
_lua_log('[LOAD-URL] Closing menu due to parse error')
|
||||||
mp.commandv('script-message-to', 'uosc', 'close-menu', LOAD_URL_MENU_TYPE)
|
mp.commandv('script-message-to', 'uosc', 'close-menu', LOAD_URL_MENU_TYPE)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
_lua_log('[LOAD-URL] Parsed event: type=' .. tostring(event.type) .. ', query=' .. tostring(event.query))
|
||||||
if event.type ~= 'search' then
|
if event.type ~= 'search' then
|
||||||
_lua_log('Load URL: event type is ' .. tostring(event.type) .. ', expected search')
|
_lua_log('[LOAD-URL] Event type is not search: ' .. tostring(event.type))
|
||||||
if ensure_uosc_loaded() then
|
if ensure_uosc_loaded() then
|
||||||
|
_lua_log('[LOAD-URL] Closing menu due to type mismatch')
|
||||||
mp.commandv('script-message-to', 'uosc', 'close-menu', LOAD_URL_MENU_TYPE)
|
mp.commandv('script-message-to', 'uosc', 'close-menu', LOAD_URL_MENU_TYPE)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local url = trim(tostring(event.query or ''))
|
local url = trim(tostring(event.query or ''))
|
||||||
|
_lua_log('[LOAD-URL] Trimmed URL: "' .. url .. '"')
|
||||||
if url == '' then
|
if url == '' then
|
||||||
|
_lua_log('[LOAD-URL] URL is empty')
|
||||||
mp.osd_message('URL is empty', 2)
|
mp.osd_message('URL is empty', 2)
|
||||||
if ensure_uosc_loaded() then
|
if ensure_uosc_loaded() then
|
||||||
|
_lua_log('[LOAD-URL] Closing menu due to empty URL')
|
||||||
mp.commandv('script-message-to', 'uosc', 'close-menu', LOAD_URL_MENU_TYPE)
|
mp.commandv('script-message-to', 'uosc', 'close-menu', LOAD_URL_MENU_TYPE)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
mp.osd_message('Loading URL...', 1)
|
mp.osd_message('Loading URL...', 1)
|
||||||
_lua_log('Load URL: ' .. url)
|
_lua_log('[LOAD-URL] Starting to load: ' .. url)
|
||||||
|
|
||||||
local function close_menu()
|
local function close_menu()
|
||||||
_lua_log('Load URL: closing menu')
|
_lua_log('[LOAD-URL] Closing menu')
|
||||||
if ensure_uosc_loaded() then
|
if ensure_uosc_loaded() then
|
||||||
|
_lua_log('[LOAD-URL] Sending close-menu command to UOSC')
|
||||||
mp.commandv('script-message-to', 'uosc', 'close-menu', LOAD_URL_MENU_TYPE)
|
mp.commandv('script-message-to', 'uosc', 'close-menu', LOAD_URL_MENU_TYPE)
|
||||||
|
else
|
||||||
|
_lua_log('[LOAD-URL] UOSC not loaded, cannot close menu')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- First, always try direct loadfile. This is the fastest path.
|
-- First, always try direct loadfile. This is the fastest path.
|
||||||
local can_direct = _url_can_direct_load(url)
|
local can_direct = _url_can_direct_load(url)
|
||||||
_lua_log('Load URL: can_direct_load=' .. tostring(can_direct))
|
_lua_log('[LOAD-URL] Checking if URL can be loaded directly: ' .. tostring(can_direct))
|
||||||
|
|
||||||
if can_direct then
|
if can_direct then
|
||||||
_lua_log('Load URL: attempting direct loadfile')
|
_lua_log('[LOAD-URL] Attempting direct loadfile')
|
||||||
local ok_load = pcall(mp.commandv, 'loadfile', url, 'replace')
|
local ok_load = pcall(mp.commandv, 'loadfile', url, 'replace')
|
||||||
if ok_load then
|
if ok_load then
|
||||||
_lua_log('Load URL: direct loadfile succeeded')
|
_lua_log('[LOAD-URL] Direct loadfile command sent successfully')
|
||||||
mp.osd_message('URL loaded', 2)
|
mp.osd_message('URL loaded', 2)
|
||||||
close_menu()
|
close_menu()
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
_lua_log('Load URL: direct loadfile failed')
|
_lua_log('[LOAD-URL] Direct loadfile command failed')
|
||||||
mp.osd_message('Load URL failed (direct)', 3)
|
mp.osd_message('Load URL failed (direct)', 3)
|
||||||
close_menu()
|
close_menu()
|
||||||
return
|
return
|
||||||
@@ -2809,29 +2818,30 @@ mp.register_script_message('medios-load-url-event', function(json)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Complex streams (YouTube, DASH, etc.) need the pipeline helper.
|
-- Complex streams (YouTube, DASH, etc.) need the pipeline helper.
|
||||||
_lua_log('Load URL: URL needs pipeline helper')
|
_lua_log('[LOAD-URL] URL requires pipeline helper for processing')
|
||||||
ensure_mpv_ipc_server()
|
ensure_mpv_ipc_server()
|
||||||
local helper_ready = ensure_pipeline_helper_running()
|
local helper_ready = ensure_pipeline_helper_running()
|
||||||
_lua_log('Load URL: helper_ready=' .. tostring(helper_ready))
|
_lua_log('[LOAD-URL] Pipeline helper ready: ' .. tostring(helper_ready))
|
||||||
|
|
||||||
if not helper_ready then
|
if not helper_ready then
|
||||||
mp.osd_message('Pipeline helper not running (try right-click menu)', 3)
|
_lua_log('[LOAD-URL] Pipeline helper not available')
|
||||||
|
mp.osd_message('Pipeline helper not running (try menu again)', 3)
|
||||||
close_menu()
|
close_menu()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Use pipeline to download/prepare the URL
|
-- Use pipeline to download/prepare the URL
|
||||||
local pipeline_cmd = '.mpv -url ' .. quote_pipeline_arg(url) .. ' -play'
|
local pipeline_cmd = '.mpv -url ' .. quote_pipeline_arg(url) .. ' -play'
|
||||||
_lua_log('Load URL: executing pipeline command: ' .. pipeline_cmd)
|
_lua_log('[LOAD-URL] Sending to pipeline: ' .. pipeline_cmd)
|
||||||
M.run_pipeline(pipeline_cmd, nil, function(resp, err)
|
M.run_pipeline(pipeline_cmd, nil, function(resp, err)
|
||||||
_lua_log('Load URL: pipeline callback fired. resp=' .. tostring(resp) .. ', err=' .. tostring(err))
|
_lua_log('[LOAD-URL] Pipeline callback received: resp=' .. tostring(resp) .. ', err=' .. tostring(err))
|
||||||
if err then
|
if err then
|
||||||
_lua_log('Load URL: pipeline error: ' .. tostring(err))
|
_lua_log('[LOAD-URL] Pipeline error: ' .. tostring(err))
|
||||||
mp.osd_message('Load URL failed: ' .. tostring(err), 3)
|
mp.osd_message('Load URL failed: ' .. tostring(err), 3)
|
||||||
close_menu()
|
close_menu()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
_lua_log('Load URL: URL loaded successfully via pipeline')
|
_lua_log('[LOAD-URL] URL loaded successfully')
|
||||||
mp.osd_message('URL loaded', 2)
|
mp.osd_message('URL loaded', 2)
|
||||||
close_menu()
|
close_menu()
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user