blob: 060ec33e5523185ac0a38863290dcddd5988414f (
plain) (
blame)
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
141
142
143
144
145
146
|
#!/usr/bin/env bash
# ==================================================
# KoolDots (2026)
# Project URL: https://github.com/LinuxBeginnings
# License: GNU GPLv3
# SPDX-License-Identifier: GPL-3.0-or-later
# ==================================================
# RofiBeats - unified, dynamic UI (add, remove, manage, play)
mDIR="$HOME/Music/"
iDIR="$HOME/.config/swaync/icons"
rofi_theme="$HOME/.config/rofi/config-rofi-Beats.rasi"
rofi_theme_menu="$HOME/.config/rofi/config-rofi-Beats-menu.rasi"
music_list="$HOME/.config/rofi/online_music.list"
mkdir -p "$(dirname "$music_list")"
[[ -f "$music_list" ]] || touch "$music_list"
# Send notification
notification() {
notify-send -u normal -i "$iDIR/music.png" "$@"
}
# Check if mpv is currently playing
music_playing() { pgrep -x "mpv" >/dev/null; }
# Stop all mpv processes except mpvpaper
stop_music() {
mpv_pids=$(pgrep -x mpv)
if [ -n "$mpv_pids" ]; then
mpvpaper_pid=$(ps aux | grep -- 'unique-wallpaper-process' | grep -v 'grep' | awk '{print $2}')
for pid in $mpv_pids; do
if ! echo "$mpvpaper_pid" | grep -q "$pid"; then
kill -9 $pid || true
fi
done
notification "Music stopped"
fi
}
# Populate local music file list
populate_local_music() {
local_music=()
filenames=()
declare -A seen_names
while IFS= read -r file; do
basename_file="$(basename "$file")"
if [[ -z "${seen_names[$basename_file]}" ]]; then
local_music+=("$file")
filenames+=("$basename_file")
seen_names["$basename_file"]=1
fi
done < <(find -L "$mDIR" -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.wav" -o -iname "*.ogg" -o -iname "*.mp4" \))
}
# Play selected local music file
play_local_music() {
populate_local_music
choice=$(printf "%s\n" "${filenames[@]}" | rofi -i -dmenu -config "$rofi_theme" \
-theme-str 'entry { placeholder: "🎵 Choose Local Music"; }')
[[ -z "$choice" ]] && exit 1
for ((i = 0; i < "${#filenames[@]}"; ++i)); do
if [ "${filenames[$i]}" = "$choice" ]; then
music_playing && stop_music
notification "Now Playing:" "$choice"
mpv --no-video --playlist-start="$i" --loop-playlist "${local_music[@]}"
break
fi
done
}
# Shuffle and play all local music
shuffle_local_music() {
music_playing && stop_music
notification "Shuffle Play local music"
mpv --no-video --shuffle --loop-playlist "$mDIR"
}
# Play selected online music
play_online_music() {
if [ ! -s "$music_list" ]; then
notify-send -u low -i "$iDIR/music.png" "No online music found" "Add some with Manage Music"
exit 0
fi
choice=$(awk -F'|' '{print $1}' "$music_list" | sort | rofi -i -dmenu -config "$rofi_theme" \
-theme-str 'entry { placeholder: "🌐 Choose Online Station"; }')
[[ -z "$choice" ]] && exit 1
link=$(awk -F'|' -v name="$choice" '$1 == name {print $2; exit}' "$music_list")
[[ -z "$link" ]] && {
notify-send -u low -i "$iDIR/music.png" "URL not found for" "$choice"
exit 1
}
music_playing && stop_music
notification "Now Playing:" "$choice"
mpv --no-video --shuffle "$link"
}
# Manage online music list (add, remove, view)
manage_music() {
sub_choice=$(printf "Add Music\nRemove Music\nView List" | rofi -dmenu \
-config "$rofi_theme_menu" \
-theme-str 'entry { placeholder: "🛠️ Manage Music List"; }')
case "$sub_choice" in
"Add Music")
name=$(rofi -dmenu -lines 0 -config "$rofi_theme_menu" \
-theme-str 'entry { placeholder: "🎼 Enter Music Title"; }')
[[ -z "$name" ]] && return
url=$(rofi -dmenu -lines 0 -config "$rofi_theme_menu" \
-theme-str 'entry { placeholder: "🔗 Enter Music URL"; }')
[[ -z "$url" ]] && return
echo "$name|$url" >>"$music_list"
notification "Added" "$name"
;;
"Remove Music")
entry=$(awk -F'|' '{print $1}' "$music_list" | rofi -dmenu -config "$rofi_theme_menu" \
-theme-str 'entry { placeholder: "🗑️ Select Music to Remove"; }')
[[ -z "$entry" ]] && return
grep -vF "$entry" "$music_list" >"$music_list.tmp" && mv "$music_list.tmp" "$music_list"
notification "Removed" "$entry"
;;
"View List")
# Show only titles, not URLs
awk -F'|' '{print $1}' "$music_list" | rofi -dmenu -config "$rofi_theme_menu" \
-theme-str 'entry { placeholder: "📜 Online Music List"; }' >/dev/null
;;
esac
}
# Main menu
user_choice=$(printf "%s\n" \
"Play from Online Stations" \
"Play from Music directory" \
"Shuffle Play from Music directory" \
"Stop RofiBeats" \
"Manage Music List" |
rofi -dmenu -config "$rofi_theme_menu" \
-theme-str 'entry { placeholder: "Play Some Music"; }')
case "$user_choice" in
"Play from Online Stations") play_online_music ;;
"Play from Music directory") play_local_music ;;
"Shuffle Play from Music directory") shuffle_local_music ;;
"Stop RofiBeats") music_playing && stop_music ;;
"Manage Music List") manage_music ;;
esac
|