using System.Text.RegularExpressions; namespace Jellyfin.Plugin.TubeArchivistMetadata.Utilities { /// /// Class containing common utils. /// public static class Utils { /// /// Sanitize the given URL. /// /// An URL string. /// The URL string without spaces, doubled slashes and with a trailing slash. public static string SanitizeUrl(string inputUrl) { // Extract the schema part Match schemaMatch = Regex.Match(inputUrl, @"^(?https?://)"); // Remove double slashes and spaces from the remaining part of the URL string cleanedPath = Regex.Replace(inputUrl.Substring(schemaMatch.Length), @"[/\s]+", "/"); // Remove slashes at the start cleanedPath = cleanedPath.TrimStart('/'); // Add a trailing slash if not already present cleanedPath = cleanedPath.TrimEnd('/') + "/"; // Combine the schema and cleaned path string cleanedUrl = schemaMatch.Groups["schema"].Value + cleanedPath; return cleanedUrl; } /// /// Format episodes and series descriptions replacing newlines with br tags. /// /// String to format. /// A string with \n replaced by br tags. public static string FormatDescription(string description) { var maxLength = 500; if (Plugin.Instance != null) { maxLength = Plugin.Instance.Configuration.MaxDescriptionLength; } if (description.Length > maxLength) { description = description.Substring(0, maxLength); description = description.Replace("\n", "
", System.StringComparison.CurrentCulture); } return description; } } }