using System.Text.RegularExpressions; namespace AnimeAnnouncer.Torrents { public static class TorrentDirectoryNamer { /// /// Turns a release title into a dotted directory name, stripping the episode number /// (keeping the resolution) and any trailing parenthesised suffix. /// e.g. "Show Name S01E05 1080p WEB (Group)" -> "Show.Name.S01.1080p.WEB" /// public static String FromTitle(String title) { String name = title.Trim(); name = Regex.Replace(name, @"E\d{2,3}.*?(\d{3,4}p)", " $1"); name = Regex.Replace(name, @"\s\(.*?\)$", ""); return name.Replace(" ", "."); } public static String PrepareForURI(String title) { var titlePart = Regex.Replace(title, @"[^\w\s]+", String.Empty); titlePart = Regex.Replace(titlePart, @"\s+", "+"); return titlePart; } /// /// Builds the full save path for a release title under . /// public static String FromTitle(String title, String destinationFolder) { return destinationFolder + (destinationFolder.EndsWith("/") ? String.Empty : "/") + FromTitle(title); } } }