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
|
2018-02-18 17:16:45 +00:00
|
|
|
// @version 2018.2.18.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
|
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;
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
2015-06-15 07:52:59 +00:00
|
|
|
MBImportStyle();
|
|
|
|
|
2015-06-12 19:37:19 +00:00
|
|
|
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, '');
|
|
|
|
var 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) {
|
2017-06-13 10:23:30 +00:00
|
|
|
var releaseDate = ProductDetail.date.published.split("-");
|
2014-10-03 23:50:48 +00:00
|
|
|
|
|
|
|
// Release information global to all Beatport releases
|
2015-06-12 20:08:40 +00:00
|
|
|
var release = {
|
|
|
|
artist_credit: [],
|
2017-06-13 10:25:02 +00:00
|
|
|
title: ProductDetail.name,
|
2015-06-12 20:08:40 +00:00
|
|
|
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: [],
|
2017-06-13 11:41:23 +00:00
|
|
|
discs: []
|
2015-06-12 20:08:40 +00:00
|
|
|
};
|
2014-10-04 00:04:33 +00:00
|
|
|
|
2015-06-12 19:37:19 +00:00
|
|
|
// URLs
|
|
|
|
release.urls.push({
|
|
|
|
'url': release_url,
|
2015-06-17 22:29:08 +00:00
|
|
|
'link_type': MBImport.URL_TYPES.purchase_for_download
|
2015-06-12 19:37:19 +00:00
|
|
|
});
|
|
|
|
|
2014-10-03 23:50:48 +00:00
|
|
|
release.labels.push(
|
|
|
|
{
|
2017-06-13 10:53:27 +00:00
|
|
|
name: ProductDetail.label.name,
|
|
|
|
catno: ProductDetail.catalog
|
2014-10-03 23:50:48 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// Tracks
|
|
|
|
var tracks = [];
|
2015-06-12 17:57:46 +00:00
|
|
|
var the_tracks = unsafeWindow.Playables.tracks;
|
|
|
|
var seen_tracks = {}; // to shoot duplicates ...
|
|
|
|
var release_artists = [];
|
|
|
|
$.each(the_tracks,
|
|
|
|
function (idx, track) {
|
2017-06-13 11:41:23 +00:00
|
|
|
if (track.release.id !== ProductDetail.id) {
|
2014-10-03 23:50:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-12 17:57:46 +00:00
|
|
|
if (seen_tracks[track.id]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
seen_tracks[track.id] = true;
|
2014-10-03 23:50:48 +00:00
|
|
|
|
2015-06-12 17:57:46 +00:00
|
|
|
var artists = [];
|
|
|
|
$.each(track.artists,
|
|
|
|
function (idx2, artist) {
|
2015-06-12 20:04:01 +00:00
|
|
|
artists.push(artist.name);
|
2015-06-12 17:57:46 +00:00
|
|
|
release_artists.push(artist.name);
|
2014-10-03 23:50:48 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-06-12 17:57:46 +00:00
|
|
|
var title = track.name;
|
2017-06-13 11:41:23 +00:00
|
|
|
if (track.mix && track.mix !== 'Original Mix') {
|
2015-06-12 17:57:46 +00:00
|
|
|
title += ' (' + track.mix + ')';
|
|
|
|
}
|
2014-10-03 23:50:48 +00:00
|
|
|
tracks.push({
|
2015-06-17 22:29:08 +00:00
|
|
|
'artist_credit': MBImport.makeArtistCredits(artists),
|
2015-06-12 17:57:46 +00:00
|
|
|
'title': title,
|
|
|
|
'duration': track.duration.minutes
|
2014-10-03 23:50:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2015-06-12 20:08:40 +00:00
|
|
|
|
2015-06-12 17:57:46 +00:00
|
|
|
var unique_artists = [];
|
|
|
|
$.each(release_artists, function(i, el){
|
|
|
|
if ($.inArray(el, unique_artists) === -1) {
|
|
|
|
unique_artists.push(el);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-12 21:21:37 +00:00
|
|
|
if (unique_artists.length > 4) {
|
2015-06-21 14:26:45 +00:00
|
|
|
release.artist_credit = [ MBImport.specialArtist('various_artists') ];
|
|
|
|
} else {
|
|
|
|
release.artist_credit = MBImport.makeArtistCredits(unique_artists);
|
2015-06-12 21:21:37 +00:00
|
|
|
}
|
2014-10-03 23:50:48 +00:00
|
|
|
release.discs.push( {
|
|
|
|
'tracks': tracks,
|
2015-06-12 20:08:40 +00:00
|
|
|
'format': release.format
|
2014-10-03 23:50:48 +00:00
|
|
|
} );
|
|
|
|
|
2015-01-18 13:13:32 +00:00
|
|
|
LOGGER.info("Parsed release: ", release);
|
2014-10-03 23:50:48 +00:00
|
|
|
return release;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert button into page under label information
|
2015-06-12 19:37:19 +00:00
|
|
|
function insertLink(release, release_url) {
|
2017-06-13 09:13:12 +00:00
|
|
|
var edit_note = MBImport.makeEditNote(release_url, 'Beatport');
|
2015-06-17 22:29:08 +00:00
|
|
|
var parameters = MBImport.buildFormParameters(release, edit_note);
|
2014-10-03 23:50:48 +00:00
|
|
|
|
2015-06-16 13:34:02 +00:00
|
|
|
var mbUI = $('<li class="interior-release-chart-content-item musicbrainz-import">'
|
2015-06-17 22:29:08 +00:00
|
|
|
+ MBImport.buildFormHTML(parameters)
|
|
|
|
+ MBImport.buildSearchButton(release)
|
2015-06-16 13:34:02 +00:00
|
|
|
+ '</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'});
|
|
|
|
mbUI.slideDown();
|
2015-06-10 22:22:38 +00:00
|
|
|
}
|