Enabled image file scan (#151)

This commit is contained in:
Moritz Weber 2023-09-25 20:15:41 -04:00 committed by GitHub
parent ec36fcd105
commit a750a52e2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,7 +23,7 @@ import 'local_music_fetcher.dart';
import 'music_data_source_contract.dart';
import 'settings_data_source.dart';
const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png'];
const IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png'];
class LocalMusicFetcherImpl implements LocalMusicFetcher {
LocalMusicFetcherImpl(
@ -140,22 +140,27 @@ class LocalMusicFetcherImpl implements LocalMusicFetcher {
albumIdMap[albumString] = albumId;
newAlbumId = max(newAlbumId, albumId + 1);
final Uint8List? albumArt = songData.picture?.data;
Uint8List? albumArt = songData.picture?.data;
// fallback to get albumArt
// TODO: enable when everything else works as expected
// if (albumArt == null) {
// // get directory of song and look for image files
// final images = await songFile.parent
// .list(recursive: false, followLinks: false)
// .where((item) =>
// FileSystemEntity.isFileSync(item.path) &&
// IMAGE_EXTENSIONS.contains(
// p.extension(item.path).toLowerCase().substring(1)))
// .asyncMap((item) => File(item.path))
// .toList();
// if (images.isNotEmpty) albumArt = images.first.readAsBytesSync();
// }
if (albumArt == null) {
// get directory of song and look for image files
final images = await songFile.parent
.list(recursive: false, followLinks: false)
.where((item) =>
FileSystemEntity.isFileSync(item.path) &&
IMAGE_EXTENSIONS.contains(p.extension(item.path).toLowerCase()))
.asyncMap((item) => File(item.path))
.toList();
for (final image in images) {
try {
albumArt = image.readAsBytesSync();
break;
} catch (e) {
_log.e('Could not read image file: ${image.path}');
}
}
}
if (albumArt != null) {
albumArtMap[albumId] = await cacheAlbumArt(albumArt, albumId);