fix(cover): preserve provider high-resolution artwork

This commit is contained in:
zarzet
2026-09-04 19:48:15 +07:00
parent 448a3426a0
commit 514081fc6a
2 changed files with 40 additions and 6 deletions
+9 -6
View File
@@ -3,8 +3,9 @@ final RegExp _deezerCoverSizeRegex = RegExp(
r'/(\d+)x(\d+)-(\d+)-(\d+)-(\d+)-(\d+)\.jpg$',
);
/// Upgrades a Spotify/Deezer cover URL to a display-quality resolution
/// (Spotify 300px → 640px, Deezer → 1000x1000 preserving quality params).
/// Upgrades a Spotify/Deezer cover URL to a display-quality resolution.
/// Existing Deezer URLs at or above 1000px are preserved so provider
/// extensions can supply higher-resolution artwork without being downgraded.
/// Non-matching URLs pass through unchanged.
String? highResCoverUrl(String? url) {
if (url == null) return null;
@@ -13,10 +14,12 @@ String? highResCoverUrl(String? url) {
}
if (url.contains('cdn-images.dzcdn.net') &&
_deezerCoverSizeRegex.hasMatch(url)) {
return url.replaceAllMapped(
_deezerCoverSizeRegex,
(m) => '/1000x1000-${m[3]}-${m[4]}-${m[5]}-${m[6]}.jpg',
);
return url.replaceAllMapped(_deezerCoverSizeRegex, (m) {
final width = int.tryParse(m[1] ?? '') ?? 0;
final height = int.tryParse(m[2] ?? '') ?? 0;
if (width >= 1000 && height >= 1000) return m[0]!;
return '/1000x1000-${m[3]}-${m[4]}-${m[5]}-${m[6]}.jpg';
});
}
return url;
}