refactor: strip year prefix from movie titles

Extract StripMoviePrefix method across all movie providers to remove year
prefixes (e.g., "2023 - Movie Title" → "Movie Title") from displayed titles.
Simplify label construction in UaTUT controller by removing redundant movie
name prefix from variant labels.
This commit is contained in:
Felix 2026-02-21 13:37:58 +02:00
parent 224f11b1f0
commit cd6724b452
7 changed files with 133 additions and 9 deletions

View File

@ -320,7 +320,7 @@ namespace AnimeON
private static string BuildDisplayTitle(string rawTitle, string link, int index)
{
string normalized = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : WebUtility.HtmlDecode(rawTitle).Trim();
string normalized = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : StripMoviePrefix(WebUtility.HtmlDecode(rawTitle).Trim());
string qualityTag = DetectQualityTag($"{normalized} {link}");
if (string.IsNullOrWhiteSpace(qualityTag))
return normalized;
@ -345,6 +345,27 @@ namespace AnimeON
return null;
}
private static string StripMoviePrefix(string title)
{
if (string.IsNullOrWhiteSpace(title))
return title;
string normalized = Regex.Replace(title, @"\s+", " ").Trim();
int sepIndex = normalized.LastIndexOf(" - ", StringComparison.Ordinal);
if (sepIndex <= 0 || sepIndex >= normalized.Length - 3)
return normalized;
string prefix = normalized.Substring(0, sepIndex).Trim();
string suffix = normalized.Substring(sepIndex + 3).Trim();
if (string.IsNullOrWhiteSpace(suffix))
return normalized;
if (Regex.IsMatch(prefix, @"(19|20)\d{2}"))
return suffix;
return normalized;
}
private static string ExtractPlayerFileArray(string html)
{
if (string.IsNullOrWhiteSpace(html))

View File

@ -650,7 +650,7 @@ namespace KlonFUN
private static string FormatMovieTitle(string rawTitle, string streamUrl, int index)
{
string title = CleanText(rawTitle);
string title = StripMoviePrefix(CleanText(rawTitle));
if (string.IsNullOrWhiteSpace(title))
title = $"Варіант {index}";
@ -664,6 +664,27 @@ namespace KlonFUN
return $"{tag} {title}";
}
private static string StripMoviePrefix(string title)
{
if (string.IsNullOrWhiteSpace(title))
return title;
string normalized = Regex.Replace(title, @"\s+", " ").Trim();
int sepIndex = normalized.LastIndexOf(" - ", StringComparison.Ordinal);
if (sepIndex <= 0 || sepIndex >= normalized.Length - 3)
return normalized;
string prefix = normalized.Substring(0, sepIndex).Trim();
string suffix = normalized.Substring(sepIndex + 3).Trim();
if (string.IsNullOrWhiteSpace(suffix))
return normalized;
if (Regex.IsMatch(prefix, @"(19|20)\d{2}"))
return suffix;
return normalized;
}
private static string DetectQualityTag(string source)
{
if (string.IsNullOrWhiteSpace(source))

View File

@ -615,7 +615,7 @@ namespace Makhno
private static string BuildMovieTitle(string rawTitle, string file, int index)
{
string title = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : WebUtility.HtmlDecode(rawTitle).Trim();
string title = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : StripMoviePrefix(WebUtility.HtmlDecode(rawTitle).Trim());
string qualityTag = DetectQualityTag($"{title} {file}");
if (string.IsNullOrWhiteSpace(qualityTag))
@ -641,6 +641,27 @@ namespace Makhno
return null;
}
private static string StripMoviePrefix(string title)
{
if (string.IsNullOrWhiteSpace(title))
return title;
string normalized = Regex.Replace(title, @"\s+", " ").Trim();
int sepIndex = normalized.LastIndexOf(" - ", StringComparison.Ordinal);
if (sepIndex <= 0 || sepIndex >= normalized.Length - 3)
return normalized;
string prefix = normalized.Substring(0, sepIndex).Trim();
string suffix = normalized.Substring(sepIndex + 3).Trim();
if (string.IsNullOrWhiteSpace(suffix))
return normalized;
if (Regex.IsMatch(prefix, @"(19|20)\d{2}"))
return suffix;
return normalized;
}
public string ExtractAshdiPath(string value)
{
if (string.IsNullOrWhiteSpace(value))

View File

@ -266,7 +266,7 @@ namespace Mikai
private static string BuildDisplayTitle(string rawTitle, string link, int index)
{
string normalized = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : WebUtility.HtmlDecode(rawTitle).Trim();
string normalized = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : StripMoviePrefix(WebUtility.HtmlDecode(rawTitle).Trim());
string qualityTag = DetectQualityTag($"{normalized} {link}");
if (string.IsNullOrWhiteSpace(qualityTag))
return normalized;
@ -291,6 +291,27 @@ namespace Mikai
return null;
}
private static string StripMoviePrefix(string title)
{
if (string.IsNullOrWhiteSpace(title))
return title;
string normalized = Regex.Replace(title, @"\s+", " ").Trim();
int sepIndex = normalized.LastIndexOf(" - ", StringComparison.Ordinal);
if (sepIndex <= 0 || sepIndex >= normalized.Length - 3)
return normalized;
string prefix = normalized.Substring(0, sepIndex).Trim();
string suffix = normalized.Substring(sepIndex + 3).Trim();
if (string.IsNullOrWhiteSpace(suffix))
return normalized;
if (Regex.IsMatch(prefix, @"(19|20)\d{2}"))
return suffix;
return normalized;
}
private static string ExtractPlayerFileArray(string html)
{
if (string.IsNullOrWhiteSpace(html))

View File

@ -298,14 +298,12 @@ namespace UaTUT
if (movieStreams.Count == 0)
continue;
string movieName = $"{movie.Title} ({movie.Year})";
foreach (var variant in movieStreams)
{
string variantName = !string.IsNullOrWhiteSpace(variant.Title)
string label = !string.IsNullOrWhiteSpace(variant.Title)
? variant.Title
: "Варіант";
string label = $"{movieName} - {variantName}";
movie_tpl.Append(label, BuildStreamUrl(init, variant.File));
}
}

View File

@ -329,7 +329,7 @@ namespace UaTUT
private static string BuildMovieTitle(string rawTitle, string file, int index)
{
string title = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : WebUtility.HtmlDecode(rawTitle).Trim();
string title = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : StripMoviePrefix(WebUtility.HtmlDecode(rawTitle).Trim());
string qualityTag = DetectQualityTag($"{title} {file}");
if (string.IsNullOrWhiteSpace(qualityTag))
return title;
@ -354,6 +354,27 @@ namespace UaTUT
return null;
}
private static string StripMoviePrefix(string title)
{
if (string.IsNullOrWhiteSpace(title))
return title;
string normalized = Regex.Replace(title, @"\s+", " ").Trim();
int sepIndex = normalized.LastIndexOf(" - ", StringComparison.Ordinal);
if (sepIndex <= 0 || sepIndex >= normalized.Length - 3)
return normalized;
string prefix = normalized.Substring(0, sepIndex).Trim();
string suffix = normalized.Substring(sepIndex + 3).Trim();
if (string.IsNullOrWhiteSpace(suffix))
return normalized;
if (Regex.IsMatch(prefix, @"(19|20)\d{2}"))
return suffix;
return normalized;
}
private static string ExtractPlayerFileArray(string html)
{
if (string.IsNullOrWhiteSpace(html))

View File

@ -1533,7 +1533,7 @@ namespace Uaflix
private static string BuildDisplayTitle(string rawTitle, string link, int index)
{
string normalized = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : WebUtility.HtmlDecode(rawTitle).Trim();
string normalized = string.IsNullOrWhiteSpace(rawTitle) ? $"Варіант {index}" : StripMoviePrefix(WebUtility.HtmlDecode(rawTitle).Trim());
string qualityTag = DetectQualityTag($"{normalized} {link}");
if (string.IsNullOrWhiteSpace(qualityTag))
return normalized;
@ -1558,6 +1558,27 @@ namespace Uaflix
return null;
}
private static string StripMoviePrefix(string title)
{
if (string.IsNullOrWhiteSpace(title))
return title;
string normalized = Regex.Replace(title, @"\s+", " ").Trim();
int sepIndex = normalized.LastIndexOf(" - ", StringComparison.Ordinal);
if (sepIndex <= 0 || sepIndex >= normalized.Length - 3)
return normalized;
string prefix = normalized.Substring(0, sepIndex).Trim();
string suffix = normalized.Substring(sepIndex + 3).Trim();
if (string.IsNullOrWhiteSpace(suffix))
return normalized;
if (Regex.IsMatch(prefix, @"(19|20)\d{2}"))
return suffix;
return normalized;
}
private static string ExtractPlayerFileArray(string html)
{
if (string.IsNullOrWhiteSpace(html))