Quality size sliders are implemented. Limits are calculated based on MB/Minute.

pull/6/head
Mark McDowall 13 years ago
parent 4b2427ade7
commit 8c06dde28a

@ -61,7 +61,7 @@ namespace NzbDrone.Core.Test
qualityType = Builder<QualityType>.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<QualityTypeProvider>().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<QualityTypeProvider>().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<QualityTypeProvider>().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<QualityTypeProvider>().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<QualityTypeProvider>().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<QualityTypeProvider>().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<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = mocker.Resolve<InventoryProvider>().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<QualityTypeProvider>().Setup(s => s.Get(1)).Returns(qualityType);
mocker.GetMock<EpisodeProvider>().Setup(
s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
//Act
bool result = mocker.Resolve<InventoryProvider>().IsAcceptableSize(parseResultSingle);
//Assert
result.Should().BeTrue();
}
}
}

@ -137,7 +137,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.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<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.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<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.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<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 10.Gigabytes(), MinSize = 0 });
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
episode.EpisodeFile.Quality = QualityTypes.SDTV;
//Act

@ -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)
});
}

@ -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;

@ -60,12 +60,12 @@ namespace NzbDrone.Core.Providers
Logger.Info("Setting up default quality types");
var qualityTypes = new List<QualityType>();
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);
}

@ -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()
{

@ -105,4 +105,15 @@
{
min-height: 23px;
position: relative;
}
.sliders
{
clear: both;
padding-bottom: 20px;
}
.slider-container
{
margin-bottom: 10px;
}

@ -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();
}

@ -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; }
}
}

@ -23,6 +23,50 @@ Settings
<span class="small">@Html.DescriptionFor(m => m.DefaultQualityProfileId)</span>
</label>
@Html.DropDownListFor(m => m.DefaultQualityProfileId, Model.QualityProfileSelectList, new { @class = "inputClass" })
<div class="sliders">
<div class="slider-container">
<b>SDTV</b>
<div id="sdtv-slider" class="slider"></div>
@Html.HiddenFor(m => m.SdtvMaxSize, new { @class="slider-value" })
30 minute size: <span class="30-minute"></span> | 60 minute size: <span class="60-minute"></span>
</div>
<div class="slider-container">
<b>DVD</b>
<div id="dvd-slider" class="slider"></div>
@Html.HiddenFor(m => m.DvdMaxSize, new { @class = "slider-value" })
30 minute size: <span class="30-minute"></span> | 60 minute size: <span class="60-minute"></span>
</div>
<div class="slider-container">
<b>HDTV</b>
<div id="hdtv-slider" class="slider"></div>
@Html.HiddenFor(m => m.HdtvMaxSize, new { @class = "slider-value" })
30 minute size: <span class="30-minute"></span> | 60 minute size: <span class="60-minute"></span>
</div>
<div class="slider-container">
<b>WEBDL</b>
<div id="webdl-slider" class="slider"></div>
@Html.HiddenFor(m => m.WebdlMaxSize, new { @class = "slider-value" })
30 minute size: <span class="30-minute"></span> | 60 minute size: <span class="60-minute"></span>
</div>
<div class="slider-container">
<b>Bluray 720p</b>
<div id="bluray720p-slider" class="slider"></div>
@Html.HiddenFor(m => m.Bluray720pMaxSize, new { @class = "slider-value" })
30 minute size: <span class="30-minute"></span> | 60 minute size: <span class="60-minute"></span>
</div>
<div class="slider-container">
<b>Bluray 1080p</b>
<div id="bluray1080p-slider" class="slider"></div>
@Html.HiddenFor(m => m.Bluray1080pMaxSize, new { @class = "slider-value" })
30 minute size: <span class="30-minute"></span> | 60 minute size: <span class="60-minute"></span>
</div>
</div>
</div>
<div id="bottom" class="clearfix">
@ -48,7 +92,7 @@ Settings
</div>
}
@section Scripts{
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/Plugins/MicrosoftAjax.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js"
type="text/javascript"></script>
<script src="../../Scripts/settingsForm.js" type="text/javascript"></script>
@ -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);
});
}
</script>
}

Loading…
Cancel
Save