2010-09-28 19:32:19 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2010-09-28 05:01:54 +00:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using NzbDrone.Core.Repository;
|
2010-10-01 00:09:22 +00:00
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2010-09-28 19:32:19 +00:00
|
|
|
using SubSonic.Repository;
|
2010-09-28 05:01:54 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
{
|
2010-09-28 20:44:33 +00:00
|
|
|
public class EpisodeProvider : IEpisodeProvider
|
2010-09-28 05:01:54 +00:00
|
|
|
{
|
2010-09-28 19:32:19 +00:00
|
|
|
//TODO: Remove parsing of the series name, it should be done in series provider
|
2010-09-28 06:09:24 +00:00
|
|
|
private static readonly Regex ParseRegex = new Regex(@"(?<showName>.*)
|
2010-09-28 05:01:54 +00:00
|
|
|
(?:
|
|
|
|
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);
|
|
|
|
|
2010-09-28 19:32:19 +00:00
|
|
|
|
|
|
|
private readonly IRepository _sonicRepo;
|
|
|
|
private readonly ISeriesProvider _seriesProvider;
|
|
|
|
|
|
|
|
public EpisodeProvider(IRepository sonicRepo, ISeriesProvider seriesProvider)
|
2010-09-28 05:01:54 +00:00
|
|
|
{
|
2010-09-28 19:32:19 +00:00
|
|
|
_sonicRepo = sonicRepo;
|
|
|
|
_seriesProvider = seriesProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Episode GetEpisode(long id)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Episode SaveEpisode(Episode episode)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2010-09-28 20:44:33 +00:00
|
|
|
public IList<Episode> GetEpisodesBySeason(long seasonId)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public IList<Episode> GetEpisodeBySeries(long seriesId)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2010-09-28 19:32:19 +00:00
|
|
|
public String GetSabTitle(Episode episode)
|
|
|
|
{
|
|
|
|
var series = _seriesProvider.GetSeries(episode.SeriesId);
|
|
|
|
if (series == null) throw new ArgumentException("Unknown series. ID: " + episode.SeriesId);
|
|
|
|
|
|
|
|
//TODO: This method should return a standard title for the sab episode.
|
|
|
|
throw new NotImplementedException();
|
2010-09-28 05:01:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-28 19:32:19 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Comprehensive check on whether or not this episode is needed.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="episode">Episode that needs to be checked</param>
|
|
|
|
/// <returns></returns>
|
2010-09-28 20:44:33 +00:00
|
|
|
public bool IsNeeded(Episode episode)
|
2010-09-28 05:01:54 +00:00
|
|
|
{
|
2010-09-28 19:32:19 +00:00
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Parses a post title into list of episode objects
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="title">Title of the report</param>
|
|
|
|
/// <returns>List of episodes relating to the post</returns>
|
|
|
|
public static List<Episode> Parse(string title)
|
|
|
|
{
|
|
|
|
var match = ParseRegex.Match(title);
|
|
|
|
|
|
|
|
if (!match.Success)
|
|
|
|
throw new ArgumentException(String.Format("Title doesn't match any know patterns. [{0}]", title));
|
2010-09-28 06:09:24 +00:00
|
|
|
|
2010-09-28 19:32:19 +00:00
|
|
|
var result = new List<Episode>();
|
|
|
|
|
|
|
|
result.Add(new Episode() { EpisodeNumber = Convert.ToInt32(match.Groups["episodeNumber"].Value) });
|
|
|
|
|
|
|
|
if (match.Groups["episodeNumber2"].Success)
|
|
|
|
{
|
|
|
|
result.Add(new Episode() { EpisodeNumber = Convert.ToInt32(match.Groups["episodeNumber2"].Value) });
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var ep in result)
|
|
|
|
{
|
|
|
|
//TODO: Get TVDB episode Title, Series name and the rest of the details
|
2010-10-01 00:09:22 +00:00
|
|
|
ep.SeasonNumber = Convert.ToInt32(match.Groups["seasonNumber"].Value);
|
2010-09-28 19:32:19 +00:00
|
|
|
ep.Title = ReplaceSeparatorChars(match.Groups["episodeName"].Value);
|
|
|
|
ep.Proper = title.Contains("PROPER");
|
2010-10-01 00:09:22 +00:00
|
|
|
ep.Quality = QualityTypes.Unknown;
|
2010-09-28 19:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2010-09-28 05:01:54 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 19:32:19 +00:00
|
|
|
private static string ReplaceSeparatorChars(string text)
|
2010-09-28 05:01:54 +00:00
|
|
|
{
|
2010-09-28 19:32:19 +00:00
|
|
|
if (text == null)
|
|
|
|
throw new ArgumentNullException("text");
|
|
|
|
|
|
|
|
return text.Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Trim();
|
2010-09-28 05:01:54 +00:00
|
|
|
}
|
2010-09-28 19:32:19 +00:00
|
|
|
|
2010-09-28 05:01:54 +00:00
|
|
|
}
|
|
|
|
}
|