From 7d0d5ab9435f6b11039c8519770947ba2055887c Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 23 Feb 2013 15:08:22 -0800 Subject: [PATCH] Use Series.OID (Tests still need to be updated) CalendarModule working --- NzbDrone.Api/AutomapperBootstraper.cs | 2 +- NzbDrone.Api/Calendar/CalendarModule.cs | 23 +- NzbDrone.Api/Series/SeriesModule.cs | 4 +- .../Calendar/CalendarItemTemplate.html | 5 + .../Calendar/CalendarItemView.js | 16 + NzbDrone.Backbone/NzbDrone.Backbone.csproj | 2 + .../CleanUpDatabaseFixture.cs | 139 --- .../GetNewFilenameFixture.cs | 842 ------------------ .../AcceptableSizeSpecification.cs | 2 +- NzbDrone.Core/Jobs/ImportNewSeriesJob.cs | 14 +- NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs | 6 +- NzbDrone.Core/Jobs/RenameSeriesJob.cs | 6 +- NzbDrone.Core/Jobs/UpdateInfoJob.cs | 2 +- NzbDrone.Core/Providers/BannerProvider.cs | 2 +- NzbDrone.Core/Providers/DiskScanProvider.cs | 6 +- NzbDrone.Core/Providers/Metadata/Xbmc.cs | 2 +- NzbDrone.Core/Providers/MetadataProvider.cs | 2 +- NzbDrone.Core/Providers/Search/SearchBase.cs | 8 +- .../Providers/TvRageMappingProvider.cs | 2 +- NzbDrone.Core/Providers/XemProvider.cs | 2 +- NzbDrone.Core/Tv/EpisodeRepository.cs | Bin 6489 -> 6784 bytes NzbDrone.Core/Tv/EpisodeService.cs | 32 +- NzbDrone.Core/Tv/SeriesService.cs | 10 +- SqlCe/NzbDrone.SqlCe.dll | Bin 4096 -> 4096 bytes 24 files changed, 94 insertions(+), 1035 deletions(-) create mode 100644 NzbDrone.Backbone/Calendar/CalendarItemTemplate.html create mode 100644 NzbDrone.Backbone/Calendar/CalendarItemView.js delete mode 100644 NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs delete mode 100644 NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs diff --git a/NzbDrone.Api/AutomapperBootstraper.cs b/NzbDrone.Api/AutomapperBootstraper.cs index a0a650f21..dcb0a246d 100644 --- a/NzbDrone.Api/AutomapperBootstraper.cs +++ b/NzbDrone.Api/AutomapperBootstraper.cs @@ -39,7 +39,7 @@ public static void InitializeAutomapper() //Series Mapper.CreateMap() - .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.SeriesId)) + .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.OID)) .ForMember(dest => dest.CustomStartDate, opt => opt.ResolveUsing().FromMember(src => src.CustomStartDate)) .ForMember(dest => dest.BacklogSetting, opt => opt.MapFrom(src => (Int32)src.BacklogSetting)) .ForMember(dest => dest.NextAiring, opt => opt.ResolveUsing()); diff --git a/NzbDrone.Api/Calendar/CalendarModule.cs b/NzbDrone.Api/Calendar/CalendarModule.cs index dc694c1a2..3dd61fa95 100644 --- a/NzbDrone.Api/Calendar/CalendarModule.cs +++ b/NzbDrone.Api/Calendar/CalendarModule.cs @@ -5,26 +5,35 @@ using AutoMapper; using Nancy; using NzbDrone.Api.Extentions; -using NzbDrone.Core.Providers; using NzbDrone.Core.Tv; namespace NzbDrone.Api.Calendar { public class CalendarModule : NzbDroneApiModule { - private readonly UpcomingEpisodesProvider _upcomingEpisodesProvider; + private readonly EpisodeService _episodeService; - public CalendarModule(UpcomingEpisodesProvider upcomingEpisodesProvider) - : base("/Calendar") + public CalendarModule(EpisodeService episodeService) + : base("/calendar") { - _upcomingEpisodesProvider = upcomingEpisodesProvider; + _episodeService = episodeService; Get["/"] = x => Calendar(); } private Response Calendar() { - var upcoming = _upcomingEpisodesProvider.UpcomingEpisodes(); - return Mapper.Map, List>(upcoming).AsResponse(); + var year = DateTime.Now.Year; + var month = DateTime.Now.Month; + + var yearQuery = Request.Query.Year; + var monthQuery = Request.Query.Month; + + if (yearQuery.HasValue) year = Convert.ToInt32(yearQuery.Value); + + if(monthQuery.HasValue) month = Convert.ToInt32(monthQuery.Value); + + var episodes = _episodeService.GetEpisodesAiredInMonth(year, month); + return Mapper.Map, List>(episodes).AsResponse(); } } } \ No newline at end of file diff --git a/NzbDrone.Api/Series/SeriesModule.cs b/NzbDrone.Api/Series/SeriesModule.cs index 84972871f..ae7b9a6f5 100644 --- a/NzbDrone.Api/Series/SeriesModule.cs +++ b/NzbDrone.Api/Series/SeriesModule.cs @@ -88,7 +88,7 @@ private Response UpdateSeries() _seriesRepository.Update(series); if (oldPath != series.Path) - _jobProvider.QueueJob(typeof(DiskScanJob), new { SeriesId = series.SeriesId }); + _jobProvider.QueueJob(typeof(DiskScanJob), new { SeriesId = series.OID }); _seriesRepository.Update(series); @@ -116,7 +116,7 @@ public SeriesValidator() { RuleSet("POST", () => { - RuleFor(s => s.SeriesId).GreaterThan(0); + RuleFor(s => s.OID).GreaterThan(0); RuleFor(s => s.Path).NotEmpty().Must(_diskProvider.FolderExists); RuleFor(s => s.QualityProfileId).GreaterThan(0); }); diff --git a/NzbDrone.Backbone/Calendar/CalendarItemTemplate.html b/NzbDrone.Backbone/Calendar/CalendarItemTemplate.html new file mode 100644 index 000000000..b53ef04e9 --- /dev/null +++ b/NzbDrone.Backbone/Calendar/CalendarItemTemplate.html @@ -0,0 +1,5 @@ +{{seriesTitle}} +{{seasonNumber}}x{{episodeNumber}} +{{episodeTitle}} +{{airTime}} +{{status}} \ No newline at end of file diff --git a/NzbDrone.Backbone/Calendar/CalendarItemView.js b/NzbDrone.Backbone/Calendar/CalendarItemView.js new file mode 100644 index 000000000..e7c2a8cf8 --- /dev/null +++ b/NzbDrone.Backbone/Calendar/CalendarItemView.js @@ -0,0 +1,16 @@ +'use strict'; + +define([ + 'app', + 'Calendar/CalendarCollection' + +], function () { + NzbDrone.Calendar.CalendarItemView = Backbone.Marionette.ItemView.extend({ + template: 'Calendar/CalendarItemTemplate', + tagName: 'tr', + + onRender: function () { + NzbDrone.ModelBinder.bind(this.model, this.el); + } + }) +}) \ No newline at end of file diff --git a/NzbDrone.Backbone/NzbDrone.Backbone.csproj b/NzbDrone.Backbone/NzbDrone.Backbone.csproj index 275139c3d..7393a357c 100644 --- a/NzbDrone.Backbone/NzbDrone.Backbone.csproj +++ b/NzbDrone.Backbone/NzbDrone.Backbone.csproj @@ -52,7 +52,9 @@ + + diff --git a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs deleted file mode 100644 index 9e54e4865..000000000 --- a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FizzWare.NBuilder; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Model; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; -using NzbDrone.Core.Test.Framework; - -namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests -{ - [TestFixture] - public class CleanUpDatabaseFixture : SqlCeTest - { - - [SetUp] - public void Setup() - { - WithRealDb(); - } - - private void WithAutoIgnore(bool autoIgnore) - { - - Mocker.GetMock() - .SetupGet(c => c.AutoIgnorePreviouslyDownloadedEpisodes).Returns(autoIgnore); - } - - - - [Test] - public void CleanUpDatabse_should_detach_none_existing_file_from_episodes_with_auto_ignore() - { - WithAutoIgnore(true); - - var episodes = Builder.CreateListOfSize(3) - .All().With(c => c.GrabDate = DateTime.Now) - .And(c => c.Ignored = false) - .And(c => c.PostDownloadStatus = PostDownloadStatusType.NoError) - .Build(); - - - Db.InsertMany(episodes); - - //Act - Mocker.Resolve().CleanUpDatabase(); - var result = Db.Fetch(); - - //Assert - result.Should().HaveSameCount(episodes); - result.Should().OnlyContain(e => e.EpisodeFileId == 0); - result.Should().OnlyContain(e => e.PostDownloadStatus == PostDownloadStatusType.Unknown); - result.Should().OnlyContain(e => e.Ignored); - result.Should().OnlyContain(e => e.GrabDate == null); - } - - [Test] - public void CleanUpDatabse_should_detach_none_existing_file_from_episodes_with_no_auto_ignore() - { - WithAutoIgnore(false); - - var episodes = Builder.CreateListOfSize(3) - .All().With(c => c.GrabDate = DateTime.Now) - .And(c => c.PostDownloadStatus = PostDownloadStatusType.NoError) - .TheFirst(2).With(c => c.Ignored = true) - .TheLast(1).With(c => c.Ignored = false) - .Build(); - - - Db.InsertMany(episodes); - - //Act - Mocker.Resolve().CleanUpDatabase(); - var result = Db.Fetch(); - - //Assert - result.Should().HaveSameCount(episodes); - result.Should().OnlyContain(e => e.EpisodeFileId == 0); - result.Should().OnlyContain(e => e.PostDownloadStatus == PostDownloadStatusType.Unknown); - result.Should().OnlyContain(e => e.GrabDate == null); - result.Should().Contain(c => c.Ignored == true); - result.Should().Contain(c => c.Ignored == false); - } - - [Test] - public void CleanUpDatabse_should_not_change_episodes_with_no_file_id() - { - //Setup - var episodes = Builder.CreateListOfSize(3) - .All().With(c => c.GrabDate = DateTime.Now) - .And(c => c.Ignored = false) - .And(c => c.PostDownloadStatus = PostDownloadStatusType.NoError) - .Build(); - - Db.InsertMany(episodes); - - //Act - Mocker.Resolve().CleanUpDatabase(); - var result = Db.Fetch(); - - //Assert - result.Should().HaveSameCount(episodes); - result.Should().OnlyContain(e => e.EpisodeFileId == 0); - result.Should().NotContain(e => e.PostDownloadStatus == PostDownloadStatusType.Unknown); - result.Should().NotContain(e => e.Ignored); - result.Should().NotContain(e => e.GrabDate == null); - } - - - [Test] - public void DeleteOrphanedEpisodeFiles() - { - //Setup - var episodeFiles = Builder - .CreateListOfSize(10) - .All() - .With(e => e.Quality = QualityTypes.DVD) - .Build(); - var episodes = Builder.CreateListOfSize(5).Build(); - - Db.InsertMany(episodes); - Db.InsertMany(episodeFiles); - - //Act - Mocker.Resolve().CleanUpDatabase(); - var result = Db.Fetch(); - - //Assert - result.Should().HaveCount(5); - result.Should().OnlyContain(e => e.EpisodeFileId > 0); - } - } -} diff --git a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs deleted file mode 100644 index 3a2ca17c1..000000000 --- a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs +++ /dev/null @@ -1,842 +0,0 @@ -// ReSharper disable RedundantUsingDirective - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using FizzWare.NBuilder; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common.AutoMoq; - -namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests -{ - [TestFixture] - // ReSharper disable InconsistentNaming - public class MediaFileProvider_GetNewFilenameTest : CoreTest - { - private Series _series; - - [SetUp] - public void Setup() - { - _series = Builder - .CreateNew() - .With(s => s.Title = "South Park") - .Build(); - } - - [Test] - public void GetNewFilename_Series_Episode_Quality_S01E05_Dash() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV-720p]", result); - } - - [Test] - public void GetNewFilename_Episode_Quality_1x05_Dash() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("15x06 - City Sushi [HDTV-720p]", result); - } - - [Test] - public void GetNewFilename_Series_Quality_01x05_Space() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 5) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("South Park 05x06 [HDTV-720p]", result); - } - - [Test] - public void GetNewFilename_Series_s01e05_Space() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 5) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("South Park s05e06", result); - } - - [Test] - public void GetNewFilename_Series_Episode_s01e05_Periods() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 5) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("South.Park.s05e06.City.Sushi", result); - } - - [Test] - public void GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 5) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV-720p]", result); - } - - [Test] - public void GetNewFilename_S01E05_Dash() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("S15E06", result); - } - - [Test] - public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); - - var episodeOne = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (1)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 23) - .Build(); - - var episodeTwo = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (2)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 24) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream [HDTV-720p]", result); - } - - [Test] - public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(2); - - var episodeOne = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (1)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 23) - .Build(); - - var episodeTwo = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (2)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 24) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("3x23x24 - Strawberries and Cream [HDTV-720p]", result); - } - - [Test] - public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(2); - - var episodeOne = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (1)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 23) - .Build(); - - var episodeTwo = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (2)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 24) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("3x23x24 Strawberries and Cream [HDTV-720p]", result); - } - - [Test] - public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(1); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(3); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(1); - - var episodeOne = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (1)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 23) - .Build(); - - var episodeTwo = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (2)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 24) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream", result); - } - - [Test] - public void GetNewFilename_multi_Series_S01E05_Extend_Dash_Period() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(0); - - var episodeOne = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (1)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 23) - .Build(); - - var episodeTwo = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (2)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 24) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("The.Mentalist.-.S03E23-24", result); - } - - [Test] - public void GetNewFilename_multi_1x05_Repeat_Dash_Period() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(true); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(2); - - var episodeOne = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (1)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 23) - .Build(); - - var episodeTwo = Builder.CreateNew() - .With(e => e.Title = "Strawberries and Cream (2)") - .With(e => e.SeasonNumber = 3) - .With(e => e.EpisodeNumber = 24) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("3x23x24", result); - } - - [Test] - public void GetNewFilename_should_append_proper_when_proper_and_append_quality_is_true() - { - //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, true, new EpisodeFile()); - - //Assert - result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p] [Proper]"); - } - - [Test] - public void GetNewFilename_should_not_append_proper_when_not_proper_and_append_quality_is_true() - { - //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p]"); - } - - [Test] - public void GetNewFilename_should_not_append_proper_when_proper_and_append_quality_is_false() - { - //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, true, new EpisodeFile()); - - //Assert - result.Should().Be("South Park - S15E06 - City Sushi"); - } - - [Test] - public void GetNewFilename_should_order_multiple_episode_files_in_numerical_order() - { - //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); - - var episode = Builder.CreateNew() - .With(e => e.Title = "Hey, Baby, What's Wrong? (1)") - .With(e => e.SeasonNumber = 6) - .With(e => e.EpisodeNumber = 6) - .Build(); - - var episode2 = Builder.CreateNew() - .With(e => e.Title = "Hey, Baby, What's Wrong? (2)") - .With(e => e.SeasonNumber = 6) - .With(e => e.EpisodeNumber = 7) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!"); - } - - [Test] - public void GetNewFilename_Series_Episode_Quality_S01E05_Period() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("South Park.S15E06.City Sushi [HDTV-720p]", result); - } - - [Test] - public void GetNewFilename_Episode_Quality_1x05_Period() - { - //Setup - - - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - Assert.AreEqual("15x06.City Sushi [HDTV-720p]", result); - } - - [Test] - public void GetNewFilename_UseSceneName_when_sceneName_isNull() - { - //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingUseSceneName).Returns(true); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - var episodeFile = Builder.CreateNew() - .With(e => e.SceneName = null) - .With(e => e.Path = @"C:\Test\TV\30 Rock - S01E01 - Test") - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, episodeFile); - - //Assert - result.Should().Be(Path.GetFileNameWithoutExtension(episodeFile.Path)); - } - - [Test] - public void GetNewFilename_UseSceneName_when_sceneName_isNotNull() - { - //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(false); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingUseSceneName).Returns(true); - - var episode = Builder.CreateNew() - .With(e => e.Title = "City Sushi") - .With(e => e.SeasonNumber = 15) - .With(e => e.EpisodeNumber = 6) - .Build(); - - var episodeFile = Builder.CreateNew() - .With(e => e.SceneName = "30.Rock.S01E01.xvid-LOL") - .With(e => e.Path = @"C:\Test\TV\30 Rock - S01E01 - Test") - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode }, _series, QualityTypes.HDTV720p, false, episodeFile); - - //Assert - result.Should().Be(episodeFile.SceneName); - } - - [Test] - public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same() - { - //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); - - var episode = Builder.CreateNew() - .With(e => e.Title = "Hey, Baby, What's Wrong? (1)") - .With(e => e.SeasonNumber = 6) - .With(e => e.EpisodeNumber = 6) - .Build(); - - var episode2 = Builder.CreateNew() - .With(e => e.Title = "Hey, Baby, What's Wrong? (2)") - .With(e => e.SeasonNumber = 6) - .With(e => e.EpisodeNumber = 7) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!"); - } - - [Test] - public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same() - { - //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); - - var episode = Builder.CreateNew() - .With(e => e.Title = "Hello") - .With(e => e.SeasonNumber = 6) - .With(e => e.EpisodeNumber = 6) - .Build(); - - var episode2 = Builder.CreateNew() - .With(e => e.Title = "World") - .With(e => e.SeasonNumber = 6) - .With(e => e.EpisodeNumber = 7) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode2, episode }, new Series { Title = "30 Rock" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - result.Should().Be("30 Rock - S06E06-E07 - Hello + World"); - } - - [Test] - public void should_have_two_episodeTitles_when_distinct_count_is_two() - { - //Setup - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3); - - var episode = Builder.CreateNew() - .With(e => e.Title = "Hello (3)") - .With(e => e.SeasonNumber = 6) - .With(e => e.EpisodeNumber = 6) - .Build(); - - var episode2 = Builder.CreateNew() - .With(e => e.Title = "Hello (2)") - .With(e => e.SeasonNumber = 6) - .With(e => e.EpisodeNumber = 7) - .Build(); - - var episode3 = Builder.CreateNew() - .With(e => e.Title = "World") - .With(e => e.SeasonNumber = 6) - .With(e => e.EpisodeNumber = 8) - .Build(); - - //Act - string result = Mocker.Resolve().GetNewFilename(new List { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, QualityTypes.HDTV720p, false, new EpisodeFile()); - - //Assert - result.Should().Be("30 Rock - S06E06-E07-E08 - Hello + World"); - } - - [Test] - public void should_use_airDate_if_series_isDaily() - { - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(true); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var series = Builder - .CreateNew() - .With(s => s.SeriesType = SeriesType.Daily) - .With(s => s.Title = "The Daily Show with Jon Stewart") - .Build(); - - var episodes = Builder - .CreateListOfSize(1) - .All() - .With(e => e.AirDate = new DateTime(2012, 12, 13)) - .With(e => e.Title = "Kristen Stewart") - .Build(); - - var result = Mocker.Resolve() - .GetNewFilename(episodes, series, QualityTypes.HDTV720p, false, new EpisodeFile()); - result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13 - Kristen Stewart [HDTV-720p]"); - } - - [Test] - public void should_use_airDate_if_series_isDaily_no_episode_title() - { - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(false); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var series = Builder - .CreateNew() - .With(s => s.SeriesType = SeriesType.Daily) - .With(s => s.Title = "The Daily Show with Jon Stewart") - .Build(); - - var episodes = Builder - .CreateListOfSize(1) - .All() - .With(e => e.AirDate = new DateTime(2012, 12, 13)) - .With(e => e.Title = "Kristen Stewart") - .Build(); - - var result = Mocker.Resolve() - .GetNewFilename(episodes, series, QualityTypes.HDTV720p, false, new EpisodeFile()); - result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13"); - } - - [Test] - public void should_set_airdate_to_unknown_if_not_available() - { - var fakeConfig = Mocker.GetMock(); - fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true); - fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true); - fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false); - fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0); - fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2); - fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false); - - var series = Builder - .CreateNew() - .With(s => s.SeriesType = SeriesType.Daily) - .With(s => s.Title = "The Daily Show with Jon Stewart") - .Build(); - - var episodes = Builder - .CreateListOfSize(1) - .All() - .With(e => e.AirDate = null) - .With(e => e.Title = "Kristen Stewart") - .Build(); - - var result = Mocker.Resolve() - .GetNewFilename(episodes, series, QualityTypes.HDTV720p, false, new EpisodeFile()); - result.Should().Be("The Daily Show with Jon Stewart - Unknown - Kristen Stewart"); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/DecisionEngine/AcceptableSizeSpecification.cs b/NzbDrone.Core/DecisionEngine/AcceptableSizeSpecification.cs index 8947f86d2..ac6ccca2b 100644 --- a/NzbDrone.Core/DecisionEngine/AcceptableSizeSpecification.cs +++ b/NzbDrone.Core/DecisionEngine/AcceptableSizeSpecification.cs @@ -56,7 +56,7 @@ public virtual bool IsSatisfiedBy(EpisodeParseResult subject) //Check if there was only one episode parsed //and it is the first or last episode of the season if (subject.EpisodeNumbers != null && subject.EpisodeNumbers.Count == 1 && - _episodeService.IsFirstOrLastEpisodeOfSeason(series.SeriesId, + _episodeService.IsFirstOrLastEpisodeOfSeason(series.OID, subject.SeasonNumber, subject.EpisodeNumbers[0])) { maxSize = maxSize * 2; diff --git a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs index 2eaf12cfa..03ba79db7 100644 --- a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs +++ b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs @@ -75,20 +75,20 @@ private void ScanSeries(ProgressNotification notification) { try { - _attemptedSeries.Add(currentSeries.SeriesId); + _attemptedSeries.Add(currentSeries.OID); notification.CurrentMessage = String.Format("Searching for '{0}'", new DirectoryInfo(currentSeries.Path).Name); - _updateInfoJob.Start(notification, new { SeriesId = currentSeries.SeriesId }); - _diskScanJob.Start(notification, new { SeriesId = currentSeries.SeriesId }); + _updateInfoJob.Start(notification, new { SeriesId = currentSeries.OID }); + _diskScanJob.Start(notification, new { SeriesId = currentSeries.OID }); - var updatedSeries = _seriesRepository.Get(currentSeries.SeriesId); - AutoIgnoreSeasons(updatedSeries.SeriesId); + var updatedSeries = _seriesRepository.Get(currentSeries.OID); + AutoIgnoreSeasons(updatedSeries.OID); //Download the banner for the new series - _bannerDownloadJob.Start(notification, new { SeriesId = updatedSeries.SeriesId }); + _bannerDownloadJob.Start(notification, new { SeriesId = updatedSeries.OID }); //Get Scene Numbering if applicable - _xemUpdateJob.Start(notification, new { SeriesId = updatedSeries.SeriesId }); + _xemUpdateJob.Start(notification, new { SeriesId = updatedSeries.OID }); notification.CurrentMessage = String.Format("{0} was successfully imported", updatedSeries.Title); } diff --git a/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs b/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs index f297ab7f9..4b7c4d348 100644 --- a/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs +++ b/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs @@ -57,12 +57,12 @@ private void RefreshMetadata(ProgressNotification notification, Series series) { notification.CurrentMessage = String.Format("Refreshing episode metadata for '{0}'", series.Title); - Logger.Debug("Getting episodes from database for series: {0}", series.SeriesId); - var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.SeriesId); + Logger.Debug("Getting episodes from database for series: {0}", series.OID); + var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.OID); if (episodeFiles == null || episodeFiles.Count == 0) { - Logger.Warn("No episodes in database found for series: {0}", series.SeriesId); + Logger.Warn("No episodes in database found for series: {0}", series.OID); return; } diff --git a/NzbDrone.Core/Jobs/RenameSeriesJob.cs b/NzbDrone.Core/Jobs/RenameSeriesJob.cs index 2b8d17ba8..6d976f830 100644 --- a/NzbDrone.Core/Jobs/RenameSeriesJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeriesJob.cs @@ -60,12 +60,12 @@ public void Start(ProgressNotification notification, dynamic options) { notification.CurrentMessage = String.Format("Renaming episodes for '{0}'", series.Title); - Logger.Debug("Getting episodes from database for series: {0}", series.SeriesId); - var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.SeriesId); + Logger.Debug("Getting episodes from database for series: {0}", series.OID); + var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.OID); if (episodeFiles == null || episodeFiles.Count == 0) { - Logger.Warn("No episodes in database found for series: {0}", series.SeriesId); + Logger.Warn("No episodes in database found for series: {0}", series.OID); return; } diff --git a/NzbDrone.Core/Jobs/UpdateInfoJob.cs b/NzbDrone.Core/Jobs/UpdateInfoJob.cs index 4cb5d1d43..3332c141d 100644 --- a/NzbDrone.Core/Jobs/UpdateInfoJob.cs +++ b/NzbDrone.Core/Jobs/UpdateInfoJob.cs @@ -72,7 +72,7 @@ public virtual void Start(ProgressNotification notification, dynamic options) try { notification.CurrentMessage = "Updating " + series.Title; - _seriesService.UpdateSeriesInfo(series.SeriesId); + _seriesService.UpdateSeriesInfo(series.OID); _episodeService.RefreshEpisodeInfo(series); notification.CurrentMessage = "Update completed for " + series.Title; } diff --git a/NzbDrone.Core/Providers/BannerProvider.cs b/NzbDrone.Core/Providers/BannerProvider.cs index f97119001..6b055f96b 100644 --- a/NzbDrone.Core/Providers/BannerProvider.cs +++ b/NzbDrone.Core/Providers/BannerProvider.cs @@ -40,7 +40,7 @@ public virtual bool Download(Series series) logger.Trace("Ensuring Banner Folder exists: ", bannerPath); _diskProvider.CreateDirectory(bannerPath); - var bannerFilename = Path.Combine(bannerPath, series.SeriesId.ToString()) + ".jpg"; + var bannerFilename = Path.Combine(bannerPath, series.OID.ToString()) + ".jpg"; logger.Trace("Downloading banner for '{0}'", series.Title); diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index 58f07d4c6..261f9964e 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -74,13 +74,13 @@ public virtual List Scan(Series series, string path) return new List(); } - if (_episodeService.GetEpisodeBySeries(series.SeriesId).Count == 0) + if (_episodeService.GetEpisodeBySeries(series.OID).Count == 0) { Logger.Debug("Series {0} has no episodes. skipping", series.Title); return new List(); } - var seriesFile = _mediaFileProvider.GetSeriesFiles(series.SeriesId); + var seriesFile = _mediaFileProvider.GetSeriesFiles(series.OID); CleanUp(seriesFile); var mediaFileList = GetVideoFiles(path); @@ -162,7 +162,7 @@ public virtual EpisodeFile ImportFile(Series series, string filePath) var episodeFile = new EpisodeFile(); episodeFile.DateAdded = DateTime.Now; - episodeFile.SeriesId = series.SeriesId; + episodeFile.SeriesId = series.OID; episodeFile.Path = filePath.NormalizePath(); episodeFile.Size = size; episodeFile.Quality = parseResult.Quality.Quality; diff --git a/NzbDrone.Core/Providers/Metadata/Xbmc.cs b/NzbDrone.Core/Providers/Metadata/Xbmc.cs index acf4c39af..48efbc15a 100644 --- a/NzbDrone.Core/Providers/Metadata/Xbmc.cs +++ b/NzbDrone.Core/Providers/Metadata/Xbmc.cs @@ -30,7 +30,7 @@ public override string Name public override void CreateForSeries(Series series, TvdbSeries tvDbSeries) { //Create tvshow.nfo, fanart.jpg, folder.jpg and season##.tbn - var episodeGuideUrl = GetEpisodeGuideUrl(series.SeriesId); + var episodeGuideUrl = GetEpisodeGuideUrl(series.OID); _logger.Debug("Generating tvshow.nfo for: {0}", series.Title); var sb = new StringBuilder(); diff --git a/NzbDrone.Core/Providers/MetadataProvider.cs b/NzbDrone.Core/Providers/MetadataProvider.cs index 5fc83d022..3a4e094f0 100644 --- a/NzbDrone.Core/Providers/MetadataProvider.cs +++ b/NzbDrone.Core/Providers/MetadataProvider.cs @@ -93,7 +93,7 @@ private void Initialize(IList metabaseProviders) public virtual void CreateForSeries(Series series) { - var tvDbSeries = _tvDbProvider.GetSeries(series.SeriesId, false, true); + var tvDbSeries = _tvDbProvider.GetSeries(series.OID, false, true); CreateForSeries(series, tvDbSeries); } diff --git a/NzbDrone.Core/Providers/Search/SearchBase.cs b/NzbDrone.Core/Providers/Search/SearchBase.cs index 748e5ae19..4dc32738e 100644 --- a/NzbDrone.Core/Providers/Search/SearchBase.cs +++ b/NzbDrone.Core/Providers/Search/SearchBase.cs @@ -58,7 +58,7 @@ public virtual List Search(Series series, dynamic options, ProgressNotifi var searchResult = new SearchHistory { SearchTime = DateTime.Now, - SeriesId = series.SeriesId, + SeriesId = series.OID, EpisodeId = options.GetType().GetProperty("Episode") != null ? options.Episode.EpisodeId : null, SeasonNumber = options.GetType().GetProperty("SeasonNumber") != null ? options.SeasonNumber : null }; @@ -108,7 +108,7 @@ public virtual SearchHistory ProcessReports(Series series, dynamic options, List logger.Trace("Analysing report " + episodeParseResult); episodeParseResult.Series = _seriesRepository.GetByTitle(episodeParseResult.CleanTitle); - if(episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId) + if(episodeParseResult.Series == null || episodeParseResult.Series.OID != series.OID) { item.SearchError = ReportRejectionType.WrongSeries; continue; @@ -170,12 +170,12 @@ public virtual Boolean DownloadReport(ProgressNotification notification, Episode public virtual string GetSearchTitle(Series series, int seasonNumber = -1) { - var seasonTitle = _sceneMappingProvider.GetSceneName(series.SeriesId, seasonNumber); + var seasonTitle = _sceneMappingProvider.GetSceneName(series.OID, seasonNumber); if(!String.IsNullOrWhiteSpace(seasonTitle)) return seasonTitle; - var title = _sceneMappingProvider.GetSceneName(series.SeriesId); + var title = _sceneMappingProvider.GetSceneName(series.OID); if (String.IsNullOrWhiteSpace(title)) { diff --git a/NzbDrone.Core/Providers/TvRageMappingProvider.cs b/NzbDrone.Core/Providers/TvRageMappingProvider.cs index 3d26773f7..1c3ca397f 100644 --- a/NzbDrone.Core/Providers/TvRageMappingProvider.cs +++ b/NzbDrone.Core/Providers/TvRageMappingProvider.cs @@ -31,7 +31,7 @@ public TvRageMappingProvider() public Series FindMatchingTvRageSeries(Series series) { - var firstEpisode = _episodeService.GetEpisode(series.SeriesId, 1, 1); + var firstEpisode = _episodeService.GetEpisode(series.OID, 1, 1); var cleanName = _sceneMappingProvider.GetCleanName(series.SeriesId); var results = _tvRageProvider.SearchSeries(series.Title); diff --git a/NzbDrone.Core/Providers/XemProvider.cs b/NzbDrone.Core/Providers/XemProvider.cs index 32159d831..5b421aaad 100644 --- a/NzbDrone.Core/Providers/XemProvider.cs +++ b/NzbDrone.Core/Providers/XemProvider.cs @@ -89,7 +89,7 @@ public virtual void PerformUpdate(Series series) return; } - var episodes = _episodeService.GetEpisodeBySeries(series.SeriesId); + var episodes = _episodeService.GetEpisodeBySeries(series.OID); foreach (var mapping in mappings) { diff --git a/NzbDrone.Core/Tv/EpisodeRepository.cs b/NzbDrone.Core/Tv/EpisodeRepository.cs index 2d7ecf95ad5ee5c710b821ff556a3564ed4339da..530f48128f0dcdbed974efb6a385accdc7da0d1f 100644 GIT binary patch delta 226 zcmca<)L^>d9Fw;K5cp&km)N)#WESVAq}nM!8O2ViCFQB9c`k`1sl^%~G9)uMRiU^f zv8V*Z(@}tnrRJr8*qe_r9c7=~%OdDbB?BjaWY(T+z|O1Vm{|m}K*7!yVZVZ!nnJN2 VOvc7m0qTm$4_GBOcXOTN0{~(SP`Cg9 delta 17 ZcmZoLy=k=J9Mfh+=DqBjH*ufi0{}y)2Pgml diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs index a402948e4..380726c63 100644 --- a/NzbDrone.Core/Tv/EpisodeService.cs +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -30,6 +30,7 @@ public interface IEpisodeService void SetPostDownloadStatus(List episodeIds, PostDownloadStatusType postDownloadStatus); void UpdateEpisodes(List episodes); Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber); + List GetEpisodesAiredInMonth(int year, int month); } public class EpisodeService : IEpisodeService @@ -100,7 +101,7 @@ public virtual IList GetEpisodesByParseResult(EpisodeParseResult parseR return new List(); } - var episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value); + var episodeInfo = GetEpisode(parseResult.Series.OID, parseResult.AirDate.Value); if (episodeInfo != null) { @@ -122,14 +123,14 @@ public virtual IList GetEpisodesByParseResult(EpisodeParseResult parseR Episode episodeInfo = null; if (parseResult.SceneSource && parseResult.Series.UseSceneNumbering) - episodeInfo = GetEpisodeBySceneNumbering(parseResult.Series.SeriesId, parseResult.SeasonNumber, episodeNumber); + episodeInfo = GetEpisodeBySceneNumbering(parseResult.Series.OID, parseResult.SeasonNumber, episodeNumber); if (episodeInfo == null) { - episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.SeasonNumber, episodeNumber); + episodeInfo = GetEpisode(parseResult.Series.OID, parseResult.SeasonNumber, episodeNumber); if (episodeInfo == null && parseResult.AirDate != null) { - episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value); + episodeInfo = GetEpisode(parseResult.Series.OID, parseResult.AirDate.Value); } } @@ -182,7 +183,7 @@ public virtual IList EpisodesWithFiles() public virtual void RefreshEpisodeInfo(Series series) { - logger.Trace("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); + logger.Trace("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.OID)); var successCount = 0; var failCount = 0; @@ -192,7 +193,7 @@ public virtual void RefreshEpisodeInfo(Series series) (episode.FirstAired < DateTime.Now.AddDays(2) && episode.FirstAired.Year > 1900)) .ToList(); - var seriesEpisodes = GetEpisodeBySeries(series.SeriesId); + var seriesEpisodes = GetEpisodeBySeries(series.OID); var updateList = new List(); var newList = new List(); @@ -223,7 +224,7 @@ public virtual void RefreshEpisodeInfo(Series series) } else { - episodeToUpdate.Ignored = _seasonRepository.IsIgnored(series.SeriesId, episode.SeasonNumber); + episodeToUpdate.Ignored = _seasonRepository.IsIgnored(series.OID, episode.SeasonNumber); } } else @@ -239,7 +240,7 @@ public virtual void RefreshEpisodeInfo(Series series) episodeToUpdate.EpisodeFile = null; } - episodeToUpdate.SeriesId = series.SeriesId; + episodeToUpdate.SeriesId = series.OID; episodeToUpdate.TvDbEpisodeId = episode.Id; episodeToUpdate.EpisodeNumber = episode.EpisodeNumber; episodeToUpdate.SeasonNumber = episode.SeasonNumber; @@ -283,7 +284,6 @@ public virtual void UpdateEpisode(Episode episode) _episodeRepository.Update(episode); } - public virtual IList GetEpisodeNumbersBySeason(int seriesId, int seasonNumber) { return GetEpisodesBySeason(seriesId, seasonNumber).Select(c => c.OID).ToList(); @@ -315,11 +315,11 @@ public virtual bool IsFirstOrLastEpisodeOfSeason(int seriesId, int seasonNumber, public virtual void DeleteEpisodesNotInTvdb(Series series, IList tvdbEpisodes) { - logger.Trace("Starting deletion of episodes that no longer exist in TVDB: {0}", series.Title.WithDefault(series.SeriesId)); + logger.Trace("Starting deletion of episodes that no longer exist in TVDB: {0}", series.Title.WithDefault(series.OID)); if (!tvdbEpisodes.Any()) return; - var seriesEpisodeIds = _episodeRepository.GetEpisodes(series.SeriesId).Select(c => c.OID); + var seriesEpisodeIds = _episodeRepository.GetEpisodes(series.OID).Select(c => c.OID); var toBeDeleted = seriesEpisodeIds.Except(tvdbEpisodes.Select(e => e.Id)); @@ -328,7 +328,7 @@ public virtual void DeleteEpisodesNotInTvdb(Series series, IList tv _episodeRepository.Delete(id); } - logger.Trace("Deleted episodes that no longer exist in TVDB for {0}", series.SeriesId); + logger.Trace("Deleted episodes that no longer exist in TVDB for {0}", series.OID); } public virtual void SetPostDownloadStatus(List episodeIds, PostDownloadStatusType postDownloadStatus) @@ -356,5 +356,13 @@ public virtual Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber { return _episodeRepository.GetEpisodeBySceneNumbering(seriesId, seasonNumber, episodeNumber); } + + public List GetEpisodesAiredInMonth(int year, int month) + { + var firstDay = new DateTime(year, month, 1); + var lastDay = firstDay.AddMonths(1).AddDays(-1); + + return _episodeRepository.EpisodesBetweenDates(firstDay, lastDay); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index b67e0d621..2a727b26f 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -56,10 +56,9 @@ public bool IsMonitored(int id) public Series UpdateSeriesInfo(int seriesId) { - var tvDbSeries = _tvDbProvider.GetSeries(seriesId, false, true); var series = _seriesRepository.Get(seriesId); - - series.SeriesId = tvDbSeries.Id; + var tvDbSeries = _tvDbProvider.GetSeries(series.SeriesId, false, true); + series.Title = tvDbSeries.SeriesName; series.AirTime = CleanAirsTime(tvDbSeries.AirsTime); series.AirsDayOfWeek = tvDbSeries.AirsDayOfWeek; @@ -113,7 +112,8 @@ public void AddSeries(string title, string path, int tvDbSeriesId, int qualityPr logger.Info("Adding Series [{0}] Path: [{1}]", tvDbSeriesId, path); Ensure.That(() => tvDbSeriesId).IsGreaterThan(0); - Ensure.That(() => title).IsNotNullOrWhiteSpace(); + //Todo: We can't validate the title if we're passing in an empty string + //Ensure.That(() => title).IsNotNullOrWhiteSpace(); Ensure.That(() => path).IsNotNullOrWhiteSpace(); var repoSeries = new Series(); @@ -144,7 +144,7 @@ public void UpdateFromSeriesEditor(IList editedSeries) foreach (var series in allSeries) { //Only update parameters that can be changed in MassEdit - var edited = editedSeries.Single(s => s.SeriesId == series.SeriesId); + var edited = editedSeries.Single(s => s.OID == series.OID); series.QualityProfileId = edited.QualityProfileId; series.Monitored = edited.Monitored; series.SeasonFolder = edited.SeasonFolder; diff --git a/SqlCe/NzbDrone.SqlCe.dll b/SqlCe/NzbDrone.SqlCe.dll index 5ba0e889b9a9eba3cdb364fbabfaae27002fc36a..47c21596a34ea3048a3c85ddf02702ad63f9e3c1 100644 GIT binary patch delta 122 zcmZorXi%8Y!Td-~b7Qw5n}AvQ!6yuRHC&b#DA)A8k5Hd{hV6tGP%@AK2$+CahLM3` zjVchcGcW`Ny995@pHQVzV&J*U*7I)WbvGuUG()mgOlWaxQE`lKVo`RCdwza;PO5@S VQD#}{6N|F-e3M=B%M){Q WVqA*y3zG6HCf{R!w)q5y1v>yOk0|s2