2014-10-03 23:50:48 +00:00
|
|
|
// ==UserScript==
|
2015-06-10 12:59:12 +00:00
|
|
|
// @name Import Beatport Pro 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/
|
2014-10-03 23:50:48 +00:00
|
|
|
// @description One-click importing of releases from pro.beatport.com/release pages into MusicBrainz
|
2015-06-14 13:02:07 +00:00
|
|
|
// @version 2015.06.14.0
|
2014-10-03 23:50:48 +00:00
|
|
|
// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/beatport_pro_importer.user.js
|
|
|
|
// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/beatport_pro_importer.user.js
|
|
|
|
// @include http://pro.beatport.com/release/*
|
|
|
|
// @include https://pro.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
|
|
|
|
// @require lib/import_functions.js
|
|
|
|
// @require lib/logger.js
|
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-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) {
|
2015-06-12 20:08:40 +00:00
|
|
|
var releaseDate = $( ".category:contains('Release Date')" ).next().text().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: [],
|
|
|
|
title: $( "h3.interior-type:contains('Release')" ).next().text().trim(),
|
|
|
|
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: [],
|
|
|
|
discs: [],
|
|
|
|
};
|
2014-10-04 00:04:33 +00:00
|
|
|
|
2015-06-12 20:06:00 +00:00
|
|
|
var release_id = $( "span.playable-play-all[data-release]" ).attr('data-release');
|
2014-10-03 23:50:48 +00:00
|
|
|
|
2015-06-12 19:37:19 +00:00
|
|
|
// URLs
|
|
|
|
release.urls.push({
|
|
|
|
'url': release_url,
|
|
|
|
'link_type': MBReleaseImportHelper.URL_TYPES.purchase_for_download
|
|
|
|
});
|
|
|
|
|
2014-10-03 23:50:48 +00:00
|
|
|
release.labels.push(
|
|
|
|
{
|
|
|
|
name: $( ".category:contains('Labels')" ).next().text().trim(),
|
|
|
|
catno: $( ".category:contains('Catalog')" ).next().text()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// 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) {
|
2015-06-12 20:06:00 +00:00
|
|
|
if (track.release.id != release_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;
|
|
|
|
if (track.mix && track.mix != 'Original Mix') {
|
|
|
|
title += ' (' + track.mix + ')';
|
|
|
|
}
|
2014-10-03 23:50:48 +00:00
|
|
|
tracks.push({
|
2015-06-12 20:04:01 +00:00
|
|
|
'artist_credit': MBReleaseImportHelper.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) {
|
|
|
|
unique_artists = [ 'Various Artists' ];
|
|
|
|
}
|
2015-06-12 20:04:01 +00:00
|
|
|
release.artist_credit = MBReleaseImportHelper.makeArtistCredits(unique_artists);
|
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) {
|
|
|
|
var edit_note = 'Imported from ' + release_url;
|
2014-10-03 23:50:48 +00:00
|
|
|
var parameters = MBReleaseImportHelper.buildFormParameters(release, edit_note);
|
|
|
|
|
|
|
|
var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters);
|
|
|
|
|
2015-06-12 17:57:46 +00:00
|
|
|
$(".interior-release-chart-content-list").append('<li class="interior-release-chart-content-item musicbrainz-import">' + innerHTML + '</li>');
|
|
|
|
$('.musicbrainz-import input[type="submit"]').css('background', '#eee');
|
2015-06-10 22:22:38 +00:00
|
|
|
}
|