diff --git a/plugins/SongDownloader/src/index.ts b/plugins/SongDownloader/src/index.ts index 3507ce72..f2d29b35 100644 --- a/plugins/SongDownloader/src/index.ts +++ b/plugins/SongDownloader/src/index.ts @@ -104,10 +104,7 @@ const downloadTrack = async (trackItem: TrackItem, updateMethods: ButtonMethods, if (settings.useRealMAX && settings.desiredDownloadQuality === AudioQuality.HiRes) { updateMethods.set("Checking RealMAX for better quality..."); const maxTrack = await MaxTrack.getMaxTrack(trackId); - if (maxTrack !== false) { - console.log(maxTrack); - trackId = +maxTrack.id!; - } + if (maxTrack !== false) trackId = +maxTrack.id!; } updateMethods.set("Fetching playback info & tags..."); diff --git a/plugins/_lib/Caches/ExtendedTrackItem.ts b/plugins/_lib/Caches/ExtendedTrackItem.ts index 0a8e11e9..f27c3c93 100644 --- a/plugins/_lib/Caches/ExtendedTrackItem.ts +++ b/plugins/_lib/Caches/ExtendedTrackItem.ts @@ -58,23 +58,25 @@ export class ExtendedMediaItem { public async releaseTrack(): Promise { if (this._releaseTrack !== undefined) return this._releaseTrack; + const releaseTrackFromRecording = async (recording: IRecording) => { + // If a recording exists then fetch the full recording details including media for title resolution + const release = await requestJsonCached(`https://musicbrainz.org/ws/2/recording/${recording.id}?inc=releases+media+artist-credits+isrcs&fmt=json`) + .then(({ releases }) => releases?.filter((release) => release["text-representation"].language === "eng")[0] ?? releases?.[0]) + .catch(libTrace.warn.withContext("MusicBrainz.getISRCRecordings")); + if (release === undefined) return undefined; + + const releaseTrack = release.media?.[0].tracks?.[0]; + releaseTrack.recording ??= recording; + return releaseTrack; + }; + if (this.tidalTrack.isrc !== undefined) { // Lookup the recording from MusicBrainz by ISRC const recording = await requestJsonCached<{ recordings: IRecording[] }>(`https://musicbrainz.org/ws/2/isrc/${this.tidalTrack.isrc}?inc=isrcs&fmt=json`) .then(({ recordings }) => recordings[0]) .catch(libTrace.warn.withContext("MusicBrainz.getISRCRecordings")); - if (recording !== undefined) { - // If a recording exists then fetch the full recording details including media for title resolution - const release = await requestJsonCached(`https://musicbrainz.org/ws/2/recording/${recording.id}?inc=releases+media+artist-credits+isrcs&fmt=json`) - .then(({ releases }) => releases?.filter((release) => release.country === "XW")[0] ?? releases?.[0]) - .catch(libTrace.warn.withContext("MusicBrainz.getISRCRecordings")); - if (release === undefined) return undefined; - - this._releaseTrack = release.media?.[0].tracks?.[0]; - this._releaseTrack.recording = recording; - return this._releaseTrack; - } + if (recording !== undefined) return (this._releaseTrack = await releaseTrackFromRecording(recording)); } const releaseAlbum = await this.releaseAlbum(); @@ -87,7 +89,12 @@ export class ExtendedMediaItem { const volumeNumber = (this.tidalTrack.volumeNumber ?? 1) - 1; const trackNumber = (this.tidalTrack.trackNumber ?? 1) - 1; - return (this._releaseTrack = albumRelease?.media?.[volumeNumber]?.tracks?.[trackNumber]); + this._releaseTrack = albumRelease?.media?.[volumeNumber]?.tracks?.[trackNumber]; + // If this is not the english version of the release try to find the english version of the release track + if (albumRelease?.["text-representation"].language !== "eng" && this._releaseTrack?.recording !== undefined) { + return (this._releaseTrack = await releaseTrackFromRecording(this._releaseTrack.recording)); + } + return this._releaseTrack; } public async everything() {