more rss refactoring

pull/3113/head
kay.one 14 years ago
parent d7732cab3b
commit 11e2b63b60

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

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

@ -65,76 +65,53 @@ namespace NzbDrone.Core.Providers
/// <summary> /// <summary>
/// Comprehensive check on whether or not this episode is needed. /// Comprehensive check on whether or not this episode is needed.
/// </summary> /// </summary>
/// <param name="episode">Episode that needs to be checked</param> /// <param name="parsedReport">Episode that needs to be checked</param>
/// <returns></returns> /// <returns></returns>
public bool IsNeeded(EpisodeModel episode) public bool IsNeeded(EpisodeParseResult parsedReport)
{ {
//IsSeasonIgnored foreach (var episode in parsedReport.Episodes)
//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)
{ {
//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) var episodeInfo = GetEpisode(parsedReport.SeriesId, parsedReport.SeasonNumber, episode);
throw new NotImplementedException("Episode was not found in the database");
}
episode.EpisodeId = dbEpisode.EpisodeId;
var file = dbEpisode.EpisodeFile; if (episodeInfo == null)
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 the episodeFile is a Proper we don't need to download again //Todo: How do we want to handle this really? Episode could be released before information is on TheTvDB
if (file.Proper) //(Parks and Rec did this a lot in the first season, from experience)
return false; //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. var file = episodeInfo.EpisodeFile;
if (file.Quality > episode.Quality)
return false;
//Now we need to handle upgrades and actually pay attention to the Cutoff Value if (file != null)
if (file.Quality < episode.Quality)
{ {
var series = _series.GetSeries(episode.SeriesId); //If not null we need to see if this episode has the quality as the download (or if it is better)
var quality = _quality.Find(series.QualityProfileId); 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 var quality = _quality.Find(episodeInfo.Series.QualityProfileId);
if (file.Proper)
return false; if (quality.Cutoff <= file.Quality && file.Proper) continue;
} }
} }
}
//IsInHistory? (NZBDrone) //IsInHistory? (NZBDrone)
if (_history.Exists(dbEpisode.EpisodeId, episode.Quality, episode.Proper)) if (_history.Exists(episodeInfo.EpisodeId, parsedReport.Quality, parsedReport.Proper))
{ {
Logger.Debug("Episode in history: {0}", episode.ToString()); Logger.Debug("Episode in history: {0}", episode.ToString());
return false; 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) public void RefreshEpisodeInfo(int seriesId)
@ -270,7 +247,7 @@ namespace NzbDrone.Core.Providers
_sonicRepo.Update(episode); _sonicRepo.Update(episode);
} }
private bool IsSeasonIgnored(EpisodeModel episode) private bool IsSeasonIgnored(EpisodeParseResult episode)
{ {
//Check if this Season is ignored //Check if this Season is ignored
if (_seasons.IsIgnored(episode.SeriesId, episode.SeasonNumber)) if (_seasons.IsIgnored(episode.SeriesId, episode.SeasonNumber))

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

@ -13,7 +13,6 @@ namespace NzbDrone.Core.Providers
List<EpisodeFile> Scan(Series series); List<EpisodeFile> Scan(Series series);
List<EpisodeFile> Scan(Series series, string path); List<EpisodeFile> Scan(Series series, string path);
EpisodeFile ImportFile(Series series, string filePath); EpisodeFile ImportFile(Series series, string filePath);
string GenerateEpisodePath(EpisodeModel episode);
void CleanUp(List<EpisodeFile> files); void CleanUp(List<EpisodeFile> files);
void DeleteFromDb(int fileId); void DeleteFromDb(int fileId);
void DeleteFromDisk(int fileId, string path); 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) //This interface will contain methods to process individual RSS Feed Items (Queue if wanted)
void DownloadIfWanted(NzbInfoModel nzb, Indexer indexer); void DownloadIfWanted(NzbInfoModel nzb, Indexer indexer);
string GetTitleFix(EpisodeParseResult episodes, int seriesId); string GetTitleFix(EpisodeParseResult episodes);
} }
} }

@ -145,18 +145,6 @@ 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) public void DeleteFromDb(int 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; int seasonNumber = 0;
string episodeNumbers = String.Empty; string episodeNumbers = String.Empty;
string episodeTitles = String.Empty; string episodeTitles = String.Empty;
foreach (var episode in episodes.Episodes) 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) if (episodeInDb == null)
{ {
@ -99,14 +97,14 @@ namespace NzbDrone.Core.Providers
episodeInDb = new Episode { EpisodeNumber = episode, Title = "TBA" }; episodeInDb = new Episode { EpisodeNumber = episode, Title = "TBA" };
} }
seasonNumber = episodeInDb.SeasonNumber; seasonNumber = episodes.SeasonNumber;
episodeNumbers = String.Format("{0}x{1:00}", episodeNumbers, episodeInDb.EpisodeNumber); episodeNumbers = String.Format("{0}x{1:00}", episodeNumbers, episodeInDb.EpisodeNumber);
episodeTitles = String.Format("{0} + {1}", episodeTitles, episodeInDb.Title); episodeTitles = String.Format("{0} + {1}", episodeTitles, episodeInDb.Title);
} }
episodeTitles = episodeTitles.Trim(' ', '+'); 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 #endregion
@ -140,19 +138,11 @@ namespace NzbDrone.Core.Providers
//Loop through the list of the episodeParseResults to ensure that all the episodes are needed //Loop through the list of the episodeParseResults to ensure that all the episodes are needed
foreach (var episode in episodeParseResults.Episodes) foreach (var episode in episodeParseResults.Episodes)
{ {
//IsEpisodeWanted?
var episodeModel = new EpisodeModel(); if (!_episodeProvider.IsNeeded(episodeParseResults))
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))
return; return;
var titleFix = GetTitleFix(episodeParseResults, episodeModel.SeriesId); var titleFix = GetTitleFix(episodeParseResults);
titleFix = String.Format("{0} [{1}]", titleFix, nzb.Quality); //Add Quality to the titleFix 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 //If it is a PROPER we want to put PROPER in the titleFix
@ -164,7 +154,7 @@ namespace NzbDrone.Core.Providers
return; 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 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 //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) foreach (var episode in season.Episodes)
{ {
var episodeModel = new EpisodeModel();
episodeModel.Proper = nzb.Proper; //if (!_episodeProvider.IsNeeded(episode))
episodeModel.SeriesId = series.SeriesId;
episodeModel.SeriesTitle = series.Title;
episodeModel.Quality = nzb.Quality;
episodeModel.SeasonNumber = episode.SeasonNumber;
episodeModel.EpisodeNumber = episode.EpisodeNumber;
if (!_episodeProvider.IsNeeded(episodeModel))
{ {
downloadWholeSeason = false; 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 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