Skip to content

Commit

Permalink
recursive file finding
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbang committed Sep 27, 2020
1 parent c6e4933 commit cf410ee
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 2 deletions.
Binary file modified gene-pool-backend/.vs/gene-pool-backend/v16/.suo
Binary file not shown.
8 changes: 8 additions & 0 deletions gene-pool-backend/Controllers/SpeechToTextController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,13 @@ public async Task<IActionResult> LinkToWav(dynamic request) {
return BadRequest("Unknown error during transcription");
}
}

[HttpPost]
[Route("debug_find_file")]
public async Task<IActionResult> FindFile(dynamic request) {
var body = JsonConvert.DeserializeObject<dynamic>(request.ToString());

return Ok(FileHelper.FindFile("ffmpeg.exe"));
}
}
}
43 changes: 41 additions & 2 deletions gene-pool-backend/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,50 @@

namespace gene_pool_backend {
public static class FileHelper {
private static string PathToFfmpeg = "ffmpeg.exe";
private static readonly string ffmpegName = "ffmpeg.exe";

private static string ProcessDirectory(string targetDirectory, string fileName) {
string path = "";

// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string filePath in fileEntries) {
if (Path.GetFileName(filePath).Equals(fileName)) {
return filePath;
}
}

// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries) {
path = ProcessDirectory(subdirectory, fileName);
if (path.Length > 0) {
return path;
}
}

return path;
}

public static string FindFile(string fileName) {
string path = Directory.GetCurrentDirectory();
Console.WriteLine(path);

path = ProcessDirectory(path, fileName);

if (path.Length > 0) {
Console.WriteLine($"Found exe: {path}");
} else {
Console.WriteLine("Did not find path");
}

return path;
}

public static dynamic ToWavFormat(string pathToMp4, string pathToWav) {
string path = FindFile(ffmpegName);
var ffmpeg = new Process {
StartInfo = { UseShellExecute = false, RedirectStandardError = true, FileName = PathToFfmpeg }
StartInfo = { UseShellExecute = false, RedirectStandardError = true, FileName = path }
};

var arguments =
Expand Down
Binary file not shown.
Binary file modified gene-pool-backend/bin/Debug/netcoreapp3.1/gene-pool-backend.pdb
Binary file not shown.
Binary file removed gene-pool-backend/ffmpeg.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified gene-pool-backend/obj/Debug/netcoreapp3.1/gene-pool-backend.pdb
Binary file not shown.

0 comments on commit cf410ee

Please sign in to comment.