using HtmlAgilityPack;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.Playwright;
using Shared.Models.CSharpGlobals;
using Shared.Models.SISI.NextHUB;
using Shared.PlaywrightCore;
using System.Text;
using System.Web;
namespace SISI.Controllers.NextHUB
{
public class ListController : BaseSisiController
{
public ListController() : base(default) { }
[HttpGet]
[Route("nexthub")]
async public Task Index(string plugin, string search, string sort, string cat, string model, int pg = 1)
{
if (!AppInit.conf.sisi.NextHUB)
return OnError("disabled", rcache: false);
var _nxtInit = Root.goInit(plugin);
if (_nxtInit == null)
return OnError("init not found", rcache: false);
if (!string.IsNullOrEmpty(search) && string.IsNullOrEmpty(_nxtInit.search?.uri))
return OnError("search disable", rcache: false);
if (await IsRequestBlocked(_nxtInit, rch: _nxtInit.rch_access != null))
return badInitMsg;
string semaphoreKey = $"nexthub:{plugin}:{search}:{sort}:{cat}:{model}:{pg}";
if (init.menu?.customs != null)
{
foreach (var item in init.menu.customs)
semaphoreKey += $":{HttpContext.Request.Query[item.arg]}";
}
rhubFallback:
var cache = await InvokeCacheResult>(semaphoreKey, init.cache_time, async e =>
{
#region contentParse
var contentParse = init.list.contentParse ?? init.contentParse;
if (!string.IsNullOrEmpty(search) && init.search?.contentParse != null)
contentParse = init.search.contentParse;
if (!string.IsNullOrEmpty(model) && init.model?.contentParse != null)
contentParse = init.model.contentParse;
#endregion
string html = await HttpRequest(init, plugin, pg, search, sort, cat, model);
var playlists = goPlaylist(requestInfo, host, contentParse, init, html, plugin);
if (playlists == null || playlists.Count == 0)
return e.Fail("playlists", refresh_proxy: string.IsNullOrEmpty(search));
return e.Success(playlists);
});
if (IsRhubFallback(cache))
goto rhubFallback;
var menu = new List