Skip to content

Commit

Permalink
Fix ffmpeg download issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
azhuge233 committed Jun 22, 2023
1 parent abae1cc commit 82505ab
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions ConsoleWhisper/Module/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Xabe.FFmpeg;
Expand All @@ -11,8 +12,10 @@ namespace ConsoleWhisper.Module {
internal static class FileHelper {
#region Directories
internal static readonly string AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
internal static readonly string FFmpegLocation = Path.Combine(AppDirectory, "ffmpeg.exe");
internal static readonly string FFprobeLocation = Path.Combine(AppDirectory, "ffprobe.exe");
internal static readonly string FFmpegLocationWindows = Path.Combine(AppDirectory, "ffmpeg.exe");
internal static readonly string FFprobeLocationWindows = Path.Combine(AppDirectory, "ffprobe.exe");
internal static readonly string FFmpegLocationUnix = Path.Combine(AppDirectory, "ffmpeg");
internal static readonly string FFprobeLocationUnix = Path.Combine(AppDirectory, "ffprobe");
internal static readonly string ModelDirectory = Path.Combine(AppDirectory, "Model");
#endregion

Expand Down Expand Up @@ -138,11 +141,18 @@ internal static class FileHelper {

#region downloader
private static async Task DownloadFFmpeg() {
FFmpeg.SetExecutablesPath(AppDirectory);

if (!FFmpegExists()) {
Output.Warn($"FFmpeg not found, start downloading.");
await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official);
File.Delete("version.json");

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
File.Move("ffmpeg.exe", FFmpegLocationWindows);
File.Move("ffprobe.exe", FFprobeLocationWindows);
} else {
File.Move("ffmpeg", FFmpegLocationUnix);
File.Move("ffprobe", FFprobeLocationUnix);
}
}
}

Expand All @@ -156,14 +166,14 @@ internal static class FileHelper {

#region Check if necessary file exists
private static bool ModelExists(string modelFilename) {
Output.Success(ModelDirectory);
return File.Exists(Path.Combine(ModelDirectory, modelFilename));
}

private static bool FFmpegExists() {
Output.Success(FFmpegLocation);
Output.Success(FFprobeLocation);
return File.Exists(FFmpegLocation) && File.Exists(FFprobeLocation);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return File.Exists(FFmpegLocationWindows) && File.Exists(FFprobeLocationWindows);
else
return File.Exists(FFmpegLocationUnix) && File.Exists(FFprobeLocationUnix);
}
#endregion
}
Expand Down

0 comments on commit 82505ab

Please sign in to comment.