mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 19:01:02 +01:00
- Added RegexReplace class for handling regex replacements. - Created ReleaseGroupParser for extracting release groups from titles. - Developed TitleParser for parsing movie titles, including editions and IDs. - Introduced QualitySource, Resolution, QualityModifier enums and QualityResult class for quality metadata. - Set up Dockerfile and docker-compose for containerized deployment. - Implemented ASP.NET Core web API for parsing requests. - Added TypeScript client for interacting with the parser service. - Enhanced configuration to support dynamic parser service URL.
56 lines
2.1 KiB
C#
56 lines
2.1 KiB
C#
using System.Text.RegularExpressions;
|
|
|
|
namespace Parser.Core;
|
|
|
|
internal static class ParserCommon
|
|
{
|
|
internal static readonly RegexReplace[] PreSubstitutionRegex = Array.Empty<RegexReplace>();
|
|
|
|
// Valid TLDs - removes website prefixes like [www.example.com] or www.example.com -
|
|
internal static readonly RegexReplace WebsitePrefixRegex = new(
|
|
@"^(?:(?:\[|\()\s*)?(?:www\.)?[-a-z0-9-]{1,256}\.(?<!Naruto-Kun\.)(?:[a-z]{2,6}\.[a-z]{2,6}|xn--[a-z0-9-]{4,}|[a-z]{2,})\b(?:\s*(?:\]|\))|[ -]{2,})[ -]*",
|
|
string.Empty,
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
internal static readonly RegexReplace WebsitePostfixRegex = new(
|
|
@"(?:\[\s*)?(?:www\.)?[-a-z0-9-]{1,256}\.(?:xn--[a-z0-9-]{4,}|[a-z]{2,6})\b(?:\s*\])$",
|
|
string.Empty,
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
// Removes torrent site suffixes like [ettv], [rartv], etc.
|
|
internal static readonly RegexReplace CleanTorrentSuffixRegex = new(
|
|
@"\[(?:ettv|rartv|rarbg|cttv|publichd)\]$",
|
|
string.Empty,
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
// Common video file extensions
|
|
private static readonly HashSet<string> VideoExtensions = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
".mkv", ".mp4", ".avi", ".wmv", ".mov", ".m4v", ".mpg", ".mpeg",
|
|
".m2ts", ".ts", ".flv", ".webm", ".vob", ".ogv", ".divx", ".xvid",
|
|
".3gp", ".asf", ".rm", ".rmvb", ".iso", ".img"
|
|
};
|
|
|
|
private static readonly HashSet<string> UsenetExtensions = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
".par2", ".nzb"
|
|
};
|
|
|
|
private static readonly Regex FileExtensionRegex = new(
|
|
@"\.[a-z0-9]{2,4}$",
|
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
|
|
|
public static string RemoveFileExtension(string title)
|
|
{
|
|
return FileExtensionRegex.Replace(title, m =>
|
|
{
|
|
var extension = m.Value.ToLower();
|
|
if (VideoExtensions.Contains(extension) || UsenetExtensions.Contains(extension))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
return m.Value;
|
|
});
|
|
}
|
|
}
|