mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-14 13:59:11 +02:00
fix(cover): preserve provider high-resolution artwork
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:spotiflac_android/utils/cover_art_utils.dart';
|
||||
|
||||
void main() {
|
||||
group('highResCoverUrl', () {
|
||||
test('upgrades a small Deezer cover to display quality', () {
|
||||
expect(
|
||||
highResCoverUrl(
|
||||
'https://cdn-images.dzcdn.net/images/cover/hash/'
|
||||
'250x250-000000-80-0-0.jpg',
|
||||
),
|
||||
'https://cdn-images.dzcdn.net/images/cover/hash/'
|
||||
'1000x1000-000000-80-0-0.jpg',
|
||||
);
|
||||
});
|
||||
|
||||
test('does not downgrade provider-supplied Deezer artwork', () {
|
||||
const url =
|
||||
'https://cdn-images.dzcdn.net/images/cover/hash/'
|
||||
'1400x1400-000000-80-0-0.jpg';
|
||||
expect(highResCoverUrl(url), url);
|
||||
});
|
||||
|
||||
test('still upgrades a Spotify 300px cover to 640px', () {
|
||||
expect(
|
||||
highResCoverUrl('https://i.scdn.co/image/ab67616d00001e02abcdef'),
|
||||
'https://i.scdn.co/image/ab67616d0000b273abcdef',
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user