start support for daily show file import

pull/4/head
kay.one 14 years ago
parent eea6c2f896
commit 194c66f36a

@ -71,6 +71,59 @@ namespace NzbDrone.Core.Test
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 @@ namespace NzbDrone.Core.Test
[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 @@ namespace NzbDrone.Core.Test
[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 @@ namespace NzbDrone.Core.Providers
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 @@ namespace NzbDrone.Core.Providers
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,6 +69,11 @@ namespace NzbDrone.Core.Providers
{
Logger.Trace("Importing file to database [{0}]", filePath);
try
{
if (!_repository.Exists<EpisodeFile>(e => e.Path == Parser.NormalizePath(filePath)))
{
var episodesInFile = Parser.ParseEpisodeInfo(filePath);
@ -128,6 +133,12 @@ namespace NzbDrone.Core.Providers
}
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;
}
return null;
}

Loading…
Cancel
Save