summaryrefslogtreecommitdiff
path: root/debian/.local/bin/dmenudelmusic
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-12-24 13:54:03 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-12-24 13:54:03 +0900
commit28e8bdf7f8286bd431b7f3b709e79f3827b31469 (patch)
tree85b44eff6da4d8443198fb6e04dfb6ee55244588 /debian/.local/bin/dmenudelmusic
parent8470ff001befcfd0f626dea69a9e76d43aee0511 (diff)
updates
Diffstat (limited to 'debian/.local/bin/dmenudelmusic')
-rwxr-xr-xdebian/.local/bin/dmenudelmusic44
1 files changed, 44 insertions, 0 deletions
diff --git a/debian/.local/bin/dmenudelmusic b/debian/.local/bin/dmenudelmusic
new file mode 100755
index 0000000..2efbafa
--- /dev/null
+++ b/debian/.local/bin/dmenudelmusic
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+music_dir="${XDG_MUSIC_DIR:-${HOME}/Music}"
+music_txt="${music_dir}/.music.txt"
+playlist_dir="${XDG_CONFIG_HOME:-${HOME}/.config}/mpd/playlists"
+
+# Using POSIX-compliant methods for file selection
+selected_filename=$(find "$music_dir" -type f | awk -F/ '{print $NF}' | dmenu -i -l 20 -p "Select a file to delete:") || exit 1
+
+selected_file="$music_dir/$selected_filename"
+
+# Extracting YouTube video ID without using -P in grep
+video_id=$(strings "$selected_file" | grep 'watch?v=' | sed 's/.*watch?v=\([a-zA-Z0-9_-]*\).*/\1/' | head -1) || {
+ notify-send "❌ No YouTube video ID found in file: $selected_filename"
+ exit 1
+}
+
+# Confirmation dialog without using echo -e
+confirm=$(printf "Yes\nNo" | dmenu -i -p "Delete $selected_filename and update mpc?")
+
+[ "$confirm" = "Yes" ] || {
+ notify-send "❌ Operation cancelled."
+ exit 0
+}
+
+# More portable sed command without -i and updating mpc
+if grep -v "$video_id" "$music_txt" >"${music_txt}.tmp" && mv "${music_txt}.tmp" "$music_txt"; then
+ # Search and remove the filename from playlists
+ for playlist in "$playlist_dir"/*.m3u; do
+ [ -e "$playlist" ] || continue
+ if grep -q "$selected_filename" "$playlist"; then
+ grep -v "$selected_filename" "$playlist" > "${playlist}.tmp" && mv "${playlist}.tmp" "$playlist"
+ # Remove empty lines
+ sed -i '/^$/d' "$playlist"
+ fi
+ done
+
+ # Delete the music file
+ rm "$selected_file"
+ mpc update >/dev/null
+ notify-send " Success to delete:" "$selected_filename"
+else
+ notify-send "❌ An error occurred."
+fi