Skip to content

Commit

Permalink
lib.makeTags - Don't use musicbrainz disambiguation. Fixes #83 & gene…
Browse files Browse the repository at this point in the history
…ral title formatting issues
  • Loading branch information
Inrixia committed Oct 7, 2024
1 parent 66a5cb3 commit 0b5aef5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
24 changes: 10 additions & 14 deletions plugins/_lib/makeTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ import { ExtendedMediaItem } from "./Caches/ExtendedTrackItem";
import { Album, TrackItem } from "neptune-types/tidal";
import type { MediaItem } from "./Caches/MediaItemCache";

const sanitizeDisambiguation = (d?: string | null): string | false => {
if (d === undefined || d === null) return false;
let _d = d.toLowerCase();
if (_d.startsWith("deluxe")) return "Deluxe";
if (_d.includes("explicit") || _d.includes("48khz") || _d.includes("96khz") || _d.includes("24bit") || _d.includes("24-bit") || _d.includes("mastered for itunes")) return false;
return d;
};

const englishCharRegex = /[a-zA-Z]/;
const hasEnglish = (str?: string) => !!str && /[a-zA-Z]/.test(str);
const hasEnglish = (str?: string) => !!str && englishCharRegex.test(str);

export const fullTitle = (tidal?: { title?: string; version?: string }, musicBrainz?: { title?: string; disambiguation?: string }) => {
const brainzTitle = musicBrainz?.title;
Expand All @@ -31,8 +23,9 @@ export const fullTitle = (tidal?: { title?: string; version?: string }, musicBra
if (mbMissingFeat || mbInAnotherLanguage) title = tidalTitle;
if (title === undefined) return undefined;

const disambiguation = sanitizeDisambiguation(musicBrainz?.disambiguation ?? tidal?.version);
if (disambiguation && !title.includes(disambiguation)) title += ` (${disambiguation})`;
// Dont use musicBrainz disambiguation as its not the same as the tidal version!
const version = tidal?.version;
if (version && !title.includes(version)) title += ` (${version})`;

return title;
};
Expand Down Expand Up @@ -125,8 +118,11 @@ export const makeTags = async (extTrackItem: ExtendedMediaItem): Promise<MetaTag
}

// track isrc & album upc
if (mediaItem.isrc) tags.isrc = mediaItem.isrc;
if (album?.upc) tags.upc = album?.upc;
const isrc = mediaItem.isrc ?? recording?.isrcs?.[0];
if (isrc) tags.isrc = isrc;

const upc = album?.upc ?? releaseAlbum?.barcode;
if (upc) tags.upc = upc;

// Musicbrainz
if (recording?.id) tags.musicbrainz_trackid = recording.id.toString();
Expand All @@ -136,7 +132,7 @@ export const makeTags = async (extTrackItem: ExtendedMediaItem): Promise<MetaTag
const artistName = resolveArtist(mediaItem, album);
if (artistName) tags.artist = artistName;

tags.album = mediaItem.album?.title;
tags.album = fullTitle(mediaItem.album, releaseAlbum);

let cover = mediaItem.album?.cover;
if (album !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/_lib/nativeBridge/native/request/helpers.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const rejectNotOk = (res: IncomingMessage) => {
const OK = res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 300;
if (!OK) {
toJson(res)
.then((body) => libTrace.err(`(${res.statusCode})`, body))
.then((body) => libTrace.err(`(${res.statusCode})`, body, res.url))
.catch(() => {});
throw new Error(`Status code is ${res.statusCode}`);
}
Expand Down

0 comments on commit 0b5aef5

Please sign in to comment.