-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathradio
executable file
·78 lines (61 loc) · 2.14 KB
/
radio
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
#!/bin/bash
# Bashtuner V2.0 by Born2Root
# Play Internet Radio from Linux Command Line
# Features:
# - Log to played songs to terminal
# - Show Pop-Up Window when new Song is played
#====> Define Paths
# Path to radio station list
pfadsender="$HOME/sender.csv" ;
# Path to Logfile and temporary picture save location (album covers)
config_dir=~/.bash_radio
fifo=$config_dir/fifo
image_file=$config_dir/image
log_file=$config_dir/log
#====> Main Program
if [ ! -d $config_dir ]; then
mkdir $config_dir
fi
if [ ! -p $fifo ]; then
mkfifo $fifo
fi
trap "rm -f $fifo" INT TERM EXIT
check_dependencies() {
for cmd in zenity mplayer; do
if ! command -v "$cmd" &> /dev/null; then
echo "$cmd is not installed."
return 1
fi
done
return 0
}
playradio() {
auswahl=$(awk -F " " '{print $1"\n"$2}' $pfadsender | zenity --list --hide-column=1 --column "Nummer" --column "Sender" --title="Bashtuner" --ok-label="Abspielen" --cancel-label="Exit" --text="Radiosender einschalten" --width=600 --height=300)
if [ $? = "1" ] ; then exit 1 ; else
export play=$(cat $HOME/Programme/bashtuner/sender.csv | head -n"$auswahl" | tail -n1 | cut -d' ' -f3)
## old solution - current played song ist only printed to terminal
#mplayer $play 2> /dev/null | awk -F\' '/StreamTitle/ {print $2}'
#echo 'message:' | zenity --notification --listen
## new solution - current song is showed with Pop-Up window, printed to terminal and logged in logfile
mplayer $play 2>/dev/null | stdbuf -o L grep --text ICY > $fifo &
while read line < $fifo; do
args=$(echo $line | sed -r "s/ICY Info: StreamTitle='([^-]*) - ([^']*)';StreamUrl='([^']*)';/\1;\2;\3/")
saveIFS=$IFS; IFS=";"; set -- $args; IFS=$saveIFS
# Show PopUp Window 10s long, containing Song info and Cover if present
#wget -q $3 -O $image_file 2>/dev/null
notify-send -t 10000 -i $image_file "$1" "$2" 2>/dev/null
# write played songs to Logfile
#echo $(date +%D) $1 - $2 >> $log_file
# write played songs to terminal
echo $1 - $2
done
#wait
playradio
fi
}
check_dependencies
if [ $? -ne 0 ]; then
echo "Please install the missing dependencies and try again."
exit 1
fi
playradio