-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
307 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
starsky/starsky.foundation.video/GetDependencies/FfMpegPreflightRunCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Medallion.Shell; | ||
using starsky.foundation.injection; | ||
using starsky.foundation.platform.Architecture; | ||
using starsky.foundation.platform.Interfaces; | ||
using starsky.foundation.platform.Models; | ||
using starsky.foundation.video.GetDependencies.Interfaces; | ||
|
||
namespace starsky.foundation.video.GetDependencies; | ||
|
||
[Service(typeof(IFfMpegPreflightRunCheck), InjectionLifetime = InjectionLifetime.Scoped)] | ||
public class FfMpegPreflightRunCheck(AppSettings appSettings, IWebLogger logger) | ||
: IFfMpegPreflightRunCheck | ||
{ | ||
public async Task<bool> TryRun() | ||
{ | ||
var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); | ||
return await TryRun(currentArchitecture); | ||
} | ||
|
||
public async Task<bool> TryRun(string currentArchitecture) | ||
{ | ||
var exePath = new FfmpegExePath(appSettings).GetExePath(currentArchitecture); | ||
|
||
try | ||
{ | ||
var result = await Command.Run(exePath, "-version").Task; | ||
|
||
// Check if the command was successful | ||
if ( result.Success ) | ||
{ | ||
var output = result.StandardOutput; | ||
if ( output.Contains("ffmpeg", StringComparison.OrdinalIgnoreCase) ) | ||
{ | ||
return true; | ||
} | ||
|
||
logger.LogError($"[{nameof(FfMpegPreflightRunCheck)}] Invalid application"); | ||
} | ||
else | ||
{ | ||
logger.LogError($"[{nameof(FfMpegPreflightRunCheck)}] " + | ||
$"Command failed with exit code " + | ||
$"{result.ExitCode}: {result.StandardError}"); | ||
} | ||
|
||
return false; | ||
} | ||
catch ( Exception exception ) | ||
{ | ||
logger.LogError($"[{nameof(FfMpegPreflightRunCheck)}] " + | ||
$"An error occurred while checking FFMpeg: " + | ||
$"{exception.Message}"); | ||
|
||
return false; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
starsky/starsky.foundation.video/GetDependencies/Interfaces/IFfMpegPreflightRunCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace starsky.foundation.video.GetDependencies.Interfaces; | ||
|
||
public interface IFfMpegPreflightRunCheck | ||
{ | ||
Task<bool> TryRun(); | ||
Task<bool> TryRun(string currentArchitecture); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
starsky/starskytest/FakeMocks/FakeIFfMpegPreflightRunCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Threading.Tasks; | ||
using starsky.foundation.platform.Architecture; | ||
using starsky.foundation.platform.Models; | ||
using starsky.foundation.storage.Interfaces; | ||
using starsky.foundation.video.GetDependencies; | ||
using starsky.foundation.video.GetDependencies.Interfaces; | ||
|
||
namespace starskytest.FakeMocks; | ||
|
||
public class FakeIFfMpegPreflightRunCheck : IFfMpegPreflightRunCheck | ||
{ | ||
private readonly AppSettings? _appSettings; | ||
private readonly IStorage? _storage; | ||
|
||
public FakeIFfMpegPreflightRunCheck(IStorage? storage = null, AppSettings? appSettings = null) | ||
{ | ||
_storage = storage; | ||
_appSettings = appSettings; | ||
} | ||
|
||
public async Task<bool> TryRun() | ||
{ | ||
var currentArchitecture = CurrentArchitecture.GetCurrentRuntimeIdentifier(); | ||
return await TryRun(currentArchitecture); | ||
} | ||
|
||
public Task<bool> TryRun(string currentArchitecture) | ||
{ | ||
if ( _appSettings == null || _storage == null ) | ||
{ | ||
return Task.FromResult(false); | ||
} | ||
|
||
var exePath = new FfmpegExePath(_appSettings).GetExePath(currentArchitecture); | ||
return Task.FromResult(_storage.ExistFile(exePath)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.