Skip to content

Commit

Permalink
make ID3 reading exception-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
g3gg0 committed Jan 7, 2024
1 parent 51ddccc commit a90d637
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion TeddyBench/TrackSortDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

var fileTuples = FileNames.Select(f => new Tuple<string, Id3Tag>(f, new Mp3(f, Mp3Permissions.Read).GetAllTags().Where(t => t.Track.IsAssigned).FirstOrDefault()));
var fileTuples = FileNames.Select(f => new Tuple<string, Id3Tag>(f, GetTag(f)));

foreach (Tuple<string, Id3Tag> item in fileTuples.OrderBy(i => (i.Item2 == null) ? int.MaxValue : i.Item2.Track.Value))
{
Expand All @@ -40,6 +40,22 @@ protected override void OnLoad(EventArgs e)
UpdateView();
}

private Id3Tag GetTag(string f)
{
try
{
Mp3 mp3 = new Mp3(f, Mp3Permissions.Read);

Id3Tag ret = mp3.GetAllTags().Where(t => t.Track.IsAssigned).FirstOrDefault();

return ret;
}
catch(Exception ex)
{
return null;
}
}

private void UpdateView()
{
lstTracks.Items.Clear();
Expand Down

0 comments on commit a90d637

Please sign in to comment.