using Shared.Engine.RxEnumerate; using Shared.Models.SISI.Base; using Shared.Models.SISI.OnResult; using Shared.Models.SISI.Xvideos; using System.Text.Json; using System.Text.RegularExpressions; using System.Web; namespace Shared.Engine.SISI { public static class XnxxTo { public static string Uri(string host, string search, int pg) { if (!string.IsNullOrWhiteSpace(search)) return $"{host}/search/{HttpUtility.UrlEncode(search)}/{pg}"; return $"{host}/best/{DateTime.Today.AddMonths(-1):yyyy-MM}/{pg}"; } #region Playlist public static List Playlist(string route, ReadOnlySpan html, Func onplaylist = null) { if (html.IsEmpty) return null; var rx = Rx.Split("
(rx.Count); foreach (var row in rx.Rows()) { var g = row.Groups("([^<]+)", trim: true), quality = row.Match(" - ([^<]+)"), json = true, related = true, bookmark = new Bookmark() { site = "xnx", href = g[1].Value, image = img } }; if (onplaylist != null) pl = onplaylist.Invoke(pl); playlists.Add(pl); } } return playlists; } #endregion #region Menu public static List Menu(string host) { host = string.IsNullOrWhiteSpace(host) ? string.Empty : $"{host}/"; return new List() { new MenuItem() { title = "Поиск", search_on = "search_on", playlist_url = host + "xnx", } }; } #endregion #region StreamLinks public static string StreamLinksUri(string host, string url) { if (string.IsNullOrWhiteSpace(url)) return null; return $"{host}/{Regex.Replace(url ?? string.Empty, "^([^/]+)/.*", "$1/_")}"; } public static StreamItem StreamLinks(ReadOnlySpan html, string route, Func> onm3u = null) { if (html.IsEmpty) return null; string stream_link = Rx.Match(html, "html5player\\.setVideoHLS\\('([^']+)'\\);"); if (string.IsNullOrWhiteSpace(stream_link)) return null; #region getRelated List getRelated(ReadOnlySpan html) { string json = Rx.Match(html, "video_related=([^\n\r]+);window"); if (string.IsNullOrWhiteSpace(json) || !json.StartsWith("[") || !json.EndsWith("]")) return new List(); var related = new List(40); try { foreach (var r in JsonSerializer.Deserialize>(json)) { if (string.IsNullOrEmpty(r.tf) || string.IsNullOrEmpty(r.u) || string.IsNullOrEmpty(r.i)) continue; related.Add(new PlaylistItem() { name = r.tf, video = $"{route}?uri={r.u.Remove(0, 1)}", picture = r.i, json = true, related = true, bookmark = new Bookmark() { site = "xnx", href = r.u.Remove(0, 1), image = r.i } }); } } catch { } return related; } #endregion return new StreamItem() { qualitys = new Dictionary() { ["auto"] = stream_link }, recomends = getRelated(html) }; //string m3u8 = onm3u == null ? null : await onm3u.Invoke(stream_link); //if (m3u8 == null) //{ // return new StreamItem() // { // qualitys = new Dictionary() // { // ["auto"] = stream_link // }, // recomends = getRelated() // }; //} //var stream_links = new Dictionary(); //foreach (Match m in Regex.Matches(m3u8, "(hls-(2160|1440|1080|720|480|360)p[^\n\r\t ]+)")) //{ // string hls = m.Groups[1].Value; // if (string.IsNullOrEmpty(hls)) // continue; // hls = $"{Regex.Replace(stream_link, "/hls\\.m3u.*", "")}/{hls}".Replace("https:", "http:"); // stream_links.Add(int.Parse(m.Groups[2].Value), hls); //} //return new StreamItem() //{ // qualitys = stream_links.OrderByDescending(i => i.Key).ToDictionary(k => $"{k.Key}p", v => v.Value), // recomends = getRelated() //}; } #endregion } }