36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using System.Text.RegularExpressions;
|
|
|
|
namespace AnimeAnnouncer.Torrents
|
|
{
|
|
public static class TorrentDirectoryNamer
|
|
{
|
|
/// <summary>
|
|
/// 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"
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Builds the full save path for a release title under <paramref name="destinationFolder"/>.
|
|
/// </summary>
|
|
public static String FromTitle(String title, String destinationFolder)
|
|
{
|
|
return destinationFolder + (destinationFolder.EndsWith("/") ? String.Empty : "/") + FromTitle(title);
|
|
}
|
|
}
|
|
}
|