generated from nhcarrigan/template
This commit is contained in:
parent
dcf79e03b6
commit
e258a3dbd0
94
music/index.html
Normal file
94
music/index.html
Normal file
@ -0,0 +1,94 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Naomi's Music Library</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="An interactive explorer for the music Naomi listens to." />
|
||||
<script src="https://cdn.nhcarrigan.com/headers/index.js" async defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Naomi's Music Library</h1>
|
||||
<section>
|
||||
<p>An interactive explorer for the music Naomi listens to.</p>
|
||||
</section>
|
||||
<div style="display: none;">
|
||||
<span>Search Artists: </span>
|
||||
<input type="text" id="artist" />
|
||||
</div>
|
||||
<div style="display: none;">
|
||||
<span>Search Titles: </span>
|
||||
<input type="text" id="title" />
|
||||
</div>
|
||||
<table id="songs">
|
||||
|
||||
</table>
|
||||
</main>
|
||||
</body>
|
||||
<script>
|
||||
const artistQuery = document.getElementById('artist');
|
||||
const titleQuery = document.getElementById('title');
|
||||
const songTable = document.getElementById('songs');
|
||||
const filterSongs = (artist, title) => {
|
||||
let result = [...songList];
|
||||
if(artist) {
|
||||
result = result.filter(song => song.artist.toLowerCase().includes(artist.toLowerCase()));
|
||||
}
|
||||
if(title) {
|
||||
result = result.filter(song => song.title.toLowerCase().includes(title.toLowerCase()));
|
||||
}
|
||||
updateTable(result);
|
||||
}
|
||||
const loadSongs = (songs) => {
|
||||
songList.push(...songs);
|
||||
artistQuery.parentElement.style.display = "block";
|
||||
titleQuery.parentElement.style.display = "block";
|
||||
updateTable(songs);
|
||||
}
|
||||
const updateTable = (songs) => {
|
||||
songs = songs.sort((a, b) => a.title.localeCompare(b.title));
|
||||
songTable.innerHTML = "";
|
||||
const header = document.createElement('tr');
|
||||
const artistHeader = document.createElement('th');
|
||||
artistHeader.innerText = "Artist";
|
||||
const titleHeader = document.createElement('th');
|
||||
titleHeader.innerText = "Title";
|
||||
header.appendChild(titleHeader);
|
||||
header.appendChild(artistHeader);
|
||||
songTable.appendChild(header);
|
||||
songs.forEach(song => {
|
||||
const row = document.createElement('tr');
|
||||
const artist = document.createElement('td');
|
||||
artist.innerText = song.artist;
|
||||
const title = document.createElement('td');
|
||||
title.innerText = song.title;
|
||||
row.appendChild(title);
|
||||
row.appendChild(artist);
|
||||
songTable.appendChild(row);
|
||||
});
|
||||
}
|
||||
const songList = [];
|
||||
fetch("./songs.json").then(res => res.json()).then(data => loadSongs(data))
|
||||
|
||||
artistQuery?.addEventListener("input", (e) => filterSongs(e.target.value, titleQuery.value));
|
||||
titleQuery?.addEventListener("input", (e) => filterSongs(artistQuery.value, e.target.value));
|
||||
</script>
|
||||
<style>
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
tr:nth-of-type(even) {
|
||||
background-color: #db7093dd;
|
||||
color: #ffefef;
|
||||
}
|
||||
input {
|
||||
background:var(--foreground);
|
||||
color:var(--background);
|
||||
border:1px solid white;
|
||||
border-radius:10px;
|
||||
padding:.25rem
|
||||
}
|
||||
</style>
|
||||
</html>
|
11572
music/songs.json
Normal file
11572
music/songs.json
Normal file
File diff suppressed because it is too large
Load Diff
41
songs.sh
Executable file
41
songs.sh
Executable file
@ -0,0 +1,41 @@
|
||||
IFS=$'\n'
|
||||
|
||||
# Initialize an empty string to hold the list of songs in JSON-like format
|
||||
songs=""
|
||||
filecount=$(find /home/naomi/music -type f | wc -l)
|
||||
echo "Found $filecount files."
|
||||
current=0
|
||||
|
||||
# Loop over each file found by find
|
||||
for file in $(find /home/naomi/music -type f -print0 | tr '\0' '\n'); do
|
||||
current=$((current + 1))
|
||||
echo -ne "Processing $current/$filecount\r"
|
||||
title=$(id3v2 -l "$file" | grep "TIT2" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
||||
artist=$(id3v2 -l "$file" | grep "TPE1" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
||||
|
||||
if [ -z "$title" ]; then
|
||||
title=$(id3v2 -l "$file" | grep "TT2" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
||||
fi
|
||||
if [ -z "$artist" ]; then
|
||||
artist=$(id3v2 -l "$file" | grep "TP1" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
||||
fi
|
||||
if [ -z "$title" ]; then
|
||||
# remove .mp3 from the title
|
||||
title=$(basename "$file" | sed -e 's/\.mp3//g')
|
||||
fi
|
||||
if [ -z "$artist" ]; then
|
||||
artist="Unknown Artist"
|
||||
fi
|
||||
|
||||
# use jq to add the song to the list
|
||||
songs="$songs$(jq -n --arg title "$title" --arg artist "$artist" '{title: $title, artist: $artist}'),"
|
||||
|
||||
# songs="$songs{\"title\":\"$(echo "$title" | sed -e 's/[\\"\/]/\\&/g' | sed -e 's/[\x01-\x1f\x7f]//g')\",\"artist\":\"$(echo "$artist" | sed -e 's/[\\"\/]/\\&/g' | sed -e 's/[\x01-\x1f\x7f]//g')\"},"
|
||||
done
|
||||
|
||||
# Remove trailing comma and add square brackets to complete the list
|
||||
songs="[${songs%,}]"
|
||||
|
||||
# Write to ./music/songs.json
|
||||
echo "$songs" > ./music/songs.json
|
||||
echo -ne "Done!\r"
|
2
sync.sh
2
sync.sh
@ -1,6 +1,6 @@
|
||||
#! /usr/bin/bash
|
||||
|
||||
dirs=("bsky" "chat" "games" "link-redirector" "resume" "testimonials" "manual" "sitemap");
|
||||
dirs=("bsky" "chat" "games" "link-redirector" "resume" "testimonials" "manual" "sitemap" "music");
|
||||
|
||||
for dir in "${dirs[@]}"; do
|
||||
rsync -av $dir prod:/home/nhcarrigan
|
||||
|
Loading…
x
Reference in New Issue
Block a user