Basic UI + Wizard for custom naming added

pull/4/head
Mark McDowall 11 years ago
parent 7b54bca3c7
commit 0ec520c4d5

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using FluentValidation;
using Nancy.Responses;
using NzbDrone.Core.MediaFiles;
@ -28,6 +29,8 @@ namespace NzbDrone.Api.Config
Get["/samples"] = x => GetExamples(this.Bind<NamingConfigResource>());
SharedValidator.RuleFor(c => c.MultiEpisodeStyle).InclusiveBetween(0, 3);
SharedValidator.RuleFor(c => c.StandardEpisodeFormat).NotEmpty();
SharedValidator.RuleFor(c => c.DailyEpisodeFormat).NotEmpty();
}
private void UpdateNamingConfig(NamingConfigResource resource)
@ -59,7 +62,8 @@ namespace NzbDrone.Api.Config
{
SeasonNumber = 1,
EpisodeNumber = 1,
Title = "Episode Title (1)"
Title = "Episode Title (1)",
AirDate = "2013-10-30"
};
var episode2 = new Episode
@ -77,19 +81,43 @@ namespace NzbDrone.Api.Config
var sampleResource = new NamingSampleResource();
sampleResource.SingleEpisodeExample = _buildFileNames.BuildFilename(new List<Episode> { episode1 },
series,
episodeFile,
nameSpec);
sampleResource.SingleEpisodeExample = BuildSample(new List<Episode> { episode1 },
series,
episodeFile,
nameSpec);
episodeFile.Path = @"C:\Test\Series.Title.S01E01-E02.720p.HDTV.x264-EVOLVE.mkv";
sampleResource.MultiEpisodeExample = _buildFileNames.BuildFilename(new List<Episode> { episode1, episode2 },
series,
episodeFile,
nameSpec);
sampleResource.MultiEpisodeExample = BuildSample(new List<Episode> { episode1, episode2 },
series,
episodeFile,
nameSpec);
episodeFile.Path = @"C:\Test\Series.Title.2013.10.30.HDTV.x264-EVOLVE.mkv";
series.SeriesType = SeriesTypes.Daily;
sampleResource.DailyEpisodeExample = BuildSample(new List<Episode> { episode1 },
series,
episodeFile,
nameSpec);
return sampleResource.AsResponse();
}
private string BuildSample(List<Episode> episodes, Core.Tv.Series series, EpisodeFile episodeFile, NamingConfig nameSpec)
{
try
{
return _buildFileNames.BuildFilename(episodes,
series,
episodeFile,
nameSpec);
}
catch (NamingFormatException ex)
{
//Catching to avoid blowing up all samples
return String.Empty;
}
}
}
}

@ -4,5 +4,6 @@
{
public string SingleEpisodeExample { get; set; }
public string MultiEpisodeExample { get; set; }
public string DailyEpisodeExample { get; set; }
}
}

@ -38,7 +38,7 @@ namespace NzbDrone.Core.Datastore.Migration
//Output settings
var seriesTitlePattern = "";
var episodeTitlePattern = "";
var dailyEpisodePattern = "{Air Date}";
var dailyEpisodePattern = "{Air-Date}";
var qualityFormat = " [{Quality Title}]";
if (includeSeriesTitle)
@ -61,11 +61,6 @@ namespace NzbDrone.Core.Datastore.Migration
}
}
if (replaceSpaces)
{
dailyEpisodePattern = "{Air.Date}";
}
var standardEpisodeFormat = String.Format("{0}{1}{2}", seriesTitlePattern,
GetNumberStyle(numberStyle).Pattern,
episodeTitlePattern);

@ -325,6 +325,7 @@
<Compile Include="Notifications\Xbmc\Model\XbmcJsonResult.cs" />
<Compile Include="Notifications\Xbmc\Model\XbmcVersion.cs" />
<Compile Include="Organizer\EpisodeFormat.cs" />
<Compile Include="Organizer\Exception.cs" />
<Compile Include="Organizer\FilenameBuilderTokenEqualityComparer.cs" />
<Compile Include="Parser\InvalidDateException.cs" />
<Compile Include="Parser\Model\SeriesTitleInfo.cs" />

