1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00

more rss refactoring

This commit is contained in:
kay.one 2011-04-03 21:54:58 -07:00
parent d7732cab3b
commit 11e2b63b60
10 changed files with 49 additions and 146 deletions

View File

@ -71,7 +71,7 @@ public void import_new_file()
//Currently can't verify this since the list of episodes are loaded //Currently can't verify this since the list of episodes are loaded
//Dynamically by SubSonic //Dynamically by SubSonic
//Assert.AreEqual(fakeEpisode, result.Episodes[0]); //Assert.AreEqual(fakeEpisode, result.Episodes[0]);
Assert.AreEqual(fakeEpisode.SeriesId, result.SeriesId); Assert.AreEqual(fakeEpisode.SeriesId, result.SeriesId);
Assert.AreEqual(QualityTypes.BDRip, result.Quality); Assert.AreEqual(QualityTypes.BDRip, result.Quality);
Assert.AreEqual(Parser.NormalizePath(fileName), result.Path); Assert.AreEqual(Parser.NormalizePath(fileName), result.Path);
@ -163,34 +163,6 @@ public void import_file_with_no_episode()
} }
[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());
}
} }

View File

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

View File

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

View File

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

View File

@ -65,76 +65,53 @@ public String GetSabTitle(Episode episode)
/// <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); var episodeInfo = GetEpisode(parsedReport.SeriesId, parsedReport.SeasonNumber, episode);
return false;
}
//Check to see if there is an episode file for this episode if (episodeInfo == null)
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)
throw new NotImplementedException("Episode was not found in the database");
}
episode.EpisodeId = dbEpisode.EpisodeId;
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 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)
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
} }
//IsInHistory? (NZBDrone) return false;
if (_history.Exists(dbEpisode.EpisodeId, episode.Quality, episode.Proper))
{
Logger.Debug("Episode in history: {0}", episode.ToString());
return false;
}
return true;//If we get to this point and the file has not yet been rejected then accept it
} }
public void RefreshEpisodeInfo(int seriesId) public void RefreshEpisodeInfo(int seriesId)
@ -270,7 +247,7 @@ public void UpdateEpisode(Episode episode)
_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))

View File

@ -17,7 +17,7 @@ public interface IEpisodeProvider
/// </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);

View File

@ -13,7 +13,6 @@ public interface IMediaFileProvider
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);

View File

@ -12,6 +12,6 @@ public interface IRssItemProcessingProvider
//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);
} }
} }

View File

@ -145,19 +145,7 @@ public void CleanUp(List<EpisodeFile> files)
} }
} }
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)
{ {
_repository.Delete<EpisodeFile>(fileId); _repository.Delete<EpisodeFile>(fileId);

View File

@ -79,17 +79,15 @@ public void DownloadIfWanted(NzbInfoModel nzb, Indexer indexer)
} }
} }
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 @@ public string GetTitleFix(EpisodeParseResult episodes, int seriesId)
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 @@ private void ProcessStandardItem(NzbInfoModel nzb, Indexer indexer, EpisodeParse
//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();
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; 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 @@ private void ProcessStandardItem(NzbInfoModel nzb, Indexer indexer, EpisodeParse
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 @@ private void ProcessFullSeasonItem(NzbInfoModel nzb, Indexer indexer, SeasonPars
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