Skip to content

Commit

Permalink
Fix duplicated tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyfran committed Dec 23, 2024
1 parent ed259d0 commit 24b9d23
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/workers/media-provider/src/sync/file-based-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ const tryRetrieveOrCreateAlbum = (
fileMetadata,
);

const includesTrack = existingAlbum.value.tracks.some(
(existingTrack) =>
existingTrack.name === track.name &&
existingTrack.trackNumber === track.trackNumber,
);
const tracks = includesTrack
? existingAlbum.value.tracks
: [...existingAlbum.value.tracks, track];

tracks.sort((a, b) => a.trackNumber - b.trackNumber);

const genres = Genres.addTo(
existingAlbum.value.genres,
Genres.flatten(trackMetadata.genre ?? []),
Expand All @@ -353,7 +364,7 @@ const tryRetrieveOrCreateAlbum = (
return {
...existingAlbum.value,
genres,
tracks: [...existingAlbum.value.tracks, track],
tracks,
};
});

Expand Down

0 comments on commit 24b9d23

Please sign in to comment.