|
|
|
@ -1,13 +1,11 @@ |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.IO; |
|
|
|
using System.IO; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
|
|
|
using System.Threading; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using ErsatzTV.Core; |
|
|
|
using ErsatzTV.Core; |
|
|
|
using ErsatzTV.Core.Domain; |
|
|
|
using ErsatzTV.Core.Domain; |
|
|
|
using ErsatzTV.Core.Interfaces.Metadata; |
|
|
|
using ErsatzTV.Core.Interfaces.Metadata; |
|
|
|
using ErsatzTV.Core.Interfaces.Repositories; |
|
|
|
using ErsatzTV.Core.Interfaces.Repositories; |
|
|
|
using ErsatzTV.Core.Interfaces.Runtime; |
|
|
|
|
|
|
|
using LanguageExt; |
|
|
|
using LanguageExt; |
|
|
|
|
|
|
|
|
|
|
|
namespace ErsatzTV.Application.FFmpegProfiles.Commands |
|
|
|
namespace ErsatzTV.Application.FFmpegProfiles.Commands |
|
|
|
@ -16,16 +14,13 @@ namespace ErsatzTV.Application.FFmpegProfiles.Commands |
|
|
|
{ |
|
|
|
{ |
|
|
|
private readonly IConfigElementRepository _configElementRepository; |
|
|
|
private readonly IConfigElementRepository _configElementRepository; |
|
|
|
private readonly ILocalFileSystem _localFileSystem; |
|
|
|
private readonly ILocalFileSystem _localFileSystem; |
|
|
|
private readonly IRuntimeInfo _runtimeInfo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UpdateFFmpegSettingsHandler( |
|
|
|
public UpdateFFmpegSettingsHandler( |
|
|
|
IConfigElementRepository configElementRepository, |
|
|
|
IConfigElementRepository configElementRepository, |
|
|
|
ILocalFileSystem localFileSystem, |
|
|
|
ILocalFileSystem localFileSystem) |
|
|
|
IRuntimeInfo runtimeInfo) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
_configElementRepository = configElementRepository; |
|
|
|
_configElementRepository = configElementRepository; |
|
|
|
_localFileSystem = localFileSystem; |
|
|
|
_localFileSystem = localFileSystem; |
|
|
|
_runtimeInfo = runtimeInfo; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Task<Either<BaseError, Unit>> Handle( |
|
|
|
public Task<Either<BaseError, Unit>> Handle( |
|
|
|
@ -36,8 +31,8 @@ namespace ErsatzTV.Application.FFmpegProfiles.Commands |
|
|
|
.Bind(v => v.ToEitherAsync()); |
|
|
|
.Bind(v => v.ToEitherAsync()); |
|
|
|
|
|
|
|
|
|
|
|
private async Task<Validation<BaseError, Unit>> Validate(UpdateFFmpegSettings request) => |
|
|
|
private async Task<Validation<BaseError, Unit>> Validate(UpdateFFmpegSettings request) => |
|
|
|
(await FFmpegMustExist(request), await FFprobeMustExist(request), ReportsAreNotSupportedOnWindows(request)) |
|
|
|
(await FFmpegMustExist(request), await FFprobeMustExist(request)) |
|
|
|
.Apply((_, _, _) => Unit.Default); |
|
|
|
.Apply((_, _) => Unit.Default); |
|
|
|
|
|
|
|
|
|
|
|
private Task<Validation<BaseError, Unit>> FFmpegMustExist(UpdateFFmpegSettings request) => |
|
|
|
private Task<Validation<BaseError, Unit>> FFmpegMustExist(UpdateFFmpegSettings request) => |
|
|
|
ValidateToolPath(request.Settings.FFmpegPath, "ffmpeg"); |
|
|
|
ValidateToolPath(request.Settings.FFmpegPath, "ffmpeg"); |
|
|
|
@ -45,16 +40,6 @@ namespace ErsatzTV.Application.FFmpegProfiles.Commands |
|
|
|
private Task<Validation<BaseError, Unit>> FFprobeMustExist(UpdateFFmpegSettings request) => |
|
|
|
private Task<Validation<BaseError, Unit>> FFprobeMustExist(UpdateFFmpegSettings request) => |
|
|
|
ValidateToolPath(request.Settings.FFprobePath, "ffprobe"); |
|
|
|
ValidateToolPath(request.Settings.FFprobePath, "ffprobe"); |
|
|
|
|
|
|
|
|
|
|
|
private Validation<BaseError, Unit> 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<Validation<BaseError, Unit>> ValidateToolPath(string path, string name) |
|
|
|
private async Task<Validation<BaseError, Unit>> ValidateToolPath(string path, string name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!_localFileSystem.FileExists(path)) |
|
|
|
if (!_localFileSystem.FileExists(path)) |
|
|
|
|