mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-11-13 22:37:08 +00:00
beatport_importer: Adapt to website changes
This commit is contained in:
parent
3f2d037163
commit
a0e037147b
1 changed files with 54 additions and 58 deletions
|
@ -21,35 +21,36 @@ this.$ = this.jQuery = jQuery.noConflict(true);
|
||||||
|
|
||||||
if (!unsafeWindow) unsafeWindow = window;
|
if (!unsafeWindow) unsafeWindow = window;
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(() => {
|
||||||
MBImportStyle();
|
MBImportStyle();
|
||||||
|
|
||||||
$.getJSON(`https://www.beatport.com/api/v4/catalog/releases/${ProductDetail.id}`).done(release_data => {
|
const release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
||||||
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
|
||||||
let release = retrieveReleaseInfo(release_url, release_data);
|
|
||||||
|
|
||||||
const track_urls = release_data.tracks.map(url => url.replace('api.beatport.com', 'www.beatport.com/api').replace(/\/$/, ''));
|
const data = JSON.parse(document.getElementById('__NEXT_DATA__').innerHTML);
|
||||||
let results = [];
|
const release_data = data.props.pageProps.release;
|
||||||
const promises = track_urls.map((url, index) => $.getJSON(url).then(response => (results[index] = response)));
|
|
||||||
|
|
||||||
Promise.all(promises)
|
// Reversing is less reliable, but the API does not provide track numbers.
|
||||||
.then(() => results.map(({ isrc, number }) => ({ isrc, number })))
|
const tracks_table = release_data.tracks.reverse();
|
||||||
.then(isrcs => {
|
|
||||||
insertLink(release, release_url, isrcs);
|
const tracks_release = $.grep(data.props.pageProps.dehydratedState.queries, element => /tracks-release/g.test(element.queryKey))[0];
|
||||||
});
|
const tracks_data = $.map(tracks_table, url => $.grep(tracks_release.state.data.results, element => element.url === url));
|
||||||
});
|
const isrcs = tracks_data.map(track => track.isrc);
|
||||||
|
|
||||||
|
const mbrelease = retrieveReleaseInfo(release_url, release_data, tracks_data);
|
||||||
|
|
||||||
|
setTimeout(() => insertLink(mbrelease, release_url, isrcs), 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
function retrieveReleaseInfo(release_url, release_data) {
|
function retrieveReleaseInfo(release_url, release_data, tracks_data) {
|
||||||
let releaseDate = ProductDetail.date.published.split('-');
|
const release_date = release_data.new_release_date.split('-');
|
||||||
|
|
||||||
// Release information global to all Beatport releases
|
// Release information global to all Beatport releases
|
||||||
let release = {
|
const mbrelease = {
|
||||||
artist_credit: [],
|
artist_credit: [],
|
||||||
title: ProductDetail.name,
|
title: release_data.name,
|
||||||
year: releaseDate[0],
|
year: release_date[0],
|
||||||
month: releaseDate[1],
|
month: release_date[1],
|
||||||
day: releaseDate[2],
|
day: release_date[2],
|
||||||
format: 'Digital Media',
|
format: 'Digital Media',
|
||||||
packaging: 'None',
|
packaging: 'None',
|
||||||
country: 'XW',
|
country: 'XW',
|
||||||
|
@ -64,29 +65,23 @@ function retrieveReleaseInfo(release_url, release_data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// URLs
|
// URLs
|
||||||
release.urls.push({
|
mbrelease.urls.push({
|
||||||
url: release_url,
|
url: release_url,
|
||||||
link_type: MBImport.URL_TYPES.purchase_for_download,
|
link_type: MBImport.URL_TYPES.purchase_for_download,
|
||||||
});
|
});
|
||||||
|
|
||||||
release.labels.push({
|
mbrelease.labels.push({
|
||||||
name: ProductDetail.label.name,
|
name: release_data.label.name,
|
||||||
catno: ProductDetail.catalog,
|
catno: release_data.catalog_number,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reload Playables if empty
|
|
||||||
if (!Object.prototype.hasOwnProperty.call(unsafeWindow.Playables, 'tracks')) {
|
|
||||||
eval($('#data-objects').text());
|
|
||||||
unsafeWindow.Playables = window.Playables;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tracks
|
// Tracks
|
||||||
let tracks = [];
|
const mbtracks = [];
|
||||||
let the_tracks = unsafeWindow.Playables.tracks;
|
|
||||||
let seen_tracks = {}; // to shoot duplicates ...
|
const seen_tracks = {}; // to shoot duplicates ...
|
||||||
let release_artists = [];
|
const release_artists = [];
|
||||||
$.each(the_tracks, function (idx, track) {
|
$.each(tracks_data, (index, track) => {
|
||||||
if (track.release.id !== ProductDetail.id) {
|
if (track.release.id != release_data.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (seen_tracks[track.id]) {
|
if (seen_tracks[track.id]) {
|
||||||
|
@ -95,65 +90,66 @@ function retrieveReleaseInfo(release_url, release_data) {
|
||||||
seen_tracks[track.id] = true;
|
seen_tracks[track.id] = true;
|
||||||
|
|
||||||
let artists = [];
|
let artists = [];
|
||||||
$.each(track.artists, function (idx2, artist) {
|
$.each(track.artists, (index2, artist) => {
|
||||||
artists.push(artist.name);
|
artists.push(artist.name);
|
||||||
release_artists.push(artist.name);
|
release_artists.push(artist.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
let title = track.name;
|
let title = track.name;
|
||||||
if (track.mix && track.mix !== 'Original Mix') {
|
if (track.mix_name && track.mix_name !== 'Original Mix') {
|
||||||
title += ` (${track.mix})`;
|
title += ` (${track.mix_name})`;
|
||||||
}
|
}
|
||||||
tracks.push({
|
mbtracks.push({
|
||||||
artist_credit: MBImport.makeArtistCredits(artists),
|
artist_credit: MBImport.makeArtistCredits(artists),
|
||||||
title: title,
|
title: title,
|
||||||
duration: track.duration.minutes,
|
duration: track.length,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let unique_artists = [];
|
const unique_artists = [];
|
||||||
$.each(release_artists, function (i, el) {
|
$.each(release_artists, (index, el) => {
|
||||||
if ($.inArray(el, unique_artists) === -1) {
|
if ($.inArray(el, unique_artists) === -1) {
|
||||||
unique_artists.push(el);
|
unique_artists.push(el);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (unique_artists.length > 4) {
|
if (unique_artists.length > 4) {
|
||||||
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
mbrelease.artist_credit = [MBImport.specialArtist('various_artists')];
|
||||||
} else {
|
} else {
|
||||||
release.artist_credit = MBImport.makeArtistCredits(unique_artists);
|
mbrelease.artist_credit = MBImport.makeArtistCredits(unique_artists);
|
||||||
}
|
}
|
||||||
release.discs.push({
|
|
||||||
tracks: tracks,
|
mbrelease.discs.push({
|
||||||
format: release.format,
|
tracks: mbtracks,
|
||||||
|
format: mbrelease.format,
|
||||||
});
|
});
|
||||||
|
|
||||||
LOGGER.info('Parsed release: ', release);
|
LOGGER.info('Parsed release: ', mbrelease);
|
||||||
return release;
|
return mbrelease;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert button into page under label information
|
// Insert button into page under label information
|
||||||
function insertLink(release, release_url, isrcs) {
|
function insertLink(mbrelease, release_url, isrcs) {
|
||||||
let edit_note = MBImport.makeEditNote(release_url, 'Beatport');
|
const edit_note = MBImport.makeEditNote(release_url, 'Beatport');
|
||||||
let parameters = MBImport.buildFormParameters(release, edit_note);
|
const parameters = MBImport.buildFormParameters(mbrelease, edit_note);
|
||||||
|
|
||||||
let mbUI = $(
|
const mbUI = $(
|
||||||
`<li class="interior-release-chart-content-item musicbrainz-import">${MBImport.buildFormHTML(
|
`<div class="interior-release-chart-content-item musicbrainz-import">${MBImport.buildFormHTML(
|
||||||
parameters
|
parameters
|
||||||
)}${MBImport.buildSearchButton(release)}</li>`
|
)}${MBImport.buildSearchButton(mbrelease)}</div>`
|
||||||
).hide();
|
).hide();
|
||||||
|
|
||||||
$(
|
$(
|
||||||
'<form class="musicbrainz_import"><button type="submit" title="Submit ISRCs to MusicBrainz with kepstin’s MagicISRC"><span>Submit ISRCs</span></button></form>'
|
'<form class="musicbrainz_import"><button type="submit" title="Submit ISRCs to MusicBrainz with kepstin’s MagicISRC"><span>Submit ISRCs</span></button></form>'
|
||||||
)
|
)
|
||||||
.on('click', event => {
|
.on('click', event => {
|
||||||
const query = isrcs.map(({ isrc, number }) => (isrc == null ? `isrc${number}=` : `isrc${number}=${isrc}`)).join('&');
|
const query = isrcs.map((isrc, index) => (isrc == null ? `isrc${index + 1}=` : `isrc${index + 1}=${isrc}`)).join('&');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
window.open(`https://magicisrc.kepstin.ca?${query}`);
|
window.open(`https://magicisrc.kepstin.ca?${query}`);
|
||||||
})
|
})
|
||||||
.appendTo(mbUI);
|
.appendTo(mbUI);
|
||||||
|
|
||||||
$('.interior-release-chart-content-list').append(mbUI);
|
$('div[title="Collection controls"]').append(mbUI);
|
||||||
$('form.musicbrainz_import').css({ display: 'inline-block', 'margin-left': '5px' });
|
$('form.musicbrainz_import').css({ display: 'inline-block', 'margin-left': '5px' });
|
||||||
$('form.musicbrainz_import button').css({ width: '120px' });
|
$('form.musicbrainz_import button').css({ width: '120px' });
|
||||||
mbUI.slideDown();
|
mbUI.slideDown();
|
||||||
|
|
Loading…
Reference in a new issue