From 92626ce15887fdf7f2ad4857b5b987334f8d5b93 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Tue, 23 Jun 2015 08:35:20 +0200 Subject: [PATCH] discogs: introduce artistNoNum() function and reduce code redundancy --- discogs_importer.user.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/discogs_importer.user.js b/discogs_importer.user.js index 53dbe9b..d9ac5c6 100644 --- a/discogs_importer.user.js +++ b/discogs_importer.user.js @@ -430,6 +430,12 @@ function cleanup_discogs_artist_credit(obj) { } } +// Returns the name without the numerical suffic Discogs adds as disambiguation +// ie. "ABC (123)" -> "ABC" +function artistNoNum(artist_name) { + return artist_name.replace(/ \(\d+\)$/, ""); +} + // Analyze Discogs data and return a release object function parseDiscogsRelease(data) { @@ -445,8 +451,8 @@ function parseDiscogsRelease(data) { release.artist_credit = []; $.each(discogsRelease.artists, function(index, artist) { var ac = { - 'artist_name': artist.name.replace(/ \(\d+\)$/, ""), - 'credited_name': (artist.anv != "" ? artist.anv : artist.name.replace(/ \(\d+\)$/, "")), + 'artist_name': artistNoNum(artist.name), + 'credited_name': (artist.anv != "" ? artist.anv : artistNoNum(artist.name)), 'joinphrase': decodeDiscogsJoinphrase(artist.join), 'mbid': MBIDfromUrl(artist.resource_url, 'artist') }; @@ -593,8 +599,8 @@ function parseDiscogsRelease(data) { if (discogsTrack.artists) { $.each(discogsTrack.artists, function(index, artist) { var ac = { - 'artist_name': artist.name.replace(/ \(\d+\)$/, ""), - 'credited_name': (artist.anv != "" ? artist.anv : artist.name.replace(/ \(\d+\)$/, "")), + 'artist_name': artistNoNum(artist.name), + 'credited_name': (artist.anv != "" ? artist.anv : artistNoNum(artist.name)), 'joinphrase': decodeDiscogsJoinphrase(artist.join), 'mbid': MBIDfromUrl(artist.resource_url, 'artist') };