From 7aa01437e8acc3d328b557bf49363cbda352ec26 Mon Sep 17 00:00:00 2001 From: David Logie Date: Tue, 21 Jul 2020 09:54:02 +0100 Subject: [PATCH] Add Boomkat importer. --- README.md | 7 ++ boomkat_importer.user.js | 163 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 boomkat_importer.user.js diff --git a/README.md b/README.md index d4cb7b1..d1880f3 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ - [Import Bandcamp releases to MusicBrainz Album Link Helper](#bandcamp_importer_helper) - [Import Beatport Classic releases to MusicBrainz](#beatport_classic_importer) - [Import Beatport releases to MusicBrainz](#beatport_importer) +- [Import Boomkat releases to Musicbrainz](#boomkat_importer) - [Import CD Baby releases to MusicBrainz](#cdbaby_importer) - [Import CD1D releases to MusicBrainz](#cd1d_importer) - [Import DG/Decca releases to MusicBrainz](#dgdecca_importer) @@ -61,6 +62,12 @@ One-click importing of releases from beatport.com/release pages into MusicBrainz [![Source](https://github.com/jerone/UserScripts/blob/master/_resources/Source-button.png)](https://github.com/murdos/musicbrainz-userscripts/blob/master/beatport_importer.user.js) [![Install](https://raw.github.com/jerone/UserScripts/master/_resources/Install-button.png)](https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/beatport_importer.user.js) +## Import Boomkat releases to Musicbrainz + +Add a button on Boomkat release pages to open MusicBrainz release editor with pre-filled data for the selected release + +[![Source](https://github.com/jerone/UserScripts/blob/master/_resources/Source-button.png)](https://github.com/murdos/musicbrainz-userscripts/blob/master/boomkat_importer.user.js) + ## Import CD Baby releases to MusicBrainz One-click importing of releases from cdbaby.com into MusicBrainz. diff --git a/boomkat_importer.user.js b/boomkat_importer.user.js new file mode 100644 index 0000000..64a0a91 --- /dev/null +++ b/boomkat_importer.user.js @@ -0,0 +1,163 @@ +// ==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 +// @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 () { + MBImportStyle(); + + const release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, ''); + let release = 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 () { + setTimeout(function () { + release = retrieveReleaseInfo(release_url); + updateLink(release, release_url, false); + }, 150); + }); +}); + +function getFormat() { + const format = $('ul.tabs .tab-title.active a').text().trim(); + + if (format.match(/MP3|WAV|FLAC/i)) { + return 'Digital Media'; + } + + if (format.match(/CD/i)) { + return 'CD'; + } + + if (format.match(/LP|12"/i)) { + return 'Vinyl'; + } + + if (format.match(/CASSETTE/i)) { + return 'Cassette'; + } + + return ''; +} + +function getLinkType(media) { + if (media == 'Digital Media') { + return MBImport.URL_TYPES.purchase_for_download; + } + return MBImport.URL_TYPES.purchase_for_mail_order; +} + +function retrieveReleaseInfo(release_url) { + const releaseDateStr = $('span.release-date-placeholder').first().text().replace('Release date: ', ''); + const releaseDate = new Date(releaseDateStr); + const artist = $('h1.detail--artists').text().trim(); + + const release = { + artist_credit: MBImport.makeArtistCredits([artist]), + title: $('h2.detail_album').text().trim(), + year: releaseDate.getUTCFullYear(), + month: releaseDate.getUTCMonth() + 1, + day: releaseDate.getUTCDate(), + country: 'XW', + status: 'official', + language: 'eng', + script: 'Latn', + type: '', + urls: [], + labels: [], + discs: [], + }; + + // Labels + release.labels.push({ + name: $('span.label-placeholder a').first().text(), + catno: $('span.catalogue-number-placeholder') + .text() + .replace(/Cat No:/, ''), + }); + + // Format/packaging + release.format = getFormat(); + release.packaging = release.format == 'Digital Media' ? 'None' : ''; + + // URLs + release.urls.push({ + url: release_url, + link_type: getLinkType(release.format), + }); + + // Tracks + // 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 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, + }); + }, + }); + LOGGER.info('Parsed release: ', release); + return release; +} + +function updateLink(release, release_url) { + $('.musicbrainz-import').remove(); + $('.musicbrainz_import_add').remove(); + insertLink(release, release_url, false); +} + +// Insert button into page under label information +function insertLink(release, release_url, animate) { + const edit_note = MBImport.makeEditNote(release_url, 'Boomkat'); + const parameters = MBImport.buildFormParameters(release, edit_note); + + const mbUI = $( + `
  • ${MBImport.buildFormHTML(parameters)}
  • +
  • ${MBImport.buildSearchButton(release)}
  • ` + ); + + if (animate) { + mbUI.hide(); + } + + $('ul.tabs.product-page-tabs').append(mbUI); + + if (animate) { + mbUI.slideDown(); + } +}