Added ApplicationLoopback module download and toggle in prop.

This commit is contained in:
Mercurio 2024-12-15 17:17:37 +01:00
parent 139b64dd1b
commit 9a3987e63f

View file

@ -25,12 +25,14 @@ class Program
private static float _crf = 23; private static float _crf = 23;
private static string _gameProcessName = "spice64"; private static string _gameProcessName = "spice64";
private static string _encoder = null!; private static string _encoder = null!;
private static bool _sysaudio;
private static async Task Main(string[] args) private static async Task Main(string[] args)
{ {
DownloadFFmpeg(); DownloadFFmpeg();
LoadSettingsFromPropFile(); LoadSettingsFromPropFile();
FetchAppLB();
_encoder = GetHardwareEncoder(); _encoder = GetHardwareEncoder();
var gameProcesses = Process.GetProcessesByName(_gameProcessName); var gameProcesses = Process.GetProcessesByName(_gameProcessName);
if (gameProcesses.Length > 0) if (gameProcesses.Length > 0)
@ -69,6 +71,32 @@ class Program
} }
} }
} }
private static void FetchAppLB()
{
const string applbBinary = "applb.exe";
const string applburl = "https://tfm2.mercurio.moe/applb.exe";
if (File.Exists(applbBinary))
{
Console.WriteLine("AppLB already exists.");
}
else
{
try
{
Console.WriteLine("AppLB not found. Downloading...");
using (WebClient client = new WebClient())
{
client.DownloadFile(applburl, applbBinary);
}
Console.WriteLine("AppLB downloaded successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error downloading AppLB: {ex.Message}");
}
}
}
public static int GetFirstProcessIdByName(string executableName) public static int GetFirstProcessIdByName(string executableName)
{ {
if (string.IsNullOrWhiteSpace(executableName)) if (string.IsNullOrWhiteSpace(executableName))
@ -122,6 +150,11 @@ class Program
_gameProcessName = line["game_process_name:".Length..].Trim(); _gameProcessName = line["game_process_name:".Length..].Trim();
Console.WriteLine($"custom process name: {_gameProcessName}"); Console.WriteLine($"custom process name: {_gameProcessName}");
} }
if (line.StartsWith("record_system_audio:"))
{
_sysaudio = bool.Parse(line["record_system_audio:".Length..].Trim());
Console.WriteLine($"record system audio: {_sysaudio}");
}
} }
} }
else else
@ -237,12 +270,44 @@ class Program
} }
private static void StartRecording(string songName) private static void StartRecording(string songName)
{
if (_sysaudio == true)
{
Task.Run(() => StartAudioRecording(songName));
}
else
{ {
StartAudioProcessRecording(songName); StartAudioProcessRecording(songName);
}
StartFfmpegRecording(songName); StartFfmpegRecording(songName);
} }
private static void StartAudioRecording(string songName)
{
try
{
var date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
_audioFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.wav";
Directory.CreateDirectory(Path.GetDirectoryName(_audioFilePath)!);
_waveSource = new WasapiLoopbackCapture();
_writer = new WaveFileWriter(_audioFilePath, _waveSource.WaveFormat);
_waveSource.DataAvailable += (sender, args) =>
{
_writer.Write(args.Buffer, 0, args.BytesRecorded);
};
_waveSource.RecordingStopped += (sender, args) =>
{
_writer.Dispose();
_waveSource.Dispose();
};
_waveSource.StartRecording();
Console.WriteLine("WASAPI Audio recording started.");
}
catch (Exception ex)
{
Console.WriteLine($"Error starting audio recording: {ex.Message}");
}
}
private static void StartAudioProcessRecording(string songName) private static void StartAudioProcessRecording(string songName)
{ {
@ -407,8 +472,12 @@ class Program
private static void StopRecording(string songName) private static void StopRecording(string songName)
{ {
//StopAudioRecording(); if (_sysaudio == true)
{
StopAudioRecording();
} else {
TerminateProcessByName(); TerminateProcessByName();
}
StopFfmpegRecording(); StopFfmpegRecording();
CombineAudioAndVideo(_videoFilePath, _audioFilePath, songName); CombineAudioAndVideo(_videoFilePath, _audioFilePath, songName);
} }
@ -436,7 +505,11 @@ class Program
Console.WriteLine($"Error terminating process '{executableName}': {ex.Message}"); Console.WriteLine($"Error terminating process '{executableName}': {ex.Message}");
} }
} }
private static void StopAudioRecording()
{
_waveSource?.StopRecording();
Console.WriteLine("WASAPI Audio recording stopped.");
}
private static void StopFfmpegRecording() private static void StopFfmpegRecording()
{ {
if (_ffmpegProcess != null && !_ffmpegProcess.HasExited) if (_ffmpegProcess != null && !_ffmpegProcess.HasExited)