This repository has been archived by the owner on Nov 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils
executable file
·223 lines (205 loc) · 7.71 KB
/
utils
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
# Utilities used by a number of components
# Fix for users with ffmpeg and not libav-tools
which avprobe >/dev/null 2>/dev/null
if [[ $? == 1 ]]; then
alias avprobe=ffprobe
fi
to_seconds () {
IFS=: read h m s <<< "$1"
echo $(( 10#$h * 3600 + 10#$m * 60 + 10#$s ))
}
getResourceLine() {
if [[ -z $(sed -n -e "/^$1/p" /tmp/PikaDJ/resourceIDs.tmp) ]]; then
echo "nope"
else
sed -n -e "s/^$1//p" /tmp/PikaDJ/resourceIDs.tmp
fi
}
setResourceLine() {
if [[ -z $(sed -n -e "/^$1/p" /tmp/PikaDJ/resourceIDs.tmp) ]]; then
echo "$1$2" >> /tmp/PikaDJ/resourceIDs.tmp
else
sed -i -e "s/^$1.*/$1$2/" /tmp/PikaDJ/resourceIDs.tmp
fi
}
removeResourceLine() {
sed -i -e "/^$1/d" /tmp/PikaDJ/resourceIDs.tmp
}
getSongLength() {
length=$(ffprobe "$(head -1 /tmp/PikaDJ/queue.tmp)" 2>&1 | sed -n -e 's/^ *Duration: \([0-9:.]*\).*/\1/p')
lengthWhole=$(echo "$length" | sed -e 's/\.[0-9]\{2\}$//')
lengthMS=$(echo "$length" | sed -e 's/^.*\(\.[0-9]\{2\}\)$/\1/')
echo $(to_seconds "$lengthWhole")$lengthMS
}
getSongInfo() {
if [[ $(getResourceLine a) == "nope" ]]; then
echo ""
else
basename "$(head -1 /tmp/PikaDJ/queue.tmp)" | sed -e 's/"/\\"/g' -e 's/[\n\r]//g' -e 's/\.[a-zA-Z0-9]\{2,4\}$//'
fi
}
saySongInfo() {
songTitle="$(getSongInfo)"
if [[ $songTitle != "" ]]; then
songInfo="\"$songTitle\""
else
songInfo='Not currently playing!'
fi
echo "say [PikaDJ] Now Playing: $songInfo" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
}
urlencode() {
# urlencode <string>
local length="${#1}"
for (( i = 0 ; i < length ; i++ )); do
local c="${1:i:1}"
case "$c" in
[a-zA-Z0-9.~_-]) printf "$c" ;;
' ') printf + ;;
*) printf '%%%X' "'$c"
esac
done
}
playSong() {
if [[ $(getResourceLine p) != "nope" ]]; then
echo "Already playing!"
if [[ $$ == $BASHPID ]]; then
return
else
exit 0
fi
fi
if (( $(wc -l /tmp/PikaDJ/queue.tmp | cut -f1 -d' ') == 0 )); then
if [[ $$ == $BASHPID ]]; then
return
else
exit 0
fi
fi
source ./tf2ConfigFileParser
setResourceLine p $BASHPID
if [[ $shouldLoopback != "0" ]]; then
sox "$(head -1 /tmp/PikaDJ/queue.tmp)" -e signed-integer -b 16 --endian little -c 1 ../voice_input.wav gain -B -n $gain1 rate 11025 sinc $sincRange1 bass $bassReduction1 gain -B -n $gain1 pad 1.5 1.5 silence 1 0.1 0.01% reverse silence 1 0.1 0.01% reverse
echo "micspamEnable" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
> /tmp/PikaDJ/voteSkip.tmp
mplayer "../voice_input.wav" >/dev/null 2>/dev/null &
playerPID=$!
appIndex=0
while [[ $appIndex != "null" ]]; do
while read line; do
case $line in
index:\ *) appIndex=$(echo "$line" | sed -e 's/.*index: \(.*\)/\1/') ;;
application.name\ =\ *) if [[ $(echo "$line" | sed -e 's/.*application\.name = \"\(.*\)\"/\1/') == "Steam" ]]; then echo "Found it at $appIndex"; pacmd move-source-output $appIndex "null_TF2Micspam.monitor"; appIndex="null"; break; fi ;;
esac
done < <(pacmd list-source-outputs) >/dev/null 2>/dev/null
done
appIndex=0
while [[ $appIndex != "null" ]]; do
while read line; do
case $line in
index:\ *) appIndex=$(echo "$line" | sed -e 's/.*index: \(.*\)/\1/') ;;
application.process.id\ =\ *) if [[ $(echo "$line" | sed -e 's/.*application\.process\.id = \"\(.*\)\"/\1/') == "$playerPID" ]]; then echo "Found it at $appIndex"; pacmd move-sink-input $appIndex "null_TF2Micspam"; appIndex="null"; break; fi ;;
esac
done < <(pacmd list-sink-inputs) >/dev/null 2>/dev/null
done
else
sox "$(head -1 /tmp/PikaDJ/queue.tmp)" -e signed-integer -b 16 --endian little -c 1 ../voice_input.wav gain -B -n $gain0 rate 11025 sinc $sincRange0 bass $bassReduction0 gain -B -n $gain0 pad 1.5 1.5 silence 1 0.1 0.01% reverse silence 1 0.1 0.01% reverse
echo "micspamEnable" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
> /tmp/PikaDJ/voteSkip.tmp
sleep "$(getSongLength)" &
playerPID=$!
fi
setResourceLine a "$playerPID"
saySongInfo
wait "$playerPID" >/dev/null 2>/dev/null
removeResourceLine a
if [[ $shouldLoopback != "0" ]]; then
echo "micspamEnable" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
appIndex=0
while [[ $appIndex != "null" ]]; do
while read sourceLine; do
case $sourceLine in
index:\ *) appIndex=$(echo "$sourceLine" | sed -e 's/.*index: \(.*\)/\1/') ;;
application.name\ =\ *) if [[ $(echo "$sourceLine" | sed -e 's/.*application\.name = \"\(.*\)\"/\1/') == "Steam" ]]; then echo "Found it at $appIndex"; pacmd move-source-output $appIndex $(pacmd list-sources | grep -i \* | sed -e 's/.*index: \(.*\)/\1/'); appIndex="null"; break; fi ;;
esac
done < <(pacmd list-source-outputs) >/dev/null 2>/dev/null
done
fi
echo "micspamDisable" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
advanceQueue
removeResourceLine p
source ./tf2ConfigFileParser
if $autoplay && (( $(wc -l /tmp/PikaDJ/queue.tmp | cut -f1 -d' ') > 0 )); then
playSong &
elif (( $(wc -l /tmp/PikaDJ/queue.tmp | cut -f1 -d' ') == 0 )); then
rm -f ~/Music/youtubeRequests/fixedName/* >/dev/null 2>/dev/null
fi
}
advanceQueue() {
tail -n +2 /tmp/PikaDJ/queue.tmp > /tmp/PikaDJ/queueBackup.tmp
mv /tmp/PikaDJ/queueBackup.tmp /tmp/PikaDJ/queue.tmp
}
skipSong() {
> /tmp/PikaDJ/voteSkip.tmp
pidToKill="$(getResourceLine a)"
if [[ $pidToKill == "nope" ]]; then
echo "No song is playing!"
return
fi
kill $pidToKill
wait $pidToKill >/dev/null 2>/dev/null
if [[ $shouldLoopback != "0" ]]; then
echo "micspamEnable" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
appIndex=0
while [[ $appIndex != "null" ]]; do
while read sourceLine; do
case $sourceLine in
index:\ *) appIndex=$(echo "$sourceLine" | sed -e 's/.*index: \(.*\)/\1/') ;;
application.name\ =\ *) if [[ $(echo "$sourceLine" | sed -e 's/.*application\.name = \"\(.*\)\"/\1/') == "Steam" ]]; then echo "Found it at $appIndex"; pacmd move-source-output $appIndex $(pacmd list-sources | grep -i \* | sed -e 's/.*index: \(.*\)/\1/'); appIndex="null"; break; fi ;;
esac
done < <(pacmd list-source-outputs) >/dev/null 2>/dev/null
done
fi
echo "micspamDisable" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
removeResourceLine a
if (( $(wc -l /tmp/PikaDJ/queue.tmp | cut -f1 -d' ') == 0 )); then
rm -f ~/Music/youtubeRequests/fixedName/* >/dev/null 2>/dev/null
fi
}
stopSong() {
pidToKill=$(getResourceLine p)
if [[ $pidToKill == "nope" ]]; then
echo "playSong isn't running!"
elif [[ $pidToKill == $BASHPID ]]; then
echo "If I kill the player, I will kill myself!"
else
kill $pidToKill
wait $pidToKill >/dev/null 2>/dev/null
fi
removeResourceLine p
skipSong
}
clearQueue() {
> /tmp/PikaDJ/queue.tmp
stopSong
}
getPlayerCount() {
rm /tmp/PikaDJ/serverPlayers.tmp >/dev/null 2>/dev/null
> ../"$modName"/console.log
echo "status" > ../"$modName"/cfg/stdin.cfg
(sleep 0.2; while true; do > ../"$modName"/console.log; xdotool type --window "$(xdotool search --class hl2_linux)" =; sleep 1; done) & >/dev/null 2>/dev/null
pidToKill=$!
watch -g -n 0.1 'grep "players : [0-9]*" ../'"$modName"'/console.log' >/dev/null 2>/dev/null
playerCount=$(grep "players : [0-9]" ../"$modName"/console.log | sed -e 's/players : \([0-9]*\).*/\1/')
echo $playerCount
kill -9 $pidToKill >/dev/null 2>/dev/null
wait $pidToKill >/dev/null 2>/dev/null
sed -n -e 's/\# \{1,\}[0-9]\{1,\} "\(.\{1,\}\)" \{1,\}\[U:[0-9]:[0-9]\{1,\}\] \{1,\}[0-9:]\{5,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} [a-z].\{1,\}/\1/p' ../"$modName"/console.log | while read line; do echo "$line" >> /tmp/PikaDJ/serverPlayers.tmp; done
}