Skip to content

Commit 89b459c

Browse files
MeerkovYoshiRulz
authored andcommitted
Add CLI for MP3 extraction
1 parent 6a43277 commit 89b459c

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/BizHawk.Client.DiscoHawk/MainDiscoForm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ private void LblMp3ExtractMagicArea_DragDrop(object sender, DragEventArgs e)
122122
using var disc = Disc.LoadAutomagic(file);
123123
var path = Path.GetDirectoryName(file);
124124
var filename = Path.GetFileNameWithoutExtension(file);
125-
static bool? PromptForOverwrite()
125+
static bool? PromptForOverwrite(string mp3Path)
126126
=> MessageBox.Show(
127-
"Do you want to overwrite existing files? Choosing \"No\" will simply skip those. You could also \"Cancel\" the extraction entirely.",
127+
$"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}",
128128
"File to extract already exists",
129129
MessageBoxButtons.YesNoCancel) switch
130130
{

src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/AudioExtractor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace BizHawk.Client.DiscoHawk
99
{
1010
public static class AudioExtractor
1111
{
12-
public static void Extract(Disc disc, string path, string fileBase, Func<bool?> getOverwritePolicy)
12+
public static void Extract(Disc disc, string path, string fileBase, Func<string, bool?> getOverwritePolicy)
1313
{
1414
var dsr = new DiscSectorReader(disc);
1515

@@ -36,7 +36,7 @@ public static void Extract(Disc disc, string path, string fileBase, Func<bool?>
3636
var mp3Path = $"{Path.Combine(path, fileBase)} - Track {track.Number:D2}.mp3";
3737
if (File.Exists(mp3Path))
3838
{
39-
overwriteExisting ??= getOverwritePolicy();
39+
overwriteExisting ??= getOverwritePolicy(mp3Path);
4040
switch (overwriteExisting)
4141
{
4242
case true: // "Yes" -- overwrite

src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/DiscoHawkLogic.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66

7+
using BizHawk.Client.DiscoHawk;
8+
79
namespace BizHawk.Emulation.DiscSystem
810
{
911
/// <remarks>
@@ -267,7 +269,8 @@ public static void RunWithArgs(string[] args, Action<string> showComparisonResul
267269
var loadDiscInterface = DiscInterface.BizHawk;
268270
var compareDiscInterfaces = new List<DiscInterface>();
269271
bool hawk = false;
270-
272+
bool music = false;
273+
bool overwrite = false;
271274
int idx = 0;
272275
while (idx < args.Length)
273276
{
@@ -284,6 +287,14 @@ public static void RunWithArgs(string[] args, Action<string> showComparisonResul
284287
dirArg = args[idx++];
285288
scanCues = true;
286289
}
290+
else if (au is "MUSIC")
291+
{
292+
music = true;
293+
}
294+
else if (au is "OVERWRITE")
295+
{
296+
overwrite = true;
297+
}
287298
else infile = a;
288299
}
289300

@@ -296,6 +307,21 @@ public static void RunWithArgs(string[] args, Action<string> showComparisonResul
296307
discInterface: loadDiscInterface);
297308
}
298309

310+
if (music)
311+
{
312+
if (infile is null) return;
313+
using var disc = Disc.LoadAutomagic(infile);
314+
var path = Path.GetDirectoryName(infile);
315+
var filename = Path.GetFileNameWithoutExtension(infile);
316+
bool? CheckOverwrite(string mp3Path)
317+
{
318+
if (overwrite) return true; // overwrite
319+
Console.WriteLine($"{mp3Path} already exists. Remove existing output files, or retry with the extra argument \"OVERWRITE\".");
320+
return null; // cancel
321+
}
322+
AudioExtractor.Extract(disc, path, filename, CheckOverwrite);
323+
}
324+
299325
bool verbose = true;
300326

301327
if (scanCues)

0 commit comments

Comments
 (0)