Skip to content

Commit

Permalink
Enabled image file scan (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-weber authored Sep 26, 2023
1 parent ec36fcd commit a750a52
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/lib/system/datasources/local_music_fetcher_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a750a52

Please sign in to comment.