mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
start support for daily show file import
This commit is contained in:
parent
eea6c2f896
commit
194c66f36a
@ -71,6 +71,59 @@ public void import_new_file()
|
||||
Assert.AreNotEqual(new DateTime(), result.DateAdded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Description("Verifies that a new file imported properly")]
|
||||
public void import_new_daily_file()
|
||||
{
|
||||
//Arrange
|
||||
/////////////////////////////////////////
|
||||
|
||||
//Constants
|
||||
const string fileName = @"2011.01.10 - Denis Leary - HD TV.mkv";
|
||||
DateTime airDate = new DateTime(2011, 01, 10);
|
||||
const int size = 12345;
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeEpisode = Builder<Episode>.CreateNew().With(c => c.SeriesId = fakeSeries.SeriesId).Build();
|
||||
|
||||
//Mocks
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
||||
mocker.GetMock<IRepository>()
|
||||
.Setup(r => r.Add(It.IsAny<EpisodeFile>())).Returns(0).Verifiable();
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, airDate)).Returns(fakeEpisode).
|
||||
Verifiable();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
||||
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
Assert.IsNotNull(result);
|
||||
mocker.GetMock<IRepository>().VerifyAll();
|
||||
mocker.GetMock<IRepository>().Verify(r => r.Add(result), Times.Once());
|
||||
mocker.GetMock<EpisodeProvider>().VerifyAll();
|
||||
mocker.GetMock<DiskProvider>().VerifyAll();
|
||||
|
||||
//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);
|
||||
Assert.AreEqual(size, result.Size);
|
||||
Assert.AreEqual(false, result.Proper);
|
||||
Assert.AreNotEqual(new DateTime(), result.DateAdded);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[Description("Verifies that an existing file will skip import")]
|
||||
|
@ -50,6 +50,7 @@ public void episode_parse(string postTitle, string title, int season, int episod
|
||||
[Row(@"z:\tv shows\modern marvels\Season 16\S16E03 - The Potato.mkv", 16, 3)]
|
||||
[Row(@"z:\tv shows\robot chicken\Specials\S00E16 - Dear Consumer - SD TV.avi", 0, 16)]
|
||||
[Row(@"D:\shares\TV Shows\Parks And Recreation\Season 2\S02E21 - 94 Meetings - 720p TV.mkv", 2, 21)]
|
||||
[Row(@"D:\shares\TV Shows\Battlestar Galactica (2003)\Season 2\S02E21.avi", 2, 21)]
|
||||
public void file_path_parse(string path, int season, int episode)
|
||||
{
|
||||
var result = Parser.ParseEpisodeInfo(path);
|
||||
@ -111,12 +112,16 @@ public void episode_multipart_parse(string postTitle, string title, int season,
|
||||
[Row("The Tonight Show With Jay Leno 2011 04 15 1080i HDTV DD5 1 MPEG2 TrollHD", "The Tonight Show With Jay Leno", 2011, 04, 15)]
|
||||
[Row("The.Daily.Show.2010.10.11.Johnny.Knoxville.iTouch-MW", "The.Daily.Show", 2010, 10, 11)]
|
||||
[Row("The Daily Show - 2011-04-12 - Gov. Deval Patrick", "The.Daily.Show", 2011, 04, 12)]
|
||||
[Row("2011.01.10 - Denis Leary - HD TV.mkv", 2011, 1, 10)]
|
||||
[Row("2011.03.13 - Denis Leary - HD TV.mkv", 2011, 3, 13)]
|
||||
[Row("2011-03-13 - Denis Leary - HD TV.mkv", 2011, 3, 13)]
|
||||
public void episode_daily_parse(string postTitle, string title, int year, int month, int day)
|
||||
{
|
||||
var result = Parser.ParseEpisodeInfo(postTitle);
|
||||
var airDate = new DateTime(year, month, day);
|
||||
Assert.AreEqual(Parser.NormalizeTitle(title), result.CleanTitle);
|
||||
Assert.AreEqual(airDate, result.AirDate);
|
||||
Assert.IsEmpty(result.Episodes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -45,6 +45,13 @@ public virtual Episode GetEpisode(int seriesId, int seasonNumber, int episodeNum
|
||||
c => c.SeriesId == seriesId && c.SeasonNumber == seasonNumber && c.EpisodeNumber == episodeNumber);
|
||||
}
|
||||
|
||||
public virtual Episode GetEpisode(int seriesId, DateTime date)
|
||||
{
|
||||
return
|
||||
_sonicRepo.Single<Episode>(
|
||||
c => c.SeriesId == seriesId && c.AirDate == date.Date);
|
||||
}
|
||||
|
||||
public virtual IList<Episode> GetEpisodeBySeries(long seriesId)
|
||||
{
|
||||
return _sonicRepo.Find<Episode>(e => e.SeriesId == seriesId);
|
||||
@ -168,7 +175,7 @@ public virtual void RefreshEpisodeInfo(int seriesId)
|
||||
Logger.Trace("Updating info for [{0}] - S{1}E{2}", targetSeries.SeriesName, episode.SeasonNumber, episode.EpisodeNumber);
|
||||
var newEpisode = new Episode
|
||||
{
|
||||
AirDate = episode.FirstAired,
|
||||
AirDate = episode.FirstAired.Date,
|
||||
TvDbEpisodeId = episode.Id,
|
||||
EpisodeNumber = episode.EpisodeNumber,
|
||||
Language = episode.Language.Abbriviation,
|
||||
|
@ -69,65 +69,76 @@ public EpisodeFile ImportFile(Series series, string filePath)
|
||||
{
|
||||
Logger.Trace("Importing file to database [{0}]", filePath);
|
||||
|
||||
if (!_repository.Exists<EpisodeFile>(e => e.Path == Parser.NormalizePath(filePath)))
|
||||
try
|
||||
{
|
||||
var episodesInFile = Parser.ParseEpisodeInfo(filePath);
|
||||
|
||||
//Stores the list of episodes to add to the EpisodeFile
|
||||
var episodes = new List<Episode>();
|
||||
|
||||
foreach (var episodeNumber in episodesInFile.Episodes)
|
||||
|
||||
if (!_repository.Exists<EpisodeFile>(e => e.Path == Parser.NormalizePath(filePath)))
|
||||
{
|
||||
var episode = _episodeProvider.GetEpisode(series.SeriesId, episodesInFile.SeasonNumber,
|
||||
episodeNumber);
|
||||
var episodesInFile = Parser.ParseEpisodeInfo(filePath);
|
||||
|
||||
if (episode != null)
|
||||
//Stores the list of episodes to add to the EpisodeFile
|
||||
var episodes = new List<Episode>();
|
||||
|
||||
foreach (var episodeNumber in episodesInFile.Episodes)
|
||||
{
|
||||
episodes.Add(episode);
|
||||
var episode = _episodeProvider.GetEpisode(series.SeriesId, episodesInFile.SeasonNumber,
|
||||
episodeNumber);
|
||||
|
||||
if (episode != null)
|
||||
{
|
||||
episodes.Add(episode);
|
||||
}
|
||||
|
||||
else
|
||||
Logger.Warn("Unable to find Series:{0} Season:{1} Episode:{2} in the database. File:{3}",
|
||||
series.Title, episodesInFile.SeasonNumber, episodeNumber, filePath);
|
||||
}
|
||||
|
||||
else
|
||||
Logger.Warn("Unable to find Series:{0} Season:{1} Episode:{2} in the database. File:{3}",
|
||||
series.Title, episodesInFile.SeasonNumber, episodeNumber, filePath);
|
||||
//Return null if no Episodes exist in the DB for the parsed episodes from file
|
||||
if (episodes.Count < 1)
|
||||
return null;
|
||||
|
||||
var size = _diskProvider.GetSize(filePath);
|
||||
|
||||
//If Size is less than 50MB and contains sample. Check for Size to ensure its not an episode with sample in the title
|
||||
if (size < 50000000 && filePath.ToLower().Contains("sample"))
|
||||
{
|
||||
Logger.Trace("[{0}] appears to be a sample... skipping.", filePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
var episodeFile = new EpisodeFile();
|
||||
episodeFile.DateAdded = DateTime.Now;
|
||||
episodeFile.SeriesId = series.SeriesId;
|
||||
episodeFile.Path = Parser.NormalizePath(filePath);
|
||||
episodeFile.Size = size;
|
||||
episodeFile.Quality = episodesInFile.Quality;
|
||||
episodeFile.Proper = Parser.ParseProper(filePath);
|
||||
var fileId = (int)_repository.Add(episodeFile);
|
||||
|
||||
//This is for logging + updating the episodes that are linked to this EpisodeFile
|
||||
string episodeList = String.Empty;
|
||||
foreach (var ep in episodes)
|
||||
{
|
||||
ep.EpisodeFileId = fileId;
|
||||
_episodeProvider.UpdateEpisode(ep);
|
||||
episodeList += String.Format(", {0}", ep.EpisodeId).Trim(' ', ',');
|
||||
}
|
||||
Logger.Trace("File {0}:{1} attached to episode(s): '{2}'", episodeFile.EpisodeFileId, filePath,
|
||||
episodeList);
|
||||
|
||||
return episodeFile;
|
||||
}
|
||||
|
||||
//Return null if no Episodes exist in the DB for the parsed episodes from file
|
||||
if (episodes.Count < 1)
|
||||
return null;
|
||||
|
||||
var size = _diskProvider.GetSize(filePath);
|
||||
|
||||
//If Size is less than 50MB and contains sample. Check for Size to ensure its not an episode with sample in the title
|
||||
if (size < 50000000 && filePath.ToLower().Contains("sample"))
|
||||
{
|
||||
Logger.Trace("[{0}] appears to be a sample... skipping.", filePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
var episodeFile = new EpisodeFile();
|
||||
episodeFile.DateAdded = DateTime.Now;
|
||||
episodeFile.SeriesId = series.SeriesId;
|
||||
episodeFile.Path = Parser.NormalizePath(filePath);
|
||||
episodeFile.Size = size;
|
||||
episodeFile.Quality = episodesInFile.Quality;
|
||||
episodeFile.Proper = Parser.ParseProper(filePath);
|
||||
var fileId = (int)_repository.Add(episodeFile);
|
||||
|
||||
//This is for logging + updating the episodes that are linked to this EpisodeFile
|
||||
string episodeList = String.Empty;
|
||||
foreach (var ep in episodes)
|
||||
{
|
||||
ep.EpisodeFileId = fileId;
|
||||
_episodeProvider.UpdateEpisode(ep);
|
||||
episodeList += String.Format(", {0}", ep.EpisodeId).Trim(' ', ',');
|
||||
}
|
||||
Logger.Trace("File {0}:{1} attached to episode(s): '{2}'", episodeFile.EpisodeFileId, filePath,
|
||||
episodeList);
|
||||
|
||||
return episodeFile;
|
||||
Logger.Trace("[{0}] already exists in the database. skipping.", filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("An error has occurred while importing file " + filePath, ex);
|
||||
throw;
|
||||
}
|
||||
|
||||
Logger.Trace("[{0}] already exists in the database. skipping.", filePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user