From 1ccbb3c9d876cc7f2db39c017831d684f220f31e Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 3 Mar 2013 21:53:02 -0800 Subject: [PATCH] automatically download banner,poster, fanart. without a job :D --- NzbDrone.Api/Series/SeriesLookupModule.cs | 9 +- NzbDrone.Core.Test/EpisodeParseResultTest.cs | 2 +- .../JobTests/BannerDownloadJobTest.cs | 92 ---------------- .../JobTests/ImportNewSeriesJobTest.cs | 6 - .../MediaCoverServiceFixture.cs | 23 ++++ .../MediaFileTests/GetNewFilenameFixture.cs | 6 +- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 3 +- .../ProviderTests/BannerProviderTest.cs | 103 ------------------ .../ImportFileFixture.cs | 4 +- .../SabProviderTests/QueueFixture.cs | 2 +- .../ProviderTests/TvDbProviderTest.cs | 13 ++- .../FindMatchingTvRageSeriesFixture.cs | 5 +- .../ProcessResultsFixture.cs | 1 + .../TvRageProviderTests/GetSeriesFixture.cs | 5 +- .../GetUtcOffsetFixture.cs | 9 +- .../SearchSeriesFixture.cs | 11 +- NzbDrone.Core/Jobs/BannerDownloadJob.cs | 81 -------------- NzbDrone.Core/Jobs/EpisodeSearchJob.cs | 2 +- NzbDrone.Core/Jobs/ImportNewSeriesJob.cs | 9 +- NzbDrone.Core/MediaCover/MediaCover.cs | 18 +++ NzbDrone.Core/MediaCover/MediaCoverService.cs | 68 ++++++++++++ NzbDrone.Core/MediaFiles/MediaFileService.cs | 2 +- .../TvDbProxy.cs} | 29 ++++- .../TvRageMappingProvider.cs | 16 ++- .../TvRageProxy.cs} | 9 +- NzbDrone.Core/Model/EpisodeParseResult.cs | 2 +- NzbDrone.Core/NzbDrone.Core.csproj | 11 +- NzbDrone.Core/Providers/BannerProvider.cs | 102 ----------------- NzbDrone.Core/Providers/DiskScanProvider.cs | 2 +- .../DownloadClients/NzbgetProvider.cs | 2 +- .../Providers/DownloadClients/SabProvider.cs | 2 +- NzbDrone.Core/Providers/SearchProvider.cs | 4 +- .../ReferenceData/DailySeriesService.cs | 2 +- NzbDrone.Core/Tv/Episode.cs | 2 +- NzbDrone.Core/Tv/EpisodeService.cs | 11 +- NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs | 15 +++ NzbDrone.Core/Tv/Series.cs | 10 +- NzbDrone.Core/Tv/SeriesRepository.cs | 6 +- NzbDrone.Core/Tv/SeriesService.cs | 19 ++-- NzbDrone.Test.Common/LoggingTest.cs | 7 +- NzbDrone.Test.Common/TestBase.cs | 2 + NzbDrone.ncrunchsolution | 1 + 42 files changed, 245 insertions(+), 483 deletions(-) delete mode 100644 NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs create mode 100644 NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs delete mode 100644 NzbDrone.Core.Test/ProviderTests/BannerProviderTest.cs delete mode 100644 NzbDrone.Core/Jobs/BannerDownloadJob.cs create mode 100644 NzbDrone.Core/MediaCover/MediaCover.cs create mode 100644 NzbDrone.Core/MediaCover/MediaCoverService.cs rename NzbDrone.Core/{Providers/TvDbProvider.cs => MetadataSource/TvDbProxy.cs} (85%) rename NzbDrone.Core/{Providers => MetadataSource}/TvRageMappingProvider.cs (81%) rename NzbDrone.Core/{Providers/TvRageProvider.cs => MetadataSource/TvRageProxy.cs} (97%) delete mode 100644 NzbDrone.Core/Providers/BannerProvider.cs create mode 100644 NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs diff --git a/NzbDrone.Api/Series/SeriesLookupModule.cs b/NzbDrone.Api/Series/SeriesLookupModule.cs index f0c338d1d..4f9b70a54 100644 --- a/NzbDrone.Api/Series/SeriesLookupModule.cs +++ b/NzbDrone.Api/Series/SeriesLookupModule.cs @@ -2,25 +2,26 @@ using Nancy; using NzbDrone.Api.Extensions; using NzbDrone.Api.QualityType; +using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Providers; namespace NzbDrone.Api.Series { public class SeriesLookupModule : NzbDroneApiModule { - private readonly TvDbProvider _tvDbProvider; + private readonly TvDbProxy _tvDbProxy; - public SeriesLookupModule(TvDbProvider tvDbProvider) + public SeriesLookupModule(TvDbProxy tvDbProxy) : base("/Series/lookup") { - _tvDbProvider = tvDbProvider; + _tvDbProxy = tvDbProxy; Get["/"] = x => GetQualityType(); } private Response GetQualityType() { - var tvDbResults = _tvDbProvider.SearchSeries((string)Request.Query.term); + var tvDbResults = _tvDbProxy.SearchSeries((string)Request.Query.term); return tvDbResults.AsResponse(); } } diff --git a/NzbDrone.Core.Test/EpisodeParseResultTest.cs b/NzbDrone.Core.Test/EpisodeParseResultTest.cs index 594f8b9d8..4b9a897be 100644 --- a/NzbDrone.Core.Test/EpisodeParseResultTest.cs +++ b/NzbDrone.Core.Test/EpisodeParseResultTest.cs @@ -202,7 +202,7 @@ namespace NzbDrone.Core.Test public string create_proper_sab_daily_titles(bool proper) { var series = Builder.CreateNew() - .With(c => c.SeriesType = SeriesType.Daily) + .With(c => c.SeriesTypes = SeriesTypes.Daily) .With(c => c.Title = "My Series Name") .Build(); diff --git a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs deleted file mode 100644 index e63f86a74..000000000 --- a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs +++ /dev/null @@ -1,92 +0,0 @@ -using FizzWare.NBuilder; -using Moq; -using NUnit.Framework; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Jobs; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Test.Framework; -using System.Linq; - -namespace NzbDrone.Core.Test.JobTests -{ - [TestFixture] - // ReSharper disable InconsistentNaming - public class BannerDownloadJobTest : CoreTest - { - private ProgressNotification _notification; - - [SetUp] - public void Setup() - { - _notification = new ProgressNotification("Test"); - WithTempAsAppPath(); - } - - private void WithSuccessfulDownload() - { - Mocker.GetMock() - .Setup(s => s.Download(It.IsAny())) - .Returns(true); - } - - private void WithFailedDownload() - { - Mocker.GetMock() - .Setup(s => s.Download(It.IsAny())) - .Returns(false); - } - - private void VerifyDownloadMock(int times) - { - Mocker.GetMock().Verify(v => v.Download(It.IsAny()), Times.Exactly(times)); - } - - [Test] - public void Start_should_download_banners_for_all_series_when_no_targetId_is_passed_in() - { - WithSuccessfulDownload(); - - var series = Builder.CreateListOfSize(5) - .Build().ToList(); - - Mocker.GetMock().Setup(s => s.All()) - .Returns(series); - - Mocker.Resolve().Start(_notification, null); - VerifyDownloadMock(series.Count); - } - - [Test] - public void Start_should_only_attempt_to_download_for_series_with_banner_url() - { - WithSuccessfulDownload(); - - var series = Builder.CreateListOfSize(5) - .TheFirst(2) - .With(s => s.BannerUrl = null) - .Build().ToList(); - - Mocker.GetMock().Setup(s => s.All()) - .Returns(series); - - Mocker.Resolve().Start(_notification, null); - VerifyDownloadMock(3); - } - - [Test] - public void Start_should_download_single_banner_when_seriesId_is_passed_in() - { - WithSuccessfulDownload(); - - var series = Builder.CreateNew() - .Build(); - - Mocker.GetMock().Setup(s => s.Get(series.Id)) - .Returns(series); - - Mocker.Resolve().Start(_notification, new { SeriesId = series.Id }); - VerifyDownloadMock(1); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index 815445f6f..270bdfa19 100644 --- a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -48,9 +48,6 @@ namespace NzbDrone.Core.Test.JobTests .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].Id))) .Callback(() => series[1].LastDiskSync = DateTime.Now); - Mocker.GetMock() - .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") > 0))); - Mocker.GetMock() .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") > 0))); @@ -116,9 +113,6 @@ namespace NzbDrone.Core.Test.JobTests .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].Id))) .Callback(() => series[0].LastDiskSync = DateTime.Now); - Mocker.GetMock() - .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].Id))); - Mocker.GetMock() .Setup(s => s.Get(series[0].Id)).Returns(series[0]); diff --git a/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs b/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs new file mode 100644 index 000000000..a43b8c178 --- /dev/null +++ b/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs @@ -0,0 +1,23 @@ +using System.Linq; +using NUnit.Framework; +using NzbDrone.Common; +using NzbDrone.Core.MediaCover; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; +using NzbDrone.Core.Tv.Events; + +namespace NzbDrone.Core.Test.MediaCoverTests +{ + [TestFixture] + public class MediaCoverServiceFixture : CoreTest + { + [SetUp] + public void Setup() + { + Mocker.SetConstant(new HttpProvider()); + Mocker.SetConstant(new DiskProvider()); + Mocker.SetConstant(new EnvironmentProvider()); + } + + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs b/NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs index 32b8d60ad..5b774a25b 100644 --- a/NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs +++ b/NzbDrone.Core.Test/MediaFileTests/GetNewFilenameFixture.cs @@ -763,7 +763,7 @@ namespace NzbDrone.Core.Test.MediaFileTests var series = Builder .CreateNew() - .With(s => s.SeriesType = SeriesType.Daily) + .With(s => s.SeriesTypes = SeriesTypes.Daily) .With(s => s.Title = "The Daily Show with Jon Stewart") .Build(); @@ -792,7 +792,7 @@ namespace NzbDrone.Core.Test.MediaFileTests var series = Builder .CreateNew() - .With(s => s.SeriesType = SeriesType.Daily) + .With(s => s.SeriesTypes = SeriesTypes.Daily) .With(s => s.Title = "The Daily Show with Jon Stewart") .Build(); @@ -821,7 +821,7 @@ namespace NzbDrone.Core.Test.MediaFileTests var series = Builder .CreateNew() - .With(s => s.SeriesType = SeriesType.Daily) + .With(s => s.SeriesTypes = SeriesTypes.Daily) .With(s => s.Title = "The Daily Show with Jon Stewart") .Build(); diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 257dd10ee..ad8c8672e 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -140,6 +140,7 @@ + @@ -163,13 +164,11 @@ - - diff --git a/NzbDrone.Core.Test/ProviderTests/BannerProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/BannerProviderTest.cs deleted file mode 100644 index 5e084c109..000000000 --- a/NzbDrone.Core.Test/ProviderTests/BannerProviderTest.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Net; -using FizzWare.NBuilder; -using FluentAssertions; -using Moq; -using NUnit.Framework; -using NzbDrone.Common; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Repository; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common.AutoMoq; -using NzbDrone.Test.Common; - -namespace NzbDrone.Core.Test.ProviderTests -{ - [TestFixture] - // ReSharper disable InconsistentNaming - public class BannerProviderTest : CoreTest - { - private Series _series; - - [SetUp] - public void Setup() - { - WithTempAsAppPath(); - - _series = Builder.CreateNew() - .With(s => s.Id = 12345) - .Build(); - - var path = @"C:\Windows\Temp"; - - Mocker.GetMock().Setup(s => s.CreateDirectory(path)); - } - - private void WithSuccessfulDownload() - { - Mocker.GetMock().Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())); - } - - private void WithFailedDownload() - { - Mocker.GetMock().Setup(s => s.DownloadFile(It.IsAny(), It.IsAny())) - .Throws(new WebException("Failed to download file (Mocked)")); - } - - [Test] - public void Download_should_return_true_when_banner_is_downloaded_successfully() - { - WithSuccessfulDownload(); - var result = Mocker.Resolve().Download(_series); - result.Should().BeTrue(); - } - - [Test] - public void Download_should_return_false_when_banner_download_fails() - { - WithFailedDownload(); - var result = Mocker.Resolve().Download(_series); - result.Should().BeFalse(); - } - - [Test] - public void Delete_should_delete_banner_file_when_it_exists() - { - Mocker.GetMock().Setup(s => s.FileExists(It.IsAny())) - .Returns(true); - - Mocker.GetMock().Setup(s => s.DeleteFile(It.IsAny())); - - var result = Mocker.Resolve().Delete(1); - result.Should().BeTrue(); - } - - [Test] - public void Delete_should_return_true_even_when_file_sint_deleted() - { - Mocker.GetMock().Setup(s => s.FileExists(It.IsAny())) - .Returns(false); - - var result = Mocker.Resolve().Delete(1); - result.Should().BeTrue(); - } - - [Test] - public void Delete_should_return_false_when_file_fails_to_delete() - { - Mocker.GetMock().Setup(s => s.FileExists(It.IsAny())) - .Returns(true); - - Mocker.GetMock().Setup(s => s.DeleteFile(It.IsAny())) - .Throws(new SystemException("File not found.")); - - var result = Mocker.Resolve().Delete(1); - result.Should().BeFalse(); - ExceptionVerification.ExpectedWarns(1); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs index d2a8617e4..4281c1a70 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs @@ -37,7 +37,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests { _series = Builder .CreateNew() - .With(s => s.SeriesType = SeriesType.Standard) + .With(s => s.SeriesTypes = SeriesTypes.Standard) .Build(); } @@ -50,7 +50,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests public void WithDailySeries() { - _series.SeriesType = SeriesType.Daily; + _series.SeriesTypes = SeriesTypes.Daily; } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs index 81e7cfafc..fb9f27b3b 100644 --- a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs @@ -149,7 +149,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests { Quality = new QualityModel { Quality = Quality.Bluray720p, Proper = false }, AirDate = new DateTime(2011, 12, 01), - Series = new Series { Title = "The Dailyshow", CleanTitle = Parser.NormalizeTitle("The Dailyshow"), SeriesType = SeriesType.Daily }, + Series = new Series { Title = "The Dailyshow", CleanTitle = Parser.NormalizeTitle("The Dailyshow"), SeriesTypes = SeriesTypes.Daily }, }; diff --git a/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs index d287fac6a..4a25f5fb2 100644 --- a/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs @@ -7,6 +7,7 @@ using Autofac; using FluentAssertions; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; @@ -17,7 +18,7 @@ namespace NzbDrone.Core.Test.ProviderTests // ReSharper disable InconsistentNaming public class TvDbProviderTest : CoreTest { - private TvDbProvider tvDbProvider; + private TvDbProxy tvDbProxy; [SetUp] public void Setup() @@ -25,11 +26,11 @@ namespace NzbDrone.Core.Test.ProviderTests var builder = new ContainerBuilder(); builder.RegisterType(); - builder.RegisterType(); + builder.RegisterType(); var container = builder.Build(); - tvDbProvider = container.Resolve(); + tvDbProxy = container.Resolve(); } [TearDown] @@ -45,7 +46,7 @@ namespace NzbDrone.Core.Test.ProviderTests [TestCase("Franklin & Bash")] public void successful_search(string title) { - var result = tvDbProvider.SearchSeries(title); + var result = tvDbProxy.SearchSeries(title); result.Should().NotBeEmpty(); result[0].Title.Should().Be(title); @@ -56,7 +57,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void no_search_result() { //act - var result = tvDbProvider.SearchSeries(Guid.NewGuid().ToString()); + var result = tvDbProxy.SearchSeries(Guid.NewGuid().ToString()); //assert result.Should().BeEmpty(); @@ -67,7 +68,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void none_unique_season_episode_number() { //act - var result = tvDbProvider.GetEpisodes(75978);//Family guy + var result = tvDbProxy.GetEpisodes(75978);//Family guy //Asserts that when episodes are grouped by Season/Episode each group contains maximum of //one item. diff --git a/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/FindMatchingTvRageSeriesFixture.cs b/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/FindMatchingTvRageSeriesFixture.cs index d3f9f2b7b..4e2ad360a 100644 --- a/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/FindMatchingTvRageSeriesFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/FindMatchingTvRageSeriesFixture.cs @@ -5,6 +5,7 @@ using System.Text; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; +using NzbDrone.Core.MetadataSource; using NzbDrone.Core.ReferenceData; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.TvRage; @@ -54,11 +55,11 @@ namespace NzbDrone.Core.Test.ProviderTests.TvRageMappingProviderTests .Setup(s => s.GetCleanName(_series.Id)) .Returns(""); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.SearchSeries(_series.Title)) .Returns(_searchResults); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetSeries(_searchResults.First().ShowId)) .Returns(_tvRageSeries); } diff --git a/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/ProcessResultsFixture.cs b/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/ProcessResultsFixture.cs index 80b04c70e..bc3c9e4b9 100644 --- a/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/ProcessResultsFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/ProcessResultsFixture.cs @@ -5,6 +5,7 @@ using System.Text; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; +using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.TvRage; using NzbDrone.Core.Providers; diff --git a/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/GetSeriesFixture.cs b/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/GetSeriesFixture.cs index 0ed5a1caf..d36c001e7 100644 --- a/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/GetSeriesFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/GetSeriesFixture.cs @@ -8,6 +8,7 @@ using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; @@ -38,7 +39,7 @@ namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests public void should_be_null_when_no_showinfo_is_returned() { WithEmptyResults(); - Mocker.Resolve().GetSeries(100).Should().BeNull(); + Mocker.Resolve().GetSeries(100).Should().BeNull(); ExceptionVerification.ExpectedWarns(1); } @@ -47,7 +48,7 @@ namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests public void should_return_series_when_showinfo_is_valid() { WithOneResult(); - var result = Mocker.Resolve().GetSeries(29999); + var result = Mocker.Resolve().GetSeries(29999); result.ShowId.Should().Be(29999); result.Name.Should().Be("Anger Management"); diff --git a/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/GetUtcOffsetFixture.cs b/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/GetUtcOffsetFixture.cs index 6595cad7f..0401f80f6 100644 --- a/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/GetUtcOffsetFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/GetUtcOffsetFixture.cs @@ -6,6 +6,7 @@ using System.Linq; using FluentAssertions; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; @@ -19,13 +20,13 @@ namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests [Test] public void should_return_zero_if_timeZone_is_empty() { - Mocker.Resolve().GetUtcOffset("").Should().Be(0); + Mocker.Resolve().GetUtcOffset("").Should().Be(0); } [Test] public void should_return_zero_if_cannot_be_coverted_to_int() { - Mocker.Resolve().GetUtcOffset("adfhadfhdjaf").Should().Be(0); + Mocker.Resolve().GetUtcOffset("adfhadfhdjaf").Should().Be(0); } [TestCase("GMT-5", -5)] @@ -33,7 +34,7 @@ namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests [TestCase("GMT+8", 8)] public void should_return_offset_when_not_dst(string timezone, int expected) { - Mocker.Resolve().GetUtcOffset(timezone).Should().Be(expected); + Mocker.Resolve().GetUtcOffset(timezone).Should().Be(expected); } [TestCase("GMT-5 +DST", -4)] @@ -41,7 +42,7 @@ namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests [TestCase("GMT+8 +DST", 9)] public void should_return_offset_plus_one_when_dst(string timezone, int expected) { - Mocker.Resolve().GetUtcOffset(timezone).Should().Be(expected); + Mocker.Resolve().GetUtcOffset(timezone).Should().Be(expected); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/SearchSeriesFixture.cs b/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/SearchSeriesFixture.cs index e99ad530e..d5ed6e73d 100644 --- a/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/SearchSeriesFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/TvRageProviderTests/SearchSeriesFixture.cs @@ -8,6 +8,7 @@ using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; @@ -45,35 +46,35 @@ namespace NzbDrone.Core.Test.ProviderTests.TvRageProviderTests public void should_be_empty_when_no_results_are_found() { WithEmptyResults(); - Mocker.Resolve().SearchSeries("asdasdasdasdas").Should().BeEmpty(); + Mocker.Resolve().SearchSeries("asdasdasdasdas").Should().BeEmpty(); } [Test] public void should_be_have_more_than_one_when_multiple_results_are_returned() { WithManyResults(); - Mocker.Resolve().SearchSeries("top+gear").Should().NotBeEmpty(); + Mocker.Resolve().SearchSeries("top+gear").Should().NotBeEmpty(); } [Test] public void should_have_one_when_only_one_result_is_found() { WithOneResult(); - Mocker.Resolve().SearchSeries("suits").Should().HaveCount(1); + Mocker.Resolve().SearchSeries("suits").Should().HaveCount(1); } [Test] public void ended_should_not_have_a_value_when_series_has_not_ended() { WithOneResult(); - Mocker.Resolve().SearchSeries("suits").First().Ended.HasValue.Should().BeFalse(); + Mocker.Resolve().SearchSeries("suits").First().Ended.HasValue.Should().BeFalse(); } [Test] public void started_should_match_series() { WithOneResult(); - Mocker.Resolve().SearchSeries("suits").First().Started.Should().Be(new DateTime(2011, 6, 23)); + Mocker.Resolve().SearchSeries("suits").First().Started.Should().Be(new DateTime(2011, 6, 23)); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/BannerDownloadJob.cs b/NzbDrone.Core/Jobs/BannerDownloadJob.cs deleted file mode 100644 index b924407dc..000000000 --- a/NzbDrone.Core/Jobs/BannerDownloadJob.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using NLog; -using NzbDrone.Common; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; - -namespace NzbDrone.Core.Jobs -{ - public class BannerDownloadJob : IJob - { - private readonly ISeriesService _seriesService; - private readonly BannerProvider _bannerProvider; - private readonly ISeriesRepository _seriesRepository; - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - private const string BANNER_URL_PREFIX = "http://www.thetvdb.com/banners/"; - - public BannerDownloadJob(ISeriesService seriesService, BannerProvider bannerProvider, ISeriesRepository seriesRepository) - { - _seriesService = seriesService; - _bannerProvider = bannerProvider; - _seriesRepository = seriesRepository; - } - - public BannerDownloadJob() - { - } - - public string Name - { - get { return "Banner Download"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromDays(30); } - } - - public virtual void Start(ProgressNotification notification, dynamic options) - { - Logger.Debug("Starting banner download job"); - - if (options != null) - { - Series series = _seriesRepository.Get((int)options.SeriesId); - - if (series != null && !String.IsNullOrEmpty(series.BannerUrl)) - { - DownloadBanner(notification, series); - } - - return; - } - - var seriesInDb = _seriesRepository.All(); - - foreach (var series in seriesInDb.Where(s => !String.IsNullOrEmpty(s.BannerUrl))) - { - DownloadBanner(notification, series); - } - - Logger.Debug("Finished banner download job"); - } - - public virtual void DownloadBanner(ProgressNotification notification, Series series) - { - notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title); - - if (_bannerProvider.Download(series)) - notification.CurrentMessage = string.Format("Successfully download banner for '{0}'", series.Title); - - else - notification.CurrentMessage = string.Format("Failed to download banner for '{0}'", series.Title); - } - } -} diff --git a/NzbDrone.Core/Jobs/EpisodeSearchJob.cs b/NzbDrone.Core/Jobs/EpisodeSearchJob.cs index a7c462646..406f64550 100644 --- a/NzbDrone.Core/Jobs/EpisodeSearchJob.cs +++ b/NzbDrone.Core/Jobs/EpisodeSearchJob.cs @@ -64,7 +64,7 @@ namespace NzbDrone.Core.Jobs return; } - if (episode.Series.SeriesType == SeriesType.Daily) + if (episode.Series.SeriesTypes == SeriesTypes.Daily) { if (!episode.AirDate.HasValue) { diff --git a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs index 73ae6bf14..28204a134 100644 --- a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs +++ b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs @@ -22,7 +22,6 @@ namespace NzbDrone.Core.Jobs private readonly IMediaFileService _mediaFileService; private readonly UpdateInfoJob _updateInfoJob; private readonly DiskScanJob _diskScanJob; - private readonly BannerDownloadJob _bannerDownloadJob; private readonly ISeasonRepository _seasonRepository; private readonly XemUpdateJob _xemUpdateJob; private readonly ISeriesRepository _seriesRepository; @@ -34,15 +33,14 @@ namespace NzbDrone.Core.Jobs public ImportNewSeriesJob(ISeriesService seriesService, IEpisodeService episodeService, IMediaFileService mediaFileService, UpdateInfoJob updateInfoJob, - DiskScanJob diskScanJob, BannerDownloadJob bannerDownloadJob, - ISeasonRepository seasonRepository, XemUpdateJob xemUpdateJob, ISeriesRepository seriesRepository,ISeasonService seasonService) + DiskScanJob diskScanJob, + ISeasonRepository seasonRepository, XemUpdateJob xemUpdateJob, ISeriesRepository seriesRepository, ISeasonService seasonService) { _seriesService = seriesService; _episodeService = episodeService; _mediaFileService = mediaFileService; _updateInfoJob = updateInfoJob; _diskScanJob = diskScanJob; - _bannerDownloadJob = bannerDownloadJob; _seasonRepository = seasonRepository; _xemUpdateJob = xemUpdateJob; _seriesRepository = seriesRepository; @@ -86,9 +84,6 @@ namespace NzbDrone.Core.Jobs var updatedSeries = _seriesRepository.Get(((ModelBase)currentSeries).Id); AutoIgnoreSeasons(((ModelBase)updatedSeries).Id); - //Download the banner for the new series - _bannerDownloadJob.Start(notification, new { SeriesId = ((ModelBase)updatedSeries).Id }); - //Get Scene Numbering if applicable _xemUpdateJob.Start(notification, new { SeriesId = ((ModelBase)updatedSeries).Id }); diff --git a/NzbDrone.Core/MediaCover/MediaCover.cs b/NzbDrone.Core/MediaCover/MediaCover.cs new file mode 100644 index 000000000..f49d3adb3 --- /dev/null +++ b/NzbDrone.Core/MediaCover/MediaCover.cs @@ -0,0 +1,18 @@ +using System.Linq; + +namespace NzbDrone.Core.MediaCover +{ + + public enum MediaCoverTypes + { + Poster = 0, + Banner = 1, + Fanart = 2 + } + + public class MediaCover + { + public MediaCoverTypes CoverType { get; set; } + public string Url { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/MediaCover/MediaCoverService.cs b/NzbDrone.Core/MediaCover/MediaCoverService.cs new file mode 100644 index 000000000..c048d5bd9 --- /dev/null +++ b/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -0,0 +1,68 @@ +using System; +using System.IO; +using System.Linq; +using NLog; +using NzbDrone.Common; +using NzbDrone.Common.Eventing; +using NzbDrone.Core.Tv; +using NzbDrone.Core.Tv.Events; + +namespace NzbDrone.Core.MediaCover +{ + public class MediaCoverService : IHandle + { + private readonly HttpProvider _httpProvider; + private readonly DiskProvider _diskProvider; + private readonly Logger _logger; + + private readonly string _coverRootFolder; + + private const string COVER_URL_PREFIX = "http://www.thetvdb.com/banners/"; + + public MediaCoverService(HttpProvider httpProvider, DiskProvider diskProvider, EnvironmentProvider environmentProvider, Logger logger) + { + _httpProvider = httpProvider; + _diskProvider = diskProvider; + _logger = logger; + + _coverRootFolder = environmentProvider.GetMediaCoverPath(); + } + + public void Handle(SeriesUpdatedEvent message) + { + EnsureCovers(message.Series); + } + + private void EnsureCovers(Series series) + { + foreach (var cover in series.Covers) + { + var fileName = GetCoverPath(series.Id, cover.CoverType); + if (!_diskProvider.FileExists(fileName)) + { + DownloadCover(series, cover); + } + } + } + + private void DownloadCover(Series series, MediaCover cover) + { + try + { + var fileName = GetCoverPath(series.Id, cover.CoverType); + + _logger.Info("Downloading {0} for {1}", cover.CoverType, series.Title); + _httpProvider.DownloadFile(COVER_URL_PREFIX + cover.Url, fileName); + } + catch (Exception e) + { + _logger.ErrorException("Couldn't download media cover for " + series.TvDbId, e); + } + } + + private string GetCoverPath(int seriesId, MediaCoverTypes coverTypes) + { + return Path.Combine(_coverRootFolder, seriesId.ToString("0000"), coverTypes.ToString().ToLower() + ".jpg"); + } + } +} diff --git a/NzbDrone.Core/MediaFiles/MediaFileService.cs b/NzbDrone.Core/MediaFiles/MediaFileService.cs index 458577647..da8ae9baa 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileService.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileService.cs @@ -132,7 +132,7 @@ namespace NzbDrone.Core.MediaFiles result += series.Title + separatorStyle.Pattern; } - if (series.SeriesType == SeriesType.Standard) + if (series.SeriesTypes == SeriesTypes.Standard) { result += numberStyle.Pattern.Replace("%0e", String.Format("{0:00}", sortedEpisodes.First().EpisodeNumber)); diff --git a/NzbDrone.Core/Providers/TvDbProvider.cs b/NzbDrone.Core/MetadataSource/TvDbProxy.cs similarity index 85% rename from NzbDrone.Core/Providers/TvDbProvider.cs rename to NzbDrone.Core/MetadataSource/TvDbProxy.cs index 5b66ebe11..0a22dc79c 100644 --- a/NzbDrone.Core/Providers/TvDbProvider.cs +++ b/NzbDrone.Core/MetadataSource/TvDbProxy.cs @@ -3,12 +3,13 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using NLog; +using NzbDrone.Core.MediaCover; using NzbDrone.Core.Tv; using NzbDrone.Common; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.MetadataSource { - public class TvDbProvider + public class TvDbProxy { public const string TVDB_APIKEY = "5D2D188E86E07F4F"; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); @@ -18,7 +19,7 @@ namespace NzbDrone.Core.Providers private readonly Tvdb.Tvdb _handlerV2; - public TvDbProvider() + public TvDbProxy() { _handlerV2 = new Tvdb.Tvdb(TVDB_APIKEY); } @@ -58,13 +59,29 @@ namespace NzbDrone.Core.Providers series.Language = tvDbSeries.Language ?? string.Empty; series.CleanTitle = Parser.NormalizeTitle(tvDbSeries.SeriesName); series.LastInfoSync = DateTime.Now; - + if (tvDbSeries.Runtime.HasValue) { series.Runtime = Convert.ToInt32(tvDbSeries.Runtime); } - - series.BannerUrl = tvDbSeries.banner; + + series.Covers = new List(); + + if (!string.IsNullOrWhiteSpace(tvDbSeries.banner)) + { + series.Covers.Add(new MediaCover.MediaCover { CoverType = MediaCoverTypes.Banner, Url = tvDbSeries.banner }); + } + + if (!string.IsNullOrWhiteSpace(tvDbSeries.fanart)) + { + series.Covers.Add(new MediaCover.MediaCover { CoverType = MediaCoverTypes.Fanart, Url = tvDbSeries.fanart }); + } + + if (!string.IsNullOrWhiteSpace(tvDbSeries.poster)) + { + series.Covers.Add(new MediaCover.MediaCover { CoverType = MediaCoverTypes.Poster, Url = tvDbSeries.poster }); + } + series.Network = tvDbSeries.Network; if (tvDbSeries.FirstAired.HasValue && tvDbSeries.FirstAired.Value.Year > 1900) diff --git a/NzbDrone.Core/Providers/TvRageMappingProvider.cs b/NzbDrone.Core/MetadataSource/TvRageMappingProvider.cs similarity index 81% rename from NzbDrone.Core/Providers/TvRageMappingProvider.cs rename to NzbDrone.Core/MetadataSource/TvRageMappingProvider.cs index 4498191d2..0e0ba04bd 100644 --- a/NzbDrone.Core/Providers/TvRageMappingProvider.cs +++ b/NzbDrone.Core/MetadataSource/TvRageMappingProvider.cs @@ -1,29 +1,27 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using NLog; -using NzbDrone.Core.Datastore; +using NzbDrone.Core.Providers; using NzbDrone.Core.ReferenceData; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.TvRage; -using NzbDrone.Core.Repository; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.MetadataSource { public class TvRageMappingProvider { private readonly SceneMappingService _sceneMappingService; - private readonly TvRageProvider _tvRageProvider; + private readonly TvRageProxy _tvRageProxy; private readonly IEpisodeService _episodeService; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); public TvRageMappingProvider(SceneMappingService sceneMappingService, - TvRageProvider tvRageProvider, IEpisodeService episodeService) + TvRageProxy tvRageProxy, IEpisodeService episodeService) { _sceneMappingService = sceneMappingService; - _tvRageProvider = tvRageProvider; + _tvRageProxy = tvRageProxy; _episodeService = episodeService; } @@ -36,7 +34,7 @@ namespace NzbDrone.Core.Providers var firstEpisode = _episodeService.GetEpisode(series.Id, 1, 1); var cleanName = _sceneMappingService.GetCleanName(series.Id); - var results = _tvRageProvider.SearchSeries(series.Title); + var results = _tvRageProxy.SearchSeries(series.Title); var result = ProcessResults(results, series, cleanName, firstEpisode); if (result != null) @@ -44,7 +42,7 @@ namespace NzbDrone.Core.Providers logger.Trace("TV Rage: {0} matches TVDB: {1}", result.Name, series.Title); series.TvRageId = result.ShowId; series.TvRageTitle = result.Name; - series.UtcOffset = _tvRageProvider.GetSeries(result.ShowId).UtcOffset; + series.UtcOffset = _tvRageProxy.GetSeries(result.ShowId).UtcOffset; } return series; diff --git a/NzbDrone.Core/Providers/TvRageProvider.cs b/NzbDrone.Core/MetadataSource/TvRageProxy.cs similarity index 97% rename from NzbDrone.Core/Providers/TvRageProvider.cs rename to NzbDrone.Core/MetadataSource/TvRageProxy.cs index 9bce78fed..44be88ad2 100644 --- a/NzbDrone.Core/Providers/TvRageProvider.cs +++ b/NzbDrone.Core/MetadataSource/TvRageProxy.cs @@ -1,27 +1,26 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Xml.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model.TvRage; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.MetadataSource { - public class TvRageProvider + public class TvRageProxy { private readonly HttpProvider _httpProvider; private const string TVRAGE_APIKEY = "NW4v0PSmQIoVmpbASLdD"; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public TvRageProvider(HttpProvider httpProvider) + public TvRageProxy(HttpProvider httpProvider) { _httpProvider = httpProvider; } - public TvRageProvider() + public TvRageProxy() { } diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index d705082f3..c5ef82160 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -91,7 +91,7 @@ namespace NzbDrone.Core.Model return seasonResult; } - if (Series.SeriesType == SeriesType.Daily) + if (Series.SeriesTypes == SeriesTypes.Daily) { var dailyResult = String.Format("{0} - {1:yyyy-MM-dd} - {2} [{3}]", seriesTitle, AirDate, Episodes.First().Title, Quality.Quality); diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 05c980c44..056f81ff3 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -232,6 +232,7 @@ + @@ -264,6 +265,7 @@ + @@ -294,7 +296,7 @@ - + @@ -321,7 +323,6 @@ - @@ -337,8 +338,8 @@ - - + + @@ -504,7 +505,7 @@ Code - + Code diff --git a/NzbDrone.Core/Providers/BannerProvider.cs b/NzbDrone.Core/Providers/BannerProvider.cs deleted file mode 100644 index f60e136bc..000000000 --- a/NzbDrone.Core/Providers/BannerProvider.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using NLog; -using NzbDrone.Common; -using NzbDrone.Core.Datastore; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Repository; - -namespace NzbDrone.Core.Providers -{ - public class BannerProvider - { - private readonly HttpProvider _httpProvider; - private readonly EnvironmentProvider _environmentProvider; - private readonly DiskProvider _diskProvider; - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - - private const string BANNER_URL_PREFIX = "http://www.thetvdb.com/banners/"; - - public BannerProvider(HttpProvider httpProvider, EnvironmentProvider environmentProvider, - DiskProvider diskProvider) - { - _httpProvider = httpProvider; - _environmentProvider = environmentProvider; - _diskProvider = diskProvider; - } - - public BannerProvider() - { - - } - - public virtual bool Download(Series series) - { - var bannerPath = _environmentProvider.GetBannerPath(); - - logger.Trace("Ensuring Banner Folder exists: ", bannerPath); - _diskProvider.CreateDirectory(bannerPath); - - var bannerFilename = Path.Combine(bannerPath, series.Id.ToString()) + ".jpg"; - - logger.Trace("Downloading banner for '{0}'", series.Title); - - try - { - _httpProvider.DownloadFile(BANNER_URL_PREFIX + series.BannerUrl, bannerFilename); - logger.Trace("Successfully download banner for '{0}'", series.Title); - } - catch (Exception) - { - logger.Debug("Failed to download banner for '{0}'", series.Title); - return false; - } - - return true; - } - - public virtual bool Delete(int seriesId) - { - var bannerPath = _environmentProvider.GetBannerPath(); - var bannerFilename = Path.Combine(bannerPath, seriesId.ToString()) + ".jpg"; - - try - { - logger.Trace("Checking if banner exists: {0}", bannerFilename); - - if (_diskProvider.FileExists(bannerFilename)) - { - logger.Trace("Deleting existing banner: {0}", bannerFilename); - _diskProvider.DeleteFile(bannerFilename); - } - } - catch(Exception ex) - { - logger.WarnException("Failed to delete banner: " + bannerFilename, ex); - return false; - } - return true; - } - - public virtual void Download(string remotePath, string filename) - { - var url = BANNER_URL_PREFIX + remotePath; - - try - { - _httpProvider.DownloadFile(url, filename); - logger.Trace("Successfully download banner from '{0}' to '{1}'", url, filename); - } - catch (Exception ex) - { - var message = String.Format("Failed to download Banner from '{0}' to '{1}'", url, filename); - logger.DebugException(message, ex); - throw; - } - } - } -} diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index 4e6b76f98..aba46e20a 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -117,7 +117,7 @@ namespace NzbDrone.Core.Providers var size = _diskProvider.GetSize(filePath); var runTime = _mediaInfoProvider.GetRunTime(filePath); - if (series.SeriesType == SeriesType.Daily || parseResult.SeasonNumber > 0) + if (series.SeriesTypes == SeriesTypes.Daily || parseResult.SeasonNumber > 0) { if (size < Constants.IgnoreFileSize && runTime < 180) { diff --git a/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs b/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs index f12c8a59a..b2afb9828 100644 --- a/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs +++ b/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs @@ -43,7 +43,7 @@ namespace NzbDrone.Core.Providers.DownloadClients var matchingTitleWithQuality = matchigTitle.Where(q => q.ParseResult.Quality >= newParseResult.Quality); - if (newParseResult.Series.SeriesType == SeriesType.Daily) + if (newParseResult.Series.SeriesTypes == SeriesTypes.Daily) { return matchingTitleWithQuality.Any(q => q.ParseResult.AirDate.Value.Date == newParseResult.AirDate.Value.Date); } diff --git a/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs b/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs index 7a5095331..02c251d97 100644 --- a/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs +++ b/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs @@ -42,7 +42,7 @@ namespace NzbDrone.Core.Providers.DownloadClients var matchingTitleWithQuality = matchigTitle.Where(q => q.ParseResult.Quality >= newParseResult.Quality); - if (newParseResult.Series.SeriesType == SeriesType.Daily) + if (newParseResult.Series.SeriesTypes == SeriesTypes.Daily) { return matchingTitleWithQuality.Any(q => q.ParseResult.AirDate.Value.Date == newParseResult.AirDate.Value.Date); } diff --git a/NzbDrone.Core/Providers/SearchProvider.cs b/NzbDrone.Core/Providers/SearchProvider.cs index 23babebe9..4049923db 100644 --- a/NzbDrone.Core/Providers/SearchProvider.cs +++ b/NzbDrone.Core/Providers/SearchProvider.cs @@ -46,7 +46,7 @@ namespace NzbDrone.Core.Providers return new List(); } - if (series.SeriesType == SeriesType.Daily) + if (series.SeriesTypes == SeriesTypes.Daily) { logger.Trace("Daily series detected, skipping season search: {0}", series.Title); return new List(); @@ -75,7 +75,7 @@ namespace NzbDrone.Core.Providers return new List(); } - if (series.SeriesType == SeriesType.Daily) + if (series.SeriesTypes == SeriesTypes.Daily) { logger.Trace("Daily series detected, skipping season search: {0}", series.Title); return new List(); diff --git a/NzbDrone.Core/ReferenceData/DailySeriesService.cs b/NzbDrone.Core/ReferenceData/DailySeriesService.cs index 3d7ceceea..7fa9c26ad 100644 --- a/NzbDrone.Core/ReferenceData/DailySeriesService.cs +++ b/NzbDrone.Core/ReferenceData/DailySeriesService.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Core.ReferenceData if (series != null) { - _seriesService.SetSeriesType(series.Id, SeriesType.Daily); + _seriesService.SetSeriesType(series.Id, SeriesTypes.Daily); } } } diff --git a/NzbDrone.Core/Tv/Episode.cs b/NzbDrone.Core/Tv/Episode.cs index 13ea5711b..8adffc170 100644 --- a/NzbDrone.Core/Tv/Episode.cs +++ b/NzbDrone.Core/Tv/Episode.cs @@ -86,7 +86,7 @@ namespace NzbDrone.Core.Tv { string seriesTitle = Series == null ? "[NULL]" : Series.Title; - if (Series != null && Series.SeriesType == SeriesType.Daily && AirDate.HasValue) + if (Series != null && Series.SeriesTypes == SeriesTypes.Daily && AirDate.HasValue) return string.Format("{0} - {1:yyyy-MM-dd}", seriesTitle, AirDate.Value); return string.Format("{0} - S{1:00}E{2:00}", seriesTitle, SeasonNumber, EpisodeNumber); diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs index 2b27b835c..afea08d79 100644 --- a/NzbDrone.Core/Tv/EpisodeService.cs +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -5,6 +5,7 @@ using NLog; using NzbDrone.Common.Eventing; using NzbDrone.Core.Datastore; using NzbDrone.Core.Download; +using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Tv.Events; @@ -39,14 +40,14 @@ namespace NzbDrone.Core.Tv private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - private readonly TvDbProvider _tvDbProvider; + private readonly TvDbProxy _tvDbProxy; private readonly ISeasonRepository _seasonRepository; private readonly IEpisodeRepository _episodeRepository; private readonly IEventAggregator _eventAggregator; - public EpisodeService(TvDbProvider tvDbProviderProvider, ISeasonRepository seasonRepository, IEpisodeRepository episodeRepository, IEventAggregator eventAggregator) + public EpisodeService(TvDbProxy tvDbProxyProxy, ISeasonRepository seasonRepository, IEpisodeRepository episodeRepository, IEventAggregator eventAggregator) { - _tvDbProvider = tvDbProviderProvider; + _tvDbProxy = tvDbProxyProxy; _seasonRepository = seasonRepository; _episodeRepository = episodeRepository; _eventAggregator = eventAggregator; @@ -89,7 +90,7 @@ namespace NzbDrone.Core.Tv if (parseResult.AirDate.HasValue) { - if (parseResult.Series.SeriesType == SeriesType.Standard) + if (parseResult.Series.SeriesTypes == SeriesTypes.Standard) { //Todo: Collect this as a Series we want to treat as a daily series, or possible parsing error logger.Warn("Found daily-style episode for non-daily series: {0}. {1}", parseResult.Series.Title, parseResult.OriginalString); @@ -182,7 +183,7 @@ namespace NzbDrone.Core.Tv var successCount = 0; var failCount = 0; - var tvdbEpisodes = _tvDbProvider.GetEpisodes(series.TvDbId); + var tvdbEpisodes = _tvDbProxy.GetEpisodes(series.TvDbId); var seriesEpisodes = GetEpisodeBySeries(series.Id); var updateList = new List(); diff --git a/NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs b/NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs new file mode 100644 index 000000000..bc8118819 --- /dev/null +++ b/NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs @@ -0,0 +1,15 @@ +using System.Linq; +using NzbDrone.Common.Eventing; + +namespace NzbDrone.Core.Tv.Events +{ + public class SeriesUpdatedEvent : IEvent + { + public Series Series { get; private set; } + + public SeriesUpdatedEvent(Series series) + { + Series = series; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Tv/Series.cs b/NzbDrone.Core/Tv/Series.cs index e415bfd19..7a4e6a0bc 100644 --- a/NzbDrone.Core/Tv/Series.cs +++ b/NzbDrone.Core/Tv/Series.cs @@ -9,10 +9,10 @@ using Sqo.Attributes; namespace NzbDrone.Core.Tv { - public enum SeriesType + public enum SeriesTypes { - Standard =0, - Daily =1, + Standard = 0, + Daily = 1, Anime = 2, } @@ -35,8 +35,8 @@ namespace NzbDrone.Core.Tv public DateTime? LastInfoSync { get; set; } public DateTime? LastDiskSync { get; set; } public int Runtime { get; set; } - public string BannerUrl { get; set; } - public SeriesType SeriesType { get; set; } + public List Covers { get; set; } + public SeriesTypes SeriesTypes { get; set; } public BacklogSettingType BacklogSetting { get; set; } public string Network { get; set; } public DateTime? CustomStartDate { get; set; } diff --git a/NzbDrone.Core/Tv/SeriesRepository.cs b/NzbDrone.Core/Tv/SeriesRepository.cs index 57e5a6fc7..75a9547eb 100644 --- a/NzbDrone.Core/Tv/SeriesRepository.cs +++ b/NzbDrone.Core/Tv/SeriesRepository.cs @@ -11,7 +11,7 @@ namespace NzbDrone.Core.Tv List Search(string title); Series GetByTitle(string cleanTitle); Series FindByTvdbId(int tvdbId); - void SetSeriesType(int seriesId, SeriesType seriesType); + void SetSeriesType(int seriesId, SeriesTypes seriesTypes); } @@ -42,9 +42,9 @@ namespace NzbDrone.Core.Tv return Queryable.SingleOrDefault(s => s.TvDbId == tvdbId); } - public void SetSeriesType(int seriesId, SeriesType seriesType) + public void SetSeriesType(int seriesId, SeriesTypes seriesTypes) { - ObjectDatabase.UpdateField(new Series(){Id = seriesId, SeriesType =seriesType }, "SeriesType"); + ObjectDatabase.UpdateField(new Series(){Id = seriesId, SeriesTypes =seriesTypes }, "SeriesType"); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index f8145710d..b7e4c8316 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -6,6 +6,7 @@ using NzbDrone.Common.EnsureThat; using NzbDrone.Common.Eventing; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; +using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Qualities; @@ -22,14 +23,14 @@ namespace NzbDrone.Core.Tv void AddSeries(string title, string path, int tvDbSeriesId, int qualityProfileId, DateTime? airedAfter); void UpdateFromSeriesEditor(IList editedSeries); Series FindByTvdbId(int tvdbId); - void SetSeriesType(int seriesId, SeriesType seriesType); + void SetSeriesType(int seriesId, SeriesTypes seriesTypes); } public class SeriesService : ISeriesService { private readonly ISeriesRepository _seriesRepository; private readonly IConfigService _configService; - private readonly TvDbProvider _tvDbProvider; + private readonly TvDbProxy _tvDbProxy; private readonly TvRageMappingProvider _tvRageMappingProvider; private readonly IEventAggregator _eventAggregator; private readonly IQualityProfileService _qualityProfileService; @@ -39,12 +40,12 @@ namespace NzbDrone.Core.Tv private readonly SceneMappingService _sceneNameMappingService; public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService, - TvDbProvider tvDbProviderProvider, SceneMappingService sceneNameMappingService, + TvDbProxy tvDbProxyProxy, SceneMappingService sceneNameMappingService, TvRageMappingProvider tvRageMappingProvider, IEventAggregator eventAggregator, IQualityProfileService qualityProfileService) { _seriesRepository = seriesRepository; _configService = configServiceService; - _tvDbProvider = tvDbProviderProvider; + _tvDbProxy = tvDbProxyProxy; _sceneNameMappingService = sceneNameMappingService; _tvRageMappingProvider = tvRageMappingProvider; _eventAggregator = eventAggregator; @@ -61,7 +62,7 @@ namespace NzbDrone.Core.Tv public Series UpdateSeriesInfo(int seriesId) { var series = _seriesRepository.Get(seriesId); - var tvDbSeries = _tvDbProvider.GetSeries(series.TvDbId); + var tvDbSeries = _tvDbProxy.GetSeries(series.TvDbId); series.Title = tvDbSeries.Title; series.AirTime = tvDbSeries.AirTime; @@ -71,7 +72,7 @@ namespace NzbDrone.Core.Tv series.CleanTitle = tvDbSeries.CleanTitle; series.LastInfoSync = DateTime.Now; series.Runtime = tvDbSeries.Runtime; - series.BannerUrl = tvDbSeries.BannerUrl; + series.Covers = tvDbSeries.Covers; series.Network = tvDbSeries.Network; series.FirstAired = tvDbSeries.FirstAired; @@ -88,6 +89,8 @@ namespace NzbDrone.Core.Tv _seriesRepository.Update(series); + _eventAggregator.Publish(new SeriesUpdatedEvent(series)); + return series; } @@ -159,9 +162,9 @@ namespace NzbDrone.Core.Tv return _seriesRepository.FindByTvdbId(tvdbId); } - public void SetSeriesType(int seriesId, SeriesType seriesType) + public void SetSeriesType(int seriesId, SeriesTypes seriesTypes) { - _seriesRepository.SetSeriesType(seriesId, seriesType); + _seriesRepository.SetSeriesType(seriesId, seriesTypes); } diff --git a/NzbDrone.Test.Common/LoggingTest.cs b/NzbDrone.Test.Common/LoggingTest.cs index f510ac796..6d6938470 100644 --- a/NzbDrone.Test.Common/LoggingTest.cs +++ b/NzbDrone.Test.Common/LoggingTest.cs @@ -16,10 +16,9 @@ namespace NzbDrone.Test.Common if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration) { LogManager.Configuration = new LoggingConfiguration(); - var consoleTarget = new ConsoleTarget(); - consoleTarget.Layout = "${message} ${exception}"; + var consoleTarget = new ConsoleTarget { Layout = "${message} ${exception}" }; LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget); - LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", consoleTarget)); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget)); RegisterExceptionVerification(); } @@ -29,7 +28,7 @@ namespace NzbDrone.Test.Common { var exceptionVerification = new ExceptionVerification(); LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification); - LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, exceptionVerification)); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Warn, exceptionVerification)); } [SetUp] diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index 7844e818c..2c0055a66 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -49,6 +49,8 @@ namespace NzbDrone.Test.Common Mocker.SetConstant(LogManager.GetLogger("TestLogger")); + LogManager.ReconfigExistingLoggers(); + TempFolder = Path.Combine(Directory.GetCurrentDirectory(), "_temp_" + DateTime.Now.Ticks); MockedRestProvider = new Mock(); diff --git a/NzbDrone.ncrunchsolution b/NzbDrone.ncrunchsolution index 6cb47a29a..444b34b1d 100644 --- a/NzbDrone.ncrunchsolution +++ b/NzbDrone.ncrunchsolution @@ -2,6 +2,7 @@ 1 False true + true UseDynamicAnalysis Disabled Disabled