I wanted to add a “mark for deletion” feature to Volumio. The idea:
[list]
A Tampermonkey button in the web UI sends the current track’s path to a small Flask server running on Volumio.
The server writes the path into a text file (/data/delete_list.txt).
[*] A cron job runs a cleanup script every hour, deletes those files, clears the list, and updates the MPD database.
[/list]
Here’s the complete working setup.
1. Install Required Packages
sudo apt update
sudo apt install python3-flask cron
2. Create the Flask Server
sudo nano /home/volumio/delete_server.py
from flask import Flask, request
app = Flask(name)
DELETE_FILE = "/data/delete_list.txt"
def normalize_path(uri):
# Remove file:// prefix if present
if uri.startswith("file://"):
uri = uri.replace("file://", "")
# Ensure absolute path
if not uri.startswith("/"):
uri = "/" + uri
return uri
@app.route('/add_delete', methods=['POST'])
def add_delete():
path = request.json.get('path')
if not path:
return "No path", 400
real_path = normalize_path(path)
with open(DELETE_FILE, "a") as f:
f.write(real_path + "\n")
return "Added: " + real_path, 200
if name == "main":
app.run(host="0.0.0.0", port=8080)
3. Prepare the Delete List File
sudo touch /data/delete_list.txt
sudo chown volumio:volumio /data/delete_list.txt
sudo chmod 664 /data/delete_list.txt
4. Autostart the Server with systemd
sudo nano /etc/systemd/system/delete_server.service
[Unit]
Description=Volumio Delete Server
After=network.target
[Service]
User=volumio
WorkingDirectory=/home/volumio
ExecStart=/usr/bin/python3 /home/volumio/delete_server.py
Restart=always
[Install]
WantedBy=multi-user.target
Enable:
sudo systemctl daemon-reload
sudo systemctl enable --now delete_server.service
5. Create the Cleanup Script
sudo nano /home/volumio/clean_delete.sh
#!/bin/bash
LIST="/data/delete_list.txt"
if [ -f "$LIST" ]; then
while IFS= read -r file; do
if [ -n "$file" ]; then
[[ "$file" != /* ]] && file="/$file"
if [ -f "$file" ]; then
rm -f "$file"
echo "Deleted: $file"
else
echo "File not found: $file"
fi
fi
done < "$LIST"
Clear the list after deletion
"$LIST"
Update Volumio/MPD library
mpc update
fi
Make executable:
chmod +x /home/volumio/clean_delete.sh
6. Schedule with Cron
crontab -e
Add:
0 * * * * /home/volumio/clean_delete.sh >> /data/delete_log.txt 2>&1
7. Tampermonkey Script
Install Tampermonkey in your browser and add this script:
// ==UserScript==
// @name Volumio Remove Track
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Button to mark current track for deletion
// @author Alex
// @match http://volumio.local/playback*
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
const btn = document.createElement("button");
btn.textContent = "Remove Track";
btn.style.position = "fixed";
btn.style.bottom = "20px";
btn.style.right = "20px";
btn.style.zIndex = "9999";
btn.style.padding = "10px";
btn.style.background = "#f44336";
btn.style.color = "white";
btn.style.border = "none";
btn.style.borderRadius = "5px";
btn.style.cursor = "pointer";
document.body.appendChild(btn);
btn.addEventListener("click", () => {
GM_xmlhttpRequest({
method: "GET",
url: "http://volumio.local/api/v1/getstate",
onload: function(response) {
const data = JSON.parse(response.responseText);
if (data && data.uri) {
GM_xmlhttpRequest({
method: "POST",
url: "http://volumio.local:8080/add_delete",
headers: { "Content-Type": "application/json" },
data: JSON.stringify({ path: data.uri })
});
// Skip to next track
GM_xmlhttpRequest({
method: "GET",
url: "http://volumio.local/api/v1/commands/?cmd=next"
});
} else {
alert("Could not get track path.");
}
}
});
});
})();
This adds a Remove Track button to Volumio’s playback page. Clicking it sends the current track’s path to the Flask server and skips to the next track.
8. Manual Test
touch "/mnt/HDD/test.mp3"
echo "mnt/HDD/test.mp3" >> /data/delete_list.txt
/home/volumio/clean_delete.sh
The file should be deleted, the list emptied, and MPD updated.
[size=120]Result[/size]
[list]
Tampermonkey button marks the current track for deletion.
Flask server records the normalized path in /data/delete_list.txt.
Cron runs clean_delete.sh hourly, deletes files, clears the list, and updates Volumio’s library.
Systemd keeps the Flask server running permanently.
[/list]
This setup gives Volumio a reliable “mark for deletion” feature integrated into the web UI.