2015-08-23 14:38:18 +00:00
|
|
|
|
// ==UserScript==
|
2015-09-27 09:20:39 +00:00
|
|
|
|
// @name Import Metal Archives releases into MusicBrainz
|
2015-09-27 00:11:57 +00:00
|
|
|
|
// @namespace https://github.com/murdos/musicbrainz-userscripts/
|
2017-05-23 07:16:49 +00:00
|
|
|
|
// @version 2017.05.23.0
|
2015-09-27 00:11:57 +00:00
|
|
|
|
// @description Add a button on Metal Archives release pages allowing to open MusicBrainz release editor with pre-filled data for the selected release
|
|
|
|
|
// @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/metalarchives_importer.user.js
|
|
|
|
|
// @update https://raw.github.com/murdos/musicbrainz-userscripts/master/metalarchives_importer.user.js
|
2017-05-23 07:16:49 +00:00
|
|
|
|
// @include http*://www.metal-archives.com/albums/*/*/*
|
2015-09-27 00:11:57 +00:00
|
|
|
|
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
|
|
|
|
|
// @require lib/mbimport.js
|
|
|
|
|
// @require lib/mbimportstyle.js
|
|
|
|
|
// @require lib/logger.js
|
2015-10-04 07:24:06 +00:00
|
|
|
|
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
2015-08-23 14:38:18 +00:00
|
|
|
|
// ==/UserScript==
|
2015-08-25 13:21:02 +00:00
|
|
|
|
|
2015-09-27 00:11:57 +00:00
|
|
|
|
|
2015-08-25 13:21:02 +00:00
|
|
|
|
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
|
2015-09-27 00:11:57 +00:00
|
|
|
|
this.$ = this.jQuery = jQuery.noConflict(true);
|
2015-08-25 13:21:02 +00:00
|
|
|
|
|
|
|
|
|
if (!unsafeWindow) unsafeWindow = window;
|
2015-09-27 00:11:57 +00:00
|
|
|
|
|
2015-08-23 18:35:38 +00:00
|
|
|
|
$(document).ready(function() {
|
2015-09-27 00:11:57 +00:00
|
|
|
|
MBImportStyle();
|
|
|
|
|
|
|
|
|
|
var release_url = window.location.href.replace('/\?.*$/', '').replace(/#.*$/, '');
|
|
|
|
|
var release = retrieveReleaseInfo(release_url);
|
|
|
|
|
insertLink(release, release_url);
|
|
|
|
|
LOGGER.info("Parsed release: ", release);
|
2015-08-23 14:38:18 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function setreleasedate(release, datestring) {
|
2015-09-27 00:11:57 +00:00
|
|
|
|
if (/^\d{4}$/.exec(datestring)) {
|
|
|
|
|
release.year = datestring;
|
|
|
|
|
} else if (datestring.indexOf(',') != -1) {
|
|
|
|
|
var commaindex = datestring.indexOf(',');
|
|
|
|
|
var d = new Date(datestring.substring(0, commaindex - 2) + datestring.substring(commaindex));
|
|
|
|
|
release.year = d.getFullYear();
|
|
|
|
|
release.month = d.getMonth() + 1;
|
|
|
|
|
release.day = d.getDate();
|
|
|
|
|
} else {
|
|
|
|
|
var d = new Date("2 " + datestring);
|
|
|
|
|
release.year = d.getFullYear();
|
|
|
|
|
release.month = d.getMonth() + 1;
|
|
|
|
|
}
|
|
|
|
|
return release;
|
2015-08-23 14:38:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-23 18:35:38 +00:00
|
|
|
|
function getGenericalData() {
|
2015-09-27 00:11:57 +00:00
|
|
|
|
var rdata = new Array();
|
|
|
|
|
var keydata = $('dl.float_left dt, dl.float_right dt').map(function() {
|
|
|
|
|
var s = $.trim($(this).text());
|
|
|
|
|
return s.substring(0, s.length - 1);
|
|
|
|
|
}).get();
|
|
|
|
|
var valuedata = $('dl.float_left dd,dl.float_right dd').map(function() {
|
|
|
|
|
return $.trim($(this).text());
|
|
|
|
|
}).get();
|
|
|
|
|
for (i = 0; i < keydata.length; i++) {
|
|
|
|
|
rdata[keydata[i]] = valuedata[i];
|
|
|
|
|
}
|
|
|
|
|
return rdata;
|
2015-08-23 14:38:18 +00:00
|
|
|
|
}
|
2015-08-23 18:35:38 +00:00
|
|
|
|
|
2015-08-25 10:02:38 +00:00
|
|
|
|
function getArtistsList() {
|
2015-09-27 00:11:57 +00:00
|
|
|
|
return $.map($('h2.band_name').text().split('/'), $.trim);
|
2015-08-25 10:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-27 00:11:57 +00:00
|
|
|
|
function retrieveReleaseInfo(release_url) {
|
|
|
|
|
|
|
|
|
|
var release = {
|
|
|
|
|
discs: [],
|
|
|
|
|
artist_credit: [],
|
|
|
|
|
title: '',
|
|
|
|
|
year: 0,
|
|
|
|
|
month: 0,
|
|
|
|
|
day: 0,
|
|
|
|
|
parent_album_url: '',
|
|
|
|
|
labels: [],
|
|
|
|
|
format: '',
|
|
|
|
|
country: '',
|
|
|
|
|
type: '',
|
|
|
|
|
status: 'official',
|
|
|
|
|
packaging: '',
|
|
|
|
|
language: '',
|
|
|
|
|
script: '',
|
|
|
|
|
urls: [],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var rdata = getGenericalData();
|
|
|
|
|
var artists = getArtistsList();
|
2015-09-27 08:35:40 +00:00
|
|
|
|
var joinphrase = "";
|
|
|
|
|
if (artists.length > 1) {
|
|
|
|
|
if (rdata["Type"] == "Split") {
|
|
|
|
|
joinphrase = " / ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
joinphrase = " & ";
|
|
|
|
|
}
|
2015-09-27 00:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < artists.length; i++) {
|
|
|
|
|
release.artist_credit.push({
|
|
|
|
|
artist_name: artists[i],
|
|
|
|
|
credited_name: artists[i],
|
2015-09-27 08:35:40 +00:00
|
|
|
|
joinphrase: i != artists.length - 1 ? joinphrase : ""
|
2015-08-23 18:35:38 +00:00
|
|
|
|
});
|
2015-09-27 00:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
release.title = $('h1.album_name').text();
|
|
|
|
|
|
|
|
|
|
release = setreleasedate(release, rdata["Release date"]);
|
2015-09-27 09:13:01 +00:00
|
|
|
|
if ("Label" in rdata) {
|
|
|
|
|
// TODO: add case for multiple labels if such a case exist
|
|
|
|
|
var label = rdata["Label"];
|
|
|
|
|
var label_mbid = "";
|
|
|
|
|
if (label == "Independent") {
|
|
|
|
|
label = "[no label]";
|
|
|
|
|
label_mbid = '157afde4-4bf5-4039-8ad2-5a15acc85176';
|
|
|
|
|
}
|
|
|
|
|
var catno = rdata["Catalog ID"];
|
|
|
|
|
if (catno == undefined || catno == "N/A") {
|
|
|
|
|
catno = "";
|
|
|
|
|
}
|
|
|
|
|
release.labels.push({
|
|
|
|
|
name: label,
|
|
|
|
|
catno: catno,
|
|
|
|
|
mbid: label_mbid
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-09-27 00:11:57 +00:00
|
|
|
|
|
|
|
|
|
if (rdata["Type"] in ReleaseTypes) {
|
|
|
|
|
var types = ReleaseTypes[rdata["Type"]];
|
|
|
|
|
release.type = types[0];
|
2015-09-27 09:14:35 +00:00
|
|
|
|
// NOTE: secondary type may not be selected on MB editor, but it still works, a bug on MB side
|
2015-09-27 00:11:57 +00:00
|
|
|
|
release.secondary_types = types.slice(1);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-27 09:13:49 +00:00
|
|
|
|
// FIXME: multiple vinyls ie. http://www.metal-archives.com/albums/Reverend_Bizarre/III%3A_So_Long_Suckers/415313
|
|
|
|
|
if (rdata["Format"] in ReleaseFormat) {
|
|
|
|
|
release.format = ReleaseFormat[rdata["Format"]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("Version desc." in rdata) {
|
|
|
|
|
if (rdata["Version desc."].indexOf("Digipak") != -1) {
|
|
|
|
|
release.packaging = "Digipak";
|
|
|
|
|
}
|
|
|
|
|
if (release.format == "CD" && rdata["Version desc."] == "CD-R") {
|
|
|
|
|
release.format = "CD-R";
|
|
|
|
|
}
|
2015-09-27 00:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var identifiers = $("#album_tabs_notes > div:nth-child(2)").find("p:not([class])").contents();
|
|
|
|
|
for (var j = 0; j < identifiers.length; j++) {
|
|
|
|
|
if (identifiers[j].textContent.indexOf("Barcode:") != -1) {
|
|
|
|
|
release.barcode = $.trim(identifiers[j].textContent.substring(8));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// URLs
|
|
|
|
|
var link_type = MBImport.URL_TYPES;
|
|
|
|
|
release.urls.push({
|
|
|
|
|
url: release_url,
|
|
|
|
|
link_type: link_type.other_databases
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var releaseNumber = 0;
|
|
|
|
|
var disc = {
|
|
|
|
|
tracks: [],
|
|
|
|
|
format: release.format
|
|
|
|
|
};
|
|
|
|
|
release.discs.push(disc);
|
|
|
|
|
|
|
|
|
|
var tracksline = $('table.table_lyrics tr.even,table.table_lyrics tr.odd');
|
|
|
|
|
|
|
|
|
|
tracksline.each(function(index, element) {
|
|
|
|
|
var trackNumber = $.trim(element.children[0].textContent).replace('.', "");
|
|
|
|
|
if (trackNumber == "1" && trackNumber != index + 1) {
|
|
|
|
|
releaseNumber++;
|
|
|
|
|
release.discs.push({
|
|
|
|
|
tracks: [],
|
|
|
|
|
format: release.format
|
|
|
|
|
});
|
2015-08-23 14:38:18 +00:00
|
|
|
|
}
|
2015-08-23 16:24:17 +00:00
|
|
|
|
|
2015-09-27 08:36:41 +00:00
|
|
|
|
// TODO: handling of split and compilation artists (artist - title)
|
2015-09-27 00:11:57 +00:00
|
|
|
|
var track = {
|
|
|
|
|
'number': trackNumber,
|
2015-09-27 08:34:20 +00:00
|
|
|
|
'title': $.trim(element.children[1].textContent.replace(/\s+/g, ' ')),
|
2015-09-27 00:11:57 +00:00
|
|
|
|
'duration': $.trim(element.children[2].textContent),
|
|
|
|
|
'artist_credit': [release.artist_credit]
|
|
|
|
|
};
|
|
|
|
|
release.discs[releaseNumber].tracks.push(track);
|
|
|
|
|
});
|
|
|
|
|
return release;
|
2015-08-23 14:38:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-27 00:11:57 +00:00
|
|
|
|
// Insert button into page under label information
|
|
|
|
|
function insertLink(release, release_url) {
|
|
|
|
|
var edit_note = MBImport.makeEditNote(release_url, 'Metal Archives');
|
|
|
|
|
var parameters = MBImport.buildFormParameters(release, edit_note);
|
|
|
|
|
|
|
|
|
|
var mbUI = $('<div id="musicbrainz-import">' + MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release) + '</div>').hide();
|
|
|
|
|
|
|
|
|
|
$('h2.band_name').after(mbUI);
|
|
|
|
|
$('#musicbrainz-import form').css({
|
|
|
|
|
'padding': '0'
|
|
|
|
|
});
|
|
|
|
|
$('form.musicbrainz_import').css({
|
|
|
|
|
'display': 'inline-block',
|
|
|
|
|
'margin': '1px'
|
|
|
|
|
});
|
|
|
|
|
$('form.musicbrainz_import img').css({
|
|
|
|
|
'display': 'inline-block'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mbUI.slideDown();
|
2015-08-23 14:38:18 +00:00
|
|
|
|
}
|
2015-09-27 00:11:57 +00:00
|
|
|
|
|
2015-08-23 14:38:18 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Metal Archives -> MusicBrainz mapping //
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-09-27 00:11:57 +00:00
|
|
|
|
/*
|
|
|
|
|
release.type primary type release secondary release type
|
|
|
|
|
on MA on MB
|
2015-08-23 14:38:18 +00:00
|
|
|
|
|
2015-09-27 00:11:57 +00:00
|
|
|
|
Full-length Album Compilation
|
2015-08-23 14:38:18 +00:00
|
|
|
|
Live album Single Demo
|
|
|
|
|
Demo EP DJ-mix
|
2015-08-23 18:35:38 +00:00
|
|
|
|
Single Broadcast Interview
|
|
|
|
|
EP Other Live
|
|
|
|
|
Video Audiobook
|
|
|
|
|
Boxed set Mixtape/Street
|
|
|
|
|
Split Remix
|
|
|
|
|
Video/VHS (legacy) Soundtrack
|
|
|
|
|
Compilation Spokenword
|
2015-08-23 14:38:18 +00:00
|
|
|
|
Split video
|
|
|
|
|
*/
|
2015-09-27 00:11:57 +00:00
|
|
|
|
|
2015-08-23 14:38:18 +00:00
|
|
|
|
//ReleaseTypes[MAtype]=["primary type","secondary type on mb"];
|
2015-09-27 00:11:57 +00:00
|
|
|
|
var ReleaseTypes = {
|
2015-09-27 09:14:35 +00:00
|
|
|
|
"Full-length": ["album"],
|
|
|
|
|
"Live album": ["album", "live"],
|
|
|
|
|
"Demo": ["album", "demo"],
|
|
|
|
|
"Single": ["single"],
|
|
|
|
|
"EP": ["ep"],
|
|
|
|
|
"Compilation": ["album", "compilation"],
|
|
|
|
|
"Split": ["album"],
|
2015-09-27 00:11:57 +00:00
|
|
|
|
"Collaboration": [""],
|
|
|
|
|
};
|
|
|
|
|
|
2015-08-23 14:38:18 +00:00
|
|
|
|
//ReleaseFormat[MAformat]="MBformat";
|
2015-09-27 00:11:57 +00:00
|
|
|
|
var ReleaseFormat = {
|
|
|
|
|
"CD": "CD",
|
|
|
|
|
"2CD": "CD",
|
|
|
|
|
"Vinyl": "Vinyl",
|
|
|
|
|
"7\" vinyl": "7\" Vinyl",
|
|
|
|
|
"7\" vinyl (33⅓ RPM)": "7\" Vinyl",
|
|
|
|
|
"10\" vinyl (33⅓ RPM)": "10\" Vinyl",
|
|
|
|
|
"10\" vinyl": "10\" Vinyl",
|
|
|
|
|
"12\" vinyl": "12\" Vinyl",
|
|
|
|
|
"2 12\" vinyls": "12\" Vinyl",
|
|
|
|
|
"12\" vinyl (33⅓ RPM)": "12\" Vinyl",
|
|
|
|
|
"Cassette": "Cassette",
|
|
|
|
|
"Digital": "Digital Media",
|
|
|
|
|
};
|