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
|
2019-12-21 10:19:17 +00:00
|
|
|
// @version 2019.12.21.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;
|
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
$(document).ready(function () {
|
2018-11-20 22:18:49 +00:00
|
|
|
MBImportStyle();
|
2015-06-15 07:52:59 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
|
|
|
let release = retrieveReleaseInfo(release_url);
|
|
|
|
insertLink(release, release_url);
|
2014-10-03 23:50:48 +00:00
|
|
|
});
|
|
|
|
|
2015-06-12 19:37:19 +00:00
|
|
|
function retrieveReleaseInfo(release_url) {
|
2018-11-20 22:18:49 +00:00
|
|
|
let releaseDate = ProductDetail.date.published.split('-');
|
|
|
|
|
|
|
|
// Release information global to all Beatport releases
|
|
|
|
let release = {
|
|
|
|
artist_credit: [],
|
|
|
|
title: ProductDetail.name,
|
|
|
|
year: releaseDate[0],
|
|
|
|
month: releaseDate[1],
|
|
|
|
day: releaseDate[2],
|
|
|
|
format: 'Digital Media',
|
|
|
|
packaging: 'None',
|
|
|
|
country: 'XW',
|
|
|
|
status: 'official',
|
|
|
|
language: 'eng',
|
|
|
|
script: 'Latn',
|
|
|
|
type: '',
|
|
|
|
urls: [],
|
|
|
|
labels: [],
|
2020-04-05 14:01:21 +00:00
|
|
|
discs: [],
|
2018-11-20 22:18:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// URLs
|
|
|
|
release.urls.push({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
release.labels.push({
|
|
|
|
name: ProductDetail.label.name,
|
2020-04-05 14:01:21 +00:00
|
|
|
catno: ProductDetail.catalog,
|
2018-11-20 22:18:49 +00:00
|
|
|
});
|
|
|
|
|
2019-12-20 09:55:22 +00:00
|
|
|
// Reload Playables if empty
|
2020-03-14 00:43:40 +00:00
|
|
|
if (!Object.prototype.hasOwnProperty.call(unsafeWindow.Playables, 'tracks')) {
|
2019-12-20 09:55:22 +00:00
|
|
|
eval($('#data-objects').text());
|
|
|
|
unsafeWindow.Playables = window.Playables;
|
|
|
|
}
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
// Tracks
|
|
|
|
let tracks = [];
|
|
|
|
let the_tracks = unsafeWindow.Playables.tracks;
|
|
|
|
let seen_tracks = {}; // to shoot duplicates ...
|
|
|
|
let release_artists = [];
|
2020-04-05 14:01:21 +00:00
|
|
|
$.each(the_tracks, function (idx, track) {
|
2018-11-20 22:18:49 +00:00
|
|
|
if (track.release.id !== ProductDetail.id) {
|
|
|
|
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 = [];
|
2020-04-05 14:01:21 +00:00
|
|
|
$.each(track.artists, function (idx2, artist) {
|
2018-11-20 22:18:49 +00:00
|
|
|
artists.push(artist.name);
|
|
|
|
release_artists.push(artist.name);
|
|
|
|
});
|
|
|
|
|
|
|
|
let title = track.name;
|
|
|
|
if (track.mix && track.mix !== 'Original Mix') {
|
|
|
|
title += ` (${track.mix})`;
|
|
|
|
}
|
|
|
|
tracks.push({
|
|
|
|
artist_credit: MBImport.makeArtistCredits(artists),
|
|
|
|
title: title,
|
2020-04-05 14:01:21 +00:00
|
|
|
duration: track.duration.minutes,
|
2018-11-20 22:18:49 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
let unique_artists = [];
|
2020-04-05 14:01:21 +00:00
|
|
|
$.each(release_artists, function (i, 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) {
|
|
|
|
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
|
|
|
} else {
|
|
|
|
release.artist_credit = MBImport.makeArtistCredits(unique_artists);
|
2015-06-12 17:57:46 +00:00
|
|
|
}
|
2018-11-20 22:18:49 +00:00
|
|
|
release.discs.push({
|
|
|
|
tracks: tracks,
|
2020-04-05 14:01:21 +00:00
|
|
|
format: release.format,
|
2018-11-20 22:18:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
LOGGER.info('Parsed release: ', release);
|
|
|
|
return release;
|
2014-10-03 23:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Insert button into page under label information
|
2015-06-12 19:37:19 +00:00
|
|
|
function insertLink(release, release_url) {
|
2018-11-20 22:18:49 +00:00
|
|
|
let edit_note = MBImport.makeEditNote(release_url, 'Beatport');
|
|
|
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
|
|
|
|
|
|
|
let mbUI = $(
|
|
|
|
`<li class="interior-release-chart-content-item musicbrainz-import">${MBImport.buildFormHTML(
|
|
|
|
parameters
|
|
|
|
)}${MBImport.buildSearchButton(release)}</li>`
|
|
|
|
).hide();
|
|
|
|
|
|
|
|
$('.interior-release-chart-content-list').append(mbUI);
|
|
|
|
$('form.musicbrainz_import').css({ display: 'inline-block', 'margin-left': '5px' });
|
|
|
|
$('form.musicbrainz_import button').css({ width: '120px' });
|
2015-06-16 13:34:02 +00:00
|
|
|
mbUI.slideDown();
|
2015-06-10 22:22:38 +00:00
|
|
|
}
|