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:
parent
d7732cab3b
commit
11e2b63b60
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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,78 +65,55 @@ public String GetSabTitle(Episode episode)
|
||||
/// <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))
|
||||
foreach (var episode in parsedReport.Episodes)
|
||||
{
|
||||
Logger.Debug("Quality [{0}] is not wanted for: {1}", episode.Quality, episode.SeriesTitle);
|
||||
return false;
|
||||
}
|
||||
var episodeInfo = GetEpisode(parsedReport.SeriesId, parsedReport.SeasonNumber, episode);
|
||||
|
||||
//Check to see if there is an episode file for this episode
|
||||
var dbEpisode = GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
|
||||
|
||||
if (dbEpisode == null)
|
||||
if (episodeInfo == 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)
|
||||
//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");
|
||||
}
|
||||
|
||||
episode.EpisodeId = dbEpisode.EpisodeId;
|
||||
|
||||
var file = dbEpisode.EpisodeFile;
|
||||
var file = episodeInfo.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
|
||||
if (file.Proper)
|
||||
return false;
|
||||
}
|
||||
if (file.Quality == parsedReport.Quality && file.Proper) continue;
|
||||
|
||||
//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;
|
||||
if (file.Quality > parsedReport.Quality) continue;
|
||||
|
||||
//Now we need to handle upgrades and actually pay attention to the Cutoff Value
|
||||
if (file.Quality < episode.Quality)
|
||||
if (file.Quality < parsedReport.Quality)
|
||||
{
|
||||
var series = _series.GetSeries(episode.SeriesId);
|
||||
var quality = _quality.Find(series.QualityProfileId);
|
||||
var quality = _quality.Find(episodeInfo.Series.QualityProfileId);
|
||||
|
||||
if (quality.Cutoff <= file.Quality)
|
||||
{
|
||||
//If the episodeFile is a Proper we don't need to download again
|
||||
if (file.Proper)
|
||||
return false;
|
||||
}
|
||||
if (quality.Cutoff <= file.Quality && file.Proper) continue;
|
||||
}
|
||||
}
|
||||
|
||||
//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());
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Logger.Info("Starting episode info refresh for series:{0}", seriesId);
|
||||
@ -270,7 +247,7 @@ public void UpdateEpisode(Episode episode)
|
||||
_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 @@ public interface IEpisodeProvider
|
||||
/// </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 @@ public interface IMediaFileProvider
|
||||
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 @@ public interface IRssItemProcessingProvider
|
||||
//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,18 +145,6 @@ 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)
|
||||
{
|
||||
|
@ -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;
|
||||
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 @@ public string GetTitleFix(EpisodeParseResult episodes, int seriesId)
|
||||
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 @@ private void ProcessStandardItem(NzbInfoModel nzb, Indexer indexer, EpisodeParse
|
||||
//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 @@ private void ProcessStandardItem(NzbInfoModel nzb, Indexer indexer, EpisodeParse
|
||||
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 @@ private void ProcessFullSeasonItem(NzbInfoModel nzb, Indexer indexer, SeasonPars
|
||||
|
||||
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…
Reference in New Issue
Block a user