[musicbrainz] Add ISWC to Enhanced Search

This commit is contained in:
SuperSaltyGamer
2024-01-29 22:59:02 +02:00
parent 23987f4a26
commit 3f07f83735
3 changed files with 16 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @namespace ame-musicbrainz
// @name Ame (MusicBrainz)
// @version 1.7.0
// @version 1.8.0
// @author SuperSaltyGamer
// @run-at document-end
// @match https://musicbrainz.org/*

View File

@@ -6,6 +6,7 @@ enum QueryType {
Barcode = "barcode",
Catalog = "catalog",
Isrc = "isrc",
Iswc = "iswc",
Toc = "toc"
}
@@ -26,6 +27,7 @@ typeEl.options.add(fromHTML<HTMLOptionElement>(`<option value="barcode">Barcode<
typeEl.options.add(fromHTML<HTMLOptionElement>(`<option value="catalog">Catalog</option>`));
typeEl.options.add(fromHTML<HTMLOptionElement>(`<option value="toc">CD TOC</option>`));
typeEl.options.add(fromHTML<HTMLOptionElement>(`<option value="isrc">ISRC</option>`));
typeEl.options.add(fromHTML<HTMLOptionElement>(`<option value="iswc">ISWC</option>`));
queryEl.addEventListener("input", () => {
const toc = parseTocFromLog(queryEl.value);
@@ -41,6 +43,9 @@ queryEl.addEventListener("input", () => {
case QueryType.Isrc:
typeEl.value = "isrc";
break;
case QueryType.Iswc:
typeEl.value = "iswc";
break;
case QueryType.Toc:
typeEl.value = "toc";
break;
@@ -86,6 +91,9 @@ formEl.addEventListener("submit", e => {
case QueryType.Isrc:
location.href = `https://musicbrainz.org/search?type=recording&method=advanced&query=isrc:${encodeURIComponent(query)}`;
break;
case QueryType.Iswc:
location.href = `https://musicbrainz.org/search?type=work&method=advanced&query=iswc:${encodeURIComponent(query)}`;
break;
case QueryType.Toc:
let params = `?toc=${query}`;
if (location.pathname.startsWith("/release/")) params += `&filter-release.query=${getPageReleaseId()}`;
@@ -97,6 +105,7 @@ formEl.addEventListener("submit", e => {
export function identifyQuery(value: string): QueryType {
if (/^(\d{8}|\d{12}|\d{13}|\d{14})$/.test(value)) return QueryType.Barcode;
if (/^[a-zA-Z]{5}[0-9]{7}$/.test(value)) return QueryType.Isrc;
if (/^T-\d{3}.\d{3}.\d{3}-\d$/.test(value)) return QueryType.Iswc;
if (value === value.toUpperCase() && /\d/.test(value) && /[a-zA-Z]/.test(value) && /[ ~-]/.test(value)) return QueryType.Catalog;
if (value.split(" ").filter(Number).length >= 4) return QueryType.Toc;
return QueryType.Unknown;