diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/MediaFileProviderTests.cs index 9c82eec06..2efe88388 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/MediaFileProviderTests.cs @@ -71,7 +71,7 @@ namespace NzbDrone.Core.Test //Currently can't verify this since the list of episodes are loaded //Dynamically by SubSonic //Assert.AreEqual(fakeEpisode, result.Episodes[0]); - + Assert.AreEqual(fakeEpisode.SeriesId, result.SeriesId); Assert.AreEqual(QualityTypes.BDRip, result.Quality); Assert.AreEqual(Parser.NormalizePath(fileName), result.Path); @@ -163,34 +163,6 @@ namespace NzbDrone.Core.Test } - [Test] - [Row("Season {season}\\S{season:00}E{episode:00} - {title} - {quality}", "Season 6\\S06E08 - Lethal Inspection - hdtv")] - [Row("Season {season}\\{series} - {season:##}{episode:00} - {title} - {quality}", "Season 6\\Futurama - 608 - Lethal Inspection - hdtv")] - [Row("Season {season}\\{series} - {season:##}{episode:00} - {title}", "Season 6\\Futurama - 608 - Lethal Inspection")] - public void test_file_path_generation(string patern, string path) - { - var fakeConfig = new Mock(); - fakeConfig.Setup(c => c.EpisodeNameFormat).Returns(patern); - - var kernel = new MockingKernel(); - kernel.Bind().ToConstant(fakeConfig.Object); - kernel.Bind().To(); - - var fakeEpisode = new EpisodeModel - { - SeasonNumber = 6, - EpisodeNumber = 8, - EpisodeTitle = "Lethal Inspection", - Quality = QualityTypes.HDTV, - SeriesTitle = "Futurama" - }; - - //Act - var result = kernel.Get().GenerateEpisodePath(fakeEpisode); - - //Assert - Assert.AreEqual(path.ToLowerInvariant(), result.ToLowerInvariant()); - } } diff --git a/NzbDrone.Core/Model/EpisodeModel.cs b/NzbDrone.Core/Model/EpisodeModel.cs deleted file mode 100644 index 2d0d16826..000000000 --- a/NzbDrone.Core/Model/EpisodeModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using NzbDrone.Core.Repository.Quality; -using SubSonic.SqlGeneration.Schema; - -namespace NzbDrone.Core.Model -{ - public class EpisodeModel - { - public string SeriesTitle { get; set; } - public int SeriesId { get; set; } - public string EpisodeTitle { get; set; } - public int EpisodeId { get; set; } - public int SeasonNumber { get; set; } - public int EpisodeNumber { get; set; } - public QualityTypes Quality { get; set; } - public string Path { get; set; } - public long Size { get; set; } - public bool Proper { get; set; } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index 0888b07d0..f52ef7ad5 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -7,10 +7,14 @@ namespace NzbDrone.Core.Model public class EpisodeParseResult { internal string SeriesTitle { get; set; } + public int SeriesId { get; set; } + internal int SeasonNumber { get; set; } internal List Episodes { get; set; } internal int Year { get; set; } + public bool Proper { get; set; } + public QualityTypes Quality { get; set; } public override string ToString() diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 1db86fbc6..b7d348a57 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -168,7 +168,6 @@ - diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index b5781d1d9..8dda15aa6 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -65,76 +65,53 @@ namespace NzbDrone.Core.Providers /// /// Comprehensive check on whether or not this episode is needed. /// - /// Episode that needs to be checked + /// Episode that needs to be checked /// - public bool IsNeeded(EpisodeModel episode) + public bool IsNeeded(EpisodeParseResult parsedReport) { - //IsSeasonIgnored - //IsQualityWanted - //EpisodeFileExists - //IsInHistory - //IsOnDisk? (How to handle episodes that are downloaded manually?) - - if (IsSeasonIgnored(episode)) - return false; - - //Quickly check if this quality is wanted at all (We will later check if the quality is still needed) - if (!_series.QualityWanted(episode.SeriesId, episode.Quality)) - { - Logger.Debug("Quality [{0}] is not wanted for: {1}", episode.Quality, episode.SeriesTitle); - return false; - } - - //Check to see if there is an episode file for this episode - var dbEpisode = GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber); - - if (dbEpisode == null) + foreach (var episode in parsedReport.Episodes) { - //Todo: How do we want to handle this really? Episode could be released before information is on TheTvDB (Parks and Rec did this a lot in the first season, from experience) - throw new NotImplementedException("Episode was not found in the database"); - } - - episode.EpisodeId = dbEpisode.EpisodeId; + var episodeInfo = GetEpisode(parsedReport.SeriesId, parsedReport.SeasonNumber, episode); - var file = dbEpisode.EpisodeFile; - - if (file != null) - { - //If not null we need to see if this episode has the quality as the download (or if it is better) - if (file.Quality == episode.Quality) + if (episodeInfo == null) { - //If the episodeFile is a Proper we don't need to download again - if (file.Proper) - return false; + //Todo: How do we want to handle this really? Episode could be released before information is on TheTvDB + //(Parks and Rec did this a lot in the first season, from experience) + //Keivan: Should automatically add the episode to db with minimal information. then update the description/title when avilable. + throw new NotImplementedException("Episode was not found in the database"); } - //There will never be a time when the episode quality is less than what we have and we want it... ever.... I think. - if (file.Quality > episode.Quality) - return false; + var file = episodeInfo.EpisodeFile; - //Now we need to handle upgrades and actually pay attention to the Cutoff Value - if (file.Quality < episode.Quality) + if (file != null) { - var series = _series.GetSeries(episode.SeriesId); - var quality = _quality.Find(series.QualityProfileId); + //If not null we need to see if this episode has the quality as the download (or if it is better) + if (file.Quality == parsedReport.Quality && file.Proper) continue; - if (quality.Cutoff <= file.Quality) + //There will never be a time when the episode quality is less than what we have and we want it... ever.... I think. + if (file.Quality > parsedReport.Quality) continue; + + //Now we need to handle upgrades and actually pay attention to the Cutoff Value + if (file.Quality < parsedReport.Quality) { - //If the episodeFile is a Proper we don't need to download again - if (file.Proper) - return false; + var quality = _quality.Find(episodeInfo.Series.QualityProfileId); + + if (quality.Cutoff <= file.Quality && file.Proper) continue; } } - } - //IsInHistory? (NZBDrone) - if (_history.Exists(dbEpisode.EpisodeId, episode.Quality, episode.Proper)) - { - Logger.Debug("Episode in history: {0}", episode.ToString()); - return false; + //IsInHistory? (NZBDrone) + if (_history.Exists(episodeInfo.EpisodeId, parsedReport.Quality, parsedReport.Proper)) + { + Logger.Debug("Episode in history: {0}", episode.ToString()); + continue; + } + + return true;//If we get to this point and the file has not yet been rejected then accept it } - return true;//If we get to this point and the file has not yet been rejected then accept it + return false; + } public void RefreshEpisodeInfo(int seriesId) @@ -270,7 +247,7 @@ namespace NzbDrone.Core.Providers _sonicRepo.Update(episode); } - private bool IsSeasonIgnored(EpisodeModel episode) + private bool IsSeasonIgnored(EpisodeParseResult episode) { //Check if this Season is ignored if (_seasons.IsIgnored(episode.SeriesId, episode.SeasonNumber)) diff --git a/NzbDrone.Core/Providers/IEpisodeProvider.cs b/NzbDrone.Core/Providers/IEpisodeProvider.cs index c9d1104e5..9f2caf81c 100644 --- a/NzbDrone.Core/Providers/IEpisodeProvider.cs +++ b/NzbDrone.Core/Providers/IEpisodeProvider.cs @@ -17,7 +17,7 @@ namespace NzbDrone.Core.Providers /// /// Episode that needs to be checked /// - bool IsNeeded(EpisodeModel episode); + bool IsNeeded(EpisodeParseResult episode); void RefreshEpisodeInfo(int seriesId); void RefreshEpisodeInfo(Season season); diff --git a/NzbDrone.Core/Providers/IMediaFileProvider.cs b/NzbDrone.Core/Providers/IMediaFileProvider.cs index 608637d06..3a499cd47 100644 --- a/NzbDrone.Core/Providers/IMediaFileProvider.cs +++ b/NzbDrone.Core/Providers/IMediaFileProvider.cs @@ -13,7 +13,6 @@ namespace NzbDrone.Core.Providers List Scan(Series series); List Scan(Series series, string path); EpisodeFile ImportFile(Series series, string filePath); - string GenerateEpisodePath(EpisodeModel episode); void CleanUp(List files); void DeleteFromDb(int fileId); void DeleteFromDisk(int fileId, string path); diff --git a/NzbDrone.Core/Providers/IRssItemProcessingProvider.cs b/NzbDrone.Core/Providers/IRssItemProcessingProvider.cs index adcbd099c..bf596d348 100644 --- a/NzbDrone.Core/Providers/IRssItemProcessingProvider.cs +++ b/NzbDrone.Core/Providers/IRssItemProcessingProvider.cs @@ -12,6 +12,6 @@ namespace NzbDrone.Core.Providers //This interface will contain methods to process individual RSS Feed Items (Queue if wanted) void DownloadIfWanted(NzbInfoModel nzb, Indexer indexer); - string GetTitleFix(EpisodeParseResult episodes, int seriesId); + string GetTitleFix(EpisodeParseResult episodes); } } diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs index ffdf2a0f8..61659ea46 100644 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ b/NzbDrone.Core/Providers/MediaFileProvider.cs @@ -145,19 +145,7 @@ namespace NzbDrone.Core.Providers } } - public string GenerateEpisodePath(EpisodeModel episode) - { - var episodeNamePattern = _configProvider.EpisodeNameFormat; - - episodeNamePattern = episodeNamePattern.Replace("{series}", "{0}"); - episodeNamePattern = episodeNamePattern.Replace("{episode", "{1"); - episodeNamePattern = episodeNamePattern.Replace("{season", "{2"); - episodeNamePattern = episodeNamePattern.Replace("{title}", "{3}"); - episodeNamePattern = episodeNamePattern.Replace("{quality}", "{4}"); - - return String.Format(episodeNamePattern, episode.SeriesTitle, episode.EpisodeNumber, episode.SeasonNumber, episode.EpisodeTitle, episode.Quality); - } - + public void DeleteFromDb(int fileId) { _repository.Delete(fileId); diff --git a/NzbDrone.Core/Providers/RssItemProcessingProvider.cs b/NzbDrone.Core/Providers/RssItemProcessingProvider.cs index 4b07bcdce..9d5b8a611 100644 --- a/NzbDrone.Core/Providers/RssItemProcessingProvider.cs +++ b/NzbDrone.Core/Providers/RssItemProcessingProvider.cs @@ -79,17 +79,15 @@ namespace NzbDrone.Core.Providers } } - public string GetTitleFix(EpisodeParseResult episodes, int seriesId) + public string GetTitleFix(EpisodeParseResult episodes) { - var series = _seriesProvider.GetSeries(seriesId); - int seasonNumber = 0; string episodeNumbers = String.Empty; string episodeTitles = String.Empty; foreach (var episode in episodes.Episodes) { - var episodeInDb = _episodeProvider.GetEpisode(seriesId, episodes.SeasonNumber, episode); + var episodeInDb = _episodeProvider.GetEpisode(episodes.SeriesId, episodes.SeasonNumber, episode); if (episodeInDb == null) { @@ -99,14 +97,14 @@ namespace NzbDrone.Core.Providers episodeInDb = new Episode { EpisodeNumber = episode, Title = "TBA" }; } - seasonNumber = episodeInDb.SeasonNumber; + seasonNumber = episodes.SeasonNumber; episodeNumbers = String.Format("{0}x{1:00}", episodeNumbers, episodeInDb.EpisodeNumber); episodeTitles = String.Format("{0} + {1}", episodeTitles, episodeInDb.Title); } episodeTitles = episodeTitles.Trim(' ', '+'); - return String.Format("{0} - {1}{2} - {3}", series.Title, seasonNumber, episodeNumbers, episodeTitles); + return String.Format("{0} - {1}{2} - {3}", episodes.SeriesTitle, seasonNumber, episodeNumbers, episodeTitles); } #endregion @@ -140,19 +138,11 @@ namespace NzbDrone.Core.Providers //Loop through the list of the episodeParseResults to ensure that all the episodes are needed foreach (var episode in episodeParseResults.Episodes) { - //IsEpisodeWanted? - var episodeModel = new EpisodeModel(); - episodeModel.Proper = nzb.Proper; - episodeModel.SeriesId = series.SeriesId; - episodeModel.SeriesTitle = series.Title; - episodeModel.Quality = nzb.Quality; - episodeModel.SeasonNumber = episodeParseResults.SeasonNumber; - episodeModel.EpisodeNumber = episode; - - if (!_episodeProvider.IsNeeded(episodeModel)) + + if (!_episodeProvider.IsNeeded(episodeParseResults)) return; - var titleFix = GetTitleFix(episodeParseResults, episodeModel.SeriesId); + var titleFix = GetTitleFix(episodeParseResults); titleFix = String.Format("{0} [{1}]", titleFix, nzb.Quality); //Add Quality to the titleFix //If it is a PROPER we want to put PROPER in the titleFix @@ -164,7 +154,7 @@ namespace NzbDrone.Core.Providers return; } - nzb.TitleFix = GetTitleFix(episodeParseResults, series.SeriesId); //Get the TitleFix so we can use it later + nzb.TitleFix = GetTitleFix(episodeParseResults); //Get the TitleFix so we can use it later nzb.TitleFix = String.Format("{0} [{1}]", nzb.TitleFix, nzb.Quality); //Add Quality to the titleFix //If it is a PROPER we want to put PROPER in the titleFix @@ -256,15 +246,8 @@ namespace NzbDrone.Core.Providers foreach (var episode in season.Episodes) { - var episodeModel = new EpisodeModel(); - episodeModel.Proper = nzb.Proper; - episodeModel.SeriesId = series.SeriesId; - episodeModel.SeriesTitle = series.Title; - episodeModel.Quality = nzb.Quality; - episodeModel.SeasonNumber = episode.SeasonNumber; - episodeModel.EpisodeNumber = episode.EpisodeNumber; - - if (!_episodeProvider.IsNeeded(episodeModel)) + + //if (!_episodeProvider.IsNeeded(episode)) { downloadWholeSeason = false; episodesNeeded--; //Decrement the number of downloads we need, used if we want to replace all existing episodes if this will upgrade over X% of files