more rss refactoring

pull/7/merge
kay.one 14 years ago
parent d7732cab3b
commit 11e2b63b60

@ -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<IConfigProvider>();
fakeConfig.Setup(c => c.EpisodeNameFormat).Returns(patern);
var kernel = new MockingKernel();
kernel.Bind<IConfigProvider>().ToConstant(fakeConfig.Object);
kernel.Bind<IMediaFileProvider>().To<MediaFileProvider>();
var fakeEpisode = new EpisodeModel
{
SeasonNumber = 6,
EpisodeNumber = 8,
EpisodeTitle = "Lethal Inspection",
Quality = QualityTypes.HDTV,
SeriesTitle = "Futurama"
};
//Act
var result = kernel.Get<IMediaFileProvider>().GenerateEpisodePath(fakeEpisode);
//Assert
Assert.AreEqual(path.ToLowerInvariant(), result.ToLowerInvariant());
}
}

@ -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; }
}
}

@ -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<int> Episodes { get; set; }
internal int Year { get; set; }
public bool Proper { get; set; }
public QualityTypes Quality { get; set; }
public override string ToString()

@ -168,7 +168,6 @@
<Compile Include="Instrumentation\SubsonicTarget.cs" />
<Compile Include="Instrumentation\ExceptioneerTarget.cs" />
<Compile Include="Instrumentation\NlogWriter.cs" />
<Compile Include="Model\EpisodeModel.cs" />
<Compile Include="Model\EpisodeParseResult.cs" />
<Compile Include="Model\EpisodeRenameModel.cs" />
<Compile Include="Model\EpisodeSortingType.cs" />

@ -65,76 +65,53 @@ namespace NzbDrone.Core.Providers
/// <summary>
/// Comprehensive check on whether or not this episode is needed.
/// </summary>
/// <param name="episode">Episode that needs to be checked</param>
/// <param name="parsedReport">Episode that needs to be checked</param>
/// <returns></returns>
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))

@ -17,7 +17,7 @@ namespace NzbDrone.Core.Providers
/// </summary>
/// <param name="episode">Episode that needs to be checked</param>
/// <returns></returns>
bool IsNeeded(EpisodeModel episode);
bool IsNeeded(EpisodeParseResult episode);
void RefreshEpisodeInfo(int seriesId);
void RefreshEpisodeInfo(Season season);

@ -13,7 +13,6 @@ namespace NzbDrone.Core.Providers
List<EpisodeFile> Scan(Series series);
List<EpisodeFile> Scan(Series series, string path);
EpisodeFile ImportFile(Series series, string filePath);
string GenerateEpisodePath(EpisodeModel episode);
void CleanUp(List<EpisodeFile> files);
void DeleteFromDb(int fileId);
void DeleteFromDisk(int fileId, string path);

@ -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);
}
}

@ -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<EpisodeFile>(fileId);

@ -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

Loading…
Cancel
Save