2015-06-15 21:05:59 +00:00
|
|
|
|
// ==UserScript==
|
2013-09-30 20:55:16 +00:00
|
|
|
|
// @name Import Encyclopedisque releases to MusicBrainz
|
2018-02-18 17:16:45 +00:00
|
|
|
|
// @version 2018.2.18.1
|
2013-09-30 20:55:16 +00:00
|
|
|
|
// @namespace http://userscripts.org/users/22504
|
|
|
|
|
// @description Easily import Encyclopedisque releases into MusicBrainz
|
2014-02-22 09:33:26 +00:00
|
|
|
|
// @downloadURL https://raw.github.com/murdos/musicbrainz-userscripts/master/encyclopedisque_importer.user.js
|
|
|
|
|
// @updateURL https://raw.github.com/murdos/musicbrainz-userscripts/master/encyclopedisque_importer.user.js
|
2013-09-30 20:55:16 +00:00
|
|
|
|
// @include http://www.encyclopedisque.fr/disque/*.html
|
2013-09-30 21:20:38 +00:00
|
|
|
|
// @include http://www.encyclopedisque.fr/artiste/*.html
|
|
|
|
|
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
|
2015-06-17 22:29:08 +00:00
|
|
|
|
// @require lib/mbimport.js
|
2015-06-15 21:05:59 +00:00
|
|
|
|
// @require lib/mblinks.js
|
2015-06-12 22:31:10 +00:00
|
|
|
|
// @require lib/logger.js
|
2015-06-15 07:52:59 +00:00
|
|
|
|
// @require lib/mbimportstyle.js
|
2015-07-10 12:28:43 +00:00
|
|
|
|
// @icon https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/assets/images/Musicbrainz_import_logo.png
|
2013-09-30 20:55:16 +00:00
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
2015-06-16 07:14:07 +00:00
|
|
|
|
var mblinks = new MBLinks('ENCYLOPEDISQUE_MBLINKS_CACHE');
|
2015-06-15 21:05:59 +00:00
|
|
|
|
|
2013-09-30 20:55:16 +00:00
|
|
|
|
$(document).ready(function() {
|
2015-06-15 07:52:59 +00:00
|
|
|
|
MBImportStyle();
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
2015-06-15 21:05:59 +00:00
|
|
|
|
if (window.location.href.match(/encyclopedisque\.fr\/disque\/(\d+)/)) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let release = parseEncyclopedisquePage();
|
2015-06-15 21:05:59 +00:00
|
|
|
|
setupImportUI(release);
|
2013-09-30 21:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insertMBLinks();
|
2013-09-30 20:55:16 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Encyclopedisque functions
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2015-06-15 21:05:59 +00:00
|
|
|
|
function setupImportUI(release) {
|
2013-09-30 20:55:16 +00:00
|
|
|
|
// Form parameters
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let edit_note = MBImport.makeEditNote(window.location.href, 'Encyclopedisque');
|
|
|
|
|
let parameters = MBImport.buildFormParameters(release, edit_note);
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
|
|
|
|
// Build form
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let mbUI = $(MBImport.buildFormHTML(parameters) + MBImport.buildSearchButton(release)).hide();
|
2015-06-16 13:34:02 +00:00
|
|
|
|
$('#recherchebox').append(mbUI);
|
2018-11-20 22:18:49 +00:00
|
|
|
|
$('form.musicbrainz_import button').css({ width: '100%' });
|
2015-06-16 13:34:02 +00:00
|
|
|
|
mbUI.slideDown();
|
2013-09-30 20:55:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-15 21:05:59 +00:00
|
|
|
|
function insertMBLinks() {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let current_url = window.location.href;
|
2015-06-15 21:43:15 +00:00
|
|
|
|
if (current_url.match(/\/disque\//)) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
mblinks.searchAndDisplayMbLink(current_url, 'release', function(link) {
|
|
|
|
|
$('h2 span').before(link);
|
|
|
|
|
});
|
2015-06-15 21:43:15 +00:00
|
|
|
|
} else if (current_url.match(/\/artiste\//)) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
mblinks.searchAndDisplayMbLink(current_url, 'artist', function(link) {
|
|
|
|
|
$('h2').prepend(link);
|
|
|
|
|
});
|
2015-06-15 21:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
|
$('div.v7P, div.v12P')
|
|
|
|
|
.find('a[href*="/disque/"]')
|
|
|
|
|
.each(function() {
|
|
|
|
|
let $link = $(this);
|
|
|
|
|
let external_url = window.location.origin + $link.attr('href');
|
|
|
|
|
mblinks.searchAndDisplayMbLink(external_url, 'release', function(link) {
|
|
|
|
|
$link.after(link).after('<br />');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('h2, div.main')
|
|
|
|
|
.find('a[href*="/artiste/"]')
|
|
|
|
|
.each(function() {
|
|
|
|
|
let $link = $(this);
|
|
|
|
|
let external_url = window.location.origin + $link.attr('href');
|
|
|
|
|
mblinks.searchAndDisplayMbLink(external_url, 'artist', function(link) {
|
|
|
|
|
$link.before(link);
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-09-30 21:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-30 20:55:16 +00:00
|
|
|
|
// Analyze Encyclopedisque data and prepare to release object
|
|
|
|
|
function parseEncyclopedisquePage() {
|
|
|
|
|
release = new Object();
|
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let infoHeader = document.body.querySelector('#contenu > h2:nth-of-type(1)');
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
|
|
|
|
// Release artist credit
|
|
|
|
|
release.artist_credit = new Array();
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let artist_name = infoHeader.querySelector('div.floatright:nth-of-type(1)').textContent.trim();
|
|
|
|
|
release.artist_credit.push({ artist_name: artist_name });
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
|
|
|
|
// Release title
|
2018-11-20 22:18:49 +00:00
|
|
|
|
release.title = infoHeader.querySelector('span:nth-of-type(1)').textContent.trim();
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
2013-09-30 20:56:24 +00:00
|
|
|
|
// Default status is official, will change if "tirage promo" is found (see below)
|
|
|
|
|
release.status = 'official';
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
|
|
|
|
// Other hard-coded info
|
|
|
|
|
release.language = 'fra';
|
|
|
|
|
release.script = 'Latn';
|
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let disc = { position: 1, tracks: [] };
|
|
|
|
|
release.discs = [disc];
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
2014-02-21 19:05:25 +00:00
|
|
|
|
// Release URL
|
|
|
|
|
release.urls = new Array();
|
2018-11-20 22:18:49 +00:00
|
|
|
|
release.urls.push({ url: window.location.href, link_type: MBImport.URL_TYPES.other_databases });
|
2014-02-21 19:05:25 +00:00
|
|
|
|
|
2013-09-30 20:55:16 +00:00
|
|
|
|
// Parse other infos
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let releaseInfos = document.body.querySelectorAll('div.main tr');
|
|
|
|
|
let lastVinylFace = '';
|
|
|
|
|
let lastInfoType;
|
|
|
|
|
for (let i = 0; i < releaseInfos.length; i++) {
|
|
|
|
|
let infoType = releaseInfos[i].querySelector('td:nth-of-type(1)').textContent.trim();
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
|
|
|
|
// Release date
|
2018-11-20 22:18:49 +00:00
|
|
|
|
if (infoType == 'Sortie :') {
|
|
|
|
|
var infoValue = releaseInfos[i].querySelector('td:nth-of-type(2)').textContent.trim();
|
|
|
|
|
let re = /\s*(janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|décembre)?\s*([\d\?]{4})?\s*(?:chez)?\s*((?:\S+\s?)*)\s*\(?([^\)]*)?\)?/;
|
2013-09-30 20:55:16 +00:00
|
|
|
|
m = infoValue.match(re);
|
|
|
|
|
month = m[1];
|
|
|
|
|
if (month != undefined) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
switch (month) {
|
|
|
|
|
case 'janvier':
|
|
|
|
|
release.month = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'février':
|
|
|
|
|
release.month = 2;
|
|
|
|
|
break;
|
|
|
|
|
case 'mars':
|
|
|
|
|
release.month = 3;
|
|
|
|
|
break;
|
|
|
|
|
case 'avril':
|
|
|
|
|
release.month = 4;
|
|
|
|
|
break;
|
|
|
|
|
case 'mai':
|
|
|
|
|
release.month = 5;
|
|
|
|
|
break;
|
|
|
|
|
case 'juin':
|
|
|
|
|
release.month = 6;
|
|
|
|
|
break;
|
|
|
|
|
case 'juillet':
|
|
|
|
|
release.month = 7;
|
|
|
|
|
break;
|
|
|
|
|
case 'août':
|
|
|
|
|
release.month = 8;
|
|
|
|
|
break;
|
|
|
|
|
case 'septembre':
|
|
|
|
|
release.month = 9;
|
|
|
|
|
break;
|
|
|
|
|
case 'octobre':
|
|
|
|
|
release.month = 10;
|
|
|
|
|
break;
|
|
|
|
|
case 'novembre':
|
|
|
|
|
release.month = 11;
|
|
|
|
|
break;
|
|
|
|
|
case 'décembre':
|
|
|
|
|
release.month = 12;
|
|
|
|
|
break;
|
2013-09-30 20:55:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
release.year = m[2];
|
2013-09-30 20:56:24 +00:00
|
|
|
|
release.labels = [];
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let labels = m[3];
|
2013-09-30 20:55:16 +00:00
|
|
|
|
if (labels != undefined) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
$.each(labels.split('/'), function(index, label) {
|
|
|
|
|
release.labels.push({ name: label.trim(), catno: m[4] });
|
2013-09-30 20:55:16 +00:00
|
|
|
|
});
|
|
|
|
|
} else {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
release.labels.push({ catno: m[4] });
|
2013-09-30 20:55:16 +00:00
|
|
|
|
}
|
2013-09-30 20:56:24 +00:00
|
|
|
|
} else if (infoType.match(/^Face [A-Z]/) || (infoType == '' && lastInfoType.match(/^Face [A-Z]/))) {
|
|
|
|
|
// Tracks
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let track = new Object();
|
2013-09-30 20:56:24 +00:00
|
|
|
|
|
|
|
|
|
// First part of tracknumber (A, B, ...)
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let tnum_part1 = '';
|
|
|
|
|
if ((m = infoType.match(/^Face ([A-Z])/))) {
|
2013-09-30 20:56:24 +00:00
|
|
|
|
lastVinylFace = m[1];
|
|
|
|
|
tnum_part1 = m[1];
|
|
|
|
|
} else {
|
|
|
|
|
tnum_part1 = lastVinylFace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Track title
|
2018-11-20 22:18:49 +00:00
|
|
|
|
if (releaseInfos[i].querySelector('td:nth-of-type(2) em') == null) {
|
2013-09-30 20:56:24 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let title = releaseInfos[i].querySelector('td:nth-of-type(2) em').textContent.trim();
|
2013-09-30 20:56:24 +00:00
|
|
|
|
|
|
|
|
|
// 2nd part of tracknumber (1, 2, ...)
|
2018-11-20 22:18:49 +00:00
|
|
|
|
let tnum_part2 = '';
|
|
|
|
|
if ((m = infoType.match(/^Face [A-Z](\d+)/))) {
|
2013-09-30 20:56:24 +00:00
|
|
|
|
tnum_part2 = m[1];
|
2018-11-20 22:18:49 +00:00
|
|
|
|
} else if ((m = title.match(/^(\d+)\.\s+(.*)$/))) {
|
2013-09-30 20:56:24 +00:00
|
|
|
|
tnum_part2 = m[1];
|
|
|
|
|
title = m[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Track length
|
2018-11-20 22:18:49 +00:00
|
|
|
|
if (
|
|
|
|
|
(m = releaseInfos[i]
|
|
|
|
|
.querySelector('td:nth-of-type(2)')
|
|
|
|
|
.textContent.trim()
|
|
|
|
|
.match(/- (\d+)’(\d+)$/))
|
|
|
|
|
) {
|
|
|
|
|
track.duration = `${m[1]}:${m[2]}`;
|
2013-09-30 20:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
track.number = tnum_part1 + tnum_part2;
|
|
|
|
|
track.title = title;
|
2013-09-30 20:55:16 +00:00
|
|
|
|
disc.tracks.push(track);
|
2018-11-20 22:18:49 +00:00
|
|
|
|
} else if (infoType == 'Format :') {
|
2013-09-30 20:56:24 +00:00
|
|
|
|
// Format => medium format, release-group type, release status
|
2018-11-20 22:18:49 +00:00
|
|
|
|
var infoValue = releaseInfos[i].querySelector('td:nth-of-type(2)').textContent.trim();
|
|
|
|
|
let values = infoValue.split(' / ');
|
2013-09-30 20:56:24 +00:00
|
|
|
|
values.forEach(function(value) {
|
2018-11-20 22:18:49 +00:00
|
|
|
|
if (value.indexOf('45 tours') > -1) {
|
|
|
|
|
disc.format = '7" Vinyl';
|
|
|
|
|
}
|
|
|
|
|
if (value.indexOf('33 tours') > -1) {
|
|
|
|
|
disc.format = '12" Vinyl';
|
|
|
|
|
}
|
|
|
|
|
if (value.indexOf('LP') > -1) {
|
|
|
|
|
release.type = 'album';
|
|
|
|
|
}
|
|
|
|
|
if (value.indexOf('EP') > -1) {
|
|
|
|
|
release.type = 'ep';
|
|
|
|
|
}
|
|
|
|
|
if (value.indexOf('SP') > -1) {
|
|
|
|
|
release.type = 'single';
|
|
|
|
|
}
|
|
|
|
|
if (value.indexOf('tirage promo') > -1) {
|
|
|
|
|
release.status = 'promotion';
|
|
|
|
|
}
|
2013-09-30 20:56:24 +00:00
|
|
|
|
});
|
2018-11-20 22:18:49 +00:00
|
|
|
|
} else if (infoType == 'Pays :') {
|
2013-09-30 20:56:24 +00:00
|
|
|
|
// Country
|
2018-11-20 22:18:49 +00:00
|
|
|
|
var infoValue = releaseInfos[i].querySelector('td:nth-of-type(2)').textContent.trim();
|
2013-09-30 20:56:24 +00:00
|
|
|
|
if (infoValue == 'France') {
|
|
|
|
|
release.country = 'FR';
|
|
|
|
|
} else if (infoValue == 'Royaume-uni') {
|
|
|
|
|
release.country = 'UK';
|
|
|
|
|
} else if (infoValue == 'Allemagne') {
|
|
|
|
|
release.country = 'DE';
|
|
|
|
|
} else if (infoValue == 'Belgique') {
|
|
|
|
|
release.country = 'BE';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (infoType != '') {
|
|
|
|
|
lastInfoType = infoType;
|
2013-09-30 20:55:16 +00:00
|
|
|
|
}
|
2013-09-30 20:56:24 +00:00
|
|
|
|
}
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
2013-09-30 20:56:24 +00:00
|
|
|
|
// Barcode ?
|
2015-06-10 22:21:39 +00:00
|
|
|
|
if (parseInt(release.year, 10) <= 1982) {
|
2013-09-30 20:56:24 +00:00
|
|
|
|
// FIXME: not working
|
|
|
|
|
release.no_barcode = '1';
|
2013-09-30 20:55:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
|
LOGGER.info('Parsed release: ', release);
|
2013-09-30 20:55:16 +00:00
|
|
|
|
|
|
|
|
|
return release;
|
|
|
|
|
}
|