Better audio-only check (#847)

* Better IsAudio()

* null deref

* Don't set fields if empty

* Update Changelist

* Requested changes

* fix build

* fix build again

* string literal

* C# is dumb

* Revert to original

* revert further

* remove extra comma
This commit is contained in:
Deterous
2025-05-19 21:23:25 +09:00
committed by GitHub
parent 79cce37cf6
commit 59e7ecfa8a
3 changed files with 44 additions and 15 deletions

View File

@@ -640,6 +640,36 @@ namespace MPF.Processors
return sb.ToString();
}
/// <summary>
/// Returns true if a Cuesheet consists of only Audio tracks, false otherwise
/// </summary>
internal static bool IsAudio(string? cue)
{
// Ignore invalid inputs
if (string.IsNullOrEmpty(cue))
return false;
bool tracksExist = false;
foreach (string cueLine in cue!.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None))
{
string line = cueLine.Trim();
if (line.Length == 0)
continue;
string[] tokens = line.Split(new[] { " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length < 3 || !tokens[0].Equals("TRACK", StringComparison.OrdinalIgnoreCase))
continue;
tracksExist = true;
string trackType = tokens[2].ToUpperInvariant();
if (trackType != "AUDIO" && trackType != "CDG")
return false;
}
return tracksExist;
}
#endregion
}
}