BeatPort Pro: make it work again

Fixed:
- invisible import button
- more tracks than in the release
- release artist credit were the ones of the last track
- remove 'Original Mix' from track titles
- update jquery to recent version
- prevent jquery conflicts
- use relative paths for lib
This commit is contained in:
Laurent Monin 2015-06-12 19:57:46 +02:00
parent f5255fb22e
commit c8ee328d78

View file

@ -8,21 +8,22 @@
// @updateURL 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 http://pro.beatport.com/release/*
// @include https://pro.beatport.com/release/* // @include https://pro.beatport.com/release/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @require https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/lib/import_functions.js // @require lib/import_functions.js
// @require https://raw.github.com/murdos/musicbrainz-userscripts/master/lib/logger.js // @require lib/logger.js
// ==/UserScript== // ==/UserScript==
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
this.$ = this.jQuery = jQuery.noConflict(true);
if (!unsafeWindow) unsafeWindow = window; if (!unsafeWindow) unsafeWindow = window;
$(document).ready(function(){ $(document).ready(function(){
eval( $( "#data-objects" )[0].textContent );
var release = retrieveReleaseInfo(); var release = retrieveReleaseInfo();
insertLink(release); insertLink(release);
}); });
function retrieveReleaseInfo() { function retrieveReleaseInfo() {
var release = {}; var release = {};
@ -32,7 +33,7 @@ function retrieveReleaseInfo() {
release.status = 'official'; release.status = 'official';
release.urls = []; release.urls = [];
release.urls.push( { 'url': window.location.href } ); release.urls.push( { 'url': window.location.href } );
release.id = $( "a[data-release]" ).attr('data-release'); release.id = $( "span.playable-play-all[data-release]" ).attr('data-release');
release.title = $( "h3.interior-type:contains('Release')" ).next().text().trim(); release.title = $( "h3.interior-type:contains('Release')" ).next().text().trim();
@ -51,30 +52,63 @@ function retrieveReleaseInfo() {
// Tracks // Tracks
var tracks = []; var tracks = [];
var the_tracks = unsafeWindow.Playables.tracks;
window.Playables.tracks.forEach( var seen_tracks = {}; // to shoot duplicates ...
function ( j, index, arr ) { var release_artists = [];
if(j.release.id != release.id) { $.each(the_tracks,
function (idx, track) {
if (track.release.id != release.id) {
return; return;
} }
if (seen_tracks[track.id]) {
return;
}
seen_tracks[track.id] = true;
var artist = []; var artists = [];
j.artists.forEach( $.each(track.artists,
function ( a, index, arr ) { function (idx2, artist) {
artist.push({ artists.push({
'artist_name': a.name 'artist_name': artist.name
}); });
release_artists.push(artist.name);
} }
); );
release.artist_credit = artist;
var title = track.name;
if (track.mix && track.mix != 'Original Mix') {
title += ' (' + track.mix + ')';
}
tracks.push({ tracks.push({
'artist_credit': artist, 'artist_credit': artists,
'title': j.title, 'title': title,
'duration': j.duration.minutes 'duration': track.duration.minutes
}); });
} }
); );
var unique_artists = [];
$.each(release_artists, function(i, el){
if ($.inArray(el, unique_artists) === -1) {
unique_artists.push(el);
}
});
var artists = unique_artists.map(function(item) { return {artist_name: item}; });
if (artists.length > 2) {
var last = artists.pop();
last.joinphrase = '';
var prev = artists.pop();
prev.joinphrase = ' & ';
for (var i = 0; i < artists.length; i++) {
artists[i].joinphrase = ', ';
}
artists.push(prev);
artists.push(last);
} else if (artists.length == 2) {
artists[0].joinphrase = ' & ';
}
release.artist_credit = artists;
release.discs = []; release.discs = [];
release.discs.push( { release.discs.push( {
'tracks': tracks, 'tracks': tracks,
@ -92,5 +126,6 @@ function insertLink(release) {
var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters); var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters);
$(".interior-release-chart-content-list").append(innerHTML); $(".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');
} }