using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.FFmpeg.OutputFormat; namespace ErsatzTV.Application.FFmpegProfiles; public class GetFFmpegSettingsHandler : IRequestHandler { private readonly IConfigElementRepository _configElementRepository; public GetFFmpegSettingsHandler(IConfigElementRepository configElementRepository) => _configElementRepository = configElementRepository; public async Task Handle( GetFFmpegSettings request, CancellationToken cancellationToken) { Option ffmpegPath = await _configElementRepository.GetValue(ConfigElementKey.FFmpegPath); Option ffprobePath = await _configElementRepository.GetValue(ConfigElementKey.FFprobePath); Option defaultFFmpegProfileId = await _configElementRepository.GetValue(ConfigElementKey.FFmpegDefaultProfileId); Option saveReports = await _configElementRepository.GetValue(ConfigElementKey.FFmpegSaveReports); Option preferredAudioLanguageCode = await _configElementRepository.GetValue(ConfigElementKey.FFmpegPreferredLanguageCode); Option useEmbeddedSubtitles = await _configElementRepository.GetValue(ConfigElementKey.FFmpegUseEmbeddedSubtitles); Option extractEmbeddedSubtitles = await _configElementRepository.GetValue(ConfigElementKey.FFmpegExtractEmbeddedSubtitles); Option watermark = await _configElementRepository.GetValue(ConfigElementKey.FFmpegGlobalWatermarkId); Option fallbackFiller = await _configElementRepository.GetValue(ConfigElementKey.FFmpegGlobalFallbackFillerId); Option hlsSegmenterIdleTimeout = await _configElementRepository.GetValue(ConfigElementKey.FFmpegSegmenterTimeout); Option workAheadSegmenterLimit = await _configElementRepository.GetValue(ConfigElementKey.FFmpegWorkAheadSegmenters); Option initialSegmentCount = await _configElementRepository.GetValue(ConfigElementKey.FFmpegInitialSegmentCount); Option outputFormatKind = await _configElementRepository.GetValue(ConfigElementKey.FFmpegHlsDirectOutputFormat); 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), 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) }; foreach (int watermarkId in watermark) { result.GlobalWatermarkId = watermarkId; } foreach (int fallbackFillerId in fallbackFiller) { result.GlobalFallbackFillerId = fallbackFillerId; } return result; } }