init commie

This commit is contained in:
xbl
2026-03-02 21:49:19 +01:00
commit 231c37fcd6
5 changed files with 159 additions and 0 deletions

2
pausetoggle.bash Executable file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
printf '{"command":["cycle","pause"]}\n' | socat - /tmp/mpv-socket

54
style.css Normal file
View File

@ -0,0 +1,54 @@
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
font-family: sans-serif;
text-align: center;
background: #111;
font-size: 16px;
color: white;
}
#cover {
width: 100%;
height: 100%;
object-fit: contain;
border-radius: 12px;
}
#overlay {
position: fixed;
top: 5%;
left: 5%;
width: 90%;
height: 90%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
justify-content: flex-end;
padding-bottom: 3%;
text-shadow: 0 0 10px black;
}
/* Text glow */
#overlay h1, #overlay h2 {
text-shadow:
0 0 2px black,
0 0 4px black,
0 0 8px black;
color: #fff;
margin: 3px 0;
}
h1 {
margin: 5px 0;
font-size: 0.69rem;
}
h2 {
margin: 5px 0;
font-weight: normal;
font-size: 0.5rem;
}

11
z4z-service.bash Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
WEB_ROOT="/home/xbl/z4z"
MPV_WATCHER="/home/xbl/z4z/z4z.bash"
HTTP_PORT=8080
# Start the MPV watcher in background
"$MPV_WATCHER" &
# Start BusyBox httpd in foreground
exec busybox httpd -f -p "$HTTP_PORT" -h "$WEB_ROOT"

79
z4z.bash Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env bash
# Paths
MPV_SOCKET="/tmp/mpv-socket"
WEB_ROOT="/home/xbl/z4z"
COVER_PATH="$WEB_ROOT/cover.jpg"
WEB_HTML="$WEB_ROOT/index.html"
INTERVAL=0.5
last_path=""
while true; do
# Get current file path, pause state, state
path=$(echo '{ "command": ["get_property", "path"] }' | socat - "$MPV_SOCKET" 2>/dev/null | jq -r '.data')
paused=$(echo '{ "command": ["get_property", "pause"] }' | socat - "$MPV_SOCKET" 2>/dev/null | jq -r '.data // false')
# If MPV is stopped
if [[ -z "$path" || "$path" == "null" ]]; then
last_path=""
# Write "Not Playing" HTML
cat > "$WEB_HTML" <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Now Playing</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<h2>Not Playing</h2>
</body>
</html>
EOF
sleep "$INTERVAL"
continue
fi
# If track changed
if [[ "$path" != "$last_path" ]]; then
last_path="$path"
# Extract cover art (first video stream / album art)
ffmpeg -y -i "$path" -map 0:v? -c copy "$COVER_PATH" 2>/dev/null || rm -f "$COVER_PATH"
# Fetch metadata
metadata=$(echo '{ "command": ["get_property", "metadata"] }' | socat - "$MPV_SOCKET")
title=$(echo "$metadata" | jq -r '.data.title // .data.TITLE // empty')
artist=$(echo "$metadata" | jq -r '.data.artist // .data.ARTIST // empty')
album=$(echo "$metadata" | jq -r '.data.album // .data.ALBUM // empty')
year=$(echo "$metadata" | jq -r '.data.date // .data.DATE // empty')
# Write index.html dynamically
cat > "$WEB_HTML" <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Now Playing</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
EOF
# Add cover if exists
if [[ -f "$COVER_PATH" ]]; then
echo "<img id=\"cover\" src=\"/cover.jpg\" alt=\"Cover\">" >> "$WEB_HTML"
fi
# Add metadata
echo "<div id=\"overlay\">" >> "$WEB_HTML"
echo "<h1>$artist - $title</h1>" >> "$WEB_HTML"
echo "<h2>$album ($year)</h2>" >> "$WEB_HTML"
echo "</div>" >> "$WEB_HTML"
echo "</body></html>" >> "$WEB_HTML"
fi
sleep "$INTERVAL"
done

13
z4z.service Normal file
View File

@ -0,0 +1,13 @@
[Unit]
Description=Zabbix mpv Watcher & Busybox
After=network.target
[Service]
Type=simple
User=xbl
ExecStart=/home/xbl/z4z/z4z-service.bash
Restart=always
WorkingDirectory=/home/xbl/z4z
[Install]
WantedBy=multi-user.target