using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using Shared.Models.Online.Settings; namespace Online.Controllers { public class IframeVideo : BaseOnlineController { public IframeVideo() : base(AppInit.conf.IframeVideo) { } [HttpGet] [Route("lite/iframevideo")] async public Task Index(string imdb_id, long kinopoisk_id, string title, string original_title) { if (await IsRequestBlocked(rch: false)) return badInitMsg; var frame = await iframe(imdb_id, kinopoisk_id); if (frame.type == null || (frame.type != "movie" && frame.type != "anime")) return OnError(); bool firstjson = true; string html = "", "text/html; charset=utf-8"); } #region Video [HttpGet] [Route("lite/iframevideo/video")] [Route("lite/iframevideo/video.m3u8")] async public Task Video(string type, int cid, string token, string title, string original_title, bool play) { if (await IsRequestBlocked(rch: false)) return badInitMsg; string memKey = $"iframevideo:view:video:{type}:{cid}:{token}"; if (!hybridCache.TryGetValue(memKey, out string urim3u8)) { string json = await Http.Post($"{init.cdnhost}/loadvideo", $"token={token}&type={type}&season=&episode=&mobile=false&id={cid}&qt=480", timeoutSeconds: 10, proxy: proxy, headers: httpHeaders(init, HeadersModel.Init( ("DNT", "1"), ("Origin", init.cdnhost), ("P-REF", string.Empty), ("Referer", $"{init.cdnhost}/"), ("Sec-Fetch-Dest", "empty"), ("Sec-Fetch-Mode", "cors"), ("Sec-Fetch-Site", "same-origin"), ("X-REF", $"{init.host}/"), ("sec-ch-ua", "\"Google Chrome\";v=\"113\", \"Chromium\";v=\"113\", \"Not-A.Brand\";v=\"24\""), ("sec-ch-ua-mobile", "?0"), ("sec-ch-ua-platform", "\"Windows\"") ))); urim3u8 = Regex.Match(json ?? "", "{\"src\":\"([^\"]+)\"").Groups[1].Value.Replace("\\", ""); if (string.IsNullOrWhiteSpace(urim3u8)) return OnError(refresh_proxy: true); hybridCache.Set(memKey, urim3u8, cacheTime(20)); } string url = HostStreamProxy(urim3u8); if (play) return RedirectToPlay(url); return Content("{\"method\":\"play\",\"url\":\"" + url + "\",\"title\":\"" + (title ?? original_title) + "\"}", "application/json; charset=utf-8"); } #endregion #region iframe async ValueTask<(string content, string type, int cid, string path)> iframe(string imdb_id, long kinopoisk_id) { if (kinopoisk_id == 0 && string.IsNullOrWhiteSpace(imdb_id)) return (null, null, 0, null); string memKey = $"iframevideo:view:{imdb_id}:{kinopoisk_id}"; if (!hybridCache.TryGetValue(memKey, out (string content, string type, int cid, string path) res)) { string uri = $"{init.apihost}/api/v2/search?imdb={imdb_id}&kp={kinopoisk_id}"; if (!string.IsNullOrWhiteSpace(init.token)) uri = $"{init.apihost}/api/v2/movies?kp={kinopoisk_id}&imdb={imdb_id}&api_token={init.token}"; var root = await Http.Get(uri, timeoutSeconds: 8, proxy: proxy, headers: httpHeaders(init)); if (root == null) return (null, null, 0, null); var item = root.Value("results")?[0]; if (item == null) return (null, null, 0, null); res.cid = item.Value("cid"); res.path = item.Value("path"); res.type = item.Value("type"); res.content = await Http.Get(res.path, timeoutSeconds: 8, proxy: proxy, headers: httpHeaders(init, HeadersModel.Init( ("DNT", "1"), ("Referer", $"{init.host}/"), ("Sec-Fetch-Dest", "iframe"), ("Sec-Fetch-Mode", "navigate"), ("Sec-Fetch-Site", "cross-site"), ("Upgrade-Insecure-Requests", "1"), ("sec-ch-ua", "\"Google Chrome\";v=\"113\", \"Chromium\";v=\"113\", \"Not-A.Brand\";v=\"24\""), ("sec-ch-ua-mobile", "?0"), ("sec-ch-ua-platform", "\"Windows\"") ))); if (res.content == null) { proxyManager?.Refresh(); return (null, null, 0, null); } hybridCache.Set(memKey, res, cacheTime(20)); } return res; } #endregion } }