fix ffprobe parsing in some cultures (#337)

This commit is contained in:
Jason Dove
2021-08-21 05:57:39 -05:00
committed by GitHub
parent d3c8914758
commit 9d07627781
4 changed files with 49 additions and 2 deletions
+4
View File
@@ -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
@@ -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<IMetadataRepository>().Object,
new Mock<ILocalFileSystem>().Object,
new Mock<ILogger<LocalStatisticsProvider>>().Object);
var input = new LocalStatisticsProvider.FFprobe(
new LocalStatisticsProvider.FFprobeFormat("123.45"),
new List<LocalStatisticsProvider.FFprobeStream>());
MediaVersion result = provider.ProjectToMediaVersion("test", input);
result.Duration.Should().Be(TimeSpan.FromSeconds(123.45));
}
}
}
+6
View File
@@ -24,5 +24,11 @@
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>ErsatzTV.Core.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
@@ -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<BaseError>("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<MediaStream>() };
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;