mirror of
https://github.com/lampame/lampac-ukraine.git
synced 2026-04-16 09:22:21 +00:00
- Updated all HTTP route paths from "lite/lme.module" to "lite/lme_module" across LME.AnimeON, LME.Bamboo, LME.JackTor, LME.KlonFUN, LME.Makhno, LME.Mikai, LME.NMoonAnime, LME.StarLight, LME.UafilmME, LME.Uaflix, and LME.Unimay controllers - Standardized error messages, log prefixes, cache keys, and other string identifiers to use underscores instead of dots for consistency with naming conventions - Applied changes to ModInit.cs, OnlineApi.cs, and invoke classes to maintain uniformity in module references
185 lines
7.4 KiB
C#
185 lines
7.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Shared;
|
|
using Shared.Models.Online.Settings;
|
|
using Shared.Models;
|
|
using System.Linq;
|
|
using LME.Unimay.Models;
|
|
using System.Net;
|
|
using System.Text;
|
|
|
|
namespace LME.Unimay
|
|
{
|
|
public class UnimayInvoke
|
|
{
|
|
private OnlinesSettings _init;
|
|
private ProxyManager _proxyManager;
|
|
private IHybridCache _hybridCache;
|
|
private Action<string> _onLog;
|
|
private readonly HttpHydra _httpHydra;
|
|
|
|
public UnimayInvoke(OnlinesSettings init, IHybridCache hybridCache, Action<string> onLog, ProxyManager proxyManager, HttpHydra httpHydra = null)
|
|
{
|
|
_init = init;
|
|
_hybridCache = hybridCache;
|
|
_onLog = onLog;
|
|
_proxyManager = proxyManager;
|
|
_httpHydra = httpHydra;
|
|
}
|
|
|
|
public async Task<SearchResponse> Search(string title, string original_title, int serial)
|
|
{
|
|
string memKey = $"lme_unimay:search:{title}:{original_title}:{serial}";
|
|
if (_hybridCache.TryGetValue(memKey, out SearchResponse searchResults))
|
|
return searchResults;
|
|
|
|
try
|
|
{
|
|
string searchQuery = System.Web.HttpUtility.UrlEncode(title ?? original_title ?? "");
|
|
string searchUrl = $"{_init.host}/release/search?page=0&page_size=10&title={searchQuery}";
|
|
|
|
var headers = httpHeaders(_init);
|
|
SearchResponse root = await HttpGet<SearchResponse>(searchUrl, headers, timeoutSeconds: 8);
|
|
|
|
if (root == null || root.Content == null || root.Content.Count == 0)
|
|
{
|
|
// Refresh proxy on failure
|
|
_proxyManager.Refresh();
|
|
return null;
|
|
}
|
|
|
|
_hybridCache.Set(memKey, root, cacheTime(30, init: _init));
|
|
return root;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_onLog($"Unimay search error: {ex.Message}");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<ReleaseResponse> Release(string code)
|
|
{
|
|
string memKey = $"lme_unimay:release:{code}";
|
|
if (_hybridCache.TryGetValue(memKey, out ReleaseResponse releaseDetail))
|
|
return releaseDetail;
|
|
|
|
try
|
|
{
|
|
string releaseUrl = $"{_init.host}/release?code={code}";
|
|
|
|
var headers = httpHeaders(_init);
|
|
ReleaseResponse root = await HttpGet<ReleaseResponse>(releaseUrl, headers, timeoutSeconds: 8);
|
|
|
|
if (root == null)
|
|
{
|
|
// Refresh proxy on failure
|
|
_proxyManager.Refresh();
|
|
return null;
|
|
}
|
|
|
|
_hybridCache.Set(memKey, root, cacheTime(60, init: _init));
|
|
return root;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_onLog($"Unimay release error: {ex.Message}");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public List<(string title, string year, string type, string url)> GetSearchResults(string host, SearchResponse searchResults, string title, string original_title, int serial)
|
|
{
|
|
var results = new List<(string title, string year, string type, string url)>();
|
|
|
|
foreach (var item in searchResults.Content)
|
|
{
|
|
// Filter by serial if specified (0: movie "Фільм", 1: serial "Телесеріал")
|
|
if (serial != -1)
|
|
{
|
|
bool isMovie = item.Type == "Фільм";
|
|
if ((serial == 0 && !isMovie) || (serial == 1 && isMovie))
|
|
continue;
|
|
}
|
|
|
|
string itemTitle = item.Names?.Ukr ?? item.Names?.Eng ?? item.Title;
|
|
string releaseUrl = $"{host}/lite/lme_unimay?code={item.Code}&title={System.Web.HttpUtility.UrlEncode(itemTitle)}&original_title={System.Web.HttpUtility.UrlEncode(original_title ?? "")}&serial={serial}";
|
|
results.Add((itemTitle, item.Year, item.Type, releaseUrl));
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
public (string title, string link) GetMovieResult(string host, ReleaseResponse releaseDetail, string title, string original_title)
|
|
{
|
|
if (releaseDetail.Playlist == null || releaseDetail.Playlist.Count == 0)
|
|
return (null, null);
|
|
|
|
var movieEpisode = releaseDetail.Playlist[0];
|
|
string movieLink = $"{host}/lite/lme_unimay?code={releaseDetail.Code}&title={System.Web.HttpUtility.UrlEncode(title)}&original_title={System.Web.HttpUtility.UrlEncode(original_title ?? "")}&serial=0&play=true";
|
|
string movieTitle = movieEpisode.Title ?? title;
|
|
|
|
return (movieTitle, movieLink);
|
|
}
|
|
|
|
public (string seasonName, string seasonUrl, string seasonId) GetSeasonInfo(string host, string code, string title, string original_title)
|
|
{
|
|
string seasonUrl = $"{host}/lite/lme_unimay?code={code}&title={System.Web.HttpUtility.UrlEncode(title)}&original_title={System.Web.HttpUtility.UrlEncode(original_title ?? "")}&serial=1&s=1";
|
|
return ("Сезон 1", seasonUrl, "1");
|
|
}
|
|
|
|
public List<(string episodeTitle, string episodeUrl)> GetEpisodesForSeason(string host, ReleaseResponse releaseDetail, string title, string original_title)
|
|
{
|
|
var episodes = new List<(string episodeTitle, string episodeUrl)>();
|
|
|
|
if (releaseDetail.Playlist == null)
|
|
return episodes;
|
|
|
|
foreach (var ep in releaseDetail.Playlist.Where(ep => ep.Number >= 1 && ep.Number <= 24).OrderBy(ep => ep.Number))
|
|
{
|
|
string epTitle = ep.Title ?? $"Епізод {ep.Number}";
|
|
string epLink = $"{host}/lite/lme_unimay?code={releaseDetail.Code}&title={System.Web.HttpUtility.UrlEncode(title)}&original_title={System.Web.HttpUtility.UrlEncode(original_title ?? "")}&serial=1&s=1&e={ep.Number}&play=true";
|
|
episodes.Add((epTitle, epLink));
|
|
}
|
|
|
|
return episodes;
|
|
}
|
|
|
|
public string GetStreamUrl(Episode episode)
|
|
{
|
|
return episode.Hls?.Master;
|
|
}
|
|
|
|
private List<HeadersModel> httpHeaders(OnlinesSettings init)
|
|
{
|
|
return new List<HeadersModel>()
|
|
{
|
|
new HeadersModel("User-Agent", "Mozilla/5.0"),
|
|
new HeadersModel("Referer", init.host),
|
|
new HeadersModel("Accept", "application/json")
|
|
};
|
|
}
|
|
|
|
private Task<T> HttpGet<T>(string url, List<HeadersModel> headers, int timeoutSeconds = 15)
|
|
{
|
|
if (_httpHydra != null)
|
|
return _httpHydra.Get<T>(url, newheaders: headers);
|
|
|
|
return Http.Get<T>(_init.cors(url), timeoutSeconds: timeoutSeconds, proxy: _proxyManager.Get(), headers: headers);
|
|
}
|
|
|
|
public static TimeSpan cacheTime(int multiaccess, int home = 5, int mikrotik = 2, OnlinesSettings init = null, int rhub = -1)
|
|
{
|
|
if (init != null && init.rhub && rhub != -1)
|
|
return TimeSpan.FromMinutes(rhub);
|
|
|
|
int ctime = init != null && init.cache_time > 0 ? init.cache_time : multiaccess;
|
|
if (ctime > multiaccess)
|
|
ctime = multiaccess;
|
|
|
|
return TimeSpan.FromMinutes(ctime);
|
|
}
|
|
}
|
|
}
|