Skip to content

Commit cf034fc

Browse files
Prioritize primary Cover Art
Retrieve the primary cover art before fetching additional images. By separating the retrieval process, primary artwork will always appear first.
1 parent 712c54f commit cf034fc

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

CUERipper.Avalonia/ViewModels/UserControls/CoverViewAlbumViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public partial class CoverViewAlbumViewModel : ObservableObject, IEquatable<Cove
2626
{
2727
public string Uri { get; set; }
2828
public string Uri150 { get; set; }
29+
public bool IsPrimary { get; set; }
30+
2931
public Bitmap? Bitmap150 { get; set; }
3032

3133
private bool _isSelected;
@@ -42,10 +44,11 @@ public bool IsSelected
4244
[ObservableProperty]
4345
private string borderColor = "Transparent";
4446

45-
public CoverViewAlbumViewModel(string uri, string uri150)
47+
public CoverViewAlbumViewModel(string uri, string uri150, bool isPrimary)
4648
{
4749
Uri = uri;
4850
Uri150 = uri150;
51+
IsPrimary = isPrimary;
4952
}
5053

5154
public bool Equals(CoverViewAlbumViewModel? other)

CUERipper.Avalonia/Views/UserControls/CoverViewer.axaml.cs

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,45 +66,58 @@ public void Feed()
6666

6767
ClearCovers();
6868

69-
var albumCovers = _metaService.GetAlbumMetaInformation(false)
69+
var unorderedCovers = _metaService.GetAlbumMetaInformation(false)
7070
.SelectMany(x => x.Data.AlbumArt)
7171
.Where(x => !string.IsNullOrWhiteSpace(x.uri) || !string.IsNullOrWhiteSpace(x.uri150))
7272
.Select(x => new CoverViewAlbumViewModel(!string.IsNullOrWhiteSpace(x.uri) ? x.uri : x.uri150
73-
, !string.IsNullOrWhiteSpace(x.uri150) ? x.uri150 : x.uri))
73+
, !string.IsNullOrWhiteSpace(x.uri150) ? x.uri150 : x.uri
74+
, x.primary)
75+
)
7476
.Distinct()
7577
.ToArray();
7678

79+
var orderedCovers = new[]
80+
{
81+
// Primary artwork (Front cover)
82+
unorderedCovers.Where(x => x.IsPrimary)
83+
// Secondary artwork (Photo of CD, back cover, etc.)
84+
, unorderedCovers.Where(x => !x.IsPrimary)
85+
};
86+
7787
_thumbnailJob.Run(async (CancellationToken ct) =>
7888
{
7989
using var semaphore = new SemaphoreSlim(Constants.MaxCoverFetchConcurrency);
80-
await Task.WhenAll(albumCovers.Select(async cover =>
90+
foreach (var albumCovers in orderedCovers)
8191
{
82-
await semaphore.WaitAsync(ct);
83-
try
92+
await Task.WhenAll(albumCovers.Select(async cover =>
8493
{
85-
var bitmap = await _metaService.FetchImageAsync(cover.Uri150, ct);
86-
if (ct.IsCancellationRequested) return;
87-
88-
if (bitmap != null)
94+
await semaphore.WaitAsync(ct);
95+
try
8996
{
90-
cover.Bitmap150 = bitmap;
91-
Dispatcher.UIThread.Post(() =>
97+
var bitmap = await _metaService.FetchImageAsync(cover.Uri150, ct);
98+
if (ct.IsCancellationRequested) return;
99+
100+
if (bitmap != null)
92101
{
93-
if (ViewModel.AlbumCovers.None())
102+
cover.Bitmap150 = bitmap;
103+
Dispatcher.UIThread.Post(() =>
94104
{
95-
cover.IsSelected = true;
96-
ViewModel.CurrentCover = cover.Bitmap150;
97-
}
98-
99-
ViewModel.AlbumCovers.Add(cover);
100-
});
105+
if (ViewModel.AlbumCovers.None())
106+
{
107+
cover.IsSelected = true;
108+
ViewModel.CurrentCover = cover.Bitmap150;
109+
}
110+
111+
ViewModel.AlbumCovers.Add(cover);
112+
});
113+
}
101114
}
102-
}
103-
finally
104-
{
105-
semaphore.Release();
106-
}
107-
}));
115+
finally
116+
{
117+
semaphore.Release();
118+
}
119+
}));
120+
}
108121
});
109122
}
110123

0 commit comments

Comments
 (0)