mirror of
https://github.com/lampame/lampac-ukraine.git
synced 2026-04-16 17:32:20 +00:00
commit
490fed2a06
@ -1,4 +1,5 @@
|
|||||||
using Shared.Engine;
|
using Shared.Models.Templates;
|
||||||
|
using Shared.Engine;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -27,282 +28,82 @@ 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 (!init.enable)
|
if (await IsBadInitialization(init))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var invoke = new UaflixInvoke(init, hybridCache, OnLog, proxyManager);
|
var invoke = new UaflixInvoke(init, hybridCache, OnLog, proxyManager);
|
||||||
|
|
||||||
var episodesInfo = await invoke.Search(imdb_id, kinopoisk_id, title, original_title, year, serial == 0);
|
|
||||||
if (episodesInfo == null)
|
|
||||||
return Content("Uaflix", "text/html; charset=utf-8");
|
|
||||||
|
|
||||||
if (play)
|
if (play)
|
||||||
{
|
{
|
||||||
var episode = episodesInfo.FirstOrDefault(ep => ep.season == s && ep.episode == e);
|
var playResult = await invoke.ParseEpisode(t);
|
||||||
if (serial == 0) // для фильма берем первый
|
|
||||||
episode = episodesInfo.FirstOrDefault();
|
|
||||||
|
|
||||||
if (episode == null)
|
|
||||||
return Content("Uaflix", "text/html; charset=utf-8");
|
|
||||||
|
|
||||||
var playResult = await invoke.ParseEpisode(episode.url);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(playResult.ashdi_url))
|
|
||||||
{
|
|
||||||
string ashdi_kp = Regex.Match(playResult.ashdi_url, "/serial/([0-9]+)").Groups[1].Value;
|
|
||||||
if (!string.IsNullOrEmpty(ashdi_kp))
|
|
||||||
return Redirect($"/ashdi?kinopoisk_id={ashdi_kp}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&s={s}&e={e}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (playResult.streams != null && playResult.streams.Count > 0)
|
if (playResult.streams != null && playResult.streams.Count > 0)
|
||||||
return Redirect(HostStreamProxy(init, accsArgs(playResult.streams.First().link)));
|
return Redirect(HostStreamProxy(init, accsArgs(playResult.streams.First().link)));
|
||||||
|
|
||||||
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(filmUrl);
|
||||||
|
if (paginationInfo == null || paginationInfo.Episodes == null)
|
||||||
|
return Content("Uaflix", "text/html; charset=utf-8");
|
||||||
|
|
||||||
if (s == -1) // Выбор сезона
|
if (s == -1) // Выбор сезона
|
||||||
{
|
{
|
||||||
var seasons = episodesInfo.GroupBy(ep => ep.season).ToDictionary(k => k.Key, v => v.ToList());
|
var seasons = paginationInfo.Episodes.Select(se => se.season).Distinct().OrderBy(se => se);
|
||||||
var season_tpl = new SeasonTpl(seasons.Count);
|
var season_tpl = new SeasonTpl(seasons.Count());
|
||||||
foreach (var season in seasons.OrderBy(i => i.Key))
|
|
||||||
|
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.Key}";
|
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.Key}", link, $"{season.Key}");
|
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");
|
||||||
}
|
}
|
||||||
|
else // Выбор эпизода
|
||||||
// Выбор эпизода
|
{
|
||||||
var episodes = episodesInfo.Where(ep => ep.season == s).OrderBy(ep => ep.episode).ToList();
|
var episodes = paginationInfo.Episodes.Where(ep => ep.season == s).OrderBy(ep => ep.episode).ToList();
|
||||||
var movie_tpl = new MovieTpl(title, original_title, episodes.Count);
|
var episode_tpl = new EpisodeTpl();
|
||||||
foreach(var ep in episodes)
|
foreach(var ep in episodes)
|
||||||
{
|
{
|
||||||
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={s}&e={ep.episode}&play=true";
|
string link = $"{host}/uaflix?t={HttpUtility.UrlEncode(ep.url)}&play=true";
|
||||||
movie_tpl.Append(ep.title, accsArgs(link), method: "play");
|
episode_tpl.Append(ep.title, title, ep.season.ToString(), ep.episode.ToString(), accsArgs(link));
|
||||||
|
}
|
||||||
|
return rjson ? Content(episode_tpl.ToJson(), "application/json; charset=utf-8") : Content(episode_tpl.ToHtml(), "text/html; charset=utf-8");
|
||||||
}
|
}
|
||||||
return rjson ? Content(movie_tpl.ToJson(), "application/json; charset=utf-8") : Content(movie_tpl.ToHtml(), "text/html; charset=utf-8");
|
|
||||||
}
|
}
|
||||||
else // Фильм
|
else // Фильм
|
||||||
{
|
{
|
||||||
string link = $"{host}/uaflix?imdb_id={imdb_id}&kinopoisk_id={kinopoisk_id}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&year={year}&play=true";
|
string link = $"{host}/uaflix?t={HttpUtility.UrlEncode(filmUrl)}&play=true";
|
||||||
var tpl = new MovieTpl(title, original_title, 1);
|
var tpl = new MovieTpl(title, original_title, 1);
|
||||||
tpl.Append(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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async ValueTask<List<Uaflix.Models.EpisodeLinkInfo>> search(OnlinesSettings init, string imdb_id, long kinopoisk_id, string title, string original_title, int year, bool isfilm = false)
|
|
||||||
{
|
|
||||||
string memKey = $"UaFlix:search:{kinopoisk_id}:{imdb_id}";
|
|
||||||
if (hybridCache.TryGetValue(memKey, out List<Uaflix.Models.EpisodeLinkInfo> res))
|
|
||||||
return res;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string filmTitle = !string.IsNullOrEmpty(title) ? title : original_title;
|
|
||||||
string searchUrl = $"{init.host}/index.php?do=search&subaction=search&story={HttpUtility.UrlEncode(filmTitle)}";
|
|
||||||
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);
|
|
||||||
var doc = new HtmlDocument();
|
|
||||||
doc.LoadHtml(searchHtml);
|
|
||||||
|
|
||||||
var filmNodes = doc.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 (filmUrl == null)
|
|
||||||
filmUrl = filmNodes.FirstOrDefault()?.GetAttributeValue("href", "");
|
|
||||||
|
|
||||||
if (!filmUrl.StartsWith("http"))
|
|
||||||
filmUrl = init.host + filmUrl;
|
|
||||||
|
|
||||||
if (isfilm)
|
|
||||||
{
|
|
||||||
res = new List<Uaflix.Models.EpisodeLinkInfo>() { new Uaflix.Models.EpisodeLinkInfo() { url = filmUrl } };
|
|
||||||
hybridCache.Set(memKey, res, cacheTime(20));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
var filmHtml = await Http.Get(filmUrl, headers: headers);
|
|
||||||
doc.LoadHtml(filmHtml);
|
|
||||||
|
|
||||||
res = new List<Uaflix.Models.EpisodeLinkInfo>();
|
|
||||||
var episodeNodes = doc.DocumentNode.SelectNodes("//div[contains(@class, 'frels2')]//a[contains(@class, 'vi-img')]");
|
|
||||||
if (episodeNodes != null)
|
|
||||||
{
|
|
||||||
foreach (var episodeNode in episodeNodes.Reverse().ToList())
|
|
||||||
{
|
|
||||||
string episodeUrl = episodeNode.GetAttributeValue("href", "");
|
|
||||||
if (!episodeUrl.StartsWith("http"))
|
|
||||||
episodeUrl = init.host + episodeUrl;
|
|
||||||
|
|
||||||
var match = Regex.Match(episodeUrl, @"season-(\d+).*?episode-(\d+)");
|
|
||||||
if (match.Success)
|
|
||||||
{
|
|
||||||
res.Add(new Uaflix.Models.EpisodeLinkInfo
|
|
||||||
{
|
|
||||||
url = episodeUrl,
|
|
||||||
title = episodeNode.SelectSingleNode(".//div[@class='vi-rate']")?.InnerText.Trim() ?? $"Епізод {match.Groups[2].Value}",
|
|
||||||
season = int.Parse(match.Groups[1].Value),
|
|
||||||
episode = int.Parse(match.Groups[2].Value)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res.Count == 0)
|
|
||||||
{
|
|
||||||
var iframe = doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'video-box')]//iframe[contains(@src, 'ashdi.vip/serial/')]");
|
|
||||||
if (iframe != null)
|
|
||||||
{
|
|
||||||
res.Add(new Uaflix.Models.EpisodeLinkInfo() { url = filmUrl, season = 1, episode = 1 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res.Count > 0)
|
|
||||||
hybridCache.Set(memKey, res, cacheTime(20));
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
OnLog($"UaFlix search error: {ex.Message}");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task<Uaflix.Models.PlayResult> ParseEpisode(OnlinesSettings init, string url)
|
|
||||||
{
|
|
||||||
var result = new Uaflix.Models.PlayResult() { streams = new List<(string, string)>() };
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string html = await Http.Get(url, headers: new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", init.host) });
|
|
||||||
var doc = new HtmlDocument();
|
|
||||||
doc.LoadHtml(html);
|
|
||||||
|
|
||||||
var iframe = doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'video-box')]//iframe");
|
|
||||||
if (iframe != null)
|
|
||||||
{
|
|
||||||
string iframeUrl = iframe.GetAttributeValue("src", "").Replace("&", "&");
|
|
||||||
if (iframeUrl.StartsWith("//"))
|
|
||||||
iframeUrl = "https:" + iframeUrl;
|
|
||||||
|
|
||||||
if (iframeUrl.Contains("ashdi.vip/serial/"))
|
|
||||||
{
|
|
||||||
result.ashdi_url = iframeUrl;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iframeUrl.Contains("zetvideo.net"))
|
|
||||||
result.streams = await ParseAllZetvideoSources(iframeUrl);
|
|
||||||
else if (iframeUrl.Contains("ashdi.vip"))
|
|
||||||
{
|
|
||||||
result.streams = await ParseAllAshdiSources(iframeUrl);
|
|
||||||
var idMatch = Regex.Match(iframeUrl, @"_(\d+)|vod/(\d+)");
|
|
||||||
if (idMatch.Success)
|
|
||||||
{
|
|
||||||
string ashdiId = idMatch.Groups[1].Success ? idMatch.Groups[1].Value : idMatch.Groups[2].Value;
|
|
||||||
result.subtitles = await GetAshdiSubtitles(ashdiId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
OnLog($"ParseEpisode error: {ex.Message}");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Parsers
|
|
||||||
async Task<List<(string link, string quality)>> ParseAllZetvideoSources(string iframeUrl)
|
|
||||||
{
|
|
||||||
var result = new List<(string link, string quality)>();
|
|
||||||
var html = await Http.Get(iframeUrl, headers: new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", "https://zetvideo.net/") });
|
|
||||||
if (string.IsNullOrEmpty(html)) return result;
|
|
||||||
|
|
||||||
var doc = new HtmlDocument();
|
|
||||||
doc.LoadHtml(html);
|
|
||||||
|
|
||||||
var script = doc.DocumentNode.SelectSingleNode("//script[contains(text(), 'file:')]");
|
|
||||||
if (script != null)
|
|
||||||
{
|
|
||||||
var match = Regex.Match(script.InnerText, @"file:\s*""([^""]+\.m3u8)");
|
|
||||||
if (match.Success)
|
|
||||||
{
|
|
||||||
result.Add((match.Groups[1].Value, "1080p"));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var sourceNodes = doc.DocumentNode.SelectNodes("//source[contains(@src, '.m3u8')]");
|
|
||||||
if (sourceNodes != null)
|
|
||||||
{
|
|
||||||
foreach (var node in sourceNodes)
|
|
||||||
{
|
|
||||||
result.Add((node.GetAttributeValue("src", null), node.GetAttributeValue("label", null) ?? node.GetAttributeValue("res", null) ?? "1080p"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task<List<(string link, string quality)>> ParseAllAshdiSources(string iframeUrl)
|
|
||||||
{
|
|
||||||
var result = new List<(string link, string quality)>();
|
|
||||||
var html = await Http.Get(iframeUrl, headers: new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", "https://ashdi.vip/") });
|
|
||||||
if (string.IsNullOrEmpty(html)) return result;
|
|
||||||
|
|
||||||
var doc = new HtmlDocument();
|
|
||||||
doc.LoadHtml(html);
|
|
||||||
|
|
||||||
var sourceNodes = doc.DocumentNode.SelectNodes("//source[contains(@src, '.m3u8')]");
|
|
||||||
if (sourceNodes != null)
|
|
||||||
{
|
|
||||||
foreach (var node in sourceNodes)
|
|
||||||
{
|
|
||||||
result.Add((node.GetAttributeValue("src", null), node.GetAttributeValue("label", null) ?? node.GetAttributeValue("res", null) ?? "1080p"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task<SubtitleTpl?> GetAshdiSubtitles(string id)
|
|
||||||
{
|
|
||||||
var html = await Http.Get($"https://ashdi.vip/vod/{id}", headers: new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", "https://ashdi.vip/") });
|
|
||||||
string subtitle = new Regex("subtitle(\")?:\"([^\"]+)\"").Match(html).Groups[2].Value;
|
|
||||||
if (!string.IsNullOrEmpty(subtitle))
|
|
||||||
{
|
|
||||||
var match = new Regex("\\[([^\\]]+)\\](https?://[^\\,]+)").Match(subtitle);
|
|
||||||
var st = new Shared.Models.Templates.SubtitleTpl();
|
|
||||||
while (match.Success)
|
|
||||||
{
|
|
||||||
st.Append(match.Groups[1].Value, match.Groups[2].Value);
|
|
||||||
match = match.NextMatch();
|
|
||||||
}
|
|
||||||
if (!st.IsEmpty())
|
|
||||||
return st;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,8 @@ namespace Uaflix
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void loaded(InitspaceModel initspace)
|
public static void loaded(InitspaceModel initspace)
|
||||||
{
|
{
|
||||||
|
// streamproxy: false - замовчуванням вимкнено, але модуль сумісний з streamproxy=true
|
||||||
|
// Клоакінг посилань для серіалів дозволяє працювати незалежно від налаштування streamproxy
|
||||||
UaFlix = new OnlinesSettings("Uaflix", "https://uafix.net", streamproxy: false, useproxy: false)
|
UaFlix = new OnlinesSettings("Uaflix", "https://uafix.net", streamproxy: false, useproxy: false)
|
||||||
{
|
{
|
||||||
displayname = "🇺🇦 UaFlix",
|
displayname = "🇺🇦 UaFlix",
|
||||||
|
|||||||
@ -11,6 +11,7 @@ using Shared.Engine;
|
|||||||
using Uaflix.Models;
|
using Uaflix.Models;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Shared.Models.Templates;
|
using Shared.Models.Templates;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace Uaflix
|
namespace Uaflix
|
||||||
{
|
{
|
||||||
@ -29,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) };
|
||||||
|
|
||||||
@ -48,41 +49,178 @@ 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 (filmUrl == null)
|
|
||||||
filmUrl = filmNodes.FirstOrDefault()?.GetAttributeValue("href", "");
|
|
||||||
|
|
||||||
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 } };
|
|
||||||
_hybridCache.Set(memKey, res, cacheTime(20));
|
_hybridCache.Set(memKey, res, cacheTime(20));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_onLog($"UaFlix search error: {ex.Message}");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<FilmInfo> GetFilmInfo(string filmUrl)
|
||||||
|
{
|
||||||
|
string memKey = $"UaFlix:filminfo:{filmUrl}";
|
||||||
|
if (_hybridCache.TryGetValue(memKey, out FilmInfo res))
|
||||||
|
return res;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var headers = new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", _init.host) };
|
||||||
var filmHtml = await Http.Get(filmUrl, headers: headers, proxy: _proxyManager.Get());
|
var filmHtml = await Http.Get(filmUrl, headers: headers, proxy: _proxyManager.Get());
|
||||||
|
var doc = new HtmlDocument();
|
||||||
doc.LoadHtml(filmHtml);
|
doc.LoadHtml(filmHtml);
|
||||||
|
|
||||||
res = new List<Uaflix.Models.EpisodeLinkInfo>();
|
var result = new FilmInfo
|
||||||
var episodeNodes = doc.DocumentNode.SelectNodes("//div[contains(@class, 'frels2')]//a[contains(@class, 'vi-img')]");
|
{
|
||||||
|
Url = filmUrl
|
||||||
|
};
|
||||||
|
|
||||||
|
var titleNode = doc.DocumentNode.SelectSingleNode("//h1[@class='h1-title']");
|
||||||
|
if (titleNode != null)
|
||||||
|
{
|
||||||
|
result.Title = titleNode.InnerText.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
var metaDuration = doc.DocumentNode.SelectSingleNode("//meta[@property='og:video:duration']");
|
||||||
|
if (metaDuration != null)
|
||||||
|
{
|
||||||
|
string durationStr = metaDuration.GetAttributeValue("content", "");
|
||||||
|
if (int.TryParse(durationStr, out int duration))
|
||||||
|
{
|
||||||
|
result.Duration = duration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var metaActors = doc.DocumentNode.SelectSingleNode("//meta[@property='og:video:actor']");
|
||||||
|
if (metaActors != null)
|
||||||
|
{
|
||||||
|
string actorsStr = metaActors.GetAttributeValue("content", "");
|
||||||
|
result.Actors = actorsStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(a => a.Trim())
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
var metaDirector = doc.DocumentNode.SelectSingleNode("//meta[@property='og:video:director']");
|
||||||
|
if (metaDirector != null)
|
||||||
|
{
|
||||||
|
result.Director = metaDirector.GetAttributeValue("content", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
var descNode = doc.DocumentNode.SelectSingleNode("//div[@id='main-descr']//div[@itemprop='description']");
|
||||||
|
if (descNode != null)
|
||||||
|
{
|
||||||
|
result.Description = descNode.InnerText.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
var posterNode = doc.DocumentNode.SelectSingleNode("//img[@itemprop='image']");
|
||||||
|
if (posterNode != null)
|
||||||
|
{
|
||||||
|
result.PosterUrl = posterNode.GetAttributeValue("src", "");
|
||||||
|
if (!result.PosterUrl.StartsWith("http") && !string.IsNullOrEmpty(result.PosterUrl))
|
||||||
|
{
|
||||||
|
result.PosterUrl = _init.host + result.PosterUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_hybridCache.Set(memKey, result, cacheTime(60));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_onLog($"UaFlix GetFilmInfo error: {ex.Message}");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PaginationInfo> GetPaginationInfo(string filmUrl)
|
||||||
|
{
|
||||||
|
string memKey = $"UaFlix:pagination:{filmUrl}";
|
||||||
|
if (_hybridCache.TryGetValue(memKey, out PaginationInfo res))
|
||||||
|
return res;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var headers = new List<HeadersModel>() { new HeadersModel("User-Agent", "Mozilla/5.0"), new HeadersModel("Referer", _init.host) };
|
||||||
|
var filmHtml = await Http.Get(filmUrl, headers: headers, proxy: _proxyManager.Get());
|
||||||
|
var filmDoc = new HtmlDocument();
|
||||||
|
filmDoc.LoadHtml(filmHtml);
|
||||||
|
|
||||||
|
var paginationInfo = new PaginationInfo
|
||||||
|
{
|
||||||
|
SerialUrl = filmUrl
|
||||||
|
};
|
||||||
|
|
||||||
|
var allEpisodes = new List<EpisodeLinkInfo>();
|
||||||
|
var seasonUrls = new HashSet<string>();
|
||||||
|
|
||||||
|
var seasonNodes = filmDoc.DocumentNode.SelectNodes("//div[contains(@class, 'sez-wr')]//a");
|
||||||
|
if (seasonNodes == null)
|
||||||
|
seasonNodes = filmDoc.DocumentNode.SelectNodes("//div[contains(@class, 'fss-box')]//a");
|
||||||
|
if (seasonNodes != null && seasonNodes.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var node in seasonNodes)
|
||||||
|
{
|
||||||
|
string pageUrl = node.GetAttributeValue("href", null);
|
||||||
|
if (!string.IsNullOrEmpty(pageUrl))
|
||||||
|
{
|
||||||
|
if (!pageUrl.StartsWith("http"))
|
||||||
|
pageUrl = _init.host + pageUrl;
|
||||||
|
|
||||||
|
seasonUrls.Add(pageUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
seasonUrls.Add(filmUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
var seasonTasks = seasonUrls.Select(url => Http.Get(url, headers: headers, proxy: _proxyManager.Get()).AsTask());
|
||||||
|
var seasonPagesHtml = await Task.WhenAll(seasonTasks);
|
||||||
|
|
||||||
|
foreach (var html in seasonPagesHtml)
|
||||||
|
{
|
||||||
|
var pageDoc = new HtmlDocument();
|
||||||
|
pageDoc.LoadHtml(html);
|
||||||
|
|
||||||
|
var episodeNodes = pageDoc.DocumentNode.SelectNodes("//div[contains(@class, 'frels')]//a[contains(@class, 'vi-img')]");
|
||||||
if (episodeNodes != null)
|
if (episodeNodes != null)
|
||||||
{
|
{
|
||||||
foreach (var episodeNode in episodeNodes.Reverse().ToList())
|
foreach (var episodeNode in episodeNodes)
|
||||||
{
|
{
|
||||||
string episodeUrl = episodeNode.GetAttributeValue("href", "");
|
string episodeUrl = episodeNode.GetAttributeValue("href", "");
|
||||||
if (!episodeUrl.StartsWith("http"))
|
if (!episodeUrl.StartsWith("http"))
|
||||||
@ -91,7 +229,7 @@ namespace Uaflix
|
|||||||
var match = Regex.Match(episodeUrl, @"season-(\d+).*?episode-(\d+)");
|
var match = Regex.Match(episodeUrl, @"season-(\d+).*?episode-(\d+)");
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
{
|
{
|
||||||
res.Add(new Uaflix.Models.EpisodeLinkInfo
|
allEpisodes.Add(new EpisodeLinkInfo
|
||||||
{
|
{
|
||||||
url = episodeUrl,
|
url = episodeUrl,
|
||||||
title = episodeNode.SelectSingleNode(".//div[@class='vi-rate']")?.InnerText.Trim() ?? $"Епізод {match.Groups[2].Value}",
|
title = episodeNode.SelectSingleNode(".//div[@class='vi-rate']")?.InnerText.Trim() ?? $"Епізод {match.Groups[2].Value}",
|
||||||
@ -101,24 +239,28 @@ namespace Uaflix
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (res.Count == 0)
|
paginationInfo.Episodes = allEpisodes.OrderBy(e => e.season).ThenBy(e => e.episode).ToList();
|
||||||
|
|
||||||
|
if (paginationInfo.Episodes.Any())
|
||||||
{
|
{
|
||||||
var iframe = doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'video-box')]//iframe[contains(@src, 'ashdi.vip/serial/')]");
|
var uniqueSeasons = paginationInfo.Episodes.Select(e => e.season).Distinct().OrderBy(se => se);
|
||||||
if (iframe != null)
|
foreach (var season in uniqueSeasons)
|
||||||
{
|
{
|
||||||
res.Add(new Uaflix.Models.EpisodeLinkInfo() { url = filmUrl, season = 1, episode = 1 });
|
paginationInfo.Seasons[season] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.Count > 0)
|
if (paginationInfo.Episodes.Count > 0)
|
||||||
_hybridCache.Set(memKey, res, cacheTime(20));
|
{
|
||||||
|
_hybridCache.Set(memKey, paginationInfo, cacheTime(20));
|
||||||
return res;
|
return paginationInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_onLog($"UaFlix search error: {ex.Message}");
|
_onLog($"UaFlix GetPaginationInfo error: {ex.Message}");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -163,6 +305,7 @@ namespace Uaflix
|
|||||||
{
|
{
|
||||||
_onLog($"ParseEpisode error: {ex.Message}");
|
_onLog($"ParseEpisode error: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
_onLog($"ParseEpisode result: streams.count={result.streams.Count}, ashdi_url={result.ashdi_url}");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user