mirror of https://github.com/ErsatzTV/ErsatzTV.git
17 changed files with 228 additions and 29 deletions
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
using ErsatzTV.Core; |
||||
|
||||
namespace ErsatzTV.Application.Streaming; |
||||
|
||||
public record GetSeekTextSubtitleProcess(string SubtitlePath, TimeSpan Seek) |
||||
: IRequest<Either<BaseError, SeekTextSubtitleProcess>>; |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
using CliWrap; |
||||
using ErsatzTV.Core; |
||||
using ErsatzTV.Core.Domain; |
||||
using ErsatzTV.Core.Interfaces.FFmpeg; |
||||
using ErsatzTV.Infrastructure.Data; |
||||
using ErsatzTV.Infrastructure.Extensions; |
||||
using Microsoft.EntityFrameworkCore; |
||||
|
||||
namespace ErsatzTV.Application.Streaming; |
||||
|
||||
public class GetSeekTextSubtitleProcessHandler( |
||||
IDbContextFactory<TvContext> dbContextFactory, |
||||
IFFmpegProcessService ffmpegProcessService) |
||||
: IRequestHandler<GetSeekTextSubtitleProcess, |
||||
Either<BaseError, SeekTextSubtitleProcess>> |
||||
{ |
||||
public async Task<Either<BaseError, SeekTextSubtitleProcess>> Handle( |
||||
GetSeekTextSubtitleProcess request, |
||||
CancellationToken cancellationToken) |
||||
{ |
||||
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
||||
Validation<BaseError, string> validation = await Validate(dbContext); |
||||
return await validation.Match( |
||||
ffmpegPath => GetProcess(request, ffmpegPath), |
||||
error => Task.FromResult<Either<BaseError, SeekTextSubtitleProcess>>(error.Join())); |
||||
} |
||||
|
||||
private async Task<Either<BaseError, SeekTextSubtitleProcess>> GetProcess( |
||||
GetSeekTextSubtitleProcess request, |
||||
string ffmpegPath) |
||||
{ |
||||
Command process = await ffmpegProcessService.SeekTextSubtitle( |
||||
ffmpegPath, |
||||
request.SubtitlePath, |
||||
request.Seek); |
||||
|
||||
return new SeekTextSubtitleProcess(process); |
||||
} |
||||
|
||||
private static async Task<Validation<BaseError, string>> Validate(TvContext dbContext) => |
||||
await FFmpegPathMustExist(dbContext); |
||||
|
||||
private static Task<Validation<BaseError, string>> FFmpegPathMustExist(TvContext dbContext) => |
||||
dbContext.ConfigElements.GetValue<string>(ConfigElementKey.FFmpegPath) |
||||
.FilterT(File.Exists) |
||||
.Map(maybePath => maybePath.ToValidation<BaseError>("FFmpeg path does not exist on filesystem")); |
||||
} |
||||
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
using CliWrap; |
||||
|
||||
namespace ErsatzTV.Application.Streaming; |
||||
|
||||
public record SeekTextSubtitleProcess(Command Process); |
||||
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
using ErsatzTV.FFmpeg.Environment; |
||||
|
||||
namespace ErsatzTV.FFmpeg.OutputFormat; |
||||
|
||||
public class OutputFormatAss : IPipelineStep |
||||
{ |
||||
public EnvironmentVariable[] EnvironmentVariables => []; |
||||
public string[] GlobalOptions => []; |
||||
public string[] InputOptions(InputFile inputFile) => []; |
||||
public string[] FilterOptions => []; |
||||
public string[] OutputOptions => ["-f", "ass"]; |
||||
public FrameState NextState(FrameState currentState) => currentState; |
||||
} |
||||
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
using ErsatzTV.FFmpeg.Environment; |
||||
|
||||
namespace ErsatzTV.FFmpeg.OutputFormat; |
||||
|
||||
public class OutputFormatSrt : IPipelineStep |
||||
{ |
||||
public EnvironmentVariable[] EnvironmentVariables => []; |
||||
public string[] GlobalOptions => []; |
||||
public string[] InputOptions(InputFile inputFile) => []; |
||||
public string[] FilterOptions => []; |
||||
public string[] OutputOptions => ["-f", "srt"]; |
||||
public FrameState NextState(FrameState currentState) => currentState; |
||||
} |
||||
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
using ErsatzTV.FFmpeg.Environment; |
||||
|
||||
namespace ErsatzTV.FFmpeg.OutputFormat; |
||||
|
||||
public class OutputFormatWebVtt : IPipelineStep |
||||
{ |
||||
public EnvironmentVariable[] EnvironmentVariables => []; |
||||
public string[] GlobalOptions => []; |
||||
public string[] InputOptions(InputFile inputFile) => []; |
||||
public string[] FilterOptions => []; |
||||
public string[] OutputOptions => ["-f", "webvtt"]; |
||||
public FrameState NextState(FrameState currentState) => currentState; |
||||
} |
||||
Loading…
Reference in new issue