forked from CerebruxCode/shelldio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshelldio.sh
executable file
·149 lines (136 loc) · 5.51 KB
/
shelldio.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
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
147
148
149
#!/bin/bash
#
#
# Shelldio - ακούστε online ραδιόφωνο από το τερματικό
# Copyright (c)2018 Vasilis Niakas and Contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation version 3 of the License.
#
# Please read the file LICENSE and README for more information.
#
#
# Verbosity
ERR="[Πρόβλημα] : "
INFO="[Πληροφορία] : "
FATAL="[Σφάλμα] : "
# Έλεγχος προαπαιτούμενων binaries
echo "$INFO ελεγχος προαπαιτούμενων"
player=$(command -v mpv 2>/dev/null || command -v mplayer 2>/dev/null || command -v mpg123 2>/dev/null || echo "1")
if [[ $player = 1 ]];
then
echo "$FATAL δε βρέθηκε συμβατός player, συμβατοί players είναι οι 'mpv', 'mplayer' και 'mpg123'"
exit 1
fi
for binary in wget info tput sleep clear killall; do
if ! command -v $binary &> /dev/null; then
echo "$FATAL δε βρέθηκε το '$binary'"
exit 1
fi
done
# Έλεγχος αρχείου σταθμών
user_stations="$HOME/.shelldio/my_stations.txt"
all_stations="$HOME/.shelldio/all_stations.txt"
stations_url="https://raw.githubusercontent.com/CerebruxCode/shelldio/master/.shelldio/all_stations.txt"
if [ "$#" -eq "0" ]
then
echo "$ERR δεν ορίστηκε προσαρμοσμένο αρχείο σταθμών"
echo "$INFO φόρτωση αγαπημένων σταθμών του χρήστη $USER"
if [ ! -f "$user_stations" ]; then
echo "$ERR δεν βρέθηκε το αρχείο '$user_stations'"
echo "$INFO φόρτωση προκαθορισμένων σταθμών"
if [ ! -f "$all_stations" ]; then
echo "$ERR δεν βρέθηκε το αρχείο '$all_stations'"
echo "$INFO προσπάθεια ανάκτησης αρχείου προκαθορισμένων σταθμών από το github"
mkdir ~/.shelldio &> /dev/null
if ! wget $stations_url -O "$all_stations" &> /dev/null;
then
echo "$ERR προέκυψε πρόβλημα με το δίκτυο"
echo "$FATAL αδυναμία φόρτωση σταθμών"
exit 1
fi
echo "$INFO το αρχείο κατέβηκε επιτυχώς"
fi
echo "$INFO φόρτωση προκαθορισμένων σταθμών"
stations="$all_stations"
else
echo "$INFO φόρτωση αγαπημένων σταθμών"
stations="$user_stations"
fi
else
echo "$INFO φόρτωση προσαρμοσμένου αρχείου"
if [ ! -f "$1" ]; then
echo "$ERR δεν βρέθηκε το αρχείο '$1'"
echo "$FATAL αδυναμία φόρτωση σταθμών"
exit 1
fi
stations=$1
fi
while true
do
terms=0
trap ' [ $terms = 1 ] || { terms=1; kill -TERM -$$; }; exit' EXIT INT HUP TERM QUIT
info() {
tput civis -- invisible # Εξαφάνιση cursor
echo -ne "| Η ώρα είναι $(date +"%T")\n| Ακούτε $stathmos_name\n| Πατήστε Q/q για έξοδο ή R/r για επιστροφή στη λίστα σταθμών"
}
echo "---------------------------------------------------------"
echo "Shelldio - ακούστε online ραδιόφωνο από το τερματικό"
echo "---------------------------------------------------------"
echo "https://github.com/CerebruxCode/Shelldio"
while true
do
echo "---------------------------------------------------------"
num=0
while IFS='' read -r line || [[ -n "$line" ]]; do
num=$(( num + 1 ))
echo ["$num"] "$line" | cut -d "," -f1
done < "$stations"
echo "---------------------------------------------------------"
read -rp "Διαλέξτε Σταθμό (Q/q για έξοδο): " input
if [[ $input = "q" ]] || [[ $input = "Q" ]]
then
echo "$INFO έξοδος..."
tput cnorm -- normal # Εμφάνιση cursor
exit 0
fi
# Έλεγχος αν το input είναι μέσα στο εύρος της λίστας των σταθμών
if [ "$input" -gt 0 ] && [ "$input" -le $num ];
then
station=$(sed "${input}q;d" "$stations")
stathmos_name=$(echo "$station" | cut -d "," -f1)
stathmos_url=$(echo "$station" | cut -d "," -f2)
break
else
echo "$ERR αριθμός εκτός λίστας"
sleep 2
clear
fi
done
$player "$stathmos_url" &> /dev/null &
while true
do
clear
info
sleep 0
read -r -n1 -t1 input # Για μικρότερη αναμονή της read
if [[ $input = "q" ]] || [[ $input = "Q" ]]
then
clear
echo "$INFO έξοδος..."
tput cnorm -- normal # Εμφάνιση cursor
exit 0
fi
if [[ $input = "r" ]] || [[ $input = "R" ]]
then
killall -9 "$player" &> /dev/null
clear
echo "$INFO επιστροφή στη λίστα σταθμών"
tput cnorm -- normal # Εμφάνιση cursor
sleep 2
clear
break
fi
done
done