diff --git a/frontend/src/Settings/MediaManagement/Naming/Naming.js b/frontend/src/Settings/MediaManagement/Naming/Naming.js index 94ed8538c..1e13396bc 100644 --- a/frontend/src/Settings/MediaManagement/Naming/Naming.js +++ b/frontend/src/Settings/MediaManagement/Naming/Naming.js @@ -112,17 +112,13 @@ class Naming extends Component { if (examples.movieExample) { standardMovieFormatHelpTexts.push(`${translate('Movie')}: ${examples.movieExample}`); } else { - standardMovieFormatErrors.push({ get message() { - return translate('MovieInvalidFormat'); - } }); + standardMovieFormatErrors.push({ message: translate('MovieInvalidFormat') }); } if (examples.movieFolderExample) { movieFolderFormatHelpTexts.push(`${translate('Example')}: ${examples.movieFolderExample}`); } else { - movieFolderFormatErrors.push({ get message() { - return translate('InvalidFormat'); - } }); + movieFolderFormatErrors.push({ message: translate('InvalidFormat') }); } } diff --git a/frontend/src/Settings/MediaManagement/Naming/NamingConnector.js b/frontend/src/Settings/MediaManagement/Naming/NamingConnector.js index 2b033f918..55c3bc597 100644 --- a/frontend/src/Settings/MediaManagement/Naming/NamingConnector.js +++ b/frontend/src/Settings/MediaManagement/Naming/NamingConnector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; @@ -15,11 +14,11 @@ function createMapStateToProps() { (state) => state.settings.advancedSettings, (state) => state.settings.namingExamples, createSettingsSectionSelector(SECTION), - (advancedSettings, examples, sectionSettings) => { + (advancedSettings, namingExamples, sectionSettings) => { return { advancedSettings, - examples: examples.item, - examplesPopulated: !_.isEmpty(examples.item), + examples: namingExamples.item, + examplesPopulated: namingExamples.isPopulated, ...sectionSettings }; } diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 53ae1a948..fe81e168d 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -107,7 +107,13 @@ public string BuildFileName(Movie movie, MovieFile movieFile, NamingConfig namin return GetOriginalTitle(movieFile, false); } + if (namingConfig.StandardMovieFormat.IsNullOrWhiteSpace()) + { + throw new NamingFormatException("Standard movie format cannot be empty"); + } + var pattern = namingConfig.StandardMovieFormat; + var tokenHandlers = new Dictionary>(FileNameBuilderTokenEqualityComparer.Instance); var multipleTokens = TitleRegex.Matches(pattern).Count > 1; diff --git a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs index ff887adf2..c8e70e685 100644 --- a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs +++ b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs @@ -90,6 +90,8 @@ public SampleResult GetMovieSample(NamingConfig nameSpec) var result = new SampleResult { FileName = BuildSample(_movie, _movieFile, nameSpec), + Movie = _movie, + MovieFile = _movieFile }; return result; diff --git a/src/Radarr.Api.V3/Config/NamingConfigController.cs b/src/Radarr.Api.V3/Config/NamingConfigController.cs index 7ca6cf96d..cd9d2b5e3 100644 --- a/src/Radarr.Api.V3/Config/NamingConfigController.cs +++ b/src/Radarr.Api.V3/Config/NamingConfigController.cs @@ -17,17 +17,14 @@ public class NamingConfigController : RestController private readonly INamingConfigService _namingConfigService; private readonly IFilenameSampleService _filenameSampleService; private readonly IFilenameValidationService _filenameValidationService; - private readonly IBuildFileNames _filenameBuilder; public NamingConfigController(INamingConfigService namingConfigService, IFilenameSampleService filenameSampleService, - IFilenameValidationService filenameValidationService, - IBuildFileNames filenameBuilder) + IFilenameValidationService filenameValidationService) { _namingConfigService = namingConfigService; _filenameSampleService = filenameSampleService; _filenameValidationService = filenameValidationService; - _filenameBuilder = filenameBuilder; SharedValidator.RuleFor(c => c.StandardMovieFormat).ValidMovieFormat(); SharedValidator.RuleFor(c => c.MovieFolderFormat).ValidMovieFolderFormat(); @@ -72,11 +69,11 @@ public object GetExamples([FromQuery]NamingConfigResource config) var movieSampleResult = _filenameSampleService.GetMovieSample(nameSpec); sampleResource.MovieExample = nameSpec.StandardMovieFormat.IsNullOrWhiteSpace() - ? "Invalid Format" + ? null : movieSampleResult.FileName; sampleResource.MovieFolderExample = nameSpec.MovieFolderFormat.IsNullOrWhiteSpace() - ? "Invalid format" + ? null : _filenameSampleService.GetMovieFolderSample(nameSpec); return sampleResource; @@ -90,6 +87,8 @@ private void ValidateFormatResult(NamingConfig nameSpec) var validationFailures = new List(); + validationFailures.AddIfNotNull(standardMovieValidationResult); + if (validationFailures.Any()) { throw new ValidationException(validationFailures.DistinctBy(v => v.PropertyName).ToArray());