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.
This commit is contained in:
baliasnyifeliks 2026-02-03 20:05:47 +02:00
parent 6208c14ef0
commit 5ef4e2896c

View File

@ -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;
}