Browse Source

fix ffprobe parsing in some cultures (#337)

pull/338/head
Jason Dove 5 years ago committed by GitHub
parent
commit
9d07627781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CHANGELOG.md
  2. 36
      ErsatzTV.Core.Tests/Metadata/LocalStatisticsProviderTests.cs
  3. 6
      ErsatzTV.Core/ErsatzTV.Core.csproj
  4. 5
      ErsatzTV.Core/Metadata/LocalStatisticsProvider.cs

4
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/). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased] ## [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 ## [0.0.53-alpha] - 2021-08-01
### Fixed ### Fixed

36
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<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
ErsatzTV.Core/ErsatzTV.Core.csproj

@ -24,5 +24,11 @@
<PackageReference Include="Serilog" Version="2.10.0" /> <PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" /> <PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>ErsatzTV.Core.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project> </Project>

5
ErsatzTV.Core/Metadata/LocalStatisticsProvider.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using ErsatzTV.Core.Domain; 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) Optional(probeOutput)
.Filter(json => json?.format != null && json.streams != null) .Filter(json => json?.format != null && json.streams != null)
.ToValidation<BaseError>("Unable to parse ffprobe output") .ToValidation<BaseError>("Unable to parse ffprobe output")
@ -137,7 +138,7 @@ namespace ErsatzTV.Core.Metadata
var version = new MediaVersion var version = new MediaVersion
{ Name = "Main", DateAdded = DateTime.UtcNow, Streams = new List<MediaStream>() }; { 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); var seconds = TimeSpan.FromSeconds(duration);
version.Duration = seconds; version.Duration = seconds;

Loading…
Cancel
Save