using Shared.Models.Base; using Shared.Models.Online.VDBmovies; using Shared.Models.Templates; using System.Text; using System.Text.Json; using System.Text.RegularExpressions; using System.Web; namespace Shared.Engine.Online { public struct VDBmoviesInvoke { #region VDBmoviesInvoke string host; bool usehls; Func onstreamfile; public VDBmoviesInvoke(string host, bool hls, Func onstreamfile) { this.host = host != null ? $"{host}/" : null; this.onstreamfile = onstreamfile; usehls = hls; } #endregion #region EvalCode public string EvalCode(string file) { return @"(function () { var enc = function enc(str) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { return String.fromCharCode('0x' + p1); })); }; var dec = function dec(str) { return decodeURIComponent(atob(str).split('').map(function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); }; var trashList = ['wNp2wBTNcPRQvTC0_CpxCsq_8T1u9Q', 'md-Od2G9RWOgSa5HoBSSbWrCyIqQyY', 'kzuOYQqB_QSOL-xzN_Kz3kkgkHhHit', '6-xQWMh7ertLp8t_M9huUDk1M0VrYJ', 'RyTwtf15_GLEsXxnpU4Ljjd0ReY-VH']; var x = '" + file + @"'.substring(2); trashList.forEach(function (trash) { x = x.replace('//' + enc(trash), ''); }); try { x = dec(x); } catch (e) { x = ''; } return x; })(); "; } #endregion #region DecodeEval static readonly List trashList = new List { "wNp2wBTNcPRQvTC0_CpxCsq_8T1u9Q", "md-Od2G9RWOgSa5HoBSSbWrCyIqQyY", "kzuOYQqB_QSOL-xzN_Kz3kkgkHhHit", "6-xQWMh7ertLp8t_M9huUDk1M0VrYJ", "RyTwtf15_GLEsXxnpU4Ljjd0ReY-VH" }; static List trashListBase64; public string DecodeEval(string file) { if (trashListBase64 == null) { Func enc = str => { var bytes = Encoding.UTF8.GetBytes(str); return Convert.ToBase64String(bytes); }; trashListBase64 = new List(5); foreach (string trash in trashList) trashListBase64.Add("//" + enc(trash)); } foreach (string trash in trashListBase64) { if (file.Contains(trash)) file = file.Replace(trash, ""); } try { var bytes = Convert.FromBase64String(file); return Encoding.UTF8.GetString(bytes); } catch { } return file; } #endregion #region Embed public EmbedModel Embed(string json, string forbidden_quality, string default_quality) { if (string.IsNullOrEmpty(json)) return null; if (string.IsNullOrEmpty(default_quality)) default_quality = "360p"; string quality = forbidden_quality.Contains("1080p") ? "1080p" : forbidden_quality.Contains("720p") ? "720p" : forbidden_quality.Contains("480p") ? "480p" : default_quality; try { if (json.Contains("\"folder\"")) { var serial = JsonSerializer.Deserialize(json); if (serial == null || serial.Length == 0) return null; return new EmbedModel() { serial = serial, quality = quality }; } else { var movies = JsonSerializer.Deserialize(json); if (movies == null || movies.Length == 0) return null; return new EmbedModel() { movies = movies, quality = quality }; } } catch { return null; } } #endregion #region Tpl public ITplResult Tpl(EmbedModel root, string orid, string imdb_id, long kinopoisk_id, string title, string original_title, string t, int s, int sid, VastConf vast = null, bool rjson = false) { if (root == null) return default; if (root.movies != null) { #region Фильм var mtpl = new MovieTpl(title, original_title, root.movies.Length); foreach (var m in root.movies) { #region subtitle var subtitles = new SubtitleTpl(); if (!string.IsNullOrEmpty(m.subtitle)) { var match = new Regex("\\[([^\\]]+)\\](https?://[^\\,]+)").Match(m.subtitle); while (match.Success) { subtitles.Append(match.Groups[1].Value, match.Groups[2].Value); match = match.NextMatch(); } } #endregion if (string.IsNullOrEmpty(m.file)) continue; var streamquality = getStreamQualityTpl(m.file); mtpl.Append(m.title, streamquality.Firts().link, subtitles: subtitles, streamquality: streamquality, vast: vast); } return mtpl; #endregion } else { #region Сериал string enc_title = HttpUtility.UrlEncode(title); string enc_original_title = HttpUtility.UrlEncode(original_title); if (s == -1) { #region Сезоны var tpl = new SeasonTpl(root.quality, root.serial.Length); for (int i = 0; i < root.serial.Length; i++) { string season = Regex.Match(root.serial[i].title, "^([0-9]+)").Groups[1].Value; if (string.IsNullOrEmpty(season)) continue; tpl.Append($"{season} сезон", host + $"lite/vdbmovies?orid={orid}&imdb_id={imdb_id}&kinopoisk_id={kinopoisk_id}&rjson={rjson}&title={enc_title}&original_title={enc_original_title}&s={season}&sid={i}", season); } return tpl; #endregion } else { #region Серии var vtpl = new VoiceTpl(); var etpl = new EpisodeTpl(); var hashvoices = new HashSet(20); string sArhc = s.ToString(); foreach (var episode in root.serial[sid].folder) { string ename = Regex.Match(episode.title, "^([0-9]+)").Groups[1].Value; foreach (var voice in episode.folder) { string perevod = voice.title; if (string.IsNullOrEmpty(t)) t = perevod; if (hashvoices.Add(perevod)) vtpl.Append(perevod, t == perevod, host + $"lite/vdbmovies?orid={orid}&imdb_id={imdb_id}&kinopoisk_id={kinopoisk_id}&rjson={rjson}&title={enc_title}&original_title={enc_original_title}&s={s}&sid={sid}&t={HttpUtility.UrlEncode(perevod)}"); if (perevod != t) continue; var streamquality = getStreamQualityTpl(voice.file); etpl.Append($"{ename} cерия", title ?? original_title, sArhc, ename, streamquality.Firts().link, streamquality: streamquality, vast: vast); } } etpl.Append(vtpl); return etpl; #endregion } #endregion } } #endregion #region getStreamQualityTpl StreamQualityTpl getStreamQualityTpl(string file) { var streamquality = new StreamQualityTpl(); var target = Regex.Match(file, "\\[(?[^\\]]+)\\](?https?://[^\\[\\|,\n\r\t ]+\\.m3u8)").Groups; string targetQuality = target["quality"].Value.Replace("p", ""); foreach (string q in new string[] { "1080", "720", "480", "360", "240" }) { string link = target["m3u8"].Value.Replace($"/{targetQuality}.mp4:", $"/{q}.mp4:"); if (!usehls) link = link.Replace(":hls:manifest.m3u8", ""); streamquality.Append(onstreamfile.Invoke(link), $"{q}p"); } if (streamquality.data.Count == 0) { foreach (Match mf in Regex.Matches(file, "\\[([^\\]]+)\\](https?://[^\\[\\|,\n\r\t ]+\\.m3u8)")) { string link = mf.Groups[2].Value; if (!usehls) link = link.Replace(":hls:manifest.m3u8", ""); streamquality.Insert(onstreamfile.Invoke(link), mf.Groups[1].Value); } } return streamquality; } #endregion } }