diff --git a/Makhno/Controller.cs b/Makhno/Controller.cs index 0e24b41..6bf24b6 100644 --- a/Makhno/Controller.cs +++ b/Makhno/Controller.cs @@ -89,7 +89,10 @@ namespace Makhno }); if (playerData?.Voices == null || !playerData.Voices.Any()) + { + OnLog("Makhno Play: no voices parsed"); return OnError(); + } if (string.IsNullOrEmpty(t) || !int.TryParse(t, out int voiceIndex) || voiceIndex >= playerData.Voices.Count) return OnError(); @@ -143,7 +146,10 @@ namespace Makhno }); if (playerData?.File == null) + { + OnLog("Makhno PlayMovie: no file parsed"); return OnError(); + } string streamUrl = BuildStreamUrl(init, playerData.File); @@ -162,7 +168,10 @@ namespace Makhno }); if (playerData?.File == null) + { + OnLog("Makhno HandleMovie: no file parsed"); return OnError(); + } string movieLink = $"{host}/makhno/play/movie?imdb_id={HttpUtility.UrlEncode(imdb_id)}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&year={year}&play=true"; var tpl = new MovieTpl(title ?? original_title, original_title, 1); @@ -181,7 +190,10 @@ namespace Makhno }); if (playerData?.Voices == null || !playerData.Voices.Any()) + { + OnLog("Makhno HandleSerial: no voices parsed"); return OnError(); + } if (season == -1) { diff --git a/Makhno/MakhnoInvoke.cs b/Makhno/MakhnoInvoke.cs index 985631d..65771f6 100644 --- a/Makhno/MakhnoInvoke.cs +++ b/Makhno/MakhnoInvoke.cs @@ -387,6 +387,14 @@ namespace Makhno private int FindFileArrayStart(string html) { + int playerStart = html.IndexOf("Playerjs", StringComparison.OrdinalIgnoreCase); + if (playerStart >= 0) + { + int playerIndex = FindFileArrayStartInRange(html, playerStart); + if (playerIndex >= 0) + return playerIndex; + } + int index = FindFileArrayIndex(html, "file:'["); if (index >= 0) return index; @@ -402,6 +410,39 @@ namespace Makhno return -1; } + private int FindFileArrayStartInRange(string html, int startIndex) + { + int searchStart = startIndex; + int searchEnd = Math.Min(html.Length, startIndex + 200000); + + int tokenIndex = IndexOfIgnoreCase(html, "file:'[", searchStart, searchEnd); + if (tokenIndex >= 0) + return html.IndexOf('[', tokenIndex); + + tokenIndex = IndexOfIgnoreCase(html, "file:\"[", searchStart, searchEnd); + if (tokenIndex >= 0) + return html.IndexOf('[', tokenIndex); + + tokenIndex = IndexOfIgnoreCase(html, "file", searchStart, searchEnd); + if (tokenIndex >= 0) + { + int bracketIndex = html.IndexOf('[', tokenIndex); + if (bracketIndex >= 0 && bracketIndex < searchEnd) + return bracketIndex; + } + + return -1; + } + + private int IndexOfIgnoreCase(string text, string value, int startIndex, int endIndex) + { + int index = text.IndexOf(value, startIndex, StringComparison.OrdinalIgnoreCase); + if (index >= 0 && index < endIndex) + return index; + + return -1; + } + private int FindFileArrayIndex(string html, string token) { int tokenIndex = html.IndexOf(token, StringComparison.OrdinalIgnoreCase);