-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplay.sh
executable file
·52 lines (44 loc) · 1.54 KB
/
play.sh
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
#!/bin/bash
WORKING_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
selectsong() {
input_data=$(cat)
# oneline=$(awk 'BEGIN {RS=""; FS="\n"} {print $1 "\t" $2 "\n"}')
#awk 'BEGIN {RS=""; FS="\n"} {print $1 ": " $2 "\t" $3}' | \
printf "%s" "$input_data" | awk 'BEGIN {RS=""; FS="\n"} {print $1}' | \
showmenu | \
while read -r selection; do
# Extract the URL part from the selection (after the tab)
url=$(printf "%s" "$input_data" | grep -A 1 "$selection" | tail -n 1)
echo "$url"
done
}
showmenu() {
# Read input from standard input
input=$(cat)
if command -v wofi >/dev/null 2>&1; then
echo "$input" | wofi --conf $HOME/.config/wofi/config-smenu --style $HOME/.config/wofi/styleS.css
elif command -v dmenu >/dev/null 2>&1; then
echo "$input" | dmenu -i -l 25
elif command -v fzf >/dev/null 2>&1; then
echo "$input" | fzf
else
echo "Neither dmenu nor wofi is installed."
return 1
fi
}
playsong() {
songurl=$(cat)
mpv "$songurl"
}
# Check if exactly 3 parameters are provided
if [ $# -eq 3 ]; then
serverurl=$1
username=$2
password=$3
else
IFS=$'\n' read -d '' -r serverurl username password < $HOME/.config/ampache_credentials
fi
song=$(cat songs_cache | awk 'BEGIN {RS=""; FS="\n"} {print $1}' | showmenu)
songsResult=$(lua "$WORKING_DIR/songs.lua" $serverurl $username $password -f "$song")
# FIX CACHE printf "%s" "$songsResult" >> songs_cache
printf "%s" "$songsResult" | selectsong | playsong