diff --git a/NzbDrone.Core.Test/InventoryProvider_IsAcceptableSizeTest.cs b/NzbDrone.Core.Test/InventoryProvider_IsAcceptableSizeTest.cs index 75a3b5272..574b58596 100644 --- a/NzbDrone.Core.Test/InventoryProvider_IsAcceptableSizeTest.cs +++ b/NzbDrone.Core.Test/InventoryProvider_IsAcceptableSizeTest.cs @@ -61,7 +61,7 @@ namespace NzbDrone.Core.Test qualityType = Builder.CreateNew() .With(q => q.MinSize = 0) - .With(q => q.MaxSize = 314572800) + .With(q => q.MaxSize = 10) .With(q => q.QualityTypeId = 1) .Build(); @@ -116,7 +116,7 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(MockBehavior.Strict); parseResultSingle.Series = series30minutes; - parseResultSingle.Size = 1184572800; + parseResultSingle.Size = 10000.Megabytes(); mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); @@ -137,7 +137,7 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(MockBehavior.Strict); parseResultSingle.Series = series60minutes; - parseResultSingle.Size = 1368572800; + parseResultSingle.Size = 10000.Megabytes(); mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); @@ -200,7 +200,7 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(MockBehavior.Strict); parseResultMulti.Series = series30minutes; - parseResultMulti.Size = 1184572800; + parseResultMulti.Size = 10000.Megabytes(); mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); @@ -221,7 +221,7 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(MockBehavior.Strict); parseResultMulti.Series = series60minutes; - parseResultMulti.Size = 1368572800; + parseResultMulti.Size = 10000.Megabytes(); mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); @@ -284,7 +284,7 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(MockBehavior.Strict); parseResultSingle.Series = series30minutes; - parseResultSingle.Size = 1184572800; + parseResultSingle.Size = 10000.Megabytes(); mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); @@ -305,7 +305,7 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(MockBehavior.Strict); parseResultSingle.Series = series60minutes; - parseResultSingle.Size = 1368572800; + parseResultSingle.Size = 10000.Megabytes(); mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); @@ -319,5 +319,49 @@ namespace NzbDrone.Core.Test //Assert result.Should().BeFalse(); } + + [Test] + public void IsAcceptableSize_true_unlimited_30_minute() + { + var mocker = new AutoMoqer(MockBehavior.Strict); + + parseResultSingle.Series = series30minutes; + parseResultSingle.Size = 18457280000; + qualityType.MaxSize = 0; + + mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); + + mocker.GetMock().Setup( + s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(true); + + //Act + bool result = mocker.Resolve().IsAcceptableSize(parseResultSingle); + + //Assert + result.Should().BeTrue(); + } + + [Test] + public void IsAcceptableSize_true_unlimited_60_minute() + { + var mocker = new AutoMoqer(MockBehavior.Strict); + + parseResultSingle.Series = series60minutes; + parseResultSingle.Size = 36857280000; + qualityType.MaxSize = 0; + + mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); + + mocker.GetMock().Setup( + s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(true); + + //Act + bool result = mocker.Resolve().IsAcceptableSize(parseResultSingle); + + //Assert + result.Should().BeTrue(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs b/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs index d2202bc2a..59f42d8b2 100644 --- a/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs +++ b/NzbDrone.Core.Test/InventoryProvider_QualityNeededTest.cs @@ -137,7 +137,7 @@ namespace NzbDrone.Core.Test mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(new QualityType { MaxSize = 10.Gigabytes(), MinSize = 0 }); + .Returns(new QualityType { MaxSize = 100, MinSize = 0 }); episode.EpisodeFile.Quality = QualityTypes.Bluray720p; @@ -171,7 +171,7 @@ namespace NzbDrone.Core.Test mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(new QualityType { MaxSize = 10.Gigabytes(), MinSize = 0 }); + .Returns(new QualityType { MaxSize = 100, MinSize = 0 }); episode.EpisodeFile.Quality = QualityTypes.SDTV; @@ -205,7 +205,7 @@ namespace NzbDrone.Core.Test mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(new QualityType { MaxSize = 10.Gigabytes(), MinSize = 0 }); + .Returns(new QualityType { MaxSize = 100, MinSize = 0 }); episode.EpisodeFile.Quality = QualityTypes.SDTV; @@ -239,7 +239,7 @@ namespace NzbDrone.Core.Test mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(new QualityType { MaxSize = 10.Gigabytes(), MinSize = 0 }); + .Returns(new QualityType { MaxSize = 100, MinSize = 0 }); episode.EpisodeFile.Quality = QualityTypes.SDTV; //Act diff --git a/NzbDrone.Core/Datastore/Migrations/Migration20110909.cs b/NzbDrone.Core/Datastore/Migrations/Migration20110909.cs index 13a83e17c..66b77deac 100644 --- a/NzbDrone.Core/Datastore/Migrations/Migration20110909.cs +++ b/NzbDrone.Core/Datastore/Migrations/Migration20110909.cs @@ -17,8 +17,8 @@ namespace NzbDrone.Core.Datastore.Migrations { new Column("QualityTypeId", DbType.Int32, ColumnProperty.PrimaryKey), new Column("Name", DbType.String, ColumnProperty.NotNull), - new Column("MinSize", DbType.Int64, ColumnProperty.NotNull), - new Column("MaxSize", DbType.Int64, ColumnProperty.NotNull) + new Column("MinSize", DbType.Int32, ColumnProperty.NotNull), + new Column("MaxSize", DbType.Int32, ColumnProperty.NotNull) }); } diff --git a/NzbDrone.Core/Providers/InventoryProvider.cs b/NzbDrone.Core/Providers/InventoryProvider.cs index 6544831f2..fd9a99b73 100644 --- a/NzbDrone.Core/Providers/InventoryProvider.cs +++ b/NzbDrone.Core/Providers/InventoryProvider.cs @@ -111,7 +111,6 @@ namespace NzbDrone.Core.Providers return true; //If we get to this point and the file has not yet been rejected then accept it } - public static bool IsUpgrade(Quality currentQuality, Quality newQuality, QualityTypes cutOff) { if (currentQuality.QualityType >= cutOff) @@ -147,12 +146,15 @@ namespace NzbDrone.Core.Providers //Is it a multi-episode release? //Is it the first or last series of a season? - var maxSize = qualityType.MaxSize; + //0 will be treated as unlimited + if (qualityType.MaxSize == 0) + return true; + + var maxSize = qualityType.MaxSize.Megabytes(); var series = parseResult.Series; - //If this is an hour long episode (between 50 and 65 minutes) then multiply by 2 - if (series.Runtime >= 50 && series.Runtime <= 65) - maxSize = maxSize * 2; + //Multiply maxSize by Series.Runtime + maxSize = maxSize * series.Runtime; //Multiply maxSize by the number of episodes parsed maxSize = maxSize * parseResult.EpisodeNumbers.Count; diff --git a/NzbDrone.Core/Providers/QualityTypeProvider.cs b/NzbDrone.Core/Providers/QualityTypeProvider.cs index 79c28354d..34d33bd07 100644 --- a/NzbDrone.Core/Providers/QualityTypeProvider.cs +++ b/NzbDrone.Core/Providers/QualityTypeProvider.cs @@ -60,12 +60,12 @@ namespace NzbDrone.Core.Providers Logger.Info("Setting up default quality types"); var qualityTypes = new List(); - qualityTypes.Add(new QualityType { QualityTypeId = 1, Name = "SDTV", MinSize = 0, MaxSize = 10.Gigabytes() }); - qualityTypes.Add(new QualityType { QualityTypeId = 2, Name = "DVD", MinSize = 0, MaxSize = 10.Gigabytes() }); - qualityTypes.Add(new QualityType { QualityTypeId = 4, Name = "HDTV", MinSize = 0, MaxSize = 10.Gigabytes() }); - qualityTypes.Add(new QualityType { QualityTypeId = 5, Name = "WEBDL", MinSize = 0, MaxSize = 10.Gigabytes() }); - qualityTypes.Add(new QualityType { QualityTypeId = 6, Name = "Bluray720p", MinSize = 0, MaxSize = 10.Gigabytes() }); - qualityTypes.Add(new QualityType { QualityTypeId = 7, Name = "Bluray1080p", MinSize = 0, MaxSize = 10.Gigabytes() }); + qualityTypes.Add(new QualityType { QualityTypeId = 1, Name = "SDTV", MinSize = 0, MaxSize = 100 }); + qualityTypes.Add(new QualityType { QualityTypeId = 2, Name = "DVD", MinSize = 0, MaxSize = 100 }); + qualityTypes.Add(new QualityType { QualityTypeId = 4, Name = "HDTV", MinSize = 0, MaxSize = 100 }); + qualityTypes.Add(new QualityType { QualityTypeId = 5, Name = "WEBDL", MinSize = 0, MaxSize = 100 }); + qualityTypes.Add(new QualityType { QualityTypeId = 6, Name = "Bluray720p", MinSize = 0, MaxSize = 100 }); + qualityTypes.Add(new QualityType { QualityTypeId = 7, Name = "Bluray1080p", MinSize = 0, MaxSize = 100 }); _database.InsertMany(qualityTypes); } diff --git a/NzbDrone.Core/Repository/Quality/QualityType.cs b/NzbDrone.Core/Repository/Quality/QualityType.cs index 037e640e4..88f816bff 100644 --- a/NzbDrone.Core/Repository/Quality/QualityType.cs +++ b/NzbDrone.Core/Repository/Quality/QualityType.cs @@ -13,8 +13,8 @@ namespace NzbDrone.Core.Repository.Quality { public int QualityTypeId { get; set; } public string Name { get; set; } - public long MinSize { get; set; } - public long MaxSize { get; set; } + public int MinSize { get; set; } + public int MaxSize { get; set; } public override string ToString() { diff --git a/NzbDrone.Web/Content/QualitySettings.css b/NzbDrone.Web/Content/QualitySettings.css index 1a148d1c2..86ea2506e 100644 --- a/NzbDrone.Web/Content/QualitySettings.css +++ b/NzbDrone.Web/Content/QualitySettings.css @@ -105,4 +105,15 @@ { min-height: 23px; position: relative; +} + +.sliders +{ + clear: both; + padding-bottom: 20px; +} + +.slider-container +{ + margin-bottom: 10px; } \ No newline at end of file diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 1f595585e..4056dcac6 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -27,12 +27,15 @@ namespace NzbDrone.Web.Controllers private readonly AutoConfigureProvider _autoConfigureProvider; private readonly SeriesProvider _seriesProvider; private readonly ExternalNotificationProvider _externalNotificationProvider; + private readonly QualityTypeProvider _qualityTypeProvider; public SettingsController(ConfigProvider configProvider, IndexerProvider indexerProvider, QualityProvider qualityProvider, AutoConfigureProvider autoConfigureProvider, - SeriesProvider seriesProvider, ExternalNotificationProvider externalNotificationProvider) + SeriesProvider seriesProvider, ExternalNotificationProvider externalNotificationProvider, + QualityTypeProvider qualityTypeProvider) { _externalNotificationProvider = externalNotificationProvider; + _qualityTypeProvider = qualityTypeProvider; _configProvider = configProvider; _indexerProvider = indexerProvider; _qualityProvider = qualityProvider; @@ -123,12 +126,19 @@ namespace NzbDrone.Web.Controllers var defaultQualityQualityProfileId = Convert.ToInt32(_configProvider.DefaultQualityProfile); var qualityProfileSelectList = new SelectList(profiles, "QualityProfileId", "Name"); + var qualityTypesFromDb = _qualityTypeProvider.All(); var model = new QualityModel { Profiles = profiles, DefaultQualityProfileId = defaultQualityQualityProfileId, - QualityProfileSelectList = qualityProfileSelectList + QualityProfileSelectList = qualityProfileSelectList, + SdtvMaxSize = qualityTypesFromDb.Single(q => q.QualityTypeId == 1).MaxSize, + DvdMaxSize = qualityTypesFromDb.Single(q => q.QualityTypeId == 2).MaxSize, + HdtvMaxSize = qualityTypesFromDb.Single(q => q.QualityTypeId == 4).MaxSize, + WebdlMaxSize = qualityTypesFromDb.Single(q => q.QualityTypeId == 5).MaxSize, + Bluray720pMaxSize = qualityTypesFromDb.Single(q => q.QualityTypeId == 6).MaxSize, + Bluray1080pMaxSize = qualityTypesFromDb.Single(q => q.QualityTypeId == 7).MaxSize }; return View(model); @@ -322,8 +332,6 @@ namespace NzbDrone.Web.Controllers Json(new NotificationResult() { Title = "Failed", Text = "Invalid request data.", NotificationType = NotificationType.Error }); } - - [HttpPost] public JsonResult SaveQuality(QualityModel data) { @@ -358,6 +366,17 @@ namespace NzbDrone.Web.Controllers _qualityProvider.Update(profile); } + var qualityTypesFromDb = _qualityTypeProvider.All(); + + qualityTypesFromDb.Single(q => q.QualityTypeId == 1).MaxSize = data.SdtvMaxSize; + qualityTypesFromDb.Single(q => q.QualityTypeId == 2).MaxSize = data.DvdMaxSize; + qualityTypesFromDb.Single(q => q.QualityTypeId == 4).MaxSize = data.HdtvMaxSize; + qualityTypesFromDb.Single(q => q.QualityTypeId == 5).MaxSize = data.WebdlMaxSize; + qualityTypesFromDb.Single(q => q.QualityTypeId == 6).MaxSize = data.Bluray720pMaxSize; + qualityTypesFromDb.Single(q => q.QualityTypeId == 7).MaxSize = data.Bluray1080pMaxSize; + + _qualityTypeProvider.UpdateAll(qualityTypesFromDb); + return GetSuccessResult(); } diff --git a/NzbDrone.Web/Models/QualityModel.cs b/NzbDrone.Web/Models/QualityModel.cs index 0b6263b46..27796406b 100644 --- a/NzbDrone.Web/Models/QualityModel.cs +++ b/NzbDrone.Web/Models/QualityModel.cs @@ -14,5 +14,12 @@ namespace NzbDrone.Web.Models public int DefaultQualityProfileId { get; set; } public SelectList QualityProfileSelectList { get; set; } + + public int SdtvMaxSize { get; set; } + public int DvdMaxSize { get; set; } + public int HdtvMaxSize { get; set; } + public int WebdlMaxSize { get; set; } + public int Bluray720pMaxSize { get; set; } + public int Bluray1080pMaxSize { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/Quality.cshtml b/NzbDrone.Web/Views/Settings/Quality.cshtml index 82fd8754a..4c99d3425 100644 --- a/NzbDrone.Web/Views/Settings/Quality.cshtml +++ b/NzbDrone.Web/Views/Settings/Quality.cshtml @@ -23,6 +23,50 @@ Settings @Html.DescriptionFor(m => m.DefaultQualityProfileId) @Html.DropDownListFor(m => m.DefaultQualityProfileId, Model.QualityProfileSelectList, new { @class = "inputClass" }) + +
+
+ SDTV +
+ @Html.HiddenFor(m => m.SdtvMaxSize, new { @class="slider-value" }) + 30 minute size: | 60 minute size: +
+ +
+ DVD +
+ @Html.HiddenFor(m => m.DvdMaxSize, new { @class = "slider-value" }) + 30 minute size: | 60 minute size: +
+ +
+ HDTV +
+ @Html.HiddenFor(m => m.HdtvMaxSize, new { @class = "slider-value" }) + 30 minute size: | 60 minute size: +
+ +
+ WEBDL +
+ @Html.HiddenFor(m => m.WebdlMaxSize, new { @class = "slider-value" }) + 30 minute size: | 60 minute size: +
+ +
+ Bluray 720p +
+ @Html.HiddenFor(m => m.Bluray720pMaxSize, new { @class = "slider-value" }) + 30 minute size: | 60 minute size: +
+ +
+ Bluray 1080p +
+ @Html.HiddenFor(m => m.Bluray1080pMaxSize, new { @class = "slider-value" }) + 30 minute size: | 60 minute size: +
+
@@ -48,7 +92,7 @@ Settings
} @section Scripts{ - + @@ -156,5 +200,35 @@ Settings $(allowedString).empty().val(result); }); + + var sliderOptions = { + min: 0, + max: 200, + value: 0, + step: 1, + create: function( event, ui ) { + var startingValue = $(this).siblings('.slider-value').val(); + $(this).siblings('.30-minute').text(startingValue * 30); + $(this).siblings('.60-minute').text(startingValue * 60); + }, + slide: function( event, ui ) { + $(this).siblings('.slider-value').val(ui.value); + $(this).siblings('.30-minute').text(ui.value * 30); + $(this).siblings('.60-minute').text(ui.value * 60); + } + }; + + $(document).ready(function () { + setupSliders(); + }); + + function setupSliders() { + $(".slider").each(function() { + var localOptions = sliderOptions; + localOptions["value"] = $(this).siblings('.slider-value').val(); + + $(this).empty().slider(localOptions); + }); + } }