mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-12-12 19:32:27 +00:00
2011-08-20
This commit is contained in:
parent
6d4a6e5020
commit
261f8a1fec
1 changed files with 46 additions and 91 deletions
|
@ -1,9 +1,11 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Import Encyclopedisque releases to MusicBrainz
|
// @name Import Encyclopedisque releases to MusicBrainz
|
||||||
|
// @version 2011-08-20_02
|
||||||
// @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 http://userscripts.org/scripts/source/110844.user.js
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
// Script Update Checker
|
// Script Update Checker
|
||||||
|
@ -16,10 +18,7 @@ try{function updateCheck(forced){if ((forced) || (parseInt(GM_getValue('SUC_last
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
var release = parseEncyclopedisquePage();
|
var release = parseEncyclopedisquePage();
|
||||||
var url = cookImportUrl(release);
|
setupUI(release);
|
||||||
|
|
||||||
var importLink = $("<li><a href=\""+ url +"\">Import in Musicbrainz</a></li>");
|
|
||||||
importLink.appendTo("#menu ul");
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,26 +27,57 @@ $(document).ready(function() {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
function setupUI(release) {
|
||||||
|
|
||||||
|
// Form parameters
|
||||||
|
var edit_note = 'Imported from ' + window.location.href;
|
||||||
|
var parameters = MBReleaseImportHelper.buildFormParameters(release, edit_note);
|
||||||
|
|
||||||
|
// Build form
|
||||||
|
var innerHTML = MBReleaseImportHelper.buildFormHTML(parameters);
|
||||||
|
|
||||||
|
// Append search link
|
||||||
|
innerHTML += ' <small>(' + MBReleaseImportHelper.buildSearchLink(release) + ')</small>';
|
||||||
|
|
||||||
|
var importLink = $("<li>"+ innerHTML + "</li>");
|
||||||
|
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 = infoHeader.querySelector("div.floatright:nth-of-type(1)").textContent.trim().replace("’", "'");
|
// Release artist credit
|
||||||
release.title = infoHeader.querySelector("span:nth-of-type(1)").textContent.trim().replace("’", "'");
|
release.artist_credit = new Array();
|
||||||
release.format = 7; // Disque vinyl
|
var artist_name = infoHeader.querySelector("div.floatright:nth-of-type(1)").textContent.trim();
|
||||||
release.country = 73; // France - correct in most case, but not all
|
release.artist_credit.push( { 'artist_name': artist_name } );
|
||||||
release.tracks = [];
|
|
||||||
//console.log(release.artist + ": " + release.title);
|
// Release title
|
||||||
|
release.title = infoHeader.querySelector("span:nth-of-type(1)").textContent.trim();
|
||||||
|
|
||||||
|
// Release country
|
||||||
|
release.country = 'FR'; // France - correct in most case, but not all
|
||||||
|
|
||||||
|
// Other hard-coded info
|
||||||
|
release.type = 'single';
|
||||||
|
release.status = 'official';
|
||||||
|
release.language = 'fra';
|
||||||
|
release.script = 'Latn';
|
||||||
|
|
||||||
|
var disc = {'position': 1, 'tracks': [] };
|
||||||
|
disc.format = '7" Vinyl'; // Disque vinyl 7"
|
||||||
|
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 event
|
// 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*\(?([^\)]*)?\)?/;
|
||||||
|
@ -74,19 +104,17 @@ function parseEncyclopedisquePage() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
release.year = m[2];
|
release.year = m[2];
|
||||||
|
release.labels = [ { 'catno': m[4] } ]
|
||||||
var label = m[3];
|
var label = m[3];
|
||||||
if (label != undefined) release.label = label.trim();
|
if (label != undefined) release.labels[0].name = label.trim();
|
||||||
release.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("’", "'");
|
track.title = title; //.replace("(avec ", "(feat. ");
|
||||||
track.title = title.replace("(avec ", "(feat. ");
|
disc.tracks.push(track);
|
||||||
release.tracks.push(track);
|
|
||||||
//console.log("Track: " + track.title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,76 +122,3 @@ function parseEncyclopedisquePage() {
|
||||||
return release;
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function: compute url for a release object
|
|
||||||
function cookImportUrl(release) {
|
|
||||||
|
|
||||||
var importURL = "http://musicbrainz.org/cdi/enter.html?artistname=" + encodeURIComponent(release.artist) + "&releasename=" + encodeURIComponent(release.title);
|
|
||||||
|
|
||||||
// Multiple artists on tracks?
|
|
||||||
var artists = [];
|
|
||||||
for (var i=0; i < release.tracks.length; i++) {
|
|
||||||
if (release.tracks[i].artist)
|
|
||||||
artists.push(release.tracks[i].artist);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (artists.length > 1)
|
|
||||||
importURL += "&hasmultipletrackartists=1&artistid=1";
|
|
||||||
else
|
|
||||||
importURL += "&hasmultipletrackartists=0";
|
|
||||||
|
|
||||||
// Add tracks
|
|
||||||
for (var i=0; i < release.tracks.length; i++) {
|
|
||||||
|
|
||||||
importURL += "&track" + i + "=" + encodeURIComponent(release.tracks[i].title);
|
|
||||||
|
|
||||||
var tracklength = (typeof release.tracks[i].duration != 'undefined' && release.tracks[i].duration != '') ? release.tracks[i].duration : "?:??";
|
|
||||||
|
|
||||||
importURL += "&tracklength" + i + "=" + encodeURIComponent(tracklength);
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: ??
|
|
||||||
|
|
||||||
importURL += '&trackseq' + i + "=" + (i + 1);
|
|
||||||
|
|
||||||
importURL += '&tr' + i + '_mp=0';
|
|
||||||
|
|
||||||
if (artists.length > 1 && release.tracks[i].artist) {
|
|
||||||
importURL += "&tr" + i + "_artistedit=1";
|
|
||||||
importURL += "&tr" + i + "_artistname=" + encodeURIComponent(release.tracks[i].artist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
importURL += '&tracks=' + release.tracks.length;
|
|
||||||
|
|
||||||
importURL += '&submitvalue=Keep+editing'; // Needed to allow RE imports
|
|
||||||
|
|
||||||
// Release event
|
|
||||||
|
|
||||||
if (typeof release.catno != 'undefined' && release.catno != "none") {
|
|
||||||
|
|
||||||
importURL += '&rev_catno-0=' + release.catno;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
importURL += '&rev_labelname-0=' + encodeURIComponent(release.label);
|
|
||||||
|
|
||||||
importURL += '&rev_format-0=' + release.format;
|
|
||||||
|
|
||||||
if (!isNaN(release.year)) { importURL += '&rev_year-0=' + release.year; }
|
|
||||||
|
|
||||||
if (!isNaN(release.month)) { importURL += '&rev_month-0=' + release.month; }
|
|
||||||
|
|
||||||
if (!isNaN(release.day)) { importURL += '&rev_day-0=' + release.day; }
|
|
||||||
|
|
||||||
importURL += '&rev_country-0=' + release.country;
|
|
||||||
|
|
||||||
importURL += '&attr_type=2'; // Release type = single
|
|
||||||
importURL += '&attr_status=100'; // Release status = official
|
|
||||||
importURL += '&attr_language=134'; // Release lang = French
|
|
||||||
importURL += '&attr_script=28'; // Release script = Latin
|
|
||||||
|
|
||||||
importURL += '¬etext=' + encodeURIComponent(window.location.href);
|
|
||||||
|
|
||||||
return importURL;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue