-
-
Save jesus2099/3999676 to your computer and use it in GitHub Desktop.
Import ISRC from 音楽の森 to MusicBrainz release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name MusicBrainz: Search Music Forest and add ISRCs | |
// @version 2013.0527.1631 | |
// @description This adds a link to Music Forest next to catalogue numbers on release pages and a link on the Music Forest page to add the ISRCs | |
// @namespace df069240-fe79-11dc-95ff-0800200c9a66 | |
// @updateURL https://raw.github.com/gist/3999676 | |
// @downloadURL https://raw.github.com/gist/3999676 | |
// @author nikki/kepstin(2011-12-03)+jesus2099(later) | |
// @licence CC BY-NC-SA 3.0 FR (http://creativecommons.org/licenses/by-nc-sa/3.0/fr/) | |
// @grant none | |
// @match *://*.musicbrainz.org/release/* | |
// @match *://www.minc.gr.jp/db/* | |
// @run-at document-start | |
// ==/UserScript== | |
if(self.location.href.match(/^https?:\/\/(www\.minc\.gr\.jp\/db\/.+|([^.]+\.)?musicbrainz\.org\/release\/.+)$/)){/*@matchopera*/(function(){"use strict"; | |
var RE_GUID = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"; | |
var mbid; | |
if (self.location.href.match(/^https?:\/\/www\.minc\.gr\.jp\/db\/AlbInfo\.aspx/)) { | |
if (mbid = self.location.search.match(new RegExp("&mbid=("+RE_GUID+")"))) { | |
mbid = mbid[1]; | |
var href = self.location.href.replace(new RegExp("&mbid="+mbid), ""); | |
if (navigator.userAgent.match(/firefox/i) && typeof opera == "undefined") {/*FFF*/ | |
var a = document.body.appendChild(document.createElement("a")); | |
a.setAttribute("href", href); | |
a.setAttribute("target", "_self"); | |
a.click(); | |
} else { self.location.href = href; } | |
} else { mbid = document.referrer.match(new RegExp(RE_GUID)); } | |
self.addEventListener("load", function(e) { | |
var qs = "mbid="+(mbid?mbid:""); | |
var medium = 0; | |
var e = document.getElementsByTagName("table"); | |
for (var x = 0; x < e.length; x++) { | |
if (e[x].textContent.match(/収録No/)) { | |
medium = medium + 1; | |
var tr = e[x].getElementsByTagName("tr"); | |
for (var i = 1; i < tr.length; i++) { | |
var td = tr[i].getElementsByTagName("td"); | |
var tnum = td[0].textContent; //.replace(/.*>([0-9]+).*/, "$1"); | |
var tisrc = td[6].textContent.match(/[A-Z]{2}[A-Z0-9]{3}[0-9]{7}/); | |
tnum = tnum.replace(/.*>([0-9]+).*/, "$1"); | |
if (!tisrc) { | |
tisrc = ""; | |
} | |
qs += "&isrc" + medium + "-" + tnum + "=" + tisrc; | |
} | |
} | |
} | |
var a = document.createElement("a").appendChild(document.createTextNode("☞ Add ISRCs to MusicBrainz")).parentNode; | |
a.setAttribute("href", "http://notlob.eu/isrc/?"+qs); | |
a.setAttribute("target", "_self"); | |
a.style.setProperty("background-color", "yellow"); | |
a.style.setProperty("padding", ".1em .5em"); | |
a.addEventListener("click", function(e) { | |
var pmbid, nombid = this.getAttribute("href").match(/mbid=&/); | |
if (nombid && (pmbid = prompt("Please paste MB release MBID or URL")) && (pmbid = pmbid.match(new RegExp(RE_GUID)))) { | |
a.setAttribute("href", this.getAttribute("href").replace(/mbid=&/, "mbid="+pmbid+"&")); | |
} | |
else if (nombid && !pmbid) { | |
e.cancelBubble = true; | |
if (e.stopPropagation) e.stopPropagation(); | |
e.preventDefault(); | |
return false; | |
} | |
}, false); | |
if (mbid) { | |
a = document.createDocumentFragment().appendChild(a).parentNode; | |
a.appendChild(document.createElement("small").appendChild(document.createTextNode(" (release "+mbid+")")).parentNode); | |
} | |
document.querySelector("table").parentNode.insertBefore(a, document.querySelector("table").nextSibling); | |
}, false); | |
} else if (mbid = self.location.href.match(new RegExp("^https?://[^/]*musicbrainz\\.org/release/("+RE_GUID+")"))) { | |
mbid = mbid[1]; | |
self.addEventListener("load", function(e) { | |
var e = document.querySelectorAll("span[property*='mo:catalogue_number']"); | |
for (var i = 0; i < e.length; i++) { | |
var catno = e[i].textContent; | |
var m = catno.match(/^([A-Z]{3,4})[ -]([0-9]+)/); | |
if (m) { | |
var a = document.createElement("a").appendChild(document.createTextNode("音楽の森")).parentNode; | |
a.setAttribute("href", "http://www.minc.gr.jp/db/AlbInfo.aspx?CAT1="+m[1]+"&CAT2="+m[2]+(self.location.protocol.match(/https/)?"&mbid="+mbid:"")); | |
a.setAttribute("target", "_blank"); | |
a = document.createDocumentFragment().appendChild(a).parentNode; | |
a.insertBefore(document.createTextNode(" ("), a.firstChild); | |
a.appendChild(document.createTextNode(")")); | |
e[i].parentNode.insertBefore(a, e[i].parentNode.querySelector("span").nextSibling); | |
} | |
} | |
}, false); | |
} | |
})();} |
2012.1102.1228 now works even when not coming from MB (will prompt for MB release on click)
interactive mode + better HTTPS:///MB manage (as I don’t like adding stuff in URL, it prevents clean URL copy/paste)
of course another FFF bug (document.referrer)
2013.0511.2324. minc.gr.jp changed their URL patterns (to MS asp yuck)
Can you support multi-disk release?
For example:
http://musicbrainz.org/release/60f5cc7c-a2bf-43cd-a751-33253b19abc2 and
https://www.minc.gr.jp/db/AlbInfo.aspx?SHIYOSYACD=0000024&CATALOGCD=KICX-006202&SETFLG=1 (KICX-6202)
If there is no technical difficulty and you just don't have time to implement, I would implement it and send PR.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added use strict for safer run and debug.
Replace getElementsByAttribute by standard querySelectorAll.
etc.