2016-03-30 13:11:37 +00:00
|
|
|
|
// ==UserScript==
|
|
|
|
|
// @name Import CD Baby releases to MusicBrainz
|
|
|
|
|
// @namespace https://github.com/murdos/musicbrainz-userscripts/
|
|
|
|
|
// @description One-click importing of releases from cdbaby.com into MusicBrainz.
|
2018-02-18 17:16:45 +00:00
|
|
|
|
// @version 2018.2.18.1
|
2016-03-30 13:11:37 +00:00
|
|
|
|
// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/cdbaby_importer.user.js
|
|
|
|
|
// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/cdbaby_importer.user.js
|
2017-05-17 23:23:41 +00:00
|
|
|
|
// @include /^https?:\/\/(?:store\.)?(?:cdbaby\.com)\/cd\/[^\/]+/
|
2016-03-30 13:11:37 +00:00
|
|
|
|
// @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
|
|
|
|
|
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
|
|
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
|
|
|
|
this.$ = this.jQuery = jQuery.noConflict(true);
|
|
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
|
$(document).ready(function () {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
MBImportStyle();
|
|
|
|
|
let release_url = window.location.href.replace('/?.*$/', '').replace(/#.*$/, '');
|
|
|
|
|
release_url = release_url.replace(/^(?:https?:\/\/)?(?:store\.)?(?:cdbaby\.com)\//, 'http://store.cdbaby.com/');
|
|
|
|
|
|
|
|
|
|
let release;
|
|
|
|
|
let buttons = '';
|
2020-04-05 14:01:21 +00:00
|
|
|
|
$('div.album-page-buy-button-container a').each(function () {
|
|
|
|
|
let format = $(this).attr('title').trim();
|
2018-11-20 22:18:49 +00:00
|
|
|
|
release = retrieveReleaseInfo(release_url, format);
|
|
|
|
|
buttons += getImportButton(release, release_url, format);
|
|
|
|
|
});
|
2016-04-03 10:46:12 +00:00
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
|
if (release) {
|
|
|
|
|
insertImportLinks(release, buttons);
|
|
|
|
|
}
|
2016-04-03 10:46:12 +00:00
|
|
|
|
});
|
2016-03-30 13:11:37 +00:00
|
|
|
|
|
2016-04-03 10:46:12 +00:00
|
|
|
|
function retrieveReleaseInfo(release_url, format) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
// Release defaults
|
|
|
|
|
let release = {
|
|
|
|
|
artist_credit: '',
|
2020-04-05 14:01:21 +00:00
|
|
|
|
title: $("h1 span[itemprop='name']").text().trim(),
|
2018-11-20 22:18:49 +00:00
|
|
|
|
year: 0,
|
|
|
|
|
month: 0,
|
|
|
|
|
day: 0,
|
|
|
|
|
format: '',
|
|
|
|
|
packaging: '',
|
|
|
|
|
country: '',
|
|
|
|
|
status: 'official',
|
|
|
|
|
language: 'eng',
|
|
|
|
|
script: 'Latn',
|
|
|
|
|
type: '',
|
|
|
|
|
urls: [],
|
|
|
|
|
labels: [],
|
2020-04-05 14:01:21 +00:00
|
|
|
|
discs: [],
|
2018-11-20 22:18:49 +00:00
|
|
|
|
};
|
2016-03-30 13:11:37 +00:00
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let link_type = MBImport.URL_TYPES;
|
|
|
|
|
|
|
|
|
|
release.urls = [];
|
|
|
|
|
if (format.match(/^vinyl/i)) {
|
|
|
|
|
release.country = 'US';
|
|
|
|
|
release.format = 'Vinyl';
|
|
|
|
|
release.urls.push({
|
|
|
|
|
url: release_url,
|
2020-04-05 14:01:21 +00:00
|
|
|
|
link_type: link_type.purchase_for_mail_order,
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
|
|
|
|
} else if (format.match(/^cd/i)) {
|
|
|
|
|
release.country = 'US';
|
|
|
|
|
release.format = 'CD';
|
|
|
|
|
release.urls.push({
|
|
|
|
|
url: release_url,
|
2020-04-05 14:01:21 +00:00
|
|
|
|
link_type: link_type.purchase_for_mail_order,
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
|
|
|
|
} else if (format.match(/^download/i)) {
|
|
|
|
|
release.country = 'XW';
|
|
|
|
|
release.packaging = 'None';
|
|
|
|
|
release.format = 'Digital Media';
|
|
|
|
|
release.urls.push({
|
|
|
|
|
url: release_url,
|
2020-04-05 14:01:21 +00:00
|
|
|
|
link_type: link_type.purchase_for_download,
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
2016-03-30 13:11:37 +00:00
|
|
|
|
}
|
2016-04-03 10:46:12 +00:00
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
|
// Release artist
|
2020-04-05 14:01:21 +00:00
|
|
|
|
let artist = $("h2 span[itemprop='byArtist'] a").text().trim();
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let various_artists = artist == 'Various';
|
|
|
|
|
if (various_artists) {
|
|
|
|
|
release.artist_credit = [MBImport.specialArtist('various_artists')];
|
2016-03-30 13:11:37 +00:00
|
|
|
|
} else {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
release.artist_credit = MBImport.makeArtistCredits([artist]);
|
2016-03-30 13:11:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
|
release.year = $("span[itemprop='datePublished']").text().trim();
|
2018-11-20 22:18:49 +00:00
|
|
|
|
|
|
|
|
|
// Tracks
|
|
|
|
|
let tracks = [];
|
|
|
|
|
let trackcount = 0;
|
2020-04-05 14:01:21 +00:00
|
|
|
|
$("table.track-table tr[itemprop='track']").each(function () {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let artists = [];
|
|
|
|
|
let trackno = tracks.length + 1;
|
|
|
|
|
if (trackno == 1 && tracks.length) {
|
|
|
|
|
// multiple "discs"
|
|
|
|
|
release.discs.push({
|
|
|
|
|
tracks: tracks,
|
2020-04-05 14:01:21 +00:00
|
|
|
|
format: release.format,
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
|
|
|
|
tracks = [];
|
|
|
|
|
}
|
2020-04-05 14:01:21 +00:00
|
|
|
|
let trackname = $(this).find("meta[itemprop='name']").attr('content').trim();
|
|
|
|
|
let tracklength = $(this).find("meta[itemprop='duration']").attr('content').trim();
|
2018-11-20 22:18:49 +00:00
|
|
|
|
|
|
|
|
|
let track_artists = [];
|
|
|
|
|
// FIXME various artists releases ...
|
|
|
|
|
$(this)
|
|
|
|
|
.find('div.track-artist')
|
2020-04-05 14:01:21 +00:00
|
|
|
|
.each(function () {
|
|
|
|
|
let artistname = $(this).text().trim();
|
2018-11-20 22:18:49 +00:00
|
|
|
|
if (artistname) {
|
|
|
|
|
track_artists.push(artistname);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let ac = {
|
|
|
|
|
artist_credit: '',
|
|
|
|
|
title: trackname,
|
2020-04-05 14:01:21 +00:00
|
|
|
|
duration: MBImport.ISO8601toMilliSeconds(tracklength),
|
2018-11-20 22:18:49 +00:00
|
|
|
|
};
|
|
|
|
|
if (!track_artists.length && various_artists) {
|
|
|
|
|
ac.artist_credit = [MBImport.specialArtist('unknown')];
|
|
|
|
|
} else {
|
|
|
|
|
ac.artist_credit = MBImport.makeArtistCredits(track_artists);
|
|
|
|
|
}
|
|
|
|
|
tracks.push(ac);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
release.discs.push({
|
|
|
|
|
tracks: tracks,
|
2020-04-05 14:01:21 +00:00
|
|
|
|
format: release.format,
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
2016-03-30 13:11:37 +00:00
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
|
LOGGER.info('Parsed release: ', release);
|
|
|
|
|
return release;
|
2016-03-30 13:11:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-03 10:46:12 +00:00
|
|
|
|
function getImportButton(release, release_url, format) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let edit_note = MBImport.makeEditNote(release_url, 'CD Baby', format);
|
|
|
|
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
|
|
|
|
return MBImport.buildFormHTML(parameters).replace('<span>Import into MB</span>', `<span>Import ${format}</span>`);
|
2016-04-03 10:46:12 +00:00
|
|
|
|
}
|
2016-03-30 13:11:37 +00:00
|
|
|
|
|
2016-04-03 10:46:12 +00:00
|
|
|
|
function insertImportLinks(release, buttons) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
$('div.right-container-top-right').prepend($(`<div id="mb_buttons">${buttons}${MBImport.buildSearchButton(release)}</div>`).hide());
|
|
|
|
|
$('#mb_buttons').css({
|
|
|
|
|
'margin-bottom': '5px',
|
|
|
|
|
padding: '2%',
|
2020-04-05 14:01:21 +00:00
|
|
|
|
'background-color': '#fff',
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('form.musicbrainz_import').css({
|
2020-04-05 14:01:21 +00:00
|
|
|
|
'margin-bottom': '5px',
|
2018-11-20 22:18:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#mb_buttons').slideDown();
|
2016-03-30 13:11:37 +00:00
|
|
|
|
}
|