Add CLI for MP3 extraction

This commit is contained in:
Meerkov 2021-10-05 20:42:27 -07:00 committed by James Groom
parent 6a43277ae3
commit 89b459c44d
3 changed files with 31 additions and 5 deletions

View File

@ -122,9 +122,9 @@ namespace BizHawk.Client.DiscoHawk
using var disc = Disc.LoadAutomagic(file);
var path = Path.GetDirectoryName(file);
var filename = Path.GetFileNameWithoutExtension(file);
static bool? PromptForOverwrite()
static bool? PromptForOverwrite(string mp3Path)
=> MessageBox.Show(
"Do you want to overwrite existing files? Choosing \"No\" will simply skip those. You could also \"Cancel\" the extraction entirely.",
$"Do you want to overwrite existing files? Choosing \"No\" will simply skip those. You could also \"Cancel\" the extraction entirely.\n\ncaused by file: {mp3Path}",
"File to extract already exists",
MessageBoxButtons.YesNoCancel) switch
{

View File

@ -9,7 +9,7 @@ namespace BizHawk.Client.DiscoHawk
{
public static class AudioExtractor
{
public static void Extract(Disc disc, string path, string fileBase, Func<bool?> getOverwritePolicy)
public static void Extract(Disc disc, string path, string fileBase, Func<string, bool?> getOverwritePolicy)
{
var dsr = new DiscSectorReader(disc);
@ -36,7 +36,7 @@ namespace BizHawk.Client.DiscoHawk
var mp3Path = $"{Path.Combine(path, fileBase)} - Track {track.Number:D2}.mp3";
if (File.Exists(mp3Path))
{
overwriteExisting ??= getOverwritePolicy();
overwriteExisting ??= getOverwritePolicy(mp3Path);
switch (overwriteExisting)
{
case true: // "Yes" -- overwrite

View File

@ -4,6 +4,8 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using BizHawk.Client.DiscoHawk;
namespace BizHawk.Emulation.DiscSystem
{
/// <remarks>
@ -267,7 +269,8 @@ namespace BizHawk.Emulation.DiscSystem
var loadDiscInterface = DiscInterface.BizHawk;
var compareDiscInterfaces = new List<DiscInterface>();
bool hawk = false;
bool music = false;
bool overwrite = false;
int idx = 0;
while (idx < args.Length)
{
@ -284,6 +287,14 @@ namespace BizHawk.Emulation.DiscSystem
dirArg = args[idx++];
scanCues = true;
}
else if (au is "MUSIC")
{
music = true;
}
else if (au is "OVERWRITE")
{
overwrite = true;
}
else infile = a;
}
@ -296,6 +307,21 @@ namespace BizHawk.Emulation.DiscSystem
discInterface: loadDiscInterface);
}
if (music)
{
if (infile is null) return;
using var disc = Disc.LoadAutomagic(infile);
var path = Path.GetDirectoryName(infile);
var filename = Path.GetFileNameWithoutExtension(infile);
bool? CheckOverwrite(string mp3Path)
{
if (overwrite) return true; // overwrite
Console.WriteLine($"{mp3Path} already exists. Remove existing output files, or retry with the extra argument \"OVERWRITE\".");
return null; // cancel
}
AudioExtractor.Extract(disc, path, filename, CheckOverwrite);
}
bool verbose = true;
if (scanCues)