mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
38 lines
1.2 KiB
using System.IO.Abstractions; |
|
using System.Text; |
|
using CliWrap; |
|
using ErsatzTV.Core; |
|
|
|
namespace ErsatzTV.Application.Streaming; |
|
|
|
public class GetNextVersionHandler(IFileSystem fileSystem) |
|
: NextChannelHandlerBase(fileSystem), IRequestHandler<GetNextVersion, string> |
|
{ |
|
public async Task<string> Handle(GetNextVersion request, CancellationToken cancellationToken) |
|
{ |
|
try |
|
{ |
|
Validation<BaseError, string> validation = await ChannelBinaryMustExist(); |
|
foreach (string channelBinary in validation.SuccessToSeq()) |
|
{ |
|
var stdOutBuffer = new StringBuilder(); |
|
CommandResult command = await Cli.Wrap(channelBinary) |
|
.WithArguments(["--version"]) |
|
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer)) |
|
.WithValidation(CommandResultValidation.None) |
|
.ExecuteAsync(cancellationToken); |
|
|
|
if (command.IsSuccess) |
|
{ |
|
return stdOutBuffer.ToString().Replace("ersatztv-channel", string.Empty).Trim(); |
|
} |
|
} |
|
} |
|
catch (Exception) |
|
{ |
|
// do nothing |
|
} |
|
|
|
return "n/a"; |
|
} |
|
}
|
|
|