using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.FFmpeg.OutputFormat; namespace ErsatzTV.Application.FFmpegProfiles; public class GetFFmpegSettingsHandler(IConfigElementRepository configElementRepository) : IRequestHandler { public async Task Handle( GetFFmpegSettings request, CancellationToken cancellationToken) { Option ffmpegPath = await configElementRepository.GetValue( ConfigElementKey.FFmpegPath, cancellationToken); Option ffprobePath = await configElementRepository.GetValue( ConfigElementKey.FFprobePath, cancellationToken); Option defaultFFmpegProfileId = await configElementRepository.GetValue(ConfigElementKey.FFmpegDefaultProfileId, cancellationToken); Option saveReports = await configElementRepository.GetValue(ConfigElementKey.FFmpegSaveReports, cancellationToken); Option preferredAudioLanguageCode = await configElementRepository.GetValue( ConfigElementKey.FFmpegPreferredLanguageCode, cancellationToken); Option useEmbeddedSubtitles = await configElementRepository.GetValue( ConfigElementKey.FFmpegUseEmbeddedSubtitles, cancellationToken); Option extractEmbeddedSubtitles = await configElementRepository.GetValue( ConfigElementKey.FFmpegExtractEmbeddedSubtitles, cancellationToken); Option probeForInterlacedFrames = await configElementRepository.GetValue( ConfigElementKey.FFmpegProbeForInterlacedFrames, cancellationToken); Option watermark = await configElementRepository.GetValue(ConfigElementKey.FFmpegGlobalWatermarkId, cancellationToken); Option fallbackFiller = await configElementRepository.GetValue( ConfigElementKey.FFmpegGlobalFallbackFillerId, cancellationToken); Option hlsSegmenterIdleTimeout = await configElementRepository.GetValue(ConfigElementKey.FFmpegSegmenterTimeout, cancellationToken); Option workAheadSegmenterLimit = await configElementRepository.GetValue(ConfigElementKey.FFmpegWorkAheadSegmenters, cancellationToken); Option initialSegmentCount = await configElementRepository.GetValue(ConfigElementKey.FFmpegInitialSegmentCount, cancellationToken); Option outputFormatKind = await configElementRepository.GetValue( ConfigElementKey.FFmpegHlsDirectOutputFormat, cancellationToken); Option defaultMpegTsScript = await configElementRepository.GetValue( ConfigElementKey.FFmpegDefaultMpegTsScript, cancellationToken); var result = new FFmpegSettingsViewModel { FFmpegPath = await ffmpegPath.IfNoneAsync(string.Empty), FFprobePath = await ffprobePath.IfNoneAsync(string.Empty), DefaultFFmpegProfileId = await defaultFFmpegProfileId.IfNoneAsync(0), SaveReports = await saveReports.IfNoneAsync(false), UseEmbeddedSubtitles = await useEmbeddedSubtitles.IfNoneAsync(true), ExtractEmbeddedSubtitles = await extractEmbeddedSubtitles.IfNoneAsync(false), ProbeForInterlacedFrames = await probeForInterlacedFrames.IfNoneAsync(false), PreferredAudioLanguageCode = await preferredAudioLanguageCode.IfNoneAsync("eng"), HlsSegmenterIdleTimeout = await hlsSegmenterIdleTimeout.IfNoneAsync(60), WorkAheadSegmenterLimit = await workAheadSegmenterLimit.IfNoneAsync(1), InitialSegmentCount = await initialSegmentCount.IfNoneAsync(1), HlsDirectOutputFormat = await outputFormatKind.IfNoneAsync(OutputFormatKind.MpegTs), DefaultMpegTsScript = await defaultMpegTsScript.IfNoneAsync("default"), }; foreach (int watermarkId in watermark) { result.GlobalWatermarkId = watermarkId; } foreach (int fallbackFillerId in fallbackFiller) { result.GlobalFallbackFillerId = fallbackFillerId; } return result; } }