using System.Text.RegularExpressions; namespace Parser.Core; internal static class ParserCommon { internal static readonly RegexReplace[] PreSubstitutionRegex = Array.Empty(); // 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}\.(? 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 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; }); } }