From de5d5b76e8a4f82f7ed20459d3e9d24c613ef0fc Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 28 Feb 2013 23:03:41 -0800 Subject: [PATCH] moved media file service --- .../Datastore/ObjectDatabaseFixture.cs | 29 +- .../UpgradeDiskSpecificationFixture.cs | 1 + .../UpgradePossibleSpecificationFixture.cs | 1 + NzbDrone.Core.Test/EpisodeStatusTest.cs | 1 + .../DatabaseTargetFixture.cs | 1 + .../JobTests/DiskScanJobTest.cs | 1 + .../JobTests/ImportNewSeriesJobTest.cs | 21 +- .../JobTests/RenameSeasonJobFixture.cs | 5 +- .../CleanUpDatabaseFixture.cs | 14 +- .../GetNewFilenameFixture.cs | 61 ++-- .../MediaFileServiceTest.cs} | 32 +-- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 6 +- .../CleanUpDropFolderFixture.cs | 19 +- .../DiskScanProviderTests/CleanUpFixture.cs | 13 +- .../ImportFileFixture.cs | 37 +-- .../MoveEpisodeFileFixture.cs | 19 +- .../DiskScanProviderTests/ScanFixture.cs | 9 +- .../Metadata/Xbmc_ForEpisodeFile_Fixture.cs | 5 +- .../ProviderTests/MisnamedProviderTest.cs | 41 +-- .../ProcessDownloadFixture.cs | 1 + .../ProcessDropDirectoryFixture.cs | 1 + .../ProcessVideoFileFixture.cs | 1 + .../EpisodeProviderTest.cs | 27 +- .../PetaPoco/EpisodeSeasonRelator.cs | 1 + NzbDrone.Core/Datastore/SiaqodbProxy.cs | 10 +- NzbDrone.Core/Jobs/ImportNewSeriesJob.cs | 9 +- NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs | 9 +- NzbDrone.Core/Jobs/RenameSeasonJob.cs | 9 +- NzbDrone.Core/Jobs/RenameSeriesJob.cs | 9 +- .../{Tv => MediaFiles}/EpisodeFile.cs | 11 +- .../MediaFiles/MediaFileRepository.cs | 39 +++ NzbDrone.Core/MediaFiles/MediaFileService.cs | 214 ++++++++++++++ NzbDrone.Core/Model/EpisodeParseResult.cs | 3 +- NzbDrone.Core/NzbDrone.Core.csproj | 5 +- NzbDrone.Core/Providers/DiskScanProvider.cs | 31 +- .../DownloadClients/BlackholeProvider.cs | 3 +- .../DownloadClients/PneumaticProvider.cs | 3 +- NzbDrone.Core/Providers/MediaFileProvider.cs | 265 ------------------ .../Providers/Metadata/MetadataBase.cs | 1 + NzbDrone.Core/Providers/Metadata/Xbmc.cs | 9 +- NzbDrone.Core/Providers/MetadataProvider.cs | 3 +- NzbDrone.Core/Providers/MisnamedProvider.cs | 11 +- NzbDrone.Core/Tv/Episode.cs | 3 +- NzbDrone.Core/Tv/EpisodeRepository.cs | Bin 6784 -> 7033 bytes NzbDrone.Core/Tv/EpisodeService.cs | 3 +- NzbDrone.Core/Tv/SeriesService.cs | 3 +- 46 files changed, 512 insertions(+), 488 deletions(-) rename NzbDrone.Core.Test/{ProviderTests/MediaFileProviderTests => MediaFileTests}/CleanUpDatabaseFixture.cs (88%) rename NzbDrone.Core.Test/{ProviderTests/MediaFileProviderTests => MediaFileTests}/GetNewFilenameFixture.cs (95%) rename NzbDrone.Core.Test/{ProviderTests/MediaFileProviderTest.cs => MediaFileTests/MediaFileServiceTest.cs} (86%) rename NzbDrone.Core/{Tv => MediaFiles}/EpisodeFile.cs (86%) create mode 100644 NzbDrone.Core/MediaFiles/MediaFileRepository.cs create mode 100644 NzbDrone.Core/MediaFiles/MediaFileService.cs delete mode 100644 NzbDrone.Core/Providers/MediaFileProvider.cs diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index dbbab39d6..1e6689264 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -160,8 +160,8 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void deleting_child_model_directly_should_set_link_to_null() { - _parentModel.Child = _childModel; - + _parentModel.Child = _childModel; + Db.Insert(_childModel); Db.Insert(_parentModel); @@ -191,7 +191,30 @@ namespace NzbDrone.Core.Test.Datastore Db.AsQueryable().Single().ChildList.Should().HaveCount(4); } - + + [Test] + public void update_field_should_only_update_that_filed() + { + var childModel = new ChildModel + { + A = "A_Original", + B = 1, + C = 1 + + }; + + Db.Insert(childModel); + + _childModel.A = "A_New"; + _childModel.B = 2; + _childModel.C = 2; + + Db.UpdateField(childModel, "B"); + + Db.AsQueryable().Single().A.Should().Be("A_Original"); + Db.AsQueryable().Single().B.Should().Be(2); + Db.AsQueryable().Single().C.Should().Be(1); + } [Test] public void should_be_able_to_read_unknown_type() diff --git a/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs index eb62f1225..e05d43a25 100644 --- a/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs +++ b/NzbDrone.Core.Test/DecisionEngineTests/UpgradeDiskSpecificationFixture.cs @@ -6,6 +6,7 @@ using System.Linq; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; diff --git a/NzbDrone.Core.Test/DecisionEngineTests/UpgradePossibleSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/UpgradePossibleSpecificationFixture.cs index eda2b7c83..5affcec7c 100644 --- a/NzbDrone.Core.Test/DecisionEngineTests/UpgradePossibleSpecificationFixture.cs +++ b/NzbDrone.Core.Test/DecisionEngineTests/UpgradePossibleSpecificationFixture.cs @@ -5,6 +5,7 @@ using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Providers; diff --git a/NzbDrone.Core.Test/EpisodeStatusTest.cs b/NzbDrone.Core.Test/EpisodeStatusTest.cs index ddfe215d8..8f43afbee 100644 --- a/NzbDrone.Core.Test/EpisodeStatusTest.cs +++ b/NzbDrone.Core.Test/EpisodeStatusTest.cs @@ -2,6 +2,7 @@ using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Repository; diff --git a/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs b/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs index e8d786c47..cdd04ede5 100644 --- a/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs +++ b/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs @@ -4,6 +4,7 @@ using System.Linq; using FluentAssertions; using NLog; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Test.Framework; diff --git a/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs b/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs index b761e61cf..48463cbc0 100644 --- a/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using FizzWare.NBuilder; using Moq; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Jobs; using NzbDrone.Core.Model.Notification; diff --git a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index 0627a9c3b..815445f6f 100644 --- a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using FizzWare.NBuilder; using Moq; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Jobs; using NzbDrone.Core.Model.Notification; @@ -67,8 +68,8 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock() .Setup(s => s.Get(series[1].Id)).Returns(series[1]); - Mocker.GetMock() - .Setup(s => s.GetSeriesFiles(It.IsAny())).Returns(new List()); + Mocker.GetMock() + .Setup(s => s.GetFilesBySeries(It.IsAny())).Returns(new List()); //Act Mocker.Resolve().Start(notification, null); @@ -121,8 +122,8 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock() .Setup(s => s.Get(series[0].Id)).Returns(series[0]); - Mocker.GetMock() - .Setup(s => s.GetSeriesFiles(It.IsAny())).Returns(new List()); + Mocker.GetMock() + .Setup(s => s.GetFilesBySeries(It.IsAny())).Returns(new List()); Mocker.GetMock() .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].Id))); @@ -148,8 +149,8 @@ namespace NzbDrone.Core.Test.JobTests int seriesId = 12; WithStrictMocker(); - Mocker.GetMock() - .Setup(p => p.GetSeriesFiles(seriesId)) + Mocker.GetMock() + .Setup(p => p.GetFilesBySeries(seriesId)) .Returns(new List()); Mocker.GetMock() @@ -176,8 +177,8 @@ namespace NzbDrone.Core.Test.JobTests WithStrictMocker(); - Mocker.GetMock() - .Setup(p => p.GetSeriesFiles(seriesId)) + Mocker.GetMock() + .Setup(p => p.GetFilesBySeries(seriesId)) .Returns(episodesFiles); Mocker.GetMock() @@ -202,8 +203,8 @@ namespace NzbDrone.Core.Test.JobTests - Mocker.GetMock() - .Setup(p => p.GetSeriesFiles(seriesId)) + Mocker.GetMock() + .Setup(p => p.GetFilesBySeries(seriesId)) .Returns(episodesFiles); Mocker.GetMock() diff --git a/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs b/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs index 8ac0c2fa0..457b5ca9f 100644 --- a/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs +++ b/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs @@ -5,6 +5,7 @@ using System.Text; using FizzWare.NBuilder; using Moq; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Jobs; using NzbDrone.Core.Model.Notification; @@ -40,8 +41,8 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.Get(_series.Id)) .Returns(_series); - Mocker.GetMock() - .Setup(s => s.GetSeasonFiles(_series.Id, 5)) + Mocker.GetMock() + .Setup(s => s.GetFilesBySeason(_series.Id, 5)) .Returns(_episodeFiles); } diff --git a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs b/NzbDrone.Core.Test/MediaFileTests/CleanUpDatabaseFixture.cs similarity index 88% rename from NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs rename to NzbDrone.Core.Test/MediaFileTests/CleanUpDatabaseFixture.cs index 01af0804a..b56a8b313 100644 --- a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs +++ b/NzbDrone.Core.Test/MediaFileTests/CleanUpDatabaseFixture.cs @@ -1,20 +1,16 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests +namespace NzbDrone.Core.Test.MediaFileTests { [TestFixture] public class CleanUpDatabaseFixture : SqlCeTest @@ -50,7 +46,6 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests Db.InsertMany(episodes); //Act - Mocker.Resolve().CleanUpDatabase(); var result = Db.Fetch(); //Assert @@ -77,7 +72,6 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests Db.InsertMany(episodes); //Act - Mocker.Resolve().CleanUpDatabase(); var result = Db.Fetch(); //Assert @@ -102,7 +96,6 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests Db.InsertMany(episodes); //Act - Mocker.Resolve().CleanUpDatabase(); var result = Db.Fetch(); //Assert @@ -129,12 +122,11 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests Db.InsertMany(episodeFiles); //Act - Mocker.Resolve().CleanUpDatabase(); var result = Db.Fetch(); //Assert result.Should().HaveCount(5); - result.Should().OnlyContain(e => e.EpisodeFileId > 0); + result.Should().OnlyContain(e => e.Id > 0); } } } diff --git a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs b/NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs similarity index 95% rename from NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs rename to NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs index 500a610bf..32b8d60ad 100644 --- a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs +++ b/NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs @@ -8,15 +8,12 @@ using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common.AutoMoq; -namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests +namespace NzbDrone.Core.Test.MediaFileTests { [TestFixture] // ReSharper disable InconsistentNaming @@ -54,7 +51,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV-720p]", result); @@ -81,7 +78,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("15x06 - City Sushi [HDTV-720p]", result); @@ -108,7 +105,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South Park 05x06 [HDTV-720p]", result); @@ -136,7 +133,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South Park s05e06", result); @@ -163,7 +160,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South.Park.s05e06.City.Sushi", result); @@ -190,7 +187,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV-720p]", result); @@ -218,7 +215,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("S15E06", result); @@ -252,7 +249,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream [HDTV-720p]", result); @@ -286,7 +283,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("3x23x24 - Strawberries and Cream [HDTV-720p]", result); @@ -320,7 +317,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("3x23x24 Strawberries and Cream [HDTV-720p]", result); @@ -354,7 +351,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream", result); @@ -388,7 +385,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("The.Mentalist.-.S03E23-24", result); @@ -422,7 +419,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("3x23x24", result); @@ -447,7 +444,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); //Assert result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p] [Proper]"); @@ -472,7 +469,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p]"); @@ -497,7 +494,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, true, new EpisodeFile()); //Assert result.Should().Be("South Park - S15E06 - City Sushi"); @@ -529,7 +526,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!"); @@ -556,7 +553,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("South Park.S15E06.City Sushi [HDTV-720p]", result); @@ -583,7 +580,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, new EpisodeFile()); //Assert Assert.AreEqual("15x06.City Sushi [HDTV-720p]", result); @@ -614,7 +611,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); //Assert result.Should().Be(Path.GetFileNameWithoutExtension(episodeFile.Path)); @@ -645,7 +642,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); + string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, Quality.HDTV720p, false, episodeFile); //Assert result.Should().Be(episodeFile.SceneName); @@ -677,7 +674,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!"); @@ -709,7 +706,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("30 Rock - S06E06-E07 - Hello + World"); @@ -747,7 +744,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .Build(); //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); + string result = Mocker.Resolve().GetNewFilename(new List { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, Quality.HDTV720p, false, new EpisodeFile()); //Assert result.Should().Be("30 Rock - S06E06-E07-E08 - Hello + World"); @@ -777,7 +774,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .With(e => e.Title = "Kristen Stewart") .Build(); - var result = Mocker.Resolve() + var result = Mocker.Resolve() .GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile()); result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13 - Kristen Stewart [HDTV-720p]"); } @@ -806,7 +803,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .With(e => e.Title = "Kristen Stewart") .Build(); - var result = Mocker.Resolve() + var result = Mocker.Resolve() .GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile()); result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13"); } @@ -835,7 +832,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .With(e => e.Title = "Kristen Stewart") .Build(); - var result = Mocker.Resolve() + var result = Mocker.Resolve() .GetNewFilename(episodes, series, Quality.HDTV720p, false, new EpisodeFile()); result.Should().Be("The Daily Show with Jon Stewart - Unknown - Kristen Stewart"); } diff --git a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTest.cs b/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs similarity index 86% rename from NzbDrone.Core.Test/ProviderTests/MediaFileProviderTest.cs rename to NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs index 72c912d04..34bf42817 100644 --- a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTest.cs +++ b/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs @@ -1,28 +1,25 @@ // ReSharper disable RedundantUsingDirective +using System.Linq; using System; using System.Collections.Generic; - using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; -using NzbDrone.Core.Model; using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common.AutoMoq; -namespace NzbDrone.Core.Test.ProviderTests +namespace NzbDrone.Core.Test.MediaFileTests { [TestFixture] // ReSharper disable InconsistentNaming - public class MediaFileProviderTest : SqlCeTest + public class MediaFileServiceTest : SqlCeTest { [Test] public void get_series_files() @@ -45,7 +42,7 @@ namespace NzbDrone.Core.Test.ProviderTests Db.InsertMany(firstSeriesFiles); Db.InsertMany(secondSeriesFiles); - var result = Mocker.Resolve().GetSeriesFiles(12); + var result = Mocker.Resolve().GetFilesBySeries(12); result.Should().HaveSameCount(firstSeriesFiles); @@ -74,7 +71,7 @@ namespace NzbDrone.Core.Test.ProviderTests Db.InsertMany(firstSeriesFiles); Db.InsertMany(secondSeriesFiles); - var result = Mocker.Resolve().GetSeasonFiles(12, 1); + var result = Mocker.Resolve().GetFilesBySeason(12, 1); result.Should().HaveSameCount(firstSeriesFiles); } @@ -88,9 +85,6 @@ namespace NzbDrone.Core.Test.ProviderTests .Setup(c => c.GetEpisodeBySeries(12)) .Returns(new List()); - Mocker.GetMock() - .Setup(e => e.CleanUpDatabase()); - Mocker.GetMock() .Setup(c => c.FolderExists(It.IsAny())) @@ -112,7 +106,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void CleanFileName(string name, string expectedName) { //Act - var result = MediaFileProvider.CleanFilename(name); + var result = MediaFileService.CleanFilename(name); //Assert Assert.AreEqual(expectedName, result); @@ -137,7 +131,7 @@ namespace NzbDrone.Core.Test.ProviderTests Mocker.GetMock().Setup(e => e.SortingSeasonFolderFormat).Returns(seasonFolderFormat); //Act - var result = Mocker.Resolve().CalculateFilePath(fakeSeries, 1, filename, ".mkv"); + var result = Mocker.Resolve().CalculateFilePath(fakeSeries, 1, filename, ".mkv"); //Assert Assert.AreEqual(expectedPath, result.FullName); @@ -158,12 +152,12 @@ namespace NzbDrone.Core.Test.ProviderTests Db.InsertMany(episodeFiles); //Act - Mocker.Resolve().Delete(1); + Mocker.Resolve().Delete(1); var result = Db.Fetch(); //Assert result.Should().HaveCount(9); - result.Should().NotContain(e => e.EpisodeFileId == 1); + result.Should().NotContain(e => e.Id == 1); } [Test] @@ -173,7 +167,7 @@ namespace NzbDrone.Core.Test.ProviderTests WithRealDb(); //Act - var result = Mocker.Resolve().GetFileByPath(@"C:\Test\EpisodeFile.avi"); + var result = Mocker.Resolve().GetFileByPath(@"C:\Test\EpisodeFile.avi"); //Resolve result.Should().BeNull(); @@ -194,12 +188,12 @@ namespace NzbDrone.Core.Test.ProviderTests var episodeFileId = Convert.ToInt32(Db.Insert(episodeFile)); //Act - var result = Mocker.Resolve().GetFileByPath(path); + var result = Mocker.Resolve().GetFileByPath(path); //Resolve result.Should().NotBeNull(); result.Path.Should().Be(path.NormalizePath()); - result.EpisodeFileId.Should().Be(episodeFileId); + result.Id.Should().Be(episodeFileId); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index c011c01dd..f1adc1f45 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -199,7 +199,7 @@ - + @@ -232,7 +232,7 @@ - + @@ -246,7 +246,7 @@ - + diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs index 3c186415f..0fd1df5b6 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs @@ -8,6 +8,7 @@ using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -36,7 +37,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.Resolve().CleanUpDropFolder(folder); //Assert - Mocker.GetMock().Verify(v => v.GetFileByPath(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(v => v.GetFileByPath(It.IsAny()), Times.Never()); } [Test] @@ -54,14 +55,14 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.GetMock().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories)) .Returns(new string[] { filename }); - Mocker.GetMock().Setup(s => s.GetFileByPath(filename)) + Mocker.GetMock().Setup(s => s.GetFileByPath(filename)) .Returns(() => null); //Act Mocker.Resolve().CleanUpDropFolder(folder); //Assert - Mocker.GetMock().Verify(v => v.GetFileByPath(filename), Times.Once()); + Mocker.GetMock().Verify(v => v.GetFileByPath(filename), Times.Once()); Mocker.GetMock().Verify(v => v.Get(It.IsAny()), Times.Never()); } @@ -91,25 +92,25 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .With(e => e.EpisodeFile = episodeFile) .Build(); - Mocker.GetMock().Setup(v => v.GetFileByPath(filename)) + Mocker.GetMock().Setup(v => v.GetFileByPath(filename)) .Returns(() => null); Mocker.GetMock().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories)) .Returns(new string[] { filename }); - Mocker.GetMock().Setup(s => s.GetFileByPath(filename)) + Mocker.GetMock().Setup(s => s.GetFileByPath(filename)) .Returns(episodeFile); Mocker.GetMock().Setup(s => s.Get(It.IsAny())) .Returns(series); - Mocker.GetMock().Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId)) + Mocker.GetMock().Setup(s => s.GetEpisodesByFileId(episodeFile.Id)) .Returns(episode); - Mocker.GetMock().Setup(s => s.GetNewFilename(It.IsAny>(), series, Quality.Unknown, false, It.IsAny())) + Mocker.GetMock().Setup(s => s.GetNewFilename(It.IsAny>(), series, Quality.Unknown, false, It.IsAny())) .Returns(newFilename); - Mocker.GetMock().Setup(s => s.CalculateFilePath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + Mocker.GetMock().Setup(s => s.CalculateFilePath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new FileInfo(newFilePath)); Mocker.GetMock() @@ -122,7 +123,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.Resolve().CleanUpDropFolder(folder); //Assert - Mocker.GetMock().Verify(v => v.GetFileByPath(filename), Times.Once()); + Mocker.GetMock().Verify(v => v.GetFileByPath(filename), Times.Once()); Mocker.GetMock().Verify(v => v.MoveFile(filename.NormalizePath(), newFilePath), Times.Once()); } } diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs index c1964e3f0..d01847267 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs @@ -9,6 +9,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; @@ -53,7 +54,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(e => e.GetEpisodesByFileId(It.IsAny())) .Returns(new List()); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.Delete(It.IsAny())); @@ -66,7 +67,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.GetMock() .Verify(e => e.GetEpisodesByFileId(It.IsAny()), Times.Exactly(10)); - Mocker.GetMock() + Mocker.GetMock() .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10)); } @@ -82,12 +83,12 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.GetMock() .Setup(e => e.GetEpisodesByFileId(It.IsAny())) - .Returns(new List { new Episode { EpisodeFile = new EpisodeFile { EpisodeFileId = 10 } }, new Episode { EpisodeFile = new EpisodeFile { EpisodeFileId = 10 } } }); + .Returns(new List { new Episode { EpisodeFile = new EpisodeFile { Id = 10 } }, new Episode { EpisodeFile = new EpisodeFile { Id = 10 } } }); Mocker.GetMock() .Setup(e => e.UpdateEpisode(It.IsAny())); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.Delete(It.IsAny())); Mocker.GetMock() @@ -106,10 +107,10 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.GetMock() .Verify(e => e.UpdateEpisode(It.Is(g => g.EpisodeFileId == 0)), Times.Exactly(20)); - Mocker.GetMock() + Mocker.GetMock() .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10)); - Mocker.GetMock() + Mocker.GetMock() .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10)); } diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs index 06937256e..eacec038f 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs @@ -6,6 +6,7 @@ using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -63,7 +64,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests //Mocks With80MBFile(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())) .Returns(false); @@ -120,7 +121,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests //Mocks With80MBFile(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())) .Returns(false); @@ -141,7 +142,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests var fakeSeries = Builder.CreateNew().Build(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())).Returns(false); With80MBFile(); @@ -162,7 +163,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests var fakeSeries = Builder.CreateNew().Build(); WithStrictMocker(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())) .Returns(true); @@ -190,7 +191,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests With80MBFile(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())) .Returns(false); @@ -221,7 +222,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests //Mocks With80MBFile(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())) .Returns(false); @@ -253,7 +254,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests With80MBFile(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())) .Returns(false); @@ -286,7 +287,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests With80MBFile(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())) .Returns(false); @@ -324,7 +325,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests //Mocks With80MBFile(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())) .Returns(false); @@ -353,7 +354,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests //Mocks With80MBFile(); - Mocker.GetMock() + Mocker.GetMock() .Setup(p => p.Exists(It.IsAny())) .Returns(false); @@ -419,7 +420,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests { const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi"; - Mocker.GetMock() + Mocker.GetMock() .Setup(m => m.Exists(path)) .Returns(false); @@ -442,7 +443,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi"; - Mocker.GetMock() + Mocker.GetMock() .Setup(m => m.Exists(path)) .Returns(false); @@ -473,7 +474,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi"; - Mocker.GetMock() + Mocker.GetMock() .Setup(m => m.Exists(path)) .Returns(false); @@ -500,7 +501,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests const string path = @"C:\Test\TV\30.rock.s00e01.pre-pilot.avi"; - Mocker.GetMock() + Mocker.GetMock() .Setup(m => m.Exists(path)) .Returns(false); @@ -528,7 +529,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi"; - Mocker.GetMock() + Mocker.GetMock() .Setup(m => m.Exists(path)) .Returns(false); @@ -549,18 +550,18 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests result.SeriesId.Should().Be(fakeEpisode.SeriesId); result.Size.Should().Be(size); result.DateAdded.Should().HaveDay(DateTime.Now.Day); - Mocker.GetMock().Verify(p => p.Add(It.IsAny()), Times.Once()); + Mocker.GetMock().Verify(p => p.Add(It.IsAny()), Times.Once()); //Get the count of episodes linked var count = Mocker.GetMock().Object.GetEpisodesByParseResult(null).Count; - Mocker.GetMock().Verify(p => p.UpdateEpisode(It.Is(e => e.EpisodeFileId == result.EpisodeFileId)), Times.Exactly(count)); + Mocker.GetMock().Verify(p => p.UpdateEpisode(It.Is(e => e.EpisodeFileId == result.Id)), Times.Exactly(count)); } private static void VerifySkipImport(EpisodeFile result, AutoMoqer Mocker) { result.Should().BeNull(); - Mocker.GetMock().Verify(p => p.Add(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(p => p.Add(It.IsAny()), Times.Never()); Mocker.GetMock().Verify(p => p.UpdateEpisode(It.IsAny()), Times.Never()); Mocker.GetMock().Verify(p => p.DeleteFile(It.IsAny()), Times.Never()); } diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs index feb775aa7..d7be6c148 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs @@ -10,6 +10,7 @@ using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Download; using NzbDrone.Core.ExternalNotification; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -53,14 +54,14 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Returns(fakeSeries); Mocker.GetMock() - .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId)) + .Setup(e => e.GetEpisodesByFileId(file.Id)) .Returns(fakeEpisode); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny(), It.IsAny(), It.IsAny())) .Returns(filename); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".avi")) .Returns(fi); @@ -103,14 +104,14 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Returns(fakeSeries); Mocker.GetMock() - .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId)) + .Setup(e => e.GetEpisodesByFileId(file.Id)) .Returns(fakeEpisode); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny(), It.IsAny(), It.IsAny())) .Returns(filename); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) .Returns(fi); @@ -155,14 +156,14 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Returns(fakeSeries); Mocker.GetMock() - .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId)) + .Setup(e => e.GetEpisodesByFileId(file.Id)) .Returns(fakeEpisode); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries, It.IsAny(), It.IsAny(), It.IsAny())) .Returns(filename); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) .Returns(fi); diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs index 3bc9cdb15..d7bd6d020 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs @@ -4,6 +4,7 @@ using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; @@ -30,8 +31,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(c => c.FolderExists(It.IsAny())) .Returns(true); - Mocker.GetMock() - .Setup(c => c.GetSeriesFiles(It.IsAny())) + Mocker.GetMock() + .Setup(c => c.GetFilesBySeries(It.IsAny())) .Returns(new List()); Mocker.Resolve().Scan(new Series()); @@ -51,10 +52,6 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Build(); - Mocker.GetMock() - .Setup(c => c.CleanUpDatabase()); - - Mocker.GetMock() .Setup(c => c.FolderExists(series.Path)) .Returns(false); diff --git a/NzbDrone.Core.Test/ProviderTests/Metadata/Xbmc_ForEpisodeFile_Fixture.cs b/NzbDrone.Core.Test/ProviderTests/Metadata/Xbmc_ForEpisodeFile_Fixture.cs index d08d3121f..94cd2df31 100644 --- a/NzbDrone.Core.Test/ProviderTests/Metadata/Xbmc_ForEpisodeFile_Fixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/Metadata/Xbmc_ForEpisodeFile_Fixture.cs @@ -9,6 +9,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; @@ -105,7 +106,7 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata .Build(); Mocker.GetMock() - .Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId)) + .Setup(s => s.GetEpisodesByFileId(episodeFile.Id)) .Returns(new List { episode }); } @@ -118,7 +119,7 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata .Build(); Mocker.GetMock() - .Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId)) + .Setup(s => s.GetEpisodesByFileId(episodeFile.Id)) .Returns(episodes.ToList()); } diff --git a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs index 6a3751afb..97d129e33 100644 --- a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs @@ -4,6 +4,7 @@ using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Providers; @@ -26,10 +27,10 @@ namespace NzbDrone.Core.Test.ProviderTests var episodeFiles = Builder.CreateListOfSize(2) .TheFirst(1) - .With(f => f.EpisodeFileId = 1) + .With(f => f.Id = 1) .With(f => f.Path = @"C:\Test\Title1.avi") .TheNext(1) - .With(f => f.EpisodeFileId = 2) + .With(f => f.Id = 2) .With(f => f.Path = @"C:\Test\Title2.avi") .Build(); @@ -47,11 +48,11 @@ namespace NzbDrone.Core.Test.ProviderTests Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("Title1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("Title2"); @@ -73,10 +74,10 @@ namespace NzbDrone.Core.Test.ProviderTests var episodeFiles = Builder.CreateListOfSize(2) .TheFirst(1) - .With(f => f.EpisodeFileId = 1) + .With(f => f.Id = 1) .With(f => f.Path = @"C:\Test\Title1.avi") .TheNext(1) - .With(f => f.EpisodeFileId = 2) + .With(f => f.Id = 2) .With(f => f.Path = @"C:\Test\Title2.avi") .Build(); @@ -94,11 +95,11 @@ namespace NzbDrone.Core.Test.ProviderTests Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("New Title 1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("New Title 2"); @@ -120,10 +121,10 @@ namespace NzbDrone.Core.Test.ProviderTests var episodeFiles = Builder.CreateListOfSize(2) .TheFirst(1) - .With(f => f.EpisodeFileId = 1) + .With(f => f.Id = 1) .With(f => f.Path = @"C:\Test\Title1.avi") .TheNext(1) - .With(f => f.EpisodeFileId = 2) + .With(f => f.Id = 2) .With(f => f.Path = @"C:\Test\Title2.avi") .Build(); @@ -141,11 +142,11 @@ namespace NzbDrone.Core.Test.ProviderTests Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("New Title 1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("Title2"); @@ -169,10 +170,10 @@ namespace NzbDrone.Core.Test.ProviderTests var episodeFiles = Builder.CreateListOfSize(2) .TheFirst(1) - .With(f => f.EpisodeFileId = 1) + .With(f => f.Id = 1) .With(f => f.Path = @"C:\Test\Title1.avi") .TheNext(1) - .With(f => f.EpisodeFileId = 2) + .With(f => f.Id = 2) .With(f => f.Path = @"C:\Test\Title2.avi") .Build(); @@ -190,11 +191,11 @@ namespace NzbDrone.Core.Test.ProviderTests Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0], episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("New Title 1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[2] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("Title2"); @@ -218,10 +219,10 @@ namespace NzbDrone.Core.Test.ProviderTests var episodeFiles = Builder.CreateListOfSize(2) .TheFirst(1) - .With(f => f.EpisodeFileId = 1) + .With(f => f.Id = 1) .With(f => f.Path = @"C:\Test\Title1.avi") .TheNext(1) - .With(f => f.EpisodeFileId = 2) + .With(f => f.Id = 2) .With(f => f.Path = @"C:\Test\Title2.avi") .Build(); @@ -239,11 +240,11 @@ namespace NzbDrone.Core.Test.ProviderTests Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[0], episodes[1] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[0])) .Returns("Title1"); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetNewFilename(new List { episodes[2] }, It.IsAny(), It.IsAny(), It.IsAny(), episodeFiles[1])) .Returns("Title2"); diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs index e62f9b5af..a43d92355 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs @@ -8,6 +8,7 @@ using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs index 1cf32ce8a..c78ef0863 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs @@ -8,6 +8,7 @@ using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs index ef2ba6570..0119a8454 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs @@ -8,6 +8,7 @@ using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; diff --git a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest.cs b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest.cs index 366741d51..4df8ce673 100644 --- a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest.cs @@ -9,6 +9,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -86,9 +87,9 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests WithRealDb(); var fakeSeries = Builder.CreateNew().Build(); - var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = Quality.SDTV).Build(); + var fakeFile = Builder.CreateNew().With(f => f.Id).With(c => c.Quality = Quality.SDTV).Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { Id = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); @@ -630,7 +631,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests { TvDbEpisodeId = tvDbEpisode.Id, Id = 99, - EpisodeFile = new EpisodeFile { EpisodeFileId = 69 }, + EpisodeFile = new EpisodeFile { Id = 69 }, Ignored = true, Series = fakeSeries, EpisodeNumber = tvDbEpisode.EpisodeNumber, @@ -679,7 +680,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests { TvDbEpisodeId = tvDbEpisode.Id, Id = 99, - EpisodeFile = new EpisodeFile { EpisodeFileId = 69 }, + EpisodeFile = new EpisodeFile { Id = 69 }, Ignored = true, Series = fakeSeries, EpisodeNumber = tvDbEpisode.EpisodeNumber + 1, @@ -725,7 +726,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests { TvDbEpisodeId = tvDbEpisode.Id, Id = 99, - EpisodeFile = new EpisodeFile { EpisodeFileId = 69 }, + EpisodeFile = new EpisodeFile { Id = 69 }, Ignored = true, Series = fakeSeries, EpisodeNumber = tvDbEpisode.EpisodeNumber, @@ -857,9 +858,9 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests WithRealDb(); var fakeSeries = Builder.CreateNew().Build(); - var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = Quality.SDTV).Build(); + var fakeFile = Builder.CreateNew().With(f => f.Id).With(c => c.Quality = Quality.SDTV).Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).With(c => c.EpisodeFile = new EpisodeFile { Id = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); @@ -901,9 +902,9 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests WithRealDb(); var fakeSeries = Builder.CreateNew().Build(); - var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = Quality.SDTV).Build(); + var fakeFile = Builder.CreateNew().With(f => f.Id).With(c => c.Quality = Quality.SDTV).Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { Id = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); @@ -925,7 +926,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeSeries = Builder.CreateNew().Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { Id = 1 }).Build(); Db.InsertMany(fakeEpisodes); Db.Insert(fakeSeries); @@ -1212,7 +1213,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Build(); var episodeFile = Builder.CreateNew() - .With(c => c.EpisodeFileId = 1) + .With(c => c.Id = 1) .With(c => c.Quality = Quality.SDTV) .Build(); @@ -1288,7 +1289,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .All() .With(c => c.SeriesId = 10) .With(c => c.SeasonNumber = 1) - .With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 12345 }) + .With(c => c.EpisodeFile = new EpisodeFile { Id = 12345 }) .Build(); Db.Insert(series); @@ -1314,7 +1315,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeEpisode = Builder.CreateNew() .With(c => c.SeriesId = 10) .With(c => c.SeasonNumber = 1) - .With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 12345 }) + .With(c => c.EpisodeFile = new EpisodeFile { Id = 12345 }) .Build(); Db.Insert(series); diff --git a/NzbDrone.Core/Datastore/PetaPoco/EpisodeSeasonRelator.cs b/NzbDrone.Core/Datastore/PetaPoco/EpisodeSeasonRelator.cs index da316e53b..b27a4de5e 100644 --- a/NzbDrone.Core/Datastore/PetaPoco/EpisodeSeasonRelator.cs +++ b/NzbDrone.Core/Datastore/PetaPoco/EpisodeSeasonRelator.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Repository; diff --git a/NzbDrone.Core/Datastore/SiaqodbProxy.cs b/NzbDrone.Core/Datastore/SiaqodbProxy.cs index 89ca2ee07..cbb2a743e 100644 --- a/NzbDrone.Core/Datastore/SiaqodbProxy.cs +++ b/NzbDrone.Core/Datastore/SiaqodbProxy.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Core.Datastore IList UpdateMany(IList objects) where T : ModelBase; void Delete(T obj) where T : ModelBase; void DeleteMany(IEnumerable objects) where T : ModelBase; + void UpdateField(T model, string fieldName) where T : ModelBase; } public static class SiaqodbLogger @@ -22,8 +23,8 @@ namespace NzbDrone.Core.Datastore public static void ListenTo(Siaqodb db) { db.DeletedObject += OnDeletedObject; - db.LoadingObject +=OnLoadingObject; - db.LoadedObject +=OnLoadedObject; + db.LoadingObject += OnLoadingObject; + db.LoadedObject += OnLoadedObject; } private static void OnLoadedObject(object sender, LoadedObjectEventArgs e) @@ -116,6 +117,11 @@ namespace NzbDrone.Core.Datastore } } + public void UpdateField(T model, string fieldName) where T : ModelBase + { + _db.UpdateObjectBy(model, fieldName); + } + private IList DoMany(IEnumerable objects, Func function) where T : ModelBase { return objects.Select(function).ToList(); diff --git a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs index 4a7a679e2..73ae6bf14 100644 --- a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs +++ b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using NLog; using NzbDrone.Core.Datastore; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; @@ -18,7 +19,7 @@ namespace NzbDrone.Core.Jobs { private readonly ISeriesService _seriesService; private readonly IEpisodeService _episodeService; - private readonly MediaFileProvider _mediaFileProvider; + private readonly IMediaFileService _mediaFileService; private readonly UpdateInfoJob _updateInfoJob; private readonly DiskScanJob _diskScanJob; private readonly BannerDownloadJob _bannerDownloadJob; @@ -32,13 +33,13 @@ namespace NzbDrone.Core.Jobs private List _attemptedSeries; public ImportNewSeriesJob(ISeriesService seriesService, IEpisodeService episodeService, - MediaFileProvider mediaFileProvider, UpdateInfoJob updateInfoJob, + IMediaFileService mediaFileService, UpdateInfoJob updateInfoJob, DiskScanJob diskScanJob, BannerDownloadJob bannerDownloadJob, ISeasonRepository seasonRepository, XemUpdateJob xemUpdateJob, ISeriesRepository seriesRepository,ISeasonService seasonService) { _seriesService = seriesService; _episodeService = episodeService; - _mediaFileProvider = mediaFileProvider; + _mediaFileService = mediaFileService; _updateInfoJob = updateInfoJob; _diskScanJob = diskScanJob; _bannerDownloadJob = bannerDownloadJob; @@ -108,7 +109,7 @@ namespace NzbDrone.Core.Jobs { //Todo: Need to convert this over to ObjectDb return; - var episodeFiles = _mediaFileProvider.GetSeriesFiles(seriesId); + var episodeFiles = _mediaFileService.GetFilesBySeries(seriesId); if (episodeFiles.Count() != 0) { diff --git a/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs b/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs index 53b61de48..335cf81a4 100644 --- a/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs +++ b/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs @@ -3,6 +3,7 @@ using System.Linq; using System; using NLog; using NzbDrone.Core.Datastore; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; @@ -12,17 +13,17 @@ namespace NzbDrone.Core.Jobs { public class RefreshEpisodeMetadata : IJob { - private readonly MediaFileProvider _mediaFileProvider; + private readonly IMediaFileService _mediaFileService; private readonly ISeriesService _seriesService; private readonly MetadataProvider _metadataProvider; private readonly ISeriesRepository _seriesRepository; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public RefreshEpisodeMetadata(MediaFileProvider mediaFileProvider, ISeriesService seriesService, + public RefreshEpisodeMetadata(IMediaFileService mediaFileService, ISeriesService seriesService, MetadataProvider metadataProvider,ISeriesRepository seriesRepository) { - _mediaFileProvider = mediaFileProvider; + _mediaFileService = mediaFileService; _seriesService = seriesService; _metadataProvider = metadataProvider; _seriesRepository = seriesRepository; @@ -59,7 +60,7 @@ namespace NzbDrone.Core.Jobs notification.CurrentMessage = String.Format("Refreshing episode metadata for '{0}'", series.Title); Logger.Debug("Getting episodes from database for series: {0}", series.Id); - var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.Id); + var episodeFiles = _mediaFileService.GetFilesBySeries(series.Id); if (episodeFiles == null || episodeFiles.Count == 0) { diff --git a/NzbDrone.Core/Jobs/RenameSeasonJob.cs b/NzbDrone.Core/Jobs/RenameSeasonJob.cs index 387fc1b11..518a03935 100644 --- a/NzbDrone.Core/Jobs/RenameSeasonJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeasonJob.cs @@ -5,6 +5,7 @@ using NLog; using NzbDrone.Common.Eventing; using NzbDrone.Core.Download; using NzbDrone.Core.ExternalNotification; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; @@ -13,7 +14,7 @@ namespace NzbDrone.Core.Jobs { public class RenameSeasonJob : IJob { - private readonly MediaFileProvider _mediaFileProvider; + private readonly IMediaFileService _mediaFileService; private readonly DiskScanProvider _diskScanProvider; private readonly ISeriesService _seriesService; private readonly MetadataProvider _metadataProvider; @@ -22,10 +23,10 @@ namespace NzbDrone.Core.Jobs private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public RenameSeasonJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider, ISeriesService seriesService, + public RenameSeasonJob(IMediaFileService mediaFileService, DiskScanProvider diskScanProvider, ISeriesService seriesService, MetadataProvider metadataProvider, ISeriesRepository seriesRepository, IEventAggregator eventAggregator) { - _mediaFileProvider = mediaFileProvider; + _mediaFileService = mediaFileService; _diskScanProvider = diskScanProvider; _seriesService = seriesService; _metadataProvider = metadataProvider; @@ -56,7 +57,7 @@ namespace NzbDrone.Core.Jobs notification.CurrentMessage = String.Format("Renaming episodes for {0} Season {1}", series.Title, options.SeasonNumber); logger.Debug("Getting episodes from database for series: {0} and season: {1}", options.SeriesId, options.SeasonNumber); - IList episodeFiles = _mediaFileProvider.GetSeasonFiles((int)options.SeriesId, (int)options.SeasonNumber); + IList episodeFiles = _mediaFileService.GetFilesBySeason((int)options.SeriesId, (int)options.SeasonNumber); if (episodeFiles == null || !episodeFiles.Any()) { diff --git a/NzbDrone.Core/Jobs/RenameSeriesJob.cs b/NzbDrone.Core/Jobs/RenameSeriesJob.cs index 000fe7c6a..94979a0dc 100644 --- a/NzbDrone.Core/Jobs/RenameSeriesJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeriesJob.cs @@ -4,6 +4,7 @@ using System; using NLog; using NzbDrone.Common.Eventing; using NzbDrone.Core.Download; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; @@ -12,7 +13,7 @@ namespace NzbDrone.Core.Jobs { public class RenameSeriesJob : IJob { - private readonly MediaFileProvider _mediaFileProvider; + private readonly IMediaFileService _mediaFileService; private readonly DiskScanProvider _diskScanProvider; private readonly MetadataProvider _metadataProvider; private readonly ISeriesRepository _seriesRepository; @@ -20,10 +21,10 @@ namespace NzbDrone.Core.Jobs private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public RenameSeriesJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider, + public RenameSeriesJob(IMediaFileService mediaFileService, DiskScanProvider diskScanProvider, MetadataProvider metadataProvider,ISeriesRepository seriesRepository,IEventAggregator eventAggregator) { - _mediaFileProvider = mediaFileProvider; + _mediaFileService = mediaFileService; _diskScanProvider = diskScanProvider; _metadataProvider = metadataProvider; _seriesRepository = seriesRepository; @@ -59,7 +60,7 @@ namespace NzbDrone.Core.Jobs notification.CurrentMessage = String.Format("Renaming episodes for '{0}'", series.Title); Logger.Debug("Getting episodes from database for series: {0}", series.Id); - var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.Id); + var episodeFiles = _mediaFileService.GetFilesBySeries(series.Id); if (episodeFiles == null || episodeFiles.Count == 0) { diff --git a/NzbDrone.Core/Tv/EpisodeFile.cs b/NzbDrone.Core/MediaFiles/EpisodeFile.cs similarity index 86% rename from NzbDrone.Core/Tv/EpisodeFile.cs rename to NzbDrone.Core/MediaFiles/EpisodeFile.cs index 0438b9fab..a3a6365ed 100644 --- a/NzbDrone.Core/Tv/EpisodeFile.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeFile.cs @@ -1,11 +1,12 @@ using System.Linq; using System; +using NzbDrone.Core.Datastore; using NzbDrone.Core.Qualities; -using PetaPoco; +using NzbDrone.Core.Tv; -namespace NzbDrone.Core.Tv +namespace NzbDrone.Core.MediaFiles { - public class EpisodeFile + public class EpisodeFile : ModelBase { public EpisodeFile() { @@ -14,7 +15,7 @@ namespace NzbDrone.Core.Tv public EpisodeFile(EpisodeFile source) { - EpisodeFileId = source.EpisodeFileId; + Id = source.Id; SeriesId = source.SeriesId; SeasonNumber = source.SeasonNumber; Path = source.Path; @@ -23,8 +24,6 @@ namespace NzbDrone.Core.Tv Size = source.Size; } - public int EpisodeFileId { get; set; } - public int SeriesId { get; set; } public int SeasonNumber { get; set; } public string Path { get; set; } diff --git a/NzbDrone.Core/MediaFiles/MediaFileRepository.cs b/NzbDrone.Core/MediaFiles/MediaFileRepository.cs new file mode 100644 index 000000000..4f309c6d7 --- /dev/null +++ b/NzbDrone.Core/MediaFiles/MediaFileRepository.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Linq; +using NzbDrone.Core.Datastore; + +namespace NzbDrone.Core.MediaFiles +{ + public interface IMediaFileRepository : IBasicRepository + { + EpisodeFile GetFileByPath(string path); + List GetFilesBySeries(int seriesId); + List GetFilesBySeason(int seriesId, int seasonNumber); + } + + + public class MediaFileRepository : BasicRepository, IMediaFileRepository + { + public MediaFileRepository(IObjectDatabase objectDatabase) + : base(objectDatabase) + { + } + + + public EpisodeFile GetFileByPath(string path) + { + return Queryable.SingleOrDefault(c => c.Path == path); + } + + public List GetFilesBySeries(int seriesId) + { + return Queryable.Where(c => c.SeriesId == seriesId).ToList(); + } + + public List GetFilesBySeason(int seriesId, int seasonNumber) + { + return Queryable.Where(c => c.SeriesId == seriesId && c.SeasonNumber == seasonNumber).ToList(); + + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/MediaFiles/MediaFileService.cs b/NzbDrone.Core/MediaFiles/MediaFileService.cs new file mode 100644 index 000000000..458577647 --- /dev/null +++ b/NzbDrone.Core/MediaFiles/MediaFileService.cs @@ -0,0 +1,214 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using NLog; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Tv; +using NzbDrone.Core.Helpers; + +namespace NzbDrone.Core.MediaFiles +{ + public interface IMediaFileService + { + EpisodeFile Add(EpisodeFile episodeFile); + void Update(EpisodeFile episodeFile); + void Delete(int episodeFileId); + bool Exists(string path); + EpisodeFile GetFileByPath(string path); + IList GetFilesBySeries(int seriesId); + IList GetFilesBySeason(int seriesId, int seasonNumber); + FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention); + string GetNewFilename(IList episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile); + } + + public class MediaFileService : IMediaFileService + { + private readonly IConfigService _configService; + private readonly IEpisodeService _episodeService; + private readonly Logger _logger; + private readonly IMediaFileRepository _mediaFileRepository; + + + public MediaFileService(IMediaFileRepository mediaFileRepository, IConfigService configService, IEpisodeService episodeService, Logger logger) + { + _mediaFileRepository = mediaFileRepository; + _configService = configService; + _episodeService = episodeService; + _logger = logger; + } + + public EpisodeFile Add(EpisodeFile episodeFile) + { + return _mediaFileRepository.Insert(episodeFile); + } + + public void Update(EpisodeFile episodeFile) + { + _mediaFileRepository.Update(episodeFile); + } + + public void Delete(int episodeFileId) + { + _mediaFileRepository.Delete(episodeFileId); + + var ep = _episodeService.GetEpisodesByFileId(episodeFileId); + + foreach (var episode in ep) + { + _episodeService.SetEpisodeIgnore(episode.Id, true); + } + } + + public bool Exists(string path) + { + return GetFileByPath(path) != null; + } + + public EpisodeFile GetFileByPath(string path) + { + return _mediaFileRepository.GetFileByPath(path.Normalize()); + } + + public IList GetFilesBySeries(int seriesId) + { + return _mediaFileRepository.GetFilesBySeries(seriesId); + } + + public IList GetFilesBySeason(int seriesId, int seasonNumber) + { + return _mediaFileRepository.GetFilesBySeason(seriesId, seasonNumber); + } + + + public FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention) + { + string path = series.Path; + if (series.SeasonFolder) + { + var seasonFolder = _configService.SortingSeasonFolderFormat + .Replace("%0s", seasonNumber.ToString("00")) + .Replace("%s", seasonNumber.ToString()); + + path = Path.Combine(path, seasonFolder); + } + + path = Path.Combine(path, fileName + extention); + + return new FileInfo(path); + } + + + public string GetNewFilename(IList episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile) + { + if (_configService.SortingUseSceneName) + { + _logger.Trace("Attempting to use scene name"); + if (String.IsNullOrWhiteSpace(episodeFile.SceneName)) + { + var name = Path.GetFileNameWithoutExtension(episodeFile.Path); + _logger.Trace("Unable to use scene name, because it is null, sticking with current name: {0}", name); + + return name; + } + + return episodeFile.SceneName; + } + + var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber); + + var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configService.SortingSeparatorStyle); + var numberStyle = EpisodeSortingHelper.GetNumberStyle(_configService.SortingNumberStyle); + + var episodeNames = new List(); + + episodeNames.Add(Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title)); + + string result = String.Empty; + + if (_configService.SortingIncludeSeriesName) + { + result += series.Title + separatorStyle.Pattern; + } + + if (series.SeriesType == SeriesType.Standard) + { + result += numberStyle.Pattern.Replace("%0e", + String.Format("{0:00}", sortedEpisodes.First().EpisodeNumber)); + + if (episodes.Count > 1) + { + var multiEpisodeStyle = + EpisodeSortingHelper.GetMultiEpisodeStyle(_configService.SortingMultiEpisodeStyle); + + foreach (var episode in sortedEpisodes.Skip(1)) + { + if (multiEpisodeStyle.Name == "Duplicate") + { + result += separatorStyle.Pattern + numberStyle.Pattern; + } + else + { + result += multiEpisodeStyle.Pattern; + } + + result = result.Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber)); + episodeNames.Add(Parser.CleanupEpisodeTitle(episode.Title)); + } + } + + result = result + .Replace("%s", String.Format("{0}", episodes.First().SeasonNumber)) + .Replace("%0s", String.Format("{0:00}", episodes.First().SeasonNumber)) + .Replace("%x", numberStyle.EpisodeSeparator) + .Replace("%p", separatorStyle.Pattern); + } + + else + { + if (episodes.First().AirDate.HasValue) + result += episodes.First().AirDate.Value.ToString("yyyy-MM-dd"); + + else + result += "Unknown"; + } + + if (_configService.SortingIncludeEpisodeTitle) + { + if (episodeNames.Distinct().Count() == 1) + result += separatorStyle.Pattern + episodeNames.First(); + + else + result += separatorStyle.Pattern + String.Join(" + ", episodeNames.Distinct()); + } + + if (_configService.SortingAppendQuality) + { + result += String.Format(" [{0}]", quality); + + if (proper) + result += " [Proper]"; + } + + if (_configService.SortingReplaceSpaces) + result = result.Replace(' ', '.'); + + _logger.Trace("New File Name is: [{0}]", result.Trim()); + return CleanFilename(result.Trim()); + } + + + public static string CleanFilename(string name) + { + string result = name; + string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" }; + string[] goodCharacters = { "+", "+", "{", "}", "!", "@", "-", "#", "`" }; + + for (int i = 0; i < badCharacters.Length; i++) + result = result.Replace(badCharacters[i], goodCharacters[i]); + + return result.Trim(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index 7e6ef882d..d705082f3 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Collections.Generic; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Providers; using NzbDrone.Core.Tv; using NzbDrone.Core.Repository; @@ -76,7 +77,7 @@ namespace NzbDrone.Core.Model public string GetDownloadTitle() { - var seriesTitle = MediaFileProvider.CleanFilename(Series.Title); + var seriesTitle = MediaFileService.CleanFilename(Series.Title); //Handle Full Naming if (FullSeason) diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 67df16954..9a9bfa2d5 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -285,6 +285,7 @@ + @@ -508,7 +509,7 @@ Code - + Code @@ -582,7 +583,7 @@ - + diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index 20fb02aa1..4e6b76f98 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -8,6 +8,7 @@ using NzbDrone.Common.Eventing; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download; using NzbDrone.Core.ExternalNotification; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -19,7 +20,7 @@ namespace NzbDrone.Core.Providers private static readonly string[] mediaExtentions = new[] { ".mkv", ".avi", ".wmv", ".mp4", ".mpg", ".mpeg", ".xvid", ".flv", ".mov", ".rm", ".rmvb", ".divx", ".dvr-ms", ".ts", ".ogm", ".m4v", ".strm" }; private readonly DiskProvider _diskProvider; private readonly IEpisodeService _episodeService; - private readonly MediaFileProvider _mediaFileProvider; + private readonly IMediaFileService _mediaFileService; private readonly SignalRProvider _signalRProvider; private readonly IConfigService _configService; private readonly RecycleBinProvider _recycleBinProvider; @@ -27,13 +28,13 @@ namespace NzbDrone.Core.Providers private readonly ISeriesRepository _seriesRepository; private readonly IEventAggregator _eventAggregator; - public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, MediaFileProvider mediaFileProvider, + public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, IMediaFileService mediaFileService, SignalRProvider signalRProvider, IConfigService configService, RecycleBinProvider recycleBinProvider, MediaInfoProvider mediaInfoProvider, ISeriesRepository seriesRepository, IEventAggregator eventAggregator) { _diskProvider = diskProvider; _episodeService = episodeService; - _mediaFileProvider = mediaFileProvider; + _mediaFileService = mediaFileService; _signalRProvider = signalRProvider; _configService = configService; _recycleBinProvider = recycleBinProvider; @@ -62,8 +63,6 @@ namespace NzbDrone.Core.Providers /// Path to scan public virtual List Scan(Series series, string path) { - _mediaFileProvider.CleanUpDatabase(); - if (!_diskProvider.FolderExists(path)) { Logger.Warn("Series folder doesn't exist: {0}", path); @@ -76,7 +75,7 @@ namespace NzbDrone.Core.Providers return new List(); } - var seriesFile = _mediaFileProvider.GetSeriesFiles(series.Id); + var seriesFile = _mediaFileService.GetFilesBySeries(series.Id); CleanUp(seriesFile); var mediaFileList = GetVideoFiles(path); @@ -104,7 +103,7 @@ namespace NzbDrone.Core.Providers { Logger.Trace("Importing file to database [{0}]", filePath); - if (_mediaFileProvider.Exists(filePath)) + if (_mediaFileService.Exists(filePath)) { Logger.Trace("[{0}] already exists in the database. skipping.", filePath); return null; @@ -169,7 +168,7 @@ namespace NzbDrone.Core.Providers //Todo: We shouldn't actually import the file until we confirm its the only one we want. //Todo: Separate episodeFile creation from importing (pass file to import to import) - _mediaFileProvider.Add(episodeFile); + _mediaFileService.Add(episodeFile); //Link file to all episodes foreach (var ep in episodes) @@ -189,9 +188,9 @@ namespace NzbDrone.Core.Providers throw new ArgumentNullException("episodeFile"); var series = _seriesRepository.Get(episodeFile.SeriesId); - var episodes = _episodeService.GetEpisodesByFileId(episodeFile.EpisodeFileId); - string newFileName = _mediaFileProvider.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile); - var newFile = _mediaFileProvider.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); + var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id); + string newFileName = _mediaFileService.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile); + var newFile = _mediaFileService.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); //Only rename if existing and new filenames don't match if (DiskProvider.PathEquals(episodeFile.Path, newFile.FullName)) @@ -223,7 +222,7 @@ namespace NzbDrone.Core.Providers } episodeFile.Path = newFile.FullName; - _mediaFileProvider.Update(episodeFile); + _mediaFileService.Update(episodeFile); var parseResult = Parser.ParsePath(episodeFile.Path); parseResult.Series = series; @@ -257,7 +256,7 @@ namespace NzbDrone.Core.Providers Logger.Trace("File [{0}] no longer exists on disk. removing from db", episodeFile.Path); //Set the EpisodeFileId for each episode attached to this file to 0 - foreach (var episode in _episodeService.GetEpisodesByFileId(episodeFile.EpisodeFileId)) + foreach (var episode in _episodeService.GetEpisodesByFileId(episodeFile.Id)) { Logger.Trace("Detaching episode {0} from file.", episode.Id); episode.EpisodeFile = null; @@ -269,12 +268,12 @@ namespace NzbDrone.Core.Providers //Delete it from the DB Logger.Trace("Removing EpisodeFile from DB."); - _mediaFileProvider.Delete(episodeFile.EpisodeFileId); + _mediaFileService.Delete(episodeFile.Id); } } catch (Exception ex) { - var message = String.Format("Unable to cleanup EpisodeFile in DB: {0}", episodeFile.EpisodeFileId); + var message = String.Format("Unable to cleanup EpisodeFile in DB: {0}", episodeFile.Id); Logger.ErrorException(message, ex); } } @@ -290,7 +289,7 @@ namespace NzbDrone.Core.Providers { try { - var episodeFile = _mediaFileProvider.GetFileByPath(file); + var episodeFile = _mediaFileService.GetFileByPath(file); if (episodeFile != null) { diff --git a/NzbDrone.Core/Providers/DownloadClients/BlackholeProvider.cs b/NzbDrone.Core/Providers/DownloadClients/BlackholeProvider.cs index 1e8c12a6b..72d9d99bb 100644 --- a/NzbDrone.Core/Providers/DownloadClients/BlackholeProvider.cs +++ b/NzbDrone.Core/Providers/DownloadClients/BlackholeProvider.cs @@ -5,6 +5,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Core.Configuration; using NzbDrone.Core.History; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.DecisionEngine; @@ -38,7 +39,7 @@ namespace NzbDrone.Core.Providers.DownloadClients { try { - title = MediaFileProvider.CleanFilename(title); + title = MediaFileService.CleanFilename(title); var filename = Path.Combine(_configService.BlackholeDirectory, title + ".nzb"); diff --git a/NzbDrone.Core/Providers/DownloadClients/PneumaticProvider.cs b/NzbDrone.Core/Providers/DownloadClients/PneumaticProvider.cs index 59a7d7697..1191c429d 100644 --- a/NzbDrone.Core/Providers/DownloadClients/PneumaticProvider.cs +++ b/NzbDrone.Core/Providers/DownloadClients/PneumaticProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.DecisionEngine; @@ -43,7 +44,7 @@ namespace NzbDrone.Core.Providers.DownloadClients return false; } - title = MediaFileProvider.CleanFilename(title); + title = MediaFileService.CleanFilename(title); //Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC) var filename = Path.Combine(_configService.PneumaticDirectory, title + ".nzb"); diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs deleted file mode 100644 index 11503d0dd..000000000 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ /dev/null @@ -1,265 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using NLog; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.Qualities; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Helpers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; -using PetaPoco; -using NzbDrone.Common; - -namespace NzbDrone.Core.Providers -{ - public class MediaFileProvider - { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private readonly IConfigService _configService; - private readonly IDatabase _database; - private readonly IEpisodeService _episodeService; - - public MediaFileProvider(IEpisodeService episodeService, IConfigService configService, IDatabase database) - { - _episodeService = episodeService; - _configService = configService; - _database = database; - } - - public MediaFileProvider() - { - } - - public virtual int Add(EpisodeFile episodeFile) - { - return Convert.ToInt32(_database.Insert(episodeFile)); - } - - public virtual void Update(EpisodeFile episodeFile) - { - _database.Update(episodeFile); - } - - public virtual void Delete(int episodeFileId) - { - _database.Delete(episodeFileId); - } - - public virtual bool Exists(string path) - { - return _database.Exists("WHERE Path =@0", path.NormalizePath()); - } - - public virtual EpisodeFile GetFileByPath(string path) - { - return _database.SingleOrDefault("WHERE Path =@0", path.NormalizePath()); - } - - public virtual EpisodeFile GetEpisodeFile(int episodeFileId) - { - return _database.Single(episodeFileId); - } - - public virtual List GetEpisodeFiles() - { - return _database.Fetch(); - } - - public virtual IList GetSeriesFiles(int seriesId) - { - return _database.Fetch("WHERE SeriesId= @0", seriesId); - } - - public virtual IList GetSeasonFiles(int seriesId, int seasonNumber) - { - return _database.Fetch("WHERE SeriesId= @0 AND SeasonNumber = @1", seriesId, seasonNumber); - } - - public virtual Tuple GetEpisodeFilesCount(int seriesId) - { - var allEpisodes = _episodeService.GetEpisodeBySeries(seriesId).ToList(); - - var episodeTotal = allEpisodes.Where(e => !e.Ignored && e.AirDate != null && e.AirDate <= DateTime.Today).ToList(); - var avilableEpisodes = episodeTotal.Where(e => e.EpisodeFileId > 0).ToList(); - - return new Tuple(avilableEpisodes.Count, episodeTotal.Count); - } - - public virtual FileInfo CalculateFilePath(Series series, int seasonNumber, string fileName, string extention) - { - string path = series.Path; - if (series.SeasonFolder) - { - var seasonFolder = _configService.SortingSeasonFolderFormat - .Replace("%0s", seasonNumber.ToString("00")) - .Replace("%s", seasonNumber.ToString()); - - path = Path.Combine(path, seasonFolder); - } - - path = Path.Combine(path, fileName + extention); - - return new FileInfo(path); - } - - public virtual void CleanUpDatabase() - { - Logger.Trace("Verifying Episode > Episode file relationships."); - - string updateString = "UPDATE Episodes SET EpisodeFileId = 0, GrabDate = NULL, PostDownloadStatus = 0"; - - if (_configService.AutoIgnorePreviouslyDownloadedEpisodes) - { - updateString += ", Ignored = 1"; - } - - var updated = _database.Execute(updateString + - @"WHERE EpisodeFileId IN - (SELECT Episodes.EpisodeFileId FROM Episodes - LEFT OUTER JOIN EpisodeFiles - ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId - WHERE Episodes.EpisodeFileId > 0 AND EpisodeFiles.EpisodeFileId IS NULL)"); - - if (updated > 0) - { - Logger.Debug("Removed {0} invalid links to episode files.", updated); - } - - Logger.Trace("Deleting orphan files."); - - updated = _database.Execute(@"DELETE FROM EpisodeFiles - WHERE EpisodeFileId IN - (SELECT EpisodeFiles.EpisodeFileId FROM EpisodeFiles - LEFT OUTER JOIN Episodes - ON EpisodeFiles.EpisodeFileId = Episodes.EpisodeFileId - WHERE Episodes.EpisodeFileId IS NULL)"); - - if (updated > 0) - { - Logger.Debug("Removed {0} orphan file(s) from database.", updated); - } - } - - public virtual string GetNewFilename(IList episodes, Series series, Quality quality, bool proper, EpisodeFile episodeFile) - { - if (_configService.SortingUseSceneName) - { - Logger.Trace("Attempting to use scene name"); - if (String.IsNullOrWhiteSpace(episodeFile.SceneName)) - { - var name = Path.GetFileNameWithoutExtension(episodeFile.Path); - Logger.Trace("Unable to use scene name, because it is null, sticking with current name: {0}", name); - - return name; - } - - return episodeFile.SceneName; - } - - var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber); - - var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configService.SortingSeparatorStyle); - var numberStyle = EpisodeSortingHelper.GetNumberStyle(_configService.SortingNumberStyle); - - var episodeNames = new List(); - - episodeNames.Add(Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title)); - - string result = String.Empty; - - if (_configService.SortingIncludeSeriesName) - { - result += series.Title + separatorStyle.Pattern; - } - - if (series.SeriesType == SeriesType.Standard) - { - result += numberStyle.Pattern.Replace("%0e", - String.Format("{0:00}", sortedEpisodes.First().EpisodeNumber)); - - if(episodes.Count > 1) - { - var multiEpisodeStyle = - EpisodeSortingHelper.GetMultiEpisodeStyle(_configService.SortingMultiEpisodeStyle); - - foreach(var episode in sortedEpisodes.Skip(1)) - { - if(multiEpisodeStyle.Name == "Duplicate") - { - result += separatorStyle.Pattern + numberStyle.Pattern; - } - else - { - result += multiEpisodeStyle.Pattern; - } - - result = result.Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber)); - episodeNames.Add(Parser.CleanupEpisodeTitle(episode.Title)); - } - } - - result = result - .Replace("%s", String.Format("{0}", episodes.First().SeasonNumber)) - .Replace("%0s", String.Format("{0:00}", episodes.First().SeasonNumber)) - .Replace("%x", numberStyle.EpisodeSeparator) - .Replace("%p", separatorStyle.Pattern); - } - - else - { - if(episodes.First().AirDate.HasValue) - result += episodes.First().AirDate.Value.ToString("yyyy-MM-dd"); - - else - result += "Unknown"; - } - - if (_configService.SortingIncludeEpisodeTitle) - { - if (episodeNames.Distinct().Count() == 1) - result += separatorStyle.Pattern + episodeNames.First(); - - else - result += separatorStyle.Pattern + String.Join(" + ", episodeNames.Distinct()); - } - - if (_configService.SortingAppendQuality) - { - result += String.Format(" [{0}]", quality); - - if (proper) - result += " [Proper]"; - } - - if (_configService.SortingReplaceSpaces) - result = result.Replace(' ', '.'); - - Logger.Trace("New File Name is: [{0}]", result.Trim()); - return CleanFilename(result.Trim()); - } - - public virtual void ChangeQuality(int episodeFileId, Quality quality) - { - _database.Execute("UPDATE EpisodeFiles SET Quality = @quality WHERE EpisodeFileId = @episodeFileId", new { episodeFileId, quality }); - } - - public virtual void ChangeQuality(int seriesId, int seasonNumber, Quality quality) - { - _database.Execute("UPDATE EpisodeFiles SET Quality = @quality WHERE SeriesId = @seriesId AND SeasonNumber = @seasonNumber", new { seriesId, seasonNumber, quality }); - } - - public static string CleanFilename(string name) - { - string result = name; - string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" }; - string[] goodCharacters = { "+", "+", "{", "}", "!", "@", "-", "#", "`" }; - - for (int i = 0; i < badCharacters.Length; i++) - result = result.Replace(badCharacters[i], goodCharacters[i]); - - return result.Trim(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Metadata/MetadataBase.cs b/NzbDrone.Core/Providers/Metadata/MetadataBase.cs index 205e88a44..ad432df7e 100644 --- a/NzbDrone.Core/Providers/Metadata/MetadataBase.cs +++ b/NzbDrone.Core/Providers/Metadata/MetadataBase.cs @@ -2,6 +2,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; diff --git a/NzbDrone.Core/Providers/Metadata/Xbmc.cs b/NzbDrone.Core/Providers/Metadata/Xbmc.cs index 880e4032f..0470927eb 100644 --- a/NzbDrone.Core/Providers/Metadata/Xbmc.cs +++ b/NzbDrone.Core/Providers/Metadata/Xbmc.cs @@ -7,6 +7,7 @@ using System.Xml.Linq; using NzbDrone.Common; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; @@ -115,11 +116,11 @@ namespace NzbDrone.Core.Providers.Metadata public override void CreateForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tvDbSeries) { //Create filename.tbn and filename.nfo - var episodes = _episodeService.GetEpisodesByFileId(episodeFile.EpisodeFileId); + var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id); if (!episodes.Any()) { - _logger.Debug("No episodes where found for this episode file: {0}", episodeFile.EpisodeFileId); + _logger.Debug("No episodes where found for this episode file: {0}", episodeFile.Id); return; } @@ -137,7 +138,7 @@ namespace NzbDrone.Core.Providers.Metadata { if (!_diskProvider.FileExists(episodeFile.Path.Replace(Path.GetExtension(episodeFile.Path), ".tbn"))) { - _logger.Debug("Downloading episode thumbnail for: {0}", episodeFile.EpisodeFileId); + _logger.Debug("Downloading episode thumbnail for: {0}", episodeFile.Id); _bannerProvider.Download(episodeFileThumbnail.BannerPath, episodeFile.Path.Replace(Path.GetExtension(episodeFile.Path), ".tbn")); } @@ -145,7 +146,7 @@ namespace NzbDrone.Core.Providers.Metadata - _logger.Debug("Generating filename.nfo for: {0}", episodeFile.EpisodeFileId); + _logger.Debug("Generating filename.nfo for: {0}", episodeFile.Id); var xmlResult = String.Empty; foreach (var episode in episodes) diff --git a/NzbDrone.Core/Providers/MetadataProvider.cs b/NzbDrone.Core/Providers/MetadataProvider.cs index 250056e67..8b9e115a0 100644 --- a/NzbDrone.Core/Providers/MetadataProvider.cs +++ b/NzbDrone.Core/Providers/MetadataProvider.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Providers.Metadata; using NzbDrone.Core.Repository; @@ -135,7 +136,7 @@ namespace NzbDrone.Core.Providers { foreach (var provider in _metadataProviders.Where(i => GetSettings(i.GetType()).Enable)) { - Logger.Trace("Creating {0} metadata for {1}", provider.Name, episodeFile.EpisodeFileId); + Logger.Trace("Creating {0} metadata for {1}", provider.Name, episodeFile.Id); provider.CreateForEpisodeFile(episodeFile, tvDbSeries); } } diff --git a/NzbDrone.Core/Providers/MisnamedProvider.cs b/NzbDrone.Core/Providers/MisnamedProvider.cs index ebce3e00b..d9dd17b7a 100644 --- a/NzbDrone.Core/Providers/MisnamedProvider.cs +++ b/NzbDrone.Core/Providers/MisnamedProvider.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Diagnostics; using NLog; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Repository; @@ -13,14 +14,14 @@ namespace NzbDrone.Core.Providers { public class MisnamedProvider { - private readonly MediaFileProvider _mediaFileProvider; + private readonly IMediaFileService _mediaFileService; private readonly IEpisodeService _episodeService; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public MisnamedProvider(MediaFileProvider mediaFileProvider, IEpisodeService episodeService) + public MisnamedProvider(IMediaFileService mediaFileService, IEpisodeService episodeService) { - _mediaFileProvider = mediaFileProvider; + _mediaFileService = mediaFileService; _episodeService = episodeService; } @@ -36,7 +37,7 @@ namespace NzbDrone.Core.Providers var misnamedFilesSelect = episodesWithFiles.AsParallel().Where( w => w.First().EpisodeFile.Path != - _mediaFileProvider.GetNewFilename(w.Select(e => e).ToList(), w.First().Series, + _mediaFileService.GetNewFilename(w.Select(e => e).ToList(), w.First().Series, w.First().EpisodeFile.Quality, w.First().EpisodeFile.Proper, w.First().EpisodeFile)).Skip(Math.Max(pageSize * (pageNumber - 1), 0)).Take(pageSize); //Process the episodes @@ -44,7 +45,7 @@ namespace NzbDrone.Core.Providers { var episodes = f.Select(e => e).ToList(); var firstEpisode = episodes[0]; - var properName = _mediaFileProvider.GetNewFilename(episodes, + var properName = _mediaFileService.GetNewFilename(episodes, firstEpisode.Series, firstEpisode.EpisodeFile.Quality, firstEpisode.EpisodeFile.Proper, firstEpisode.EpisodeFile); diff --git a/NzbDrone.Core/Tv/Episode.cs b/NzbDrone.Core/Tv/Episode.cs index bae36b6af..5a36388ec 100644 --- a/NzbDrone.Core/Tv/Episode.cs +++ b/NzbDrone.Core/Tv/Episode.cs @@ -1,6 +1,7 @@ using System.Linq; using System; using NzbDrone.Core.Datastore; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model; using Sqo.Attributes; @@ -40,7 +41,7 @@ namespace NzbDrone.Core.Tv get { if (!HasFile) return 0; - return EpisodeFile.EpisodeFileId; + return EpisodeFile.Id; } } diff --git a/NzbDrone.Core/Tv/EpisodeRepository.cs b/NzbDrone.Core/Tv/EpisodeRepository.cs index 530f48128f0dcdbed974efb6a385accdc7da0d1f..40a5c260ce828e51d48cb4a87fa1d4ddbaa9cdaf 100644 GIT binary patch delta 227 zcmZoL{b{yAk=a}U2+Hy^Qxt+zOFYx_@{3a4auQ24TnjRb^HWk4QX#aCLQ;NyjzT6( zLHcG%<~b~z53qk?p8SAC(3lJpChKxYML><$gV>y+V2fmhH7^&)aWLSYl$DxX;*waB in3PzYsux<2l30@JmYJH9q5*fL64V@}&5OD3@&N#>qfYk# delta 56 zcmexq)?m6pk$H0h^Ar|Q*MiLA{FGF;%$!uu6a`ybg)|^*asivwWC13v$+tMTHs^3u LF>hYYbB+%HE>;sq diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs index b4073356d..cca30175e 100644 --- a/NzbDrone.Core/Tv/EpisodeService.cs +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -283,8 +283,7 @@ namespace NzbDrone.Core.Tv public virtual void SetEpisodeIgnore(int episodeId, bool isIgnored) { var episode = _episodeRepository.Get(episodeId); - episode.Ignored = isIgnored; - _episodeRepository.Update(episode); + _episodeRepository.SetIgnoreFlat(episode, isIgnored); logger.Info("Ignore flag for Episode:{0} was set to {1}", episodeId, isIgnored); } diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index 09d7e906d..41a495dff 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -9,7 +9,6 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv.Events; @@ -185,4 +184,4 @@ namespace NzbDrone.Core.Tv return dateTime.ToString("hh:mm tt"); } } -} \ No newline at end of file +}