Rearanged episodes object, added method stubs
This commit is contained in:
parent
de212f8b98
commit
8d47bcbe5e
|
@ -145,6 +145,8 @@
|
||||||
<Compile Include="Providers\ITvDbProvider.cs" />
|
<Compile Include="Providers\ITvDbProvider.cs" />
|
||||||
<Compile Include="Providers\SabProvider.cs" />
|
<Compile Include="Providers\SabProvider.cs" />
|
||||||
<Compile Include="Repository\Config.cs" />
|
<Compile Include="Repository\Config.cs" />
|
||||||
|
<Compile Include="Repository\RemoteEpisode.cs" />
|
||||||
|
<Compile Include="Repository\LocalEpisode.cs" />
|
||||||
<Compile Include="Repository\Episode.cs" />
|
<Compile Include="Repository\Episode.cs" />
|
||||||
<Compile Include="Repository\Quality.cs" />
|
<Compile Include="Repository\Quality.cs" />
|
||||||
<Compile Include="Repository\Series.cs" />
|
<Compile Include="Repository\Series.cs" />
|
||||||
|
@ -201,7 +203,9 @@
|
||||||
<Content Include="Libraries\TvdbLib.pdb" />
|
<Content Include="Libraries\TvdbLib.pdb" />
|
||||||
<Content Include="Libraries\TvdbLib.XML" />
|
<Content Include="Libraries\TvdbLib.XML" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup>
|
||||||
|
<None Include="nzbdrone.db" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
|
using SubSonic.Repository;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers
|
namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
public class EpisodeProvider
|
public class EpisodeProvider
|
||||||
{
|
{
|
||||||
|
//TODO: Remove parsing of the series name, it should be done in series provider
|
||||||
private static readonly Regex ParseRegex = new Regex(@"(?<showName>.*)
|
private static readonly Regex ParseRegex = new Regex(@"(?<showName>.*)
|
||||||
(?:
|
(?:
|
||||||
s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)-?e(?<episodeNumber2>\d+)
|
s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)-?e(?<episodeNumber2>\d+)
|
||||||
|
@ -20,36 +24,88 @@ namespace NzbDrone.Core.Providers
|
||||||
| (?<episodeName>.*)
|
| (?<episodeName>.*)
|
||||||
)", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);
|
)", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);
|
||||||
|
|
||||||
public static Episode Parse(string title)
|
|
||||||
|
private readonly IRepository _sonicRepo;
|
||||||
|
private readonly ISeriesProvider _seriesProvider;
|
||||||
|
|
||||||
|
public EpisodeProvider(IRepository sonicRepo, ISeriesProvider seriesProvider)
|
||||||
{
|
{
|
||||||
Match match = ParseRegex.Match(title);
|
_sonicRepo = sonicRepo;
|
||||||
|
_seriesProvider = seriesProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Episode GetEpisode(long id)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Episode SaveEpisode(Episode episode)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Comprehensive check on whether or not this episode is needed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="episode">Episode that needs to be checked</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IsEpisodeNeeded(Episode episode)
|
||||||
|
{
|
||||||
|
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)
|
if (!match.Success)
|
||||||
return null;
|
throw new ArgumentException(String.Format("Title doesn't match any know patterns. [{0}]", title));
|
||||||
|
|
||||||
return new Episode {
|
var result = new List<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)
|
result.Add(new Episode() { EpisodeNumber = Convert.ToInt32(match.Groups["episodeNumber"].Value) });
|
||||||
|
|
||||||
|
if (match.Groups["episodeNumber2"].Success)
|
||||||
{
|
{
|
||||||
if (s == null)
|
result.Add(new Episode() { EpisodeNumber = Convert.ToInt32(match.Groups["episodeNumber2"].Value) });
|
||||||
return string.Empty;
|
|
||||||
|
|
||||||
return s.Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ParseInt(string s)
|
foreach (var ep in result)
|
||||||
{
|
{
|
||||||
int i;
|
//TODO: Get TVDB episode Title, Series name and the rest of the details
|
||||||
int.TryParse(s, out i);
|
ep.Season = Convert.ToInt32(match.Groups["seasonNumber"].Value);
|
||||||
return i;
|
ep.Title = ReplaceSeparatorChars(match.Groups["episodeName"].Value);
|
||||||
|
ep.Proper = title.Contains("PROPER");
|
||||||
|
ep.Quality = Quality.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ReplaceSeparatorChars(string text)
|
||||||
|
{
|
||||||
|
if (text == null)
|
||||||
|
throw new ArgumentNullException("text");
|
||||||
|
|
||||||
|
return text.Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Trim();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,21 @@ namespace NzbDrone.Core.Providers
|
||||||
public interface ISeriesProvider
|
public interface ISeriesProvider
|
||||||
{
|
{
|
||||||
IQueryable<Series> GetSeries();
|
IQueryable<Series> GetSeries();
|
||||||
Series GetSeries(int tvdbId);
|
Series GetSeries(long tvdbId);
|
||||||
void SyncSeriesWithDisk();
|
void SyncSeriesWithDisk();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses a post title
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="postTitle">Title of the report</param>
|
||||||
|
/// <returns>TVDB id of the series this report belongs to</returns>
|
||||||
|
long Parse(string postTitle);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if a series is being actively watched.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TVDB ID of the series</param>
|
||||||
|
/// <returns>Whether or not the show is monitored</returns>
|
||||||
|
bool IsMonitored(long id);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
using System.IO;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using log4net;
|
using log4net;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using SubSonic.Repository;
|
using SubSonic.Repository;
|
||||||
|
@ -9,6 +12,22 @@ namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
public class SeriesProvider : ISeriesProvider
|
public class SeriesProvider : ISeriesProvider
|
||||||
{
|
{
|
||||||
|
//TODO: Remove parsing of rest of tv show info we just need the show name
|
||||||
|
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);
|
||||||
|
|
||||||
private readonly IConfigProvider _config;
|
private readonly IConfigProvider _config;
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
private readonly ILog _logger;
|
private readonly ILog _logger;
|
||||||
|
@ -31,7 +50,7 @@ namespace NzbDrone.Core.Providers
|
||||||
return _sonioRepo.All<Series>();
|
return _sonioRepo.All<Series>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Series GetSeries(int tvdbId)
|
public Series GetSeries(long tvdbId)
|
||||||
{
|
{
|
||||||
return _sonioRepo.Single<Series>(s => s.TvdbId == tvdbId.ToString());
|
return _sonioRepo.Single<Series>(s => s.TvdbId == tvdbId.ToString());
|
||||||
}
|
}
|
||||||
|
@ -71,5 +90,33 @@ namespace NzbDrone.Core.Providers
|
||||||
repoSeries.Path = path;
|
repoSeries.Path = path;
|
||||||
_sonioRepo.Add(repoSeries);
|
_sonioRepo.Add(repoSeries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses a post title
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="postTitle">Title of the report</param>
|
||||||
|
/// <returns>TVDB id of the series this report belongs to</returns>
|
||||||
|
public long Parse(string postTitle)
|
||||||
|
{
|
||||||
|
var match = ParseRegex.Match(postTitle);
|
||||||
|
|
||||||
|
if (!match.Success)
|
||||||
|
throw new ArgumentException(String.Format("Title doesn't match any know patterns. [{0}]", postTitle));
|
||||||
|
|
||||||
|
//TODO: title should be mapped to a proper Series object. with tvdbId and everything even if it is not in the db or being tracked.
|
||||||
|
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if a series is being actively watched.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The TVDB ID of the series</param>
|
||||||
|
/// <returns>Whether or not the show is monitored</returns>
|
||||||
|
public bool IsMonitored(long id)
|
||||||
|
{
|
||||||
|
//should just check the db for now, if it exists its being monitored.
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,18 +8,12 @@ namespace NzbDrone.Core.Repository
|
||||||
{
|
{
|
||||||
[SubSonicPrimaryKey]
|
[SubSonicPrimaryKey]
|
||||||
public string EpisodeId { get; set; }
|
public string EpisodeId { get; set; }
|
||||||
|
public long SeriesId { get; set; }
|
||||||
public string SeriesId { get; set; }
|
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string Title2 { get; set; }
|
public long Season { get; set; }
|
||||||
public int Season { get; set; }
|
|
||||||
public int EpisodeNumber { get; set; }
|
public int EpisodeNumber { get; set; }
|
||||||
public int EpisodeNumber2 { get; set; }
|
|
||||||
public DateTime AirDate { get; set; }
|
public DateTime AirDate { get; set; }
|
||||||
public string Release { get; set; }
|
public Quality Quality { get; set; }
|
||||||
public int Quality { get; set; }
|
|
||||||
public bool Proper { get; set; }
|
public bool Proper { get; set; }
|
||||||
public String FileName { get; set; }
|
|
||||||
public SyndicationItem Feed { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
using System.ServiceModel.Syndication;
|
||||||
|
using SubSonic.SqlGeneration.Schema;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Repository
|
||||||
|
{
|
||||||
|
public class LocalEpisode : Episode
|
||||||
|
{
|
||||||
|
public String Path { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
using System.ServiceModel.Syndication;
|
||||||
|
using SubSonic.SqlGeneration.Schema;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Repository
|
||||||
|
{
|
||||||
|
public class RemoteEpisode : Episode
|
||||||
|
{
|
||||||
|
[SubSonicIgnore]
|
||||||
|
public SyndicationItem Feed { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue