From 24b8029d2e4a8aa5a42b2fbb70283a02cef3e4e8 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 7 May 2021 22:09:23 +0200 Subject: [PATCH] Fixed: Release Year in renaming format for certain OS language cultures Based-On: https://github.com/Radarr/Radarr/commit/a0d2af54e854a77e7e61d1c79a433c488cf9ac41 (cherry picked from commit 87897d56ea62544a36986eb09d420649668d7400) --- .../FileNameBuilderFixture.cs | 26 +++++++++++++++++++ .../Organizer/FileNameBuilder.cs | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs index a042757e9..550288f69 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; +using System.Threading; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; @@ -793,6 +795,30 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests .Should().Be(releaseGroup); } + [TestCase("en-US")] + [TestCase("fr-FR")] + [TestCase("az")] + [TestCase("tr-TR")] + public void should_replace_all_tokens_for_different_cultures(string culture) + { + var oldCulture = Thread.CurrentThread.CurrentCulture; + try + { + Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); + + _album.ReleaseDate = new DateTime(2021, 1, 15); + + _namingConfig.StandardTrackFormat = "{Release Year}"; + + Subject.BuildTrackFileName(new List { _track1 }, _artist, _album, _trackFile) + .Should().Be("2021"); + } + finally + { + Thread.CurrentThread.CurrentCulture = oldCulture; + } + } + [Test] public void should_replace_artist_name_for_Various_Artists_album() { diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 36ec1227e..b9f3a318b 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Core.Organizer private readonly Logger _logger; private static readonly Regex TitleRegex = new Regex(@"(?\{\{|\}\})|\{(?[- ._\[(]*)(?(?:[a-z0-9]+)(?:(?[- ._]+)(?:[a-z0-9]+))?)(?::(?[a-z0-9]+))?(?[- ._)\]]*)\}", - RegexOptions.Compiled | RegexOptions.IgnoreCase); + RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); public static readonly Regex TrackRegex = new Regex(@"(?\{track(?:\:0+)?})", RegexOptions.Compiled | RegexOptions.IgnoreCase);