-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcsgo_transmit_song
executable file
·100 lines (97 loc) · 3.9 KB
/
csgo_transmit_song
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
#!/bin/bash
set -e
set -u
set -o pipefail
# Copyright (C) 2019 Amirreza Firoozi
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
CSGO_PATH="$HOME/.local/share/Steam/steamapps/common/Counter-Strike Global Offensive"
CSGO_ST_DATA_PATH="$HOME/Music/.csgo_st"
APPEND=false
function selectSongs(){
FILES=$(zenity --file-selection --multiple --separator=$'\n' --title="select your songs")
case $? in
0)
if [ "$APPEND" == "true" ]; then
echo "$FILES" >> "$CSGO_ST_DATA_PATH/songs_list"
else
echo "1" > "$CSGO_ST_DATA_PATH/current_song_index"
echo "$FILES" > "$CSGO_ST_DATA_PATH/songs_list"
fi
;;
esac
}
function playSong(){
INDEX=$(cat "$CSGO_ST_DATA_PATH/current_song_index")
FILE=$(sed -n ${INDEX}p "$CSGO_ST_DATA_PATH/songs_list" )
sox "$FILE" -b 16 -r 22050 -c 1 -t wavpcm /tmp/voice_input.wav
cp -r /tmp/voice_input.wav "$CSGO_PATH"
FILENAME=$(basename "${FILE}" )
echo "say ${FILENAME}; echo ${FILENAME}" > "$CSGO_PATH/csgo/cfg/current_track.cfg"
cat "$CSGO_ST_DATA_PATH/songs_list" | sed 's/\(.*\)\/\(.*\)\.\(.*\)$/"\2" /g' | nl | sed 's/^/echo/g' > "$CSGO_ST_DATA_PATH/track_list.cfg"
echo "exec current_track.cfg" >> "$CSGO_PATH/csgo/cfg/track_list.cfg"
#notify-send "$FILENAME"
}
function write_cfg(){
echo -e "alias track \"exec current_track.cfg\" \n alias tracks \" exec track_list.cfg\"\n clear\nvoice_modenable 1\n bind \"/\" music_on\n alias music_on \"voice_inputfromfile 1;+voicerecord; voice_loopback 1; exec current_track.cfg ; bind / music_off\"
\n alias music_off \"voice_inputfromfile 0;-voicerecord; voice_loopback 0; bind / music_on\"
\n clear\n echo 'csgo_st is successfully loaded. Use slash to toggle your song on and off' " > /tmp/csgo_st.cfg
chmod +x "/tmp/csgo_st.cfg"
cp "/tmp/csgo_st.cfg" "$CSGO_PATH/csgo/cfg/csgo_st.cfg"
rm "/tmp/csgo_st.cfg"
}
if [ ! -d "$CSGO_ST_DATA_PATH" ]; then
mkdir -p "$CSGO_ST_DATA_PATH"
fi
#append, next, previous, default, write_cfg
while getopts 'anpdw' OPTION; do
case "$OPTION" in
a)
APPEND=true
selectSongs
;;
n)
TOTAL_SONG_COUNT=$(cat "$CSGO_ST_DATA_PATH/songs_list" | wc -l)
INDEX=$(cat "$CSGO_ST_DATA_PATH/current_song_index")
if [ "$INDEX" == "$TOTAL_SONG_COUNT" ]; then
INDEX=1
echo "$INDEX" > "$CSGO_ST_DATA_PATH/current_song_index"
else
echo "$((INDEX + 1))" > "$CSGO_ST_DATA_PATH/current_song_index"
fi
playSong
;;
p)
TOTAL_SONG_COUNT=$(cat "$CSGO_ST_DATA_PATH/songs_list" | wc -l)
INDEX=$(cat "$CSGO_ST_DATA_PATH/current_song_index")
if [ "$INDEX" == "1" ];then
INDEX=$TOTAL_SONG_COUNT
echo "$INDEX" > "$CSGO_ST_DATA_PATH/current_song_index"
else
echo "$((INDEX - 1))" > "$CSGO_ST_DATA_PATH/current_song_index"
fi
playSong
;;
d)
selectSongs
playSong
;;
w)
write_cfg
;;
?)
exit 1;
;;
esac
done
shift "$(($OPTIND -1))"