From 6144ff8f3e7c53def0b9a9504cf8ce964c61ff66 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 28 May 2013 18:28:47 -0700 Subject: [PATCH] better handling of situations where a parsed episode isn't in the database. --- NzbDrone.Core/Parser/ParsingService.cs | 6 +++--- NzbDrone.Core/Tv/EpisodeRepository.cs | 20 ++++++++++++++++++- NzbDrone.Core/Tv/EpisodeService.cs | 21 ++++++++++++++++---- UI/Series/Details/SeriesDetailsTemplate.html | 1 + 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/NzbDrone.Core/Parser/ParsingService.cs b/NzbDrone.Core/Parser/ParsingService.cs index 79995d75a..852c94ef2 100644 --- a/NzbDrone.Core/Parser/ParsingService.cs +++ b/NzbDrone.Core/Parser/ParsingService.cs @@ -64,7 +64,7 @@ namespace NzbDrone.Core.Parser return _seriesService.FindByTitle(searchTitle); } - public RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo) + public RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo) { var remoteEpisode = new RemoteEpisode { @@ -120,7 +120,7 @@ namespace NzbDrone.Core.Parser if (series.UseSceneNumbering && parsedEpisodeInfo.SceneSource) { - episodeInfo = _episodeService.GetEpisode(series.Id, parsedEpisodeInfo.SeasonNumber, episodeNumber, true); + episodeInfo = _episodeService.FindEpisode(series.Id, parsedEpisodeInfo.SeasonNumber, episodeNumber, true); } if (episodeInfo == null) @@ -128,7 +128,7 @@ namespace NzbDrone.Core.Parser episodeInfo = _episodeService.GetEpisode(series.Id, parsedEpisodeInfo.SeasonNumber, episodeNumber); if (episodeInfo == null && parsedEpisodeInfo.AirDate != null) { - episodeInfo = _episodeService.GetEpisode(series.Id, parsedEpisodeInfo.AirDate.Value); + episodeInfo = _episodeService.FindEpisode(series.Id, parsedEpisodeInfo.AirDate.Value); } } diff --git a/NzbDrone.Core/Tv/EpisodeRepository.cs b/NzbDrone.Core/Tv/EpisodeRepository.cs index 3372960a4..f30acb27f 100644 --- a/NzbDrone.Core/Tv/EpisodeRepository.cs +++ b/NzbDrone.Core/Tv/EpisodeRepository.cs @@ -13,12 +13,15 @@ namespace NzbDrone.Core.Tv public interface IEpisodeRepository : IBasicRepository { Episode Get(int seriesId, int season, int episodeNumber); + Episode Find(int seriesId, int season, int episodeNumber); Episode Get(int seriesId, DateTime date); + Episode Find(int seriesId, DateTime date); List GetEpisodes(int seriesId); List GetEpisodes(int seriesId, int seasonNumber); List GetEpisodeByFileId(int fileId); PagingSpec EpisodesWithoutFiles(PagingSpec pagingSpec, bool includeSpecials); Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber); + Episode FindEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber); List EpisodesWithFiles(); List EpisodesBetweenDates(DateTime startDate, DateTime endDate); void SetIgnoreFlat(Episode episode, bool ignoreFlag); @@ -40,11 +43,21 @@ namespace NzbDrone.Core.Tv return Query.Single(s => s.SeriesId == seriesId && s.SeasonNumber == season && s.EpisodeNumber == episodeNumber); } + public Episode Find(int seriesId, int season, int episodeNumber) + { + return Query.SingleOrDefault(s => s.SeriesId == seriesId && s.SeasonNumber == season && s.EpisodeNumber == episodeNumber); + } + public Episode Get(int seriesId, DateTime date) { return Query.Single(s => s.SeriesId == seriesId && s.AirDate.HasValue && s.AirDate.Value.Date == date.Date); } + public Episode Find(int seriesId, DateTime date) + { + return Query.SingleOrDefault(s => s.SeriesId == seriesId && s.AirDate.HasValue && s.AirDate.Value.Date == date.Date); + } + public List GetEpisodes(int seriesId) { return Query.Where(s => s.SeriesId == seriesId).ToList(); @@ -81,7 +94,7 @@ namespace NzbDrone.Core.Tv pagingSpec.Records = pagingQuery.ToList(); //TODO: Use the same query for count and records - pagingSpec.TotalRecords = Query.Where(e => e.EpisodeFileId == 0 && e.SeasonNumber >= startingSeasonNumber && e.AirDate <= currentTime).Count(); + pagingSpec.TotalRecords = Query.Count(e => e.EpisodeFileId == 0 && e.SeasonNumber >= startingSeasonNumber && e.AirDate <= currentTime); return pagingSpec; } @@ -91,6 +104,11 @@ namespace NzbDrone.Core.Tv return Query.Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber && s.SceneEpisodeNumber == episodeNumber); } + public Episode FindEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber) + { + return Query.SingleOrDefault(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber && s.SceneEpisodeNumber == episodeNumber); + } + public List EpisodesWithFiles() { return Query.Where(s => s.EpisodeFileId != 0).ToList(); diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs index 5ba9c4ae2..430201859 100644 --- a/NzbDrone.Core/Tv/EpisodeService.cs +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -5,11 +5,8 @@ using NLog; using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; -using NzbDrone.Core.Download; -using NzbDrone.Core.Helpers; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.MetadataSource; -using NzbDrone.Core.Model; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.Tv @@ -18,7 +15,9 @@ namespace NzbDrone.Core.Tv { Episode GetEpisode(int id); Episode GetEpisode(int seriesId, int seasonNumber, int episodeNumber, bool useScene = false); + Episode FindEpisode(int seriesId, int seasonNumber, int episodeNumber, bool useScene = false); Episode GetEpisode(int seriesId, DateTime date); + Episode FindEpisode(int seriesId, DateTime date); List GetEpisodeBySeries(int seriesId); List GetEpisodesBySeason(int seriesId, int seasonNumber); PagingSpec EpisodesWithoutFiles(PagingSpec pagingSpec); @@ -75,7 +74,16 @@ namespace NzbDrone.Core.Tv { return _episodeRepository.GetEpisodeBySceneNumbering(seriesId, seasonNumber, episodeNumber); } - return _episodeRepository.Get(seriesId, seasonNumber, episodeNumber); + return _episodeRepository.Find(seriesId, seasonNumber, episodeNumber); + } + + public Episode FindEpisode(int seriesId, int seasonNumber, int episodeNumber, bool useSceneNumbering = false) + { + if (useSceneNumbering) + { + return _episodeRepository.FindEpisodeBySceneNumbering(seriesId, seasonNumber, episodeNumber); + } + return _episodeRepository.Find(seriesId, seasonNumber, episodeNumber); } public Episode GetEpisode(int seriesId, DateTime date) @@ -83,6 +91,11 @@ namespace NzbDrone.Core.Tv return _episodeRepository.Get(seriesId, date); } + public Episode FindEpisode(int seriesId, DateTime date) + { + return _episodeRepository.Find(seriesId, date); + } + public List GetEpisodeBySeries(int seriesId) { return _episodeRepository.GetEpisodes(seriesId).ToList(); diff --git a/UI/Series/Details/SeriesDetailsTemplate.html b/UI/Series/Details/SeriesDetailsTemplate.html index 1d353442a..be3ea84ec 100644 --- a/UI/Series/Details/SeriesDetailsTemplate.html +++ b/UI/Series/Details/SeriesDetailsTemplate.html @@ -14,6 +14,7 @@
{{network}} {{runtime}} minutes + {{path}}