musicbrainz-userscripts/beatport_importer.user.js

137 lines
4.1 KiB
JavaScript
Raw Normal View History

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
2017-06-13 11:42:10 +00:00
// @version 2017.06.13.0
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/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @require lib/mbimport.js
// @require lib/logger.js
// @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==
// 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(){
MBImportStyle();
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
});
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
var release = {
artist_credit: [],
2017-06-13 10:25:02 +00:00
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: [],
discs: []
};
2014-10-04 00:04:33 +00:00
// URLs
release.urls.push({
'url': release_url,
'link_type': MBImport.URL_TYPES.purchase_for_download
});
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 = [];
var the_tracks = unsafeWindow.Playables.tracks;
var seen_tracks = {}; // to shoot duplicates ...
var release_artists = [];
$.each(the_tracks,
function (idx, track) {
if (track.release.id !== ProductDetail.id) {
2014-10-03 23:50:48 +00:00
return;
}
if (seen_tracks[track.id]) {
return;
}
seen_tracks[track.id] = true;
2014-10-03 23:50:48 +00:00
var artists = [];
$.each(track.artists,
function (idx2, artist) {
artists.push(artist.name);
release_artists.push(artist.name);
2014-10-03 23:50:48 +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({
'artist_credit': MBImport.makeArtistCredits(artists),
'title': title,
'duration': track.duration.minutes
2014-10-03 23:50:48 +00:00
});
}
);
var unique_artists = [];
$.each(release_artists, function(i, el){
if ($.inArray(el, unique_artists) === -1) {
unique_artists.push(el);
}
});
if (unique_artists.length > 4) {
release.artist_credit = [ MBImport.specialArtist('various_artists') ];
} else {
release.artist_credit = MBImport.makeArtistCredits(unique_artists);
}
2014-10-03 23:50:48 +00:00
release.discs.push( {
'tracks': tracks,
'format': release.format
2014-10-03 23:50:48 +00:00
} );
LOGGER.info("Parsed release: ", release);
2014-10-03 23:50:48 +00:00
return release;
}
// Insert button into page under label information
function insertLink(release, release_url) {
2017-06-13 09:13:12 +00:00
var edit_note = MBImport.makeEditNote(release_url, 'Beatport');
var parameters = MBImport.buildFormParameters(release, edit_note);
2014-10-03 23:50:48 +00:00
var 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'});
mbUI.slideDown();
2015-06-10 22:22:38 +00:00
}