1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00
Radarr/NzbDrone.Core/Providers/EpisodeProvider.cs
2010-09-27 23:09:24 -07:00

55 lines
1.8 KiB
C#

using System.Text.RegularExpressions;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers
{
public class EpisodeProvider
{
private static readonly Regex ParseRegex = new Regex(@"(?<showName>.*)
(?:
s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)-?e(?<episodeNumber2>\d+)
| s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)
| (?<seasonNumber>\d+)x(?<episodeNumber>\d+)
| (?<airDate>\d{4}.\d{2}.\d{2})
)
(?:
(?<episodeName>.*?)
(?<release>
(?:hdtv|pdtv|xvid|ws|720p|x264|bdrip|dvdrip|dsr|proper)
.*)
| (?<episodeName>.*)
)", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);
public static Episode Parse(string title)
{
Match match = ParseRegex.Match(title);
if (!match.Success)
return null;
return new Episode {
Season = ParseInt(match.Groups["seasonNumber"].Value),
EpisodeNumber = ParseInt(match.Groups["episodeNumber"].Value),
EpisodeNumber2 = ParseInt(match.Groups["episodeNumber2"].Value),
Title = ReplaceSeparatorChars(match.Groups["episodeName"].Value),
Release = ReplaceSeparatorChars(match.Groups["release"].Value),
Proper = title.Contains("PROPER")
};
}
private static string ReplaceSeparatorChars(string s)
{
if (s == null)
return string.Empty;
return s.Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Trim();
}
private static int ParseInt(string s)
{
int i;
int.TryParse(s, out i);
return i;
}
}
}