mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-12-13 11:52:27 +00:00
boomkat_importer: Fix for recent Boomkat changes.
Rather than fight with jQuery conflicts, just use regular JS.
This commit is contained in:
parent
e801047823
commit
f06a211699
1 changed files with 46 additions and 58 deletions
|
@ -1,43 +1,36 @@
|
|||
// ==UserScript==
|
||||
// @name Import Boomkat releases to Musicbrainz
|
||||
// @description Add a button on Boomkat release pages to open MusicBrainz release editor with pre-filled data for the selected release
|
||||
// @version 2020.07.21.1
|
||||
// @version 2024.09.10.1
|
||||
// @license X11
|
||||
// @namespace https://github.com/murdos/musicbrainz-userscripts
|
||||
// @include https://boomkat.com/products/*
|
||||
// @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
|
||||
|
||||
// ==/UserScript==
|
||||
|
||||
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
||||
this.$ = this.jQuery = jQuery.noConflict(true);
|
||||
|
||||
if (!unsafeWindow) unsafeWindow = window;
|
||||
|
||||
$(document).ready(function () {
|
||||
async function onLoad() {
|
||||
MBImportStyle();
|
||||
|
||||
const release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
||||
let release = retrieveReleaseInfo(release_url);
|
||||
let release = await retrieveReleaseInfo(release_url);
|
||||
insertLink(release, release_url, true);
|
||||
|
||||
// Update the release info when a different tab/format is
|
||||
// selected. We need a timeout here due to a slight delay between
|
||||
// clicking the tab and the tab's classes (and the tracklist)
|
||||
// being updated.
|
||||
$('ul.tabs li.tab-title a').click(function () {
|
||||
document.querySelector('ul.tabs li.tab-title a').addEventListener('click', function () {
|
||||
setTimeout(function () {
|
||||
release = retrieveReleaseInfo(release_url);
|
||||
updateLink(release, release_url, false);
|
||||
}, 150);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getFormat() {
|
||||
const format = $('ul.tabs .tab-title.active a').text().trim();
|
||||
const format = document.querySelector('ul.tabs .tab-title.active a').textContent.trim();
|
||||
|
||||
if (format.match(/MP3|WAV|FLAC/i)) {
|
||||
return 'Digital Media';
|
||||
|
@ -65,14 +58,14 @@ function getLinkType(media) {
|
|||
return MBImport.URL_TYPES.purchase_for_mail_order;
|
||||
}
|
||||
|
||||
function retrieveReleaseInfo(release_url) {
|
||||
const releaseDateStr = $('span.release-date-placeholder').first().text().replace('Release date: ', '');
|
||||
async function retrieveReleaseInfo(release_url) {
|
||||
const releaseDateStr = document.querySelector('span.release-date-placeholder').textContent.replace('Release date: ', '');
|
||||
const releaseDate = new Date(releaseDateStr);
|
||||
const artist = $('h1.detail--artists').text().trim();
|
||||
const artist = document.querySelector('h1.detail--artists').textContent.trim();
|
||||
|
||||
const release = {
|
||||
artist_credit: MBImport.makeArtistCredits([artist]),
|
||||
title: $('h2.detail_album').text().trim(),
|
||||
title: document.querySelector('h2.detail_album').textContent.trim(),
|
||||
year: releaseDate.getUTCFullYear(),
|
||||
month: releaseDate.getUTCMonth() + 1,
|
||||
day: releaseDate.getUTCDate(),
|
||||
|
@ -88,10 +81,8 @@ function retrieveReleaseInfo(release_url) {
|
|||
|
||||
// Labels
|
||||
release.labels.push({
|
||||
name: $('span.label-placeholder a').first().text(),
|
||||
catno: $('span.catalogue-number-placeholder')
|
||||
.text()
|
||||
.replace(/Cat No:/, ''),
|
||||
name: document.querySelector('span.label-placeholder a').textContent,
|
||||
catno: document.querySelector('span.catalogue-number-placeholder').textContent.replace(/Cat No:/, ''),
|
||||
});
|
||||
|
||||
// Format/packaging
|
||||
|
@ -108,56 +99,53 @@ function retrieveReleaseInfo(release_url) {
|
|||
// Boomkat loads the tracklist dynamically. Using setTimeout()
|
||||
// here is not consistent for reasons I have not yet figured out.
|
||||
// For now, just fetch the tracks the same way Boomkat does.
|
||||
const releaseID = $('a.play-all').first().data('audio-player-release');
|
||||
const releaseID = document.querySelector('a.play-all').dataset.audioPlayerRelease;
|
||||
const tracklistURL = `https://boomkat.com/tracklist/${releaseID}`;
|
||||
const tracks = [];
|
||||
$.ajax({
|
||||
url: tracklistURL,
|
||||
async: false,
|
||||
success: function (data) {
|
||||
$($.parseHTML(data))
|
||||
.find('div.table-row.track.mp3.clearfix a')
|
||||
.each(function (index, link) {
|
||||
tracks.push({
|
||||
artist_credit: MBImport.makeArtistCredits([$(link).data('artist')]),
|
||||
title: $(link).data('name'),
|
||||
duration: $(link).siblings('.time').first().text(),
|
||||
});
|
||||
});
|
||||
|
||||
release.discs.push({
|
||||
tracks: tracks,
|
||||
format: release.format,
|
||||
});
|
||||
},
|
||||
let tracks = [];
|
||||
const response = await fetch(tracklistURL);
|
||||
const body = await response.text();
|
||||
const doc = document.implementation.createHTMLDocument('');
|
||||
doc.body.innerHTML = body;
|
||||
doc.querySelectorAll('div.table-row.track.mp3.clearfix a').forEach(function (link) {
|
||||
tracks.push({
|
||||
artist_credit: MBImport.makeArtistCredits([link.dataset.artist]),
|
||||
title: link.dataset.name,
|
||||
duration: link.dataset.duration,
|
||||
});
|
||||
});
|
||||
release.discs.push({
|
||||
tracks: tracks,
|
||||
format: release.format,
|
||||
});
|
||||
LOGGER.info('Parsed release: ', release);
|
||||
return release;
|
||||
}
|
||||
|
||||
function updateLink(release, release_url) {
|
||||
$('.musicbrainz-import').remove();
|
||||
$('.musicbrainz_import_add').remove();
|
||||
document.querySelector('.musicbrainz-import').remove();
|
||||
document.querySelector('.musicbrainz_import_add').remove();
|
||||
insertLink(release, release_url, false);
|
||||
}
|
||||
|
||||
// Insert button into page under label information
|
||||
function insertLink(release, release_url, animate) {
|
||||
function insertLink(release, release_url) {
|
||||
const edit_note = MBImport.makeEditNote(release_url, 'Boomkat');
|
||||
const parameters = MBImport.buildFormParameters(release, edit_note);
|
||||
|
||||
const mbUI = $(
|
||||
`<li class="tab-title musicbrainz-import">${MBImport.buildFormHTML(parameters)}</li>
|
||||
<li class="tab-title musicbrainz-import">${MBImport.buildSearchButton(release)}</li>`
|
||||
);
|
||||
const formButton = document.createElement('li');
|
||||
formButton.className = 'tab-title musicbrainz-import';
|
||||
formButton.innerHTML = MBImport.buildFormHTML(MBImport.buildFormParameters(release, edit_note));
|
||||
|
||||
if (animate) {
|
||||
mbUI.hide();
|
||||
}
|
||||
const searchButton = document.createElement('li');
|
||||
searchButton.className = 'tab-title musicbrainz-import';
|
||||
searchButton.innerHTML = MBImport.buildSearchButton(release);
|
||||
|
||||
$('ul.tabs.product-page-tabs').append(mbUI);
|
||||
|
||||
if (animate) {
|
||||
mbUI.slideDown();
|
||||
}
|
||||
const tabs = document.querySelector('ul.tabs.product-page-tabs');
|
||||
tabs.appendChild(formButton);
|
||||
tabs.appendChild(searchButton);
|
||||
}
|
||||
|
||||
if (document.readyState !== 'loading') {
|
||||
onLoad();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', onLoad);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue