-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathartists.html
140 lines (129 loc) · 3.97 KB
/
artists.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=yes">
<title>#listeningclub artist search</title>
</head>
<script>
async function fetchArtistsFromEntries() {
const tsv = await fetch("./entries.tsv");
const data = await tsv.text();
const results = [];
for(const row of data.split("\n")) {
if(!row.length || row.startsWith("Date\t") || row.startsWith("-\t")) {
continue;
}
if(/#\S+vortex/i.test(row)) {
continue;
}
const [date, selector, album, artist] = row.split("\t");
results.push([artist, date]);
}
return results;
}
const seps = [" / ", " - ", " – ", " by "];
async function fetchArtistsFromVortices() {
const tsv = await fetch("./vortices.txt");
const data = await tsv.text();
let vortex = null;
const results = [];
for (let line of data.split("\n")) {
if (!line.trim().length) {
continue;
}
if (line.startsWith("#")) {
vortex = line;
continue;
}
if (line.startsWith("Date:")) {
continue;
}
line = line.replace(/^\d+[\s.:*]*/g, '');
let found = false;
for (const sep of seps) {
if (line.includes(sep)) {
results.push([line.split(sep)[0], vortex]);
found = true;
break;
}
}
if (!found) {
console.log("Unable to parse:", line);
}
}
return results;
}
async function loadData() {
const artists = new Map();
const add = (artist, source) => {
if (artist === "Various" || artist === "Artist" || artist === "-") {
return;
}
if (!artist) return;
if (!artists.has(artist)) {
artists.set(artist, new Set());
}
artists.get(artist).add(source);
};
for (const [artist, date] of await fetchArtistsFromEntries()) {
add(artist, date);
}
for (const [artist, vortex] of await fetchArtistsFromVortices()) {
add(artist, vortex);
}
return artists;
}
let artists = new Map();
function update() {
const ul = document.getElementById("artists");
const filter = (document.getElementById("filter").value ?? "").toLowerCase().trim();
const matching = Array.from(artists.keys()).filter(a => a ? a.toLowerCase().includes(filter) : true).sort();
const info = document.getElementById("info");
info.textContent = `Showing ${matching.length} of ${artists.size} artists.`;
ul.innerHTML = "";
for (const artist of matching) {
const sources = Array.from(artists.get(artist)).sort();
const li = document.createElement("li");
li.textContent = artist + " ";
const sourcesSpan = document.createElement("span");
sourcesSpan.textContent = "(" + sources.join(", ") + ")";
sourcesSpan.className = "sources";
li.appendChild(sourcesSpan);
ul.appendChild(li);
}
}
async function init() {
artists = await loadData();
update();
}
</script>
<style>
* {
box-sizing: border-box;
}
body {
font-family: sans-serif;
font-size: 12pt;
line-height: 1.5;
}
main {
max-width: 60em;
margin: auto;
}
input {
width: 100%;
padding: 1em;
}
.sources {
opacity: .6;
}
</style>
<body onload="init()">
<main>
<input type="search" id="filter" placeholder="Filter..." autofocus oninput="update()">
<p id="info"></p>
<ul id="artists"></ul>
</main>
</body>
</html>