mirror of
https://github.com/lampame/lampac-ukraine.git
synced 2026-04-16 09:22:21 +00:00
refactor(nmoonanime): simplify search method by removing original_title parameter
- Add ResolveMalId helper to resolve effective MAL ID from mal_id or kinopoisk_id - Remove original_title from Search method signature and cache keys - Simplify BuildSearchUrl to prioritize query parameters (mal_id > imdb_id > title)
This commit is contained in:
parent
dbb24205d7
commit
4532c621c7
@ -35,22 +35,23 @@ namespace NMoonAnime.Controllers
|
|||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var invoke = new NMoonAnimeInvoke(init, hybridCache, OnLog, proxyManager);
|
var invoke = new NMoonAnimeInvoke(init, hybridCache, OnLog, proxyManager);
|
||||||
|
string effectiveMalId = ResolveMalId(mal_id, kinopoisk_id);
|
||||||
|
|
||||||
if (checksearch)
|
if (checksearch)
|
||||||
{
|
{
|
||||||
if (AppInit.conf?.online?.checkOnlineSearch != true)
|
if (AppInit.conf?.online?.checkOnlineSearch != true)
|
||||||
return OnError("nmoonanime", proxyManager);
|
return OnError("nmoonanime", proxyManager);
|
||||||
|
|
||||||
var checkResults = await invoke.Search(imdb_id, mal_id, title, original_title, year);
|
var checkResults = await invoke.Search(imdb_id, effectiveMalId, title, year);
|
||||||
if (checkResults != null && checkResults.Count > 0)
|
if (checkResults != null && checkResults.Count > 0)
|
||||||
return Content("data-json=", "text/plain; charset=utf-8");
|
return Content("data-json=", "text/plain; charset=utf-8");
|
||||||
|
|
||||||
return OnError("nmoonanime", proxyManager);
|
return OnError("nmoonanime", proxyManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnLog($"NMoonAnime: назва={title}, оригінальна_назва={original_title}, imdb={imdb_id}, mal_id={mal_id}, серіал={serial}, сезон={s}, озвучка={t}");
|
OnLog($"NMoonAnime: назва={title}, imdb={imdb_id}, kinopoisk_id(як mal_id)={kinopoisk_id}, mal_id_ефективний={effectiveMalId}, рік={year}, серіал={serial}, сезон={s}, озвучка={t}");
|
||||||
|
|
||||||
var seasons = await invoke.Search(imdb_id, mal_id, title, original_title, year);
|
var seasons = await invoke.Search(imdb_id, effectiveMalId, title, year);
|
||||||
if (seasons == null || seasons.Count == 0)
|
if (seasons == null || seasons.Count == 0)
|
||||||
return OnError("nmoonanime", proxyManager);
|
return OnError("nmoonanime", proxyManager);
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ namespace NMoonAnime.Controllers
|
|||||||
|
|
||||||
if (isSeries)
|
if (isSeries)
|
||||||
{
|
{
|
||||||
return await RenderSerial(invoke, seasons, imdb_id, kinopoisk_id, title, original_title, year, mal_id, s, t, rjson);
|
return await RenderSerial(invoke, seasons, imdb_id, kinopoisk_id, title, original_title, year, effectiveMalId, s, t, rjson);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await RenderMovie(invoke, seasons, title, original_title, firstSeasonData, rjson);
|
return await RenderMovie(invoke, seasons, title, original_title, firstSeasonData, rjson);
|
||||||
@ -297,6 +298,14 @@ namespace NMoonAnime.Controllers
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ResolveMalId(string malId, long kinopoiskId)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(malId))
|
||||||
|
return malId.Trim();
|
||||||
|
|
||||||
|
return kinopoiskId > 0 ? kinopoiskId.ToString() : null;
|
||||||
|
}
|
||||||
|
|
||||||
private string BuildStreamUrl(OnlinesSettings init, string streamLink)
|
private string BuildStreamUrl(OnlinesSettings init, string streamLink)
|
||||||
{
|
{
|
||||||
string link = StripLampacArgs(streamLink?.Trim());
|
string link = StripLampacArgs(streamLink?.Trim());
|
||||||
|
|||||||
@ -33,9 +33,9 @@ namespace NMoonAnime
|
|||||||
_proxyManager = proxyManager;
|
_proxyManager = proxyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<NMoonAnimeSeasonRef>> Search(string imdbId, string malId, string title, string originalTitle, int year)
|
public async Task<List<NMoonAnimeSeasonRef>> Search(string imdbId, string malId, string title, int year)
|
||||||
{
|
{
|
||||||
string memKey = $"NMoonAnime:search:{imdbId}:{malId}:{title}:{originalTitle}:{year}";
|
string memKey = $"NMoonAnime:search:{imdbId}:{malId}:{title}:{year}";
|
||||||
if (_hybridCache.TryGetValue(memKey, out List<NMoonAnimeSeasonRef> cached))
|
if (_hybridCache.TryGetValue(memKey, out List<NMoonAnimeSeasonRef> cached))
|
||||||
return cached;
|
return cached;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ namespace NMoonAnime
|
|||||||
|
|
||||||
foreach (var endpoint in endpoints)
|
foreach (var endpoint in endpoints)
|
||||||
{
|
{
|
||||||
string searchUrl = BuildSearchUrl(endpoint, imdbId, malId, title, originalTitle, year);
|
string searchUrl = BuildSearchUrl(endpoint, imdbId, malId, title, year);
|
||||||
if (string.IsNullOrWhiteSpace(searchUrl))
|
if (string.IsNullOrWhiteSpace(searchUrl))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -198,21 +198,18 @@ namespace NMoonAnime
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string BuildSearchUrl(string endpoint, string imdbId, string malId, string title, string originalTitle, int year)
|
private string BuildSearchUrl(string endpoint, string imdbId, string malId, string title, int year)
|
||||||
{
|
{
|
||||||
var query = HttpUtility.ParseQueryString(string.Empty);
|
var query = HttpUtility.ParseQueryString(string.Empty);
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(imdbId))
|
|
||||||
query["imdb_id"] = imdbId;
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(malId))
|
if (!string.IsNullOrWhiteSpace(malId))
|
||||||
query["mal_id"] = malId;
|
query["mal_id"] = malId;
|
||||||
|
else if (!string.IsNullOrWhiteSpace(imdbId))
|
||||||
if (!string.IsNullOrWhiteSpace(title))
|
query["imdb_id"] = imdbId;
|
||||||
|
else if (!string.IsNullOrWhiteSpace(title))
|
||||||
query["title"] = title;
|
query["title"] = title;
|
||||||
|
else
|
||||||
if (!string.IsNullOrWhiteSpace(originalTitle))
|
return null;
|
||||||
query["original_title"] = originalTitle;
|
|
||||||
|
|
||||||
if (year > 0)
|
if (year > 0)
|
||||||
query["year"] = year.ToString();
|
query["year"] = year.ToString();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user