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
// @include http://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://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/lib/import_functions.js
// @require https://raw.github.com/murdos/musicbrainz-userscripts/master/lib/logger.js
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @require lib/import_functions.js
// @require lib/logger.js
// ==/UserScript==
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
this.$ = this.jQuery = jQuery.noConflict(true);
if (!unsafeWindow) unsafeWindow = window;
$(document).ready(function(){
eval( $( "#data-objects" )[0].textContent );
var release = retrieveReleaseInfo();
insertLink(release);
});
function retrieveReleaseInfo() {
var release = {};
@ -32,7 +33,7 @@ function retrieveReleaseInfo() {
release.status = 'official';
release.urls = [];
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();
@ -51,30 +52,63 @@ function retrieveReleaseInfo() {
// Tracks
var tracks = [];
window.Playables.tracks.forEach(
function ( j, index, arr ) {
if(j.release.id != release.id) {
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 != release.id) {
return;
}
if (seen_tracks[track.id]) {
return;
}
seen_tracks[track.id] = true;
var artist = [];
j.artists.forEach(
function ( a, index, arr ) {
artist.push({
'artist_name': a.name
var artists = [];
$.each(track.artists,
function (idx2, artist) {
artists.push({
'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({
'artist_credit': artist,
'title': j.title,
'duration': j.duration.minutes
'artist_credit': artists,
'title': title,
'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.push( {
'tracks': tracks,
@ -92,5 +126,6 @@ function insertLink(release) {
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');
}