From 5ef4e2896ceb3dde49cfb4612c19234e721d281d Mon Sep 17 00:00:00 2001 From: baliasnyifeliks Date: Tue, 3 Feb 2026 20:05:47 +0200 Subject: [PATCH] refactor(makhno): enhance file array detection with multiple strategies Add fallback mechanisms for locating file arrays using different quote styles and regex matching. Include debug logging to track JSON parsing and voice extraction process. --- Makhno/MakhnoInvoke.cs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Makhno/MakhnoInvoke.cs b/Makhno/MakhnoInvoke.cs index 825df49..6393e88 100644 --- a/Makhno/MakhnoInvoke.cs +++ b/Makhno/MakhnoInvoke.cs @@ -275,13 +275,19 @@ namespace Makhno } string jsonData = ExtractPlayerJson(html); + if (jsonData == null) + _onLog("Makhno ParsePlayerData: file array not found"); + else + _onLog($"Makhno ParsePlayerData: file array length={jsonData.Length}"); if (!string.IsNullOrEmpty(jsonData)) { + var voices = ParseVoicesJson(jsonData); + _onLog($"Makhno ParsePlayerData: voices={voices?.Count ?? 0}"); return new PlayerData { File = null, Poster = null, - Voices = ParseVoicesJson(jsonData) + Voices = voices }; } @@ -381,11 +387,28 @@ namespace Makhno private int FindFileArrayStart(string html) { - int fileIndex = html.IndexOf("file", StringComparison.OrdinalIgnoreCase); - if (fileIndex < 0) + int index = FindFileArrayIndex(html, "file:'["); + if (index >= 0) + return index; + + index = FindFileArrayIndex(html, "file:\"["); + if (index >= 0) + return index; + + var match = Regex.Match(html, @"file\s*:\s*'?\[", RegexOptions.IgnoreCase); + if (match.Success) + return match.Index + match.Value.LastIndexOf('['); + + return -1; + } + + private int FindFileArrayIndex(string html, string token) + { + int tokenIndex = html.IndexOf(token, StringComparison.OrdinalIgnoreCase); + if (tokenIndex < 0) return -1; - int bracketIndex = html.IndexOf('[', fileIndex); + int bracketIndex = html.IndexOf('[', tokenIndex); return bracketIndex; }