From 7b73677bad8ea1ecde4926a418982525820fe61a Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Tue, 21 Dec 2021 09:27:49 -0600 Subject: [PATCH] allow ffmpeg reports on windows (#547) * enable troubleshooting reports on windows * update changelog * tweak changelog --- CHANGELOG.md | 3 ++- .../Commands/UpdateFFmpegSettingsHandler.cs | 21 +++---------------- .../GetConcatProcessByChannelNumberHandler.cs | 9 ++------ ...layoutItemProcessByChannelNumberHandler.cs | 7 +------ ErsatzTV.Core/FFmpeg/FFmpegProcessBuilder.cs | 12 +++++++++++ .../RunOnce/PlatformSettingsService.cs | 9 -------- 6 files changed, 20 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f7a8e5ba..524f4beb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Fixed -- Fix other video and song scanners to include videos contained directly in top-level folders that are added to a library +- Fix other video and song scanners to include videos contained directly in top-level folders that are added to a library +- Allow saving ffmpeg troubleshooting reports on Windows ## [0.3.3-alpha] - 2021-12-12 ### Fixed diff --git a/ErsatzTV.Application/FFmpegProfiles/Commands/UpdateFFmpegSettingsHandler.cs b/ErsatzTV.Application/FFmpegProfiles/Commands/UpdateFFmpegSettingsHandler.cs index efbff0641..ca9cef3dc 100644 --- a/ErsatzTV.Application/FFmpegProfiles/Commands/UpdateFFmpegSettingsHandler.cs +++ b/ErsatzTV.Application/FFmpegProfiles/Commands/UpdateFFmpegSettingsHandler.cs @@ -1,13 +1,11 @@ using System.Diagnostics; using System.IO; -using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using ErsatzTV.Core; using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.Metadata; using ErsatzTV.Core.Interfaces.Repositories; -using ErsatzTV.Core.Interfaces.Runtime; using LanguageExt; namespace ErsatzTV.Application.FFmpegProfiles.Commands @@ -16,16 +14,13 @@ namespace ErsatzTV.Application.FFmpegProfiles.Commands { private readonly IConfigElementRepository _configElementRepository; private readonly ILocalFileSystem _localFileSystem; - private readonly IRuntimeInfo _runtimeInfo; public UpdateFFmpegSettingsHandler( IConfigElementRepository configElementRepository, - ILocalFileSystem localFileSystem, - IRuntimeInfo runtimeInfo) + ILocalFileSystem localFileSystem) { _configElementRepository = configElementRepository; _localFileSystem = localFileSystem; - _runtimeInfo = runtimeInfo; } public Task> Handle( @@ -36,8 +31,8 @@ namespace ErsatzTV.Application.FFmpegProfiles.Commands .Bind(v => v.ToEitherAsync()); private async Task> Validate(UpdateFFmpegSettings request) => - (await FFmpegMustExist(request), await FFprobeMustExist(request), ReportsAreNotSupportedOnWindows(request)) - .Apply((_, _, _) => Unit.Default); + (await FFmpegMustExist(request), await FFprobeMustExist(request)) + .Apply((_, _) => Unit.Default); private Task> FFmpegMustExist(UpdateFFmpegSettings request) => ValidateToolPath(request.Settings.FFmpegPath, "ffmpeg"); @@ -45,16 +40,6 @@ namespace ErsatzTV.Application.FFmpegProfiles.Commands private Task> FFprobeMustExist(UpdateFFmpegSettings request) => ValidateToolPath(request.Settings.FFprobePath, "ffprobe"); - private Validation ReportsAreNotSupportedOnWindows(UpdateFFmpegSettings request) - { - if (request.Settings.SaveReports && _runtimeInfo.IsOSPlatform(OSPlatform.Windows)) - { - return BaseError.New("FFmpeg reports are not supported on Windows"); - } - - return Unit.Default; - } - private async Task> ValidateToolPath(string path, string name) { if (!_localFileSystem.FileExists(path)) diff --git a/ErsatzTV.Application/Streaming/Queries/GetConcatProcessByChannelNumberHandler.cs b/ErsatzTV.Application/Streaming/Queries/GetConcatProcessByChannelNumberHandler.cs index 4a673abb5..9fa8324aa 100644 --- a/ErsatzTV.Application/Streaming/Queries/GetConcatProcessByChannelNumberHandler.cs +++ b/ErsatzTV.Application/Streaming/Queries/GetConcatProcessByChannelNumberHandler.cs @@ -1,11 +1,9 @@ using System; using System.Diagnostics; -using System.Runtime.InteropServices; using System.Threading.Tasks; using ErsatzTV.Core; using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.FFmpeg; -using ErsatzTV.Core.Interfaces.Runtime; using ErsatzTV.Infrastructure.Data; using ErsatzTV.Infrastructure.Extensions; using LanguageExt; @@ -16,16 +14,13 @@ namespace ErsatzTV.Application.Streaming.Queries public class GetConcatProcessByChannelNumberHandler : FFmpegProcessHandler { private readonly IFFmpegProcessService _ffmpegProcessService; - private readonly IRuntimeInfo _runtimeInfo; public GetConcatProcessByChannelNumberHandler( IDbContextFactory dbContextFactory, - IFFmpegProcessService ffmpegProcessService, - IRuntimeInfo runtimeInfo) + IFFmpegProcessService ffmpegProcessService) : base(dbContextFactory) { _ffmpegProcessService = ffmpegProcessService; - _runtimeInfo = runtimeInfo; } protected override async Task> GetProcess( @@ -34,7 +29,7 @@ namespace ErsatzTV.Application.Streaming.Queries Channel channel, string ffmpegPath) { - bool saveReports = !_runtimeInfo.IsOSPlatform(OSPlatform.Windows) && await dbContext.ConfigElements + bool saveReports = await dbContext.ConfigElements .GetValue(ConfigElementKey.FFmpegSaveReports) .Map(result => result.IfNone(false)); diff --git a/ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs b/ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs index 29b592664..3bd396277 100644 --- a/ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs +++ b/ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Runtime.InteropServices; using System.Threading.Tasks; using ErsatzTV.Core; using ErsatzTV.Core.Domain; @@ -15,7 +14,6 @@ using ErsatzTV.Core.Interfaces.Jellyfin; using ErsatzTV.Core.Interfaces.Metadata; using ErsatzTV.Core.Interfaces.Plex; using ErsatzTV.Core.Interfaces.Repositories; -using ErsatzTV.Core.Interfaces.Runtime; using ErsatzTV.Core.Scheduling; using ErsatzTV.Infrastructure.Data; using ErsatzTV.Infrastructure.Extensions; @@ -36,7 +34,6 @@ namespace ErsatzTV.Application.Streaming.Queries private readonly IJellyfinPathReplacementService _jellyfinPathReplacementService; private readonly ILocalFileSystem _localFileSystem; private readonly IPlexPathReplacementService _plexPathReplacementService; - private readonly IRuntimeInfo _runtimeInfo; private readonly ISongVideoGenerator _songVideoGenerator; public GetPlayoutItemProcessByChannelNumberHandler( @@ -49,7 +46,6 @@ namespace ErsatzTV.Application.Streaming.Queries IMediaCollectionRepository mediaCollectionRepository, ITelevisionRepository televisionRepository, IArtistRepository artistRepository, - IRuntimeInfo runtimeInfo, ISongVideoGenerator songVideoGenerator) : base(dbContextFactory) { @@ -61,7 +57,6 @@ namespace ErsatzTV.Application.Streaming.Queries _mediaCollectionRepository = mediaCollectionRepository; _televisionRepository = televisionRepository; _artistRepository = artistRepository; - _runtimeInfo = runtimeInfo; _songVideoGenerator = songVideoGenerator; } @@ -142,7 +137,7 @@ namespace ErsatzTV.Application.Streaming.Queries ffmpegPath); } - bool saveReports = !_runtimeInfo.IsOSPlatform(OSPlatform.Windows) && await dbContext.ConfigElements + bool saveReports = await dbContext.ConfigElements .GetValue(ConfigElementKey.FFmpegSaveReports) .Map(result => result.IfNone(false)); diff --git a/ErsatzTV.Core/FFmpeg/FFmpegProcessBuilder.cs b/ErsatzTV.Core/FFmpeg/FFmpegProcessBuilder.cs index a27cb8630..f1fa9df34 100644 --- a/ErsatzTV.Core/FFmpeg/FFmpegProcessBuilder.cs +++ b/ErsatzTV.Core/FFmpeg/FFmpegProcessBuilder.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; using System.Text; using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.FFmpeg; @@ -641,6 +642,17 @@ namespace ErsatzTV.Core.FFmpeg string fileName = _isConcat ? Path.Combine(FileSystemLayout.FFmpegReportsFolder, "ffmpeg-%t-concat.log") : Path.Combine(FileSystemLayout.FFmpegReportsFolder, "ffmpeg-%t-transcode.log"); + + // rework filename in a format that works on windows + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + // \ is escape, so use / for directory separators + fileName = fileName.Replace(@"\", @"/"); + + // colon after drive letter needs to be escaped + fileName = fileName.Replace(@":/", @"\:/"); + } + startInfo.EnvironmentVariables.Add("FFREPORT", $"file={fileName}:level=32"); } diff --git a/ErsatzTV/Services/RunOnce/PlatformSettingsService.cs b/ErsatzTV/Services/RunOnce/PlatformSettingsService.cs index 30c8a5850..418a6ada1 100644 --- a/ErsatzTV/Services/RunOnce/PlatformSettingsService.cs +++ b/ErsatzTV/Services/RunOnce/PlatformSettingsService.cs @@ -2,9 +2,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.Metadata; -using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.Core.Interfaces.Runtime; using ErsatzTV.Infrastructure.Data; using Microsoft.Extensions.Caching.Memory; @@ -33,13 +31,6 @@ namespace ErsatzTV.Services.RunOnce await using TvContext dbContext = scope.ServiceProvider.GetRequiredService(); IRuntimeInfo runtimeInfo = scope.ServiceProvider.GetRequiredService(); - if (runtimeInfo != null && runtimeInfo.IsOSPlatform(OSPlatform.Windows)) - { - _logger.LogInformation("Disabling ffmpeg reports on Windows platform"); - IConfigElementRepository repo = scope.ServiceProvider.GetRequiredService(); - await repo.Upsert(ConfigElementKey.FFmpegSaveReports, false); - } - if (runtimeInfo != null && runtimeInfo.IsOSPlatform(OSPlatform.Linux) && System.IO.Directory.Exists("/dev/dri")) {