From 45c0216ea060ea2dde3b821cb54e9428619869d4 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Thu, 4 Jun 2015 00:37:15 +0200 Subject: [PATCH] Discogs importer: append sub-track titles to main title If we have an index titled "A" with 2 sub-tracks "B" and "C", set the track title to "A: B / C" Tested on http://www.discogs.com/release/5880212 --- discogs_importer.user.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/discogs_importer.user.js b/discogs_importer.user.js index fe04a87..045f824 100644 --- a/discogs_importer.user.js +++ b/discogs_importer.user.js @@ -357,7 +357,7 @@ function parseDiscogsRelease(data) { if (discogsTrack.type_ == 'heading') { heading = discogsTrack.title; return; - } else if (discogsTrack.type_ != 'track') { + } else if (discogsTrack.type_ != 'track' && discogsTrack.type_ != 'index') { return; } @@ -386,8 +386,27 @@ function parseDiscogsRelease(data) { // Track position and release number var trackPosition = discogsTrack.position; + // Handle sub-tracks if (trackPosition == "" && discogsTrack.sub_tracks) { trackPosition = discogsTrack.sub_tracks[0].position; + // Append titles of sub-tracks to main track title + var subtrack_titles = []; + $.each(discogsTrack.sub_tracks, function(subtrack_index, subtrack) { + if (subtrack.type_ != 'track') { + return; + } + if (subtrack.title) { + subtrack_titles.push(subtrack.title); + } else { + subtrack_titles.push('[unknown]'); + } + }); + if (subtrack_titles.length) { + if (track.title) { + track.title += ': '; + } + track.title += subtrack_titles.join(' / '); + } } // Skip special tracks