@ -0,0 +1,15 @@
using NzbDrone.Common.Exceptions;
namespace NzbDrone.Core.Organizer
{
public class NamingFormatException : NzbDroneException
{
public NamingFormatException(string message, params object[] args) : base(message, args)
{
}
public NamingFormatException(string message) : base(message)
{
}
}
}

@ -96,6 +96,16 @@ namespace NzbDrone.Core.Organizer
return episodeFile.SceneName;
}
if (String.IsNullOrWhiteSpace(nameSpec.StandardEpisodeFormat) && series.SeriesType == SeriesTypes.Standard)
{
throw new NamingFormatException("Standard episode format cannot be null");
}
if (String.IsNullOrWhiteSpace(nameSpec.DailyEpisodeFormat) && series.SeriesType == SeriesTypes.Daily)
{
throw new NamingFormatException("Daily episode format cannot be null");
}
var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber).ToList();
var pattern = nameSpec.StandardEpisodeFormat;
var episodeTitles = new List<string>
@ -112,7 +122,7 @@ namespace NzbDrone.Core.Organizer
if (!String.IsNullOrWhiteSpace(episodes.First().AirDate))
{
tokenValues.Add("{Air Date}", episodes.First().AirDate);
tokenValues.Add("{Air Date}", episodes.First().AirDate.Replace('-', ' '));
}
else {
@ -218,8 +228,9 @@ namespace NzbDrone.Core.Organizer
{
var separator = match.Groups["separator"].Value;
var token = match.Groups["token"].Value;
var replacementText = tokenValues[token];
var replacementText = "";
var patternTokenArray = token.ToCharArray();
if (!tokenValues.TryGetValue(token, out replacementText)) return null;
if (patternTokenArray.All(t => !char.IsLetter(t) || char.IsLower(t)))
{

@ -10,10 +10,10 @@ namespace NzbDrone.Core.Organizer
{
return new NamingConfig
{
RenameEpisodes = true,
RenameEpisodes = false,
MultiEpisodeStyle = 0,
StandardEpisodeFormat = "{Series Title} - {season}x{0episode} - {Episode Title} {Quality Title}",
DailyEpisodeFormat = "{Series Title} - {Air Date} - {Episode Title} {Quality Title}"
StandardEpisodeFormat = "",
DailyEpisodeFormat = ""
};
}
}

@ -19,7 +19,11 @@ define(
this._modelBinder = new ModelBinder();
}
this._modelBinder.bind(this.model, this.el);
var options = {
changeTriggers: {'': 'change', '[contenteditable]': 'blur', '[data-onkeyup]': 'keyup'}
};
this._modelBinder.bind(this.model, this.el, null, options);
if (originalOnRender) {
originalOnRender.call(this);

@ -6,5 +6,4 @@ define(
return Backbone.Model.extend({
url: window.NzbDrone.ApiRoot + '/config/naming/samples'
});
});

@ -1,10 +1,11 @@
'use strict';
define(
[
'vent',
'marionette',
'Settings/MediaManagement/Naming/NamingSampleModel',
'Mixins/AsModelBoundView'
], function (Marionette, NamingSampleModel, AsModelBoundView) {
], function (vent, Marionette, NamingSampleModel, AsModelBoundView) {
var view = Marionette.ItemView.extend({
template: 'Settings/MediaManagement/Naming/NamingViewTemplate',
@ -13,11 +14,13 @@ define(
namingOptions : '.x-naming-options',
renameEpisodesCheckbox: '.x-rename-episodes',
singleEpisodeExample : '.x-single-episode-example',
multiEpisodeExample : '.x-multi-episode-example'
multiEpisodeExample : '.x-multi-episode-example',
dailyEpisodeExample : '.x-daily-episode-example'
},
events: {
'change .x-rename-episodes': '_setFailedDownloadOptionsVisibility'
'change .x-rename-episodes': '_setFailedDownloadOptionsVisibility',
'click .x-show-wizard' : '_showWizard'
},
onRender: function () {
@ -50,6 +53,11 @@ define(
_showSamples: function () {
this.ui.singleEpisodeExample.html(this.namingSampleModel.get('singleEpisodeExample'));
this.ui.multiEpisodeExample.html(this.namingSampleModel.get('multiEpisodeExample'));
this.ui.dailyEpisodeExample.html(this.namingSampleModel.get('dailyEpisodeExample'));
},
_showWizard: function () {
vent.trigger(vent.Commands.ShowNamingWizard, { model: this.model });
}
});

@ -24,108 +24,30 @@
<div class="x-naming-options">
<div class="control-group">
<label class="control-label">Include Series Title</label>
<label class="control-label">Wizard</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="includeSeriesTitle"/>
<button class="btn x-show-wizard">Show Wizard</button>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">Include Episode Title</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="includeEpisodeTitle"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
<span class="help-inline">
<i class="icon-nd-form-info" title="Wizard to setup preferred naming style"/>
</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Include Quality</label>
<label class="control-label">Standard Episode Format</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="includeQuality"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">Replace Spaces</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="replaceSpaces"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
<input type="text" class="naming-format" name="standardEpisodeFormat" data-onkeyup="true" />
</div>
</div>
<div class="control-group">
<label class="control-label">Separator</label>
<label class="control-label">Daily Episode Format</label>
<div class="controls">
<select class="inputClass" name="separator">
<option value=" - ">Dash</option>
<option value=" ">Space</option>
<option value=".">Period</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Numbering Style</label>
<div class="controls">
<select class="inputClass" name="numberStyle">
<option value="0">1x05</option>
<option value="1">01x05</option>
<option value="2">S01E05</option>
<option value="3">s01e05</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Multi-Episode Style</label>
<div class="controls">
<select class="inputClass" name="multiEpisodeStyle">
<option value="0">Extend</option>
<option value="1">Duplicate</option>
<option value="2">Repeat</option>
<option value="3">Scene</option>
</select>
<input type="text" class="naming-format" name="dailyEpisodeFormat" data-onkeyup="true" />
</div>
</div>
</div>
@ -145,4 +67,12 @@
<span class="x-multi-episode-example naming-example"></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Daily-Episode Example</label>
<div class="controls">
<span class="x-daily-episode-example naming-example"></span>
</div>
</div>
</fieldset>

@ -0,0 +1,17 @@
'use strict';
define(
[
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
defaults: {
includeSeriesTitle : true,
includeEpisodeTitle: true,
includeQuality : true,
replaceSpaces : false,
separator : ' - ',
numberStyle : '2',
multiEpisodeStyle : 0
}
});
});

@ -0,0 +1,141 @@
'use strict';
define(
[
'vent',
'marionette',
'Settings/MediaManagement/Naming/NamingSampleModel',
'Settings/MediaManagement/Naming/Wizard/NamingWizardModel',
'Mixins/AsModelBoundView'
], function (vent, Marionette, NamingSampleModel, NamingWizardModel, AsModelBoundView) {
var view = Marionette.ItemView.extend({
template: 'Settings/MediaManagement/Naming/Wizard/NamingWizardViewTemplate',
ui: {
namingOptions : '.x-naming-options',
singleEpisodeExample : '.x-single-episode-example',
multiEpisodeExample : '.x-multi-episode-example',
dailyEpisodeExample : '.x-daily-episode-example'
},
events: {
'click .x-apply': '_applyNaming'
},
initialize: function (options) {
this.model = new NamingWizardModel();
this.namingModel = options.model;
this.namingSampleModel = new NamingSampleModel();
},
onRender: function () {
if (!this.model.get('renameEpisodes')) {
this.ui.namingOptions.hide();
}
this.listenTo(this.model, 'change', this._buildFormat);
this.listenTo(this.namingSampleModel, 'sync', this._showSamples);
this._buildFormat();
},
_updateSamples: function () {
var data = {
renameEpisodes: true,
standardEpisodeFormat: this.standardEpisodeFormat,
dailyEpisodeFormat: this.dailyEpisodeFormat,
multiEpisodeStyle: this.model.get('multiEpisodeStyle')
};
this.namingSampleModel.fetch({data: data});
},
_showSamples: function () {
this.ui.singleEpisodeExample.html(this.namingSampleModel.get('singleEpisodeExample'));
this.ui.multiEpisodeExample.html(this.namingSampleModel.get('multiEpisodeExample'));
this.ui.dailyEpisodeExample.html(this.namingSampleModel.get('dailyEpisodeExample'));
},
_applyNaming: function () {
this.namingModel.set('standardEpisodeFormat', this.standardEpisodeFormat);
this.namingModel.set('dailyEpisodeFormat', this.dailyEpisodeFormat);
this.namingModel.set('multiEpisodeStyle', this.model.get('multiEpisodeStyle'));
vent.trigger(vent.Commands.CloseModalCommand);
},
_buildFormat: function () {
this.standardEpisodeFormat = '';
this.dailyEpisodeFormat = '';
if (this.model.get('includeSeriesTitle')) {
if (this.model.get('replaceSpaces')) {
this.standardEpisodeFormat += '{Series.Title}';
this.dailyEpisodeFormat += '{Series.Title}';
}
else {
this.standardEpisodeFormat += '{Series Title}';
this.dailyEpisodeFormat += '{Series Title}';
}
this.standardEpisodeFormat += this.model.get('separator');
this.dailyEpisodeFormat += this.model.get('separator');
}
switch (this.model.get('numberStyle')) {
case '0':
this.standardEpisodeFormat += '{season}x{0episode}';
break;
case '1':
this.standardEpisodeFormat += '{0season}x{0episode}';
break;
case '2':
this.standardEpisodeFormat += 'S{0season}E{0episode}';
break;
case '3':
this.standardEpisodeFormat += 's{0season}e{0episode}';
break;
default:
this.standardEpisodeFormat += 'Unknown Number Pattern';
}
this.dailyEpisodeFormat += '{Air-Date}';
if (this.model.get('includeEpisodeTitle')) {
this.standardEpisodeFormat += this.model.get('separator');
this.dailyEpisodeFormat += this.model.get('separator');
if (this.model.get('replaceSpaces')) {
this.standardEpisodeFormat += '{Episode.Title}';
this.dailyEpisodeFormat += '{Episode.Title}';
}
else {
this.standardEpisodeFormat += '{Episode Title}';
this.dailyEpisodeFormat += '{Episode Title}';
}
}
if (this.model.get('includeQuality')) {
if (this.model.get('replaceSpaces')) {
this.standardEpisodeFormat += ' {Quality.Title}';
this.dailyEpisodeFormat += ' {Quality.Title}';
}
else {
this.standardEpisodeFormat += ' {Quality Title}';
this.dailyEpisodeFormat += ' {Quality Title}';
}
}
if (this.model.get('replaceSpaces')) {
this.standardEpisodeFormat = this.standardEpisodeFormat.replace(/\s/g, '.');
this.dailyEpisodeFormat = this.dailyEpisodeFormat.replace(/\s/g, '.');
}
this._updateSamples();
}
});
return AsModelBoundView.call(view);
});

@ -0,0 +1,141 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Naming Wizard</h3>
</div>
<div class="modal-body">
<div class="form-horizontal">
<div class="control-group">
<label class="control-label">Include Series Title</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="includeSeriesTitle"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">Include Episode Title</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="includeEpisodeTitle"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">Include Quality</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="includeQuality"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">Replace Spaces</label>
<div class="controls">
<label class="checkbox toggle well">
<input type="checkbox" name="replaceSpaces"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">Separator</label>
<div class="controls">
<select class="inputClass" name="separator">
<option value=" - ">Dash</option>
<option value=" ">Space</option>
<option value=".">Period</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Numbering Style</label>
<div class="controls">
<select class="inputClass" name="numberStyle">
<option value="0">1x05</option>
<option value="1">01x05</option>
<option value="2">S01E05</option>
<option value="3">s01e05</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Multi-Episode Style</label>
<div class="controls">
<select class="inputClass" name="multiEpisodeStyle">
<option value="0">Extend</option>
<option value="1">Duplicate</option>
<option value="2">Repeat</option>
<option value="3">Scene</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Single Episode Example</label>
<div class="controls">
<span class="x-single-episode-example naming-example"></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Multi-Episode Example</label>
<div class="controls">
<span class="x-multi-episode-example naming-example"></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Daily-Episode Example</label>
<div class="controls">
<span class="x-daily-episode-example naming-example"></span>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal">cancel</button>
<button class="btn btn-primary x-apply">apply</button>
</div>

@ -44,9 +44,9 @@
<label class="control-label">Season Folder Format</label>
<div class="controls">
<input type="text" placeholder="Season %s" name="seasonFolderFormat"/>
<input type="text" placeholder="Season {season}" name="seasonFolderFormat"/>
<span class="help-inline">
<i class="icon-question-sign" title="How should season folders be named? (Use %0s to pad to two digits, %sn for Series Name)"/>
<i class="icon-question-sign" title="How should season folders be named? Please see the wiki for customization options"/>
</span>
</div>
</div>

@ -45,6 +45,10 @@ li.save-and-add:hover {
margin-top: 5px;
}
.naming-format {
width: 500px;
}
.advanced-settings-toggle {
margin-right: 40px;
@ -77,4 +81,4 @@ li.save-and-add:hover {
.advanced-setting {
display: block;
}
}
}

@ -8,8 +8,9 @@ define(
'Series/Delete/DeleteSeriesView',
'Episode/EpisodeDetailsLayout',
'History/Details/HistoryDetailsView',
'System/Logs/Table/Details/LogDetailsView'
], function (vent, AppLayout, Marionette, EditSeriesView, DeleteSeriesView, EpisodeDetailsLayout, HistoryDetailsView, LogDetailsView) {
'System/Logs/Table/Details/LogDetailsView',
'Settings/MediaManagement/Naming/Wizard/NamingWizardView'
], function (vent, AppLayout, Marionette, EditSeriesView, DeleteSeriesView, EpisodeDetailsLayout, HistoryDetailsView, LogDetailsView, NamingWizardView) {
return Marionette.AppRouter.extend({
@ -20,6 +21,7 @@ define(
vent.on(vent.Commands.ShowEpisodeDetails, this._showEpisode, this);
vent.on(vent.Commands.ShowHistoryDetails, this._showHistory, this);
vent.on(vent.Commands.ShowLogDetails, this._showLogDetails, this);
vent.on(vent.Commands.ShowNamingWizard, this._showNamingWizard, this);
},
_closeModal: function () {
@ -49,6 +51,11 @@ define(
_showLogDetails: function (options) {
var view = new LogDetailsView({ model: options.model });
AppLayout.modalRegion.show(view);
},
_showNamingWizard: function (options) {
var view = new NamingWizardView({ model: options.model });
AppLayout.modalRegion.show(view);
}
});
});

@ -23,7 +23,8 @@ define(
ShowHistoryDetails : 'ShowHistoryDetails',
ShowLogDetails : 'ShowLogDetails',
SaveSettings : 'saveSettings',
ShowLogFile : 'showLogFile'
ShowLogFile : 'showLogFile',
ShowNamingWizard : 'showNamingWizard'
};
return vent;

Loading…
Cancel
Save