diff --git a/etc/mpv/scripts/notify.lua b/etc/mpv/scripts/notify.lua index f538f9f..ce9a237 100644 --- a/etc/mpv/scripts/notify.lua +++ b/etc/mpv/scripts/notify.lua @@ -140,16 +140,30 @@ local function fetch_tmdb_poster(title) title = clean_title_common(title) local url = string.format("https://api.themoviedb.org/3/search/movie?api_key=%s&query=%s", TMDB_API_KEY, url_encode(title)) + log("TMDB Query", url) + local res = utils.subprocess({ args = { "curl", "-s", url } }) - if res.status == 0 then - local data = utils.parse_json(res.stdout) - if data and data.results and data.results[1] and data.results[1].poster_path then - return "https://image.tmdb.org/t/p/w500" .. data.results[1].poster_path - end + if res.status ~= 0 then + log("TMDB Error", "curl failed with status " .. tostring(res.status)) + return nil + end + + log("TMDB Response", res.stdout) + + local data = utils.parse_json(res.stdout) + if not data then + log("TMDB Error", "parse_json returned nil") + return nil + end + if data.results and data.results[1] and data.results[1].poster_path then + return "https://image.tmdb.org/t/p/w500" .. data.results[1].poster_path + else + log("TMDB Error", "No poster found in results") end return nil end + local function fetch_lastfm_cover(title, artist) if not artist or artist == "" then return nil end title = clean_title_common(title) @@ -213,13 +227,27 @@ end local function infer_title_with_ollama(title) if not title or title == "" then return title end local prompt = string.format([[Archivo: "%s" -Return only a JSON: { "title": "..." } -do NOT explain anything. do NOT return anything else. + +Devuelve un JSON válido con el título real de la obra. NO incluyas: +- Número de capítulo o lista (como "01.", "16.") +- Nombre del grupo release (como "newpct", "rarbg", "YTS", etc) +- Resolución, calidad o formato ("4K", "HDR", "1080p", etc) + +Ejemplos válidos: + Archivo: "16. Licencia para Matar 1985 [newpct]" + → { "title": "Licencia para Matar" } + + Archivo: "300.mkv" + → { "title": "300" } + +NO EXPLIQUES NADA. SOLO devuélvelo como JSON exacto: { "title": "..." } ]], title) + log(" Prompt enviado a Ollama (video)", prompt) local payload = utils.format_json({ model = "gemma2:2b", prompt = prompt, stream = false }) local res = utils.subprocess({ args = { "curl", "-s", "-X", "POST", OLLAMA_URL, "-H", "Content-Type: application/json", "-d", payload } }) if res.status ~= 0 then return title end + print("\27[1;34m[OLLAMA VIDEO RAW]\27[0m " .. (res.stdout or "")) -- Color azul, puedes quitarlo local outer = utils.parse_json(res.stdout) if outer and outer.response then local clean = outer.response:gsub("```json", ""):gsub("```", ""):gsub("\n", ""):gsub("\\", "")