2014-10-03 23:50:48 +00:00
|
|
|
|
// ==UserScript==
|
2017-06-13 09:13:12 +00:00
|
|
|
|
// @name Import Beatport releases to MusicBrainz
|
2014-10-03 23:50:48 +00:00
|
|
|
|
// @author VxJasonxV
|
2015-06-12 19:29:48 +00:00
|
|
|
|
// @namespace https://github.com/murdos/musicbrainz-userscripts/
|
2017-06-13 09:13:12 +00:00
|
|
|
|
// @description One-click importing of releases from beatport.com/release pages into MusicBrainz
|
2023-10-22 10:15:04 +00:00
|
|
|
|
// @version 2023.10.22.1
|
2017-06-13 11:09:26 +00:00
|
|
|
|
// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/beatport_importer.user.js
|
|
|
|
|
// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/beatport_importer.user.js
|
2017-06-13 09:13:12 +00:00
|
|
|
|
// @include http://www.beatport.com/release/*
|
|
|
|
|
// @include https://www.beatport.com/release/*
|
2015-06-12 17:57:46 +00:00
|
|
|
|
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
|
2015-06-17 22:29:08 +00:00
|
|
|
|
// @require lib/mbimport.js
|
2015-06-12 17:57:46 +00:00
|
|
|
|
// @require lib/logger.js
|
2015-06-15 07:52:59 +00:00
|
|
|
|
// @require lib/mbimportstyle.js
|
2015-07-10 12:28:43 +00:00
|
|
|
|
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
2019-01-05 14:48:14 +00:00
|
|
|
|
// @grant unsafeWindow
|
2014-10-03 23:50:48 +00:00
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
2015-06-12 17:57:46 +00:00
|
|
|
|
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
|
|
|
|
this.$ = this.jQuery = jQuery.noConflict(true);
|
|
|
|
|
|
2014-10-03 23:50:48 +00:00
|
|
|
|
if (!unsafeWindow) unsafeWindow = window;
|
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
$(document).ready(() => {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
MBImportStyle();
|
2015-06-15 07:52:59 +00:00
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
const release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
2023-06-30 08:44:49 +00:00
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
const data = JSON.parse(document.getElementById('__NEXT_DATA__').innerHTML);
|
|
|
|
|
const release_data = data.props.pageProps.release;
|
2023-06-30 08:44:49 +00:00
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
// Reversing is less reliable, but the API does not provide track numbers.
|
|
|
|
|
const tracks_table = release_data.tracks.reverse();
|
|
|
|
|
|
2023-10-22 10:15:04 +00:00
|
|
|
|
const tracks_release = $.grep(data.props.pageProps.dehydratedState.queries, element => /tracks/g.test(element.queryKey))[0];
|
2023-07-16 03:23:58 +00:00
|
|
|
|
const tracks_data = $.map(tracks_table, url => $.grep(tracks_release.state.data.results, element => element.url === url));
|
|
|
|
|
const isrcs = tracks_data.map(track => track.isrc);
|
|
|
|
|
|
|
|
|
|
const mbrelease = retrieveReleaseInfo(release_url, release_data, tracks_data);
|
|
|
|
|
|
|
|
|
|
setTimeout(() => insertLink(mbrelease, release_url, isrcs), 1000);
|
2014-10-03 23:50:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
function retrieveReleaseInfo(release_url, release_data, tracks_data) {
|
|
|
|
|
const release_date = release_data.new_release_date.split('-');
|
2018-11-20 22:18:49 +00:00
|
|
|
|
|
|
|
|
|
// Release information global to all Beatport releases
|
2023-07-16 03:23:58 +00:00
|
|
|
|
const mbrelease = {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
artist_credit: [],
|
2023-07-16 03:23:58 +00:00
|
|
|
|
title: release_data.name,
|
|
|
|
|
year: release_date[0],
|
|
|
|
|
month: release_date[1],
|
|
|
|
|
day: release_date[2],
|
2018-11-20 22:18:49 +00:00
|
|
|
|
format: 'Digital Media',
|
|
|
|
|
packaging: 'None',
|
|
|
|
|
country: 'XW',
|
|
|
|
|
status: 'official',
|
|
|
|
|
language: 'eng',
|
|
|
|
|
script: 'Latn',
|
|
|
|
|
type: '',
|
|
|
|
|
urls: [],
|
|
|
|
|
labels: [],
|
2023-06-30 05:58:41 +00:00
|
|
|
|
barcode: release_data.upc,
|
2020-04-05 14:01:21 +00:00
|
|
|
|
discs: [],
|
2018-11-20 22:18:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// URLs
|
2023-07-16 03:23:58 +00:00
|
|
|
|
mbrelease.urls.push({
|
2018-11-20 22:18:49 +00:00
|
|
|
|
url: release_url,
|
2020-04-05 14:01:21 +00:00
|
|
|
|
link_type: MBImport.URL_TYPES.purchase_for_download,
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
mbrelease.labels.push({
|
|
|
|
|
name: release_data.label.name,
|
|
|
|
|
catno: release_data.catalog_number,
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Tracks
|
2023-07-16 03:23:58 +00:00
|
|
|
|
const mbtracks = [];
|
|
|
|
|
|
|
|
|
|
const seen_tracks = {}; // to shoot duplicates ...
|
|
|
|
|
const release_artists = [];
|
|
|
|
|
$.each(tracks_data, (index, track) => {
|
|
|
|
|
if (track.release.id != release_data.id) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
return;
|
2014-10-03 23:50:48 +00:00
|
|
|
|
}
|
2018-11-20 22:18:49 +00:00
|
|
|
|
if (seen_tracks[track.id]) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
seen_tracks[track.id] = true;
|
|
|
|
|
|
|
|
|
|
let artists = [];
|
2023-07-16 03:23:58 +00:00
|
|
|
|
$.each(track.artists, (index2, artist) => {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
artists.push(artist.name);
|
|
|
|
|
release_artists.push(artist.name);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let title = track.name;
|
2023-07-16 03:23:58 +00:00
|
|
|
|
if (track.mix_name && track.mix_name !== 'Original Mix') {
|
|
|
|
|
title += ` (${track.mix_name})`;
|
2018-11-20 22:18:49 +00:00
|
|
|
|
}
|
2023-07-16 03:23:58 +00:00
|
|
|
|
mbtracks.push({
|
2018-11-20 22:18:49 +00:00
|
|
|
|
artist_credit: MBImport.makeArtistCredits(artists),
|
|
|
|
|
title: title,
|
2023-09-15 07:30:32 +00:00
|
|
|
|
duration: track.length_ms,
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
const unique_artists = [];
|
|
|
|
|
$.each(release_artists, (index, el) => {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
if ($.inArray(el, unique_artists) === -1) {
|
|
|
|
|
unique_artists.push(el);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-06-12 20:08:40 +00:00
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
|
if (unique_artists.length > 4) {
|
2023-07-16 03:23:58 +00:00
|
|
|
|
mbrelease.artist_credit = [MBImport.specialArtist('various_artists')];
|
2018-11-20 22:18:49 +00:00
|
|
|
|
} else {
|
2023-07-16 03:23:58 +00:00
|
|
|
|
mbrelease.artist_credit = MBImport.makeArtistCredits(unique_artists);
|
2015-06-12 17:57:46 +00:00
|
|
|
|
}
|
2023-07-16 03:23:58 +00:00
|
|
|
|
|
|
|
|
|
mbrelease.discs.push({
|
|
|
|
|
tracks: mbtracks,
|
|
|
|
|
format: mbrelease.format,
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
LOGGER.info('Parsed release: ', mbrelease);
|
|
|
|
|
return mbrelease;
|
2014-10-03 23:50:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Insert button into page under label information
|
2023-07-16 03:23:58 +00:00
|
|
|
|
function insertLink(mbrelease, release_url, isrcs) {
|
|
|
|
|
const edit_note = MBImport.makeEditNote(release_url, 'Beatport');
|
|
|
|
|
const parameters = MBImport.buildFormParameters(mbrelease, edit_note);
|
2018-11-20 22:18:49 +00:00
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
const mbUI = $(
|
|
|
|
|
`<div class="interior-release-chart-content-item musicbrainz-import">${MBImport.buildFormHTML(
|
2018-11-20 22:18:49 +00:00
|
|
|
|
parameters
|
2023-07-16 03:23:58 +00:00
|
|
|
|
)}${MBImport.buildSearchButton(mbrelease)}</div>`
|
2018-11-20 22:18:49 +00:00
|
|
|
|
).hide();
|
|
|
|
|
|
2023-06-30 08:44:49 +00:00
|
|
|
|
$(
|
|
|
|
|
'<form class="musicbrainz_import"><button type="submit" title="Submit ISRCs to MusicBrainz with kepstin’s MagicISRC"><span>Submit ISRCs</span></button></form>'
|
|
|
|
|
)
|
|
|
|
|
.on('click', event => {
|
2023-07-16 03:23:58 +00:00
|
|
|
|
const query = isrcs.map((isrc, index) => (isrc == null ? `isrc${index + 1}=` : `isrc${index + 1}=${isrc}`)).join('&');
|
2023-06-30 08:44:49 +00:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
window.open(`https://magicisrc.kepstin.ca?${query}`);
|
|
|
|
|
})
|
|
|
|
|
.appendTo(mbUI);
|
|
|
|
|
|
2023-07-16 03:23:58 +00:00
|
|
|
|
$('div[title="Collection controls"]').append(mbUI);
|
2018-11-20 22:18:49 +00:00
|
|
|
|
$('form.musicbrainz_import').css({ display: 'inline-block', 'margin-left': '5px' });
|
|
|
|
|
$('form.musicbrainz_import button').css({ width: '120px' });
|
2023-07-22 01:33:18 +00:00
|
|
|
|
$('form.musicbrainz_import button img').css({ display: 'inline-block' });
|
2015-06-16 13:34:02 +00:00
|
|
|
|
mbUI.slideDown();
|
2015-06-10 22:22:38 +00:00
|
|
|
|
}
|