Skip to content

Commit 529fb00

Browse files
Merge pull request #3 from jpadgett314/jpg-album-art
Add jpg album art support
2 parents c479769 + a8e859b commit 529fb00

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/main/util.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,27 @@ export async function parseAndSaveSongs(
3636
store.delete('songs');
3737

3838
glob(`${result.filePaths[0]}/**/notes.mid`, {}, (err, files) => {
39+
const supportedImageExtensions = ['png', 'jpg', 'jpeg'];
40+
3941
const songList = files
4042
.map((file) => path.join(path.dirname(file), 'song.ini'))
4143
.filter((file) => fs.existsSync(file))
4244
.map((file) => ({
4345
info: ini.parse(fs.readFileSync(file, 'utf-8')),
4446
dir: path.dirname(file),
4547
}))
46-
.map(({ info, dir }) => ({
47-
id: randomUUID(),
48-
dir,
49-
albumCover: fs.existsSync(path.join(dir, 'album.png'))
50-
? `gh:///${path.join(dir, 'album.png')}`
51-
: null,
52-
...(info.song ?? info.Song ?? info),
53-
}));
48+
.map(({ info, dir }) => {
49+
const albumCoverPath = supportedImageExtensions
50+
.map(ext => path.join(dir, `album.${ext}`))
51+
.find(p => fs.existsSync(p));
52+
53+
return {
54+
id: randomUUID(),
55+
dir,
56+
albumCover: albumCoverPath ? `gh:///${albumCoverPath}` : null,
57+
...(info.song ?? info.Song ?? info),
58+
};
59+
});
5460

5561
const songs = songList.reduce((acc, song) => {
5662
acc[song.id] = song;

0 commit comments

Comments
 (0)