From 9d076277813b0689871f71cd4772cd2cca6bb347 Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Sat, 21 Aug 2021 05:57:39 -0500 Subject: [PATCH] fix ffprobe parsing in some cultures (#337) --- CHANGELOG.md | 4 +++ .../Metadata/LocalStatisticsProviderTests.cs | 36 +++++++++++++++++++ ErsatzTV.Core/ErsatzTV.Core.csproj | 6 ++++ .../Metadata/LocalStatisticsProvider.cs | 5 +-- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 ErsatzTV.Core.Tests/Metadata/LocalStatisticsProviderTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a638f349..6718f023f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Fix bug parsing ffprobe output in cultures where `.` is a group/thousands separator + - This bug likely prevented ETV from scheduling correctly or working at all in those cultures + - After installing a version with this fix, affected content will need to be removed from ETV and re-added ## [0.0.53-alpha] - 2021-08-01 ### Fixed diff --git a/ErsatzTV.Core.Tests/Metadata/LocalStatisticsProviderTests.cs b/ErsatzTV.Core.Tests/Metadata/LocalStatisticsProviderTests.cs new file mode 100644 index 000000000..8662befa9 --- /dev/null +++ b/ErsatzTV.Core.Tests/Metadata/LocalStatisticsProviderTests.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using ErsatzTV.Core.Domain; +using ErsatzTV.Core.Interfaces.Metadata; +using ErsatzTV.Core.Interfaces.Repositories; +using ErsatzTV.Core.Metadata; +using FluentAssertions; +using Microsoft.Extensions.Logging; +using Moq; +using NUnit.Framework; + +namespace ErsatzTV.Core.Tests.Metadata +{ + [TestFixture] + public class LocalStatisticsProviderTests + { + [Test] + // this needs to be a culture where '.' is a group separator + [SetCulture("it-IT")] + public void Test() + { + var provider = new LocalStatisticsProvider( + new Mock().Object, + new Mock().Object, + new Mock>().Object); + + var input = new LocalStatisticsProvider.FFprobe( + new LocalStatisticsProvider.FFprobeFormat("123.45"), + new List()); + + MediaVersion result = provider.ProjectToMediaVersion("test", input); + + result.Duration.Should().Be(TimeSpan.FromSeconds(123.45)); + } + } +} diff --git a/ErsatzTV.Core/ErsatzTV.Core.csproj b/ErsatzTV.Core/ErsatzTV.Core.csproj index 9eb27ac12..e47b39a0f 100644 --- a/ErsatzTV.Core/ErsatzTV.Core.csproj +++ b/ErsatzTV.Core/ErsatzTV.Core.csproj @@ -24,5 +24,11 @@ + + + + <_Parameter1>ErsatzTV.Core.Tests + + diff --git a/ErsatzTV.Core/Metadata/LocalStatisticsProvider.cs b/ErsatzTV.Core/Metadata/LocalStatisticsProvider.cs index 79375494b..a8682ee9c 100644 --- a/ErsatzTV.Core/Metadata/LocalStatisticsProvider.cs +++ b/ErsatzTV.Core/Metadata/LocalStatisticsProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.Linq; using System.Threading.Tasks; using ErsatzTV.Core.Domain; @@ -126,7 +127,7 @@ namespace ErsatzTV.Core.Metadata }); } - private MediaVersion ProjectToMediaVersion(string path, FFprobe probeOutput) => + internal MediaVersion ProjectToMediaVersion(string path, FFprobe probeOutput) => Optional(probeOutput) .Filter(json => json?.format != null && json.streams != null) .ToValidation("Unable to parse ffprobe output") @@ -137,7 +138,7 @@ namespace ErsatzTV.Core.Metadata var version = new MediaVersion { Name = "Main", DateAdded = DateTime.UtcNow, Streams = new List() }; - if (double.TryParse(json.format.duration, out double duration)) + if (double.TryParse(json.format.duration, NumberStyles.Number, CultureInfo.InvariantCulture, out double duration)) { var seconds = TimeSpan.FromSeconds(duration); version.Duration = seconds;