Merge pull request #261 from ericdaddario02/feature/replay-gain-flac
feat(downloads): save replay gain tags to FLAC metadata
This commit is contained in:
commit
de3e125bac
3 changed files with 28 additions and 1 deletions
13
js/api.js
13
js/api.js
|
|
@ -1254,7 +1254,18 @@ export class LosslessAPI {
|
|||
message: 'Adding metadata...',
|
||||
});
|
||||
}
|
||||
blob = await addMetadataToAudio(blob, track, this, quality);
|
||||
|
||||
const enrichedTrack = { ...track };
|
||||
if (lookup.info) {
|
||||
enrichedTrack.replayGain = {
|
||||
trackReplayGain: lookup.info.trackReplayGain,
|
||||
trackPeakAmplitude: lookup.info.trackPeakAmplitude,
|
||||
albumReplayGain: lookup.info.albumReplayGain,
|
||||
albumPeakAmplitude: lookup.info.albumPeakAmplitude,
|
||||
};
|
||||
}
|
||||
|
||||
blob = await addMetadataToAudio(blob, enrichedTrack, this, quality);
|
||||
}
|
||||
|
||||
// Detect actual format and fix filename extension if needed
|
||||
|
|
|
|||
|
|
@ -323,6 +323,15 @@ async function downloadTrackBlob(track, quality, api, lyricsManager = null, sign
|
|||
}
|
||||
}
|
||||
|
||||
if (lookup.info) {
|
||||
enrichedTrack.replayGain = {
|
||||
trackReplayGain: lookup.info.trackReplayGain,
|
||||
trackPeakAmplitude: lookup.info.trackPeakAmplitude,
|
||||
albumReplayGain: lookup.info.albumReplayGain,
|
||||
albumPeakAmplitude: lookup.info.albumPeakAmplitude,
|
||||
};
|
||||
}
|
||||
|
||||
// Handle DASH streams (blob URLs)
|
||||
let blob;
|
||||
if (streamUrl.startsWith('blob:')) {
|
||||
|
|
|
|||
|
|
@ -587,6 +587,13 @@ function createVorbisCommentBlock(track) {
|
|||
if (track.album?.numberOfTracks) {
|
||||
comments.push(['TRACKTOTAL', String(track.album.numberOfTracks)]);
|
||||
}
|
||||
if (track.replayGain) {
|
||||
const { albumReplayGain, albumPeakAmplitude, trackReplayGain, trackPeakAmplitude } = track.replayGain;
|
||||
if (albumReplayGain) comments.push(['REPLAYGAIN_ALBUM_GAIN', String(albumReplayGain)]);
|
||||
if (albumPeakAmplitude) comments.push(['REPLAYGAIN_ALBUM_PEAK', String(albumPeakAmplitude)]);
|
||||
if (trackReplayGain) comments.push(['REPLAYGAIN_TRACK_GAIN', String(trackReplayGain)]);
|
||||
if (trackPeakAmplitude) comments.push(['REPLAYGAIN_TRACK_PEAK', String(trackPeakAmplitude)]);
|
||||
}
|
||||
|
||||
const releaseDateStr =
|
||||
track.album?.releaseDate || (track.streamStartDate ? track.streamStartDate.split('T')[0] : '');
|
||||
|
|
|
|||
Loading…
Reference in a new issue