irongit
hygoland/UserScripts/RofiBeats.sh
134 lines4.7 KBBourne Again Shell (bash)
1#!/bin/bash
2# /* ---- ๐Ÿ’ซ https://github.com/JaKooLit ๐Ÿ’ซ ---- */ ##
3# For Rofi Beats to play online Music or Locally saved media files
4
5# Variables
6mDIR="$HOME/Music/"
7iDIR="$HOME/.config/swaync/icons"
8rofi_theme="$HOME/.config/rofi/config-rofi-Beats.rasi"
9rofi_theme_1="$HOME/.config/rofi/config-rofi-Beats-menu.rasi"
10
11# Online Stations. Edit as required
12declare -A online_music=(
13 ["FM - Easy Rock 96.3 ๐Ÿ“ป๐ŸŽถ"]="https://radio-stations-philippines.com/easy-rock"
14 ["FM - Easy Rock - Baguio 91.9 ๐Ÿ“ป๐ŸŽถ"]="https://radio-stations-philippines.com/easy-rock-baguio"
15 ["FM - Love Radio 90.7 ๐Ÿ“ป๐ŸŽถ"]="https://radio-stations-philippines.com/love"
16 ["FM - WRock - CEBU 96.3 ๐Ÿ“ป๐ŸŽถ"]="https://onlineradio.ph/126-96-3-wrock.html"
17 ["FM - Fresh Philippines ๐Ÿ“ป๐ŸŽถ"]="https://onlineradio.ph/553-fresh-fm.html"
18 ["Radio - Lofi Girl ๐ŸŽง๐ŸŽถ"]="https://play.streamafrica.net/lofiradio"
19 ["Radio - Chillhop ๐ŸŽง๐ŸŽถ"]="http://stream.zeno.fm/fyn8eh3h5f8uv"
20 ["Radio - Ibiza Global ๐ŸŽง๐ŸŽถ"]="https://filtermusic.net/ibiza-global"
21 ["Radio - Metal Music ๐ŸŽง๐ŸŽถ"]="https://tunein.com/radio/mETaLmuSicRaDio-s119867/"
22 ["YT - Wish 107.5 YT Pinoy HipHop ๐Ÿ“ป๐ŸŽถ"]="https://youtube.com/playlist?list=PLkrzfEDjeYJnmgMYwCKid4XIFqUKBVWEs&si=vahW_noh4UDJ5d37"
23 ["YT - Youtube Top 100 Songs Global ๐Ÿ“น๐ŸŽถ"]="https://youtube.com/playlist?list=PL4fGSI1pDJn6puJdseH2Rt9sMvt9E2M4i&si=5jsyfqcoUXBCSLeu"
24 ["YT - Wish 107.5 YT Wishclusives ๐Ÿ“น๐ŸŽถ"]="https://youtube.com/playlist?list=PLkrzfEDjeYJn5B22H9HOWP3Kxxs-DkPSM&si=d_Ld2OKhGvpH48WO"
25 ["YT - Relaxing Piano Music ๐ŸŽน๐ŸŽถ"]="https://youtu.be/6H7hXzjFoVU?si=nZTPREC9lnK1JJUG"
26 ["YT - Youtube Remix ๐Ÿ“น๐ŸŽถ"]="https://youtube.com/playlist?list=PLeqTkIUlrZXlSNn3tcXAa-zbo95j0iN-0"
27 ["YT - Korean Drama OST ๐Ÿ“น๐ŸŽถ"]="https://youtube.com/playlist?list=PLUge_o9AIFp4HuA-A3e3ZqENh63LuRRlQ"
28 ["YT - lofi hip hop radio beats ๐Ÿ“น๐ŸŽถ"]="https://www.youtube.com/live/jfKfPfyJRdk?si=PnJIA9ErQIAw6-qd"
29 ["YT - Relaxing Piano Jazz Music ๐ŸŽน๐ŸŽถ"]="https://youtu.be/85UEqRat6E4?si=jXQL1Yp2VP_G6NSn"
30)
31
32# Populate local_music array with files from music directory and subdirectories
33populate_local_music() {
34 local_music=()
35 filenames=()
36 while IFS= read -r file; do
37 local_music+=("$file")
38 filenames+=("$(basename "$file")")
39 done < <(find -L "$mDIR" -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.wav" -o -iname "*.ogg" -o -iname "*.mp4" \))
40}
41
42# Function for displaying notifications
43notification() {
44 notify-send -u normal -i "$iDIR/music.png" "Now Playing:" "$@"
45}
46
47# Main function for playing local music
48play_local_music() {
49 populate_local_music
50
51 # Prompt the user to select a song
52 choice=$(printf "%s\n" "${filenames[@]}" | rofi -i -dmenu -config $rofi_theme)
53
54 if [ -z "$choice" ]; then
55 exit 1
56 fi
57
58 # Find the corresponding file path based on user's choice and set that to play the song then continue on the list
59 for (( i=0; i<"${#filenames[@]}"; ++i )); do
60 if [ "${filenames[$i]}" = "$choice" ]; then
61
62 notification "$choice"
63 mpv --playlist-start="$i" --loop-playlist --vid=no "${local_music[@]}"
64
65 break
66 fi
67 done
68}
69
70# Main function for shuffling local music
71shuffle_local_music() {
72 notification "Shuffle Play local music"
73
74 # Play music in $mDIR on shuffle
75 mpv --shuffle --loop-playlist --vid=no "$mDIR"
76}
77
78# Main function for playing online music
79play_online_music() {
80 choice=$(for online in "${!online_music[@]}"; do
81 echo "$online"
82 done | sort | rofi -i -dmenu -config "$rofi_theme")
83
84 if [ -z "$choice" ]; then
85 exit 1
86 fi
87
88 link="${online_music[$choice]}"
89
90 notification "$choice"
91
92 # Play the selected online music using mpv
93 mpv --shuffle --vid=no "$link"
94}
95
96# Function to stop music and kill mpv processes
97stop_music() {
98 mpv_pids=$(pgrep -x mpv)
99
100 if [ -n "$mpv_pids" ]; then
101 # Get the PID of the mpv process used by mpvpaper (using the unique argument added)
102 mpvpaper_pid=$(ps aux | grep -- 'unique-wallpaper-process' | grep -v 'grep' | awk '{print $2}')
103
104 for pid in $mpv_pids; do
105 if ! echo "$mpvpaper_pid" | grep -q "$pid"; then
106 kill -9 $pid || true
107 fi
108 done
109 notify-send -u low -i "$iDIR/music.png" "Music stopped" || true
110 fi
111}
112
113# Check if music is already playing
114if pgrep -x "mpv" > /dev/null; then
115 stop_music
116else
117 user_choice=$(printf "Play from Online Stations\nPlay from Music directory\nShuffle Play from Music directory" | rofi -dmenu -config $rofi_theme_1)
118
119 echo "User choice: $user_choice"
120
121 case "$user_choice" in
122 "Play from Music directory")
123 play_local_music
124 ;;
125 "Play from Online Stations")
126 play_online_music
127 ;;
128 "Shuffle Play from Music directory")
129 shuffle_local_music
130 ;;
131 *)
132 ;;
133 esac
134fi