mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-12-12 19:32:27 +00:00
Cosmetics changes: re-format code, indents and line endings.
This commit is contained in:
parent
446c9487ea
commit
b9233d9dd6
1 changed files with 125 additions and 125 deletions
|
@ -1,125 +1,125 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Import Encyclopedisque releases to MusicBrainz
|
// @name Import Encyclopedisque releases to MusicBrainz
|
||||||
// @version 2012.12.13.1
|
// @version 2012.12.13.1
|
||||||
// @namespace http://userscripts.org/users/22504
|
// @namespace http://userscripts.org/users/22504
|
||||||
// @description Easily import Encyclopedisque releases into MusicBrainz
|
// @description Easily import Encyclopedisque releases into MusicBrainz
|
||||||
// @include http://www.encyclopedisque.fr/disque/*.html
|
// @include http://www.encyclopedisque.fr/disque/*.html
|
||||||
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
|
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
|
||||||
// @require https://raw.github.com/murdos/musicbrainz-userscripts/master/lib/import_functions.js
|
// @require https://raw.github.com/murdos/musicbrainz-userscripts/master/lib/import_functions.js
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
var release = parseEncyclopedisquePage();
|
var release = parseEncyclopedisquePage();
|
||||||
setupUI(release);
|
setupUI(release);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Encyclopedisque functions
|
// Encyclopedisque functions
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
function setupUI(release) {
|
function setupUI(release) {
|
||||||
|
|
||||||
// Form parameters
|
// Form parameters
|
||||||
var edit_note = 'Imported from ' + window.location.href;
|
var edit_note = 'Imported from ' + window.location.href;
|
||||||
var parameters = MBReleaseImportHelper.buildFormParameters(release, edit_note);
|
var parameters = MBReleaseImportHelper.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
// Build form
|
// Build form
|
||||||
var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters);
|
var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters);
|
||||||
|
|
||||||
// Append search link
|
// Append search link
|
||||||
innerHTML += ' <small>(' + MBReleaseImportHelper.buildSearchLink(release) + ')</small>';
|
innerHTML += ' <small>(' + MBReleaseImportHelper.buildSearchLink(release) + ')</small>';
|
||||||
|
|
||||||
var importLink = $("<li>"+ innerHTML + "</li>");
|
var importLink = $("<li>"+ innerHTML + "</li>");
|
||||||
importLink.appendTo("#menu ul");
|
importLink.appendTo("#menu ul");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Analyze Encyclopedisque data and prepare to release object
|
// Analyze Encyclopedisque data and prepare to release object
|
||||||
function parseEncyclopedisquePage() {
|
function parseEncyclopedisquePage() {
|
||||||
|
|
||||||
release = new Object();
|
release = new Object();
|
||||||
|
|
||||||
var infoHeader = document.body.querySelector("#contenu > h2:nth-of-type(1)");
|
var infoHeader = document.body.querySelector("#contenu > h2:nth-of-type(1)");
|
||||||
|
|
||||||
// Release artist credit
|
// Release artist credit
|
||||||
release.artist_credit = new Array();
|
release.artist_credit = new Array();
|
||||||
var artist_name = infoHeader.querySelector("div.floatright:nth-of-type(1)").textContent.trim();
|
var artist_name = infoHeader.querySelector("div.floatright:nth-of-type(1)").textContent.trim();
|
||||||
release.artist_credit.push( { 'artist_name': artist_name } );
|
release.artist_credit.push( { 'artist_name': artist_name } );
|
||||||
|
|
||||||
// Release title
|
// Release title
|
||||||
release.title = infoHeader.querySelector("span:nth-of-type(1)").textContent.trim();
|
release.title = infoHeader.querySelector("span:nth-of-type(1)").textContent.trim();
|
||||||
|
|
||||||
// Release country
|
// Release country
|
||||||
release.country = 'FR'; // France - correct in most case, but not all
|
release.country = 'FR'; // France - correct in most case, but not all
|
||||||
|
|
||||||
// Other hard-coded info
|
// Other hard-coded info
|
||||||
release.status = 'official';
|
release.status = 'official';
|
||||||
release.language = 'fra';
|
release.language = 'fra';
|
||||||
release.script = 'Latn';
|
release.script = 'Latn';
|
||||||
|
|
||||||
var disc = {'position': 1, 'tracks': [] };
|
var disc = {'position': 1, 'tracks': [] };
|
||||||
disc.format = '7" Vinyl'; // Disque vinyl 7"
|
disc.format = '7" Vinyl'; // Disque vinyl 7"
|
||||||
release.discs = [ disc ];
|
release.discs = [ disc ];
|
||||||
|
|
||||||
// Parse other infos
|
// Parse other infos
|
||||||
var releaseInfos = document.body.querySelectorAll("div.pochetteprincipale ~ div tr");
|
var releaseInfos = document.body.querySelectorAll("div.pochetteprincipale ~ div tr");
|
||||||
for (var i = 0; i < releaseInfos.length; i++) {
|
for (var i = 0; i < releaseInfos.length; i++) {
|
||||||
var infoType = releaseInfos[i].querySelector("td:nth-of-type(1)").textContent.trim();
|
var infoType = releaseInfos[i].querySelector("td:nth-of-type(1)").textContent.trim();
|
||||||
|
|
||||||
// Release date
|
// Release date
|
||||||
if (infoType == "Sortie :") {
|
if (infoType == "Sortie :") {
|
||||||
var infoValue = releaseInfos[i].querySelector("td:nth-of-type(2)").textContent.trim();
|
var infoValue = releaseInfos[i].querySelector("td:nth-of-type(2)").textContent.trim();
|
||||||
var 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*\(?([^\)]*)?\)?/;
|
var 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*\(?([^\)]*)?\)?/;
|
||||||
console.log(infoValue);
|
console.log(infoValue);
|
||||||
console.log(infoValue.match(re));
|
console.log(infoValue.match(re));
|
||||||
//if (m = infoValue.match(re) != null) {
|
//if (m = infoValue.match(re) != null) {
|
||||||
m = infoValue.match(re);
|
m = infoValue.match(re);
|
||||||
month = m[1];
|
month = m[1];
|
||||||
if (month != undefined) {
|
if (month != undefined) {
|
||||||
switch (month)
|
switch (month)
|
||||||
{
|
{
|
||||||
case "janvier": release.month = 1; break;
|
case "janvier": release.month = 1; break;
|
||||||
case "février": release.month = 2; break;
|
case "février": release.month = 2; break;
|
||||||
case "mars": release.month = 3; break;
|
case "mars": release.month = 3; break;
|
||||||
case "avril": release.month = 4; break;
|
case "avril": release.month = 4; break;
|
||||||
case "mai": release.month = 5; break;
|
case "mai": release.month = 5; break;
|
||||||
case "juin": release.month = 6; break;
|
case "juin": release.month = 6; break;
|
||||||
case "juillet": release.month = 7; break;
|
case "juillet": release.month = 7; break;
|
||||||
case "août": release.month = 8; break;
|
case "août": release.month = 8; break;
|
||||||
case "septembre": release.month = 9; break;
|
case "septembre": release.month = 9; break;
|
||||||
case "octobre": release.month = 10; break;
|
case "octobre": release.month = 10; break;
|
||||||
case "novembre": release.month = 11; break;
|
case "novembre": release.month = 11; break;
|
||||||
case "décembre": release.month = 12; break;
|
case "décembre": release.month = 12; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
release.year = m[2];
|
release.year = m[2];
|
||||||
release.labels = [ ];
|
release.labels = [ ];
|
||||||
var labels = m[3];
|
var labels = m[3];
|
||||||
if (labels != undefined) {
|
if (labels != undefined) {
|
||||||
$.each(labels.split("/"), function(index, label) {
|
$.each(labels.split("/"), function(index, label) {
|
||||||
release.labels.push({ 'name': label.trim(), 'catno': m[4] });
|
release.labels.push({ 'name': label.trim(), 'catno': m[4] });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
release.labels.push({ 'catno': m[4] });
|
release.labels.push({ 'catno': m[4] });
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
// Tracks
|
// Tracks
|
||||||
else if (infoType.match(/^Face [AB]/)) {
|
else if (infoType.match(/^Face [AB]/)) {
|
||||||
var title = releaseInfos[i].querySelector("td:nth-of-type(2) strong").textContent.trim();
|
var title = releaseInfos[i].querySelector("td:nth-of-type(2) strong").textContent.trim();
|
||||||
var track = new Object();
|
var track = new Object();
|
||||||
track.title = title; //.replace("(avec ", "(feat. ");
|
track.title = title; //.replace("(avec ", "(feat. ");
|
||||||
disc.tracks.push(track);
|
disc.tracks.push(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guessing release type (EP, single) from number of tracks
|
// Guessing release type (EP, single) from number of tracks
|
||||||
release.type = (disc.tracks.length > 3) ? 'ep' : 'single';
|
release.type = (disc.tracks.length > 3) ? 'ep' : 'single';
|
||||||
|
|
||||||
return release;
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue