Skip to content

Commit

Permalink
lib.ExtendedTrackItem - Validate release language and try ensure engl…
Browse files Browse the repository at this point in the history
…ish metadata
  • Loading branch information
Inrixia committed Oct 9, 2024
1 parent b8fe82e commit 1c1b1a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
5 changes: 1 addition & 4 deletions plugins/SongDownloader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Expand Down
31 changes: 19 additions & 12 deletions plugins/_lib/Caches/ExtendedTrackItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,25 @@ export class ExtendedMediaItem {
public async releaseTrack(): Promise<ITrack | undefined> {
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<IRecording>(`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<IRecording>(`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();
Expand All @@ -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() {
Expand Down

0 comments on commit 1c1b1a7

Please sign in to comment.