mirror of
https://github.com/lampame/lampac-ukraine.git
synced 2026-04-16 17:32:20 +00:00
Fix result search
This commit is contained in:
parent
7a4f3f18e9
commit
d831d38acf
@ -28,7 +28,7 @@ namespace Uaflix.Controllers
|
|||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("uaflix")]
|
[Route("uaflix")]
|
||||||
async public Task<ActionResult> Index(long id, string imdb_id, long kinopoisk_id, string title, string original_title, string original_language, int year, string source, int serial, string account_email, string t, int s = -1, int e = -1, bool play = false, bool rjson = false)
|
async public Task<ActionResult> Index(long id, string imdb_id, long kinopoisk_id, string title, string original_title, string original_language, int year, string source, int serial, string account_email, string t, int s = -1, int e = -1, bool play = false, bool rjson = false, string href = null)
|
||||||
{
|
{
|
||||||
var init = await loadKit(ModInit.UaFlix);
|
var init = await loadKit(ModInit.UaFlix);
|
||||||
if (await IsBadInitialization(init))
|
if (await IsBadInitialization(init))
|
||||||
@ -45,9 +45,31 @@ namespace Uaflix.Controllers
|
|||||||
return Content("Uaflix", "text/html; charset=utf-8");
|
return Content("Uaflix", "text/html; charset=utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string filmUrl = href;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(filmUrl))
|
||||||
|
{
|
||||||
|
var searchResults = await invoke.Search(imdb_id, kinopoisk_id, title, original_title, year, title);
|
||||||
|
if (searchResults == null || searchResults.Count == 0)
|
||||||
|
return Content("Uaflix", "text/html; charset=utf-8");
|
||||||
|
|
||||||
|
if (searchResults.Count > 1)
|
||||||
|
{
|
||||||
|
var similar_tpl = new SimilarTpl(searchResults.Count);
|
||||||
|
foreach (var res in searchResults)
|
||||||
|
{
|
||||||
|
string link = $"{host}/uaflix?imdb_id={imdb_id}&kinopoisk_id={kinopoisk_id}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&year={year}&serial={serial}&href={HttpUtility.UrlEncode(res.Url)}";
|
||||||
|
similar_tpl.Append(res.Title, res.Year.ToString(), string.Empty, link, res.PosterUrl);
|
||||||
|
}
|
||||||
|
return rjson ? Content(similar_tpl.ToJson(), "application/json; charset=utf-8") : Content(similar_tpl.ToHtml(), "text/html; charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
filmUrl = searchResults[0].Url;
|
||||||
|
}
|
||||||
|
|
||||||
if (serial == 1)
|
if (serial == 1)
|
||||||
{
|
{
|
||||||
var paginationInfo = await invoke.GetPaginationInfo(imdb_id, kinopoisk_id, title, original_title, year);
|
var paginationInfo = await invoke.GetPaginationInfo(filmUrl);
|
||||||
if (paginationInfo == null || paginationInfo.Episodes == null)
|
if (paginationInfo == null || paginationInfo.Episodes == null)
|
||||||
return Content("Uaflix", "text/html; charset=utf-8");
|
return Content("Uaflix", "text/html; charset=utf-8");
|
||||||
|
|
||||||
@ -58,7 +80,7 @@ namespace Uaflix.Controllers
|
|||||||
|
|
||||||
foreach (var season in seasons)
|
foreach (var season in seasons)
|
||||||
{
|
{
|
||||||
string link = $"{host}/uaflix?imdb_id={imdb_id}&kinopoisk_id={kinopoisk_id}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&year={year}&serial=1&s={season}";
|
string link = $"{host}/uaflix?imdb_id={imdb_id}&kinopoisk_id={kinopoisk_id}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&year={year}&serial=1&s={season}&href={HttpUtility.UrlEncode(filmUrl)}";
|
||||||
season_tpl.Append($"Сезон {season}", link, $"{season}");
|
season_tpl.Append($"Сезон {season}", link, $"{season}");
|
||||||
}
|
}
|
||||||
return rjson ? Content(season_tpl.ToJson(), "application/json; charset=utf-8") : Content(season_tpl.ToHtml(), "text/html; charset=utf-8");
|
return rjson ? Content(season_tpl.ToJson(), "application/json; charset=utf-8") : Content(season_tpl.ToHtml(), "text/html; charset=utf-8");
|
||||||
@ -77,13 +99,9 @@ namespace Uaflix.Controllers
|
|||||||
}
|
}
|
||||||
else // Фильм
|
else // Фильм
|
||||||
{
|
{
|
||||||
var episodesInfo = await invoke.Search(imdb_id, kinopoisk_id, title, original_title, year, true);
|
string link = $"{host}/uaflix?t={HttpUtility.UrlEncode(filmUrl)}&play=true";
|
||||||
if (episodesInfo == null || episodesInfo.Count == 0)
|
|
||||||
return Content("Uaflix", "text/html; charset=utf-8");
|
|
||||||
|
|
||||||
string link = $"{host}/uaflix?t={HttpUtility.UrlEncode(episodesInfo[0].url)}&play=true";
|
|
||||||
var tpl = new MovieTpl(title, original_title, 1);
|
var tpl = new MovieTpl(title, original_title, 1);
|
||||||
tpl.Append(episodesInfo[0].title, accsArgs(link), method: "play");
|
tpl.Append(title, accsArgs(link), method: "play");
|
||||||
return rjson ? Content(tpl.ToJson(), "application/json; charset=utf-8") : Content(tpl.ToHtml(), "text/html; charset=utf-8");
|
return rjson ? Content(tpl.ToJson(), "application/json; charset=utf-8") : Content(tpl.ToHtml(), "text/html; charset=utf-8");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,15 +30,15 @@ namespace Uaflix
|
|||||||
_proxyManager = proxyManager;
|
_proxyManager = proxyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Uaflix.Models.EpisodeLinkInfo>> Search(string imdb_id, long kinopoisk_id, string title, string original_title, int year, bool isfilm = false)
|
public async Task<List<SearchResult>> Search(string imdb_id, long kinopoisk_id, string title, string original_title, int year, string search_query)
|
||||||
{
|
{
|
||||||
string memKey = $"UaFlix:search:{kinopoisk_id}:{imdb_id}";
|
string memKey = $"UaFlix:search:{kinopoisk_id}:{imdb_id}:{search_query}";
|
||||||
if (_hybridCache.TryGetValue(memKey, out List<Uaflix.Models.EpisodeLinkInfo> res))
|
if (_hybridCache.TryGetValue(memKey, out List<SearchResult> res))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string filmTitle = !string.IsNullOrEmpty(title) ? title : original_title;
|
string filmTitle = !string.IsNullOrEmpty(search_query) ? search_query : (!string.IsNullOrEmpty(title) ? title : original_title);
|
||||||
string searchUrl = $"{_init.host}/index.php?do=search&subaction=search&story={System.Web.HttpUtility.UrlEncode(filmTitle)}";
|
string searchUrl = $"{_init.host}/index.php?do=search&subaction=search&story={System.Web.HttpUtility.UrlEncode(filmTitle)}";
|
||||||
var headers = new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", _init.host) };
|
var headers = new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", _init.host) };
|
||||||
|
|
||||||
@ -49,38 +49,40 @@ namespace Uaflix
|
|||||||
var filmNodes = doc.DocumentNode.SelectNodes("//a[contains(@class, 'sres-wrap')]");
|
var filmNodes = doc.DocumentNode.SelectNodes("//a[contains(@class, 'sres-wrap')]");
|
||||||
if (filmNodes == null) return null;
|
if (filmNodes == null) return null;
|
||||||
|
|
||||||
string filmUrl = null;
|
res = new List<SearchResult>();
|
||||||
foreach (var filmNode in filmNodes)
|
foreach (var filmNode in filmNodes)
|
||||||
{
|
{
|
||||||
var h2Node = filmNode.SelectSingleNode(".//h2");
|
var h2Node = filmNode.SelectSingleNode(".//h2");
|
||||||
if (h2Node == null || !h2Node.InnerText.Trim().ToLower().Contains(filmTitle.ToLower())) continue;
|
if (h2Node == null) continue;
|
||||||
|
|
||||||
var descNode = filmNode.SelectSingleNode(".//div[contains(@class, 'sres-desc')]");
|
string filmUrl = filmNode.GetAttributeValue("href", "");
|
||||||
if (year > 0 && (descNode?.InnerText ?? "").Contains(year.ToString()))
|
if (string.IsNullOrEmpty(filmUrl)) continue;
|
||||||
{
|
|
||||||
filmUrl = filmNode.GetAttributeValue("href", "");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(filmUrl))
|
|
||||||
filmUrl = filmNodes.FirstOrDefault()?.GetAttributeValue("href", "");
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(filmUrl))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (!filmUrl.StartsWith("http"))
|
if (!filmUrl.StartsWith("http"))
|
||||||
filmUrl = _init.host + filmUrl;
|
filmUrl = _init.host + filmUrl;
|
||||||
|
|
||||||
if (isfilm)
|
var descNode = filmNode.SelectSingleNode(".//div[contains(@class, 'sres-desc')]");
|
||||||
|
int.TryParse(Regex.Match(descNode?.InnerText ?? "", @"\d{4}").Value, out int filmYear);
|
||||||
|
|
||||||
|
var posterNode = filmNode.SelectSingleNode(".//img");
|
||||||
|
string posterUrl = posterNode?.GetAttributeValue("src", "");
|
||||||
|
if (!string.IsNullOrEmpty(posterUrl) && !posterUrl.StartsWith("http"))
|
||||||
|
posterUrl = _init.host + posterUrl;
|
||||||
|
|
||||||
|
res.Add(new SearchResult
|
||||||
|
{
|
||||||
|
Title = h2Node.InnerText.Trim(),
|
||||||
|
Url = filmUrl,
|
||||||
|
Year = filmYear,
|
||||||
|
PosterUrl = posterUrl
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res.Count > 0)
|
||||||
{
|
{
|
||||||
res = new List<Uaflix.Models.EpisodeLinkInfo>() { new Uaflix.Models.EpisodeLinkInfo() { url = filmUrl, title = filmTitle } };
|
|
||||||
_hybridCache.Set(memKey, res, cacheTime(20));
|
_hybridCache.Set(memKey, res, cacheTime(20));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Для серіалів використовується GetPaginationInfo
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -164,48 +166,15 @@ namespace Uaflix
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PaginationInfo> GetPaginationInfo(string imdb_id, long kinopoisk_id, string title, string original_title, int year)
|
public async Task<PaginationInfo> GetPaginationInfo(string filmUrl)
|
||||||
{
|
{
|
||||||
string memKey = $"UaFlix:pagination:{kinopoisk_id}:{imdb_id}";
|
string memKey = $"UaFlix:pagination:{filmUrl}";
|
||||||
if (_hybridCache.TryGetValue(memKey, out PaginationInfo res))
|
if (_hybridCache.TryGetValue(memKey, out PaginationInfo res))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string filmTitle = !string.IsNullOrEmpty(title) ? title : original_title;
|
|
||||||
string searchUrl = $"{_init.host}/index.php?do=search&subaction=search&story={System.Web.HttpUtility.UrlEncode(filmTitle)}";
|
|
||||||
var headers = new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", _init.host) };
|
var headers = new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", _init.host) };
|
||||||
|
|
||||||
var searchHtml = await Http.Get(searchUrl, headers: headers, proxy: _proxyManager.Get());
|
|
||||||
var searchDoc = new HtmlDocument();
|
|
||||||
searchDoc.LoadHtml(searchHtml);
|
|
||||||
|
|
||||||
var filmNodes = searchDoc.DocumentNode.SelectNodes("//a[contains(@class, 'sres-wrap')]");
|
|
||||||
if (filmNodes == null) return null;
|
|
||||||
|
|
||||||
string filmUrl = null;
|
|
||||||
foreach (var filmNode in filmNodes)
|
|
||||||
{
|
|
||||||
var h2Node = filmNode.SelectSingleNode(".//h2");
|
|
||||||
if (h2Node == null || !h2Node.InnerText.Trim().ToLower().Contains(filmTitle.ToLower())) continue;
|
|
||||||
|
|
||||||
var descNode = filmNode.SelectSingleNode(".//div[contains(@class, 'sres-desc')]");
|
|
||||||
if (year > 0 && (descNode?.InnerText ?? "").Contains(year.ToString()))
|
|
||||||
{
|
|
||||||
filmUrl = filmNode.GetAttributeValue("href", "");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(filmUrl))
|
|
||||||
filmUrl = filmNodes.FirstOrDefault()?.GetAttributeValue("href", "");
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(filmUrl))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (!filmUrl.StartsWith("http"))
|
|
||||||
filmUrl = _init.host + filmUrl;
|
|
||||||
|
|
||||||
var filmHtml = await Http.Get(filmUrl, headers: headers, proxy: _proxyManager.Get());
|
var filmHtml = await Http.Get(filmUrl, headers: headers, proxy: _proxyManager.Get());
|
||||||
var filmDoc = new HtmlDocument();
|
var filmDoc = new HtmlDocument();
|
||||||
filmDoc.LoadHtml(filmHtml);
|
filmDoc.LoadHtml(filmHtml);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user