-
Notifications
You must be signed in to change notification settings - Fork 1
/
abox
executable file
·234 lines (210 loc) · 6.09 KB
/
abox
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
224
225
226
227
228
229
230
231
232
233
234
#!/bin/bash
cookie_file="cookie"
urlencode() {
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
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 '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
}
urldecode() {
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}
cookie_gen() {
curl -si "https://acapela-box.com/AcaBox/index.php" | grep -E "Cookie:.*acabox=.*" > $cookie_file
}
get_cookie() {
if [ ! -f $cookie_file ]; then
echo "Cookie not found, generating..." 1>&2
cookie_gen
fi
coo=$(cat $cookie_file)
exp=$(echo $coo | sed -r "s/.*expires=[^,]+, ([^;]+);.*/\1/g")
# expires=Mon, 01-Aug-2016 08:24:28 GMT;
todate=$(date +%s)
cond=$(date -d "$exp" +%s)
if [ $todate -ge $cond ];
then
echo "Cookie too old, regenerating..." 1>&2
cookie_gen
fi
cat $cookie_file | sed -nr "s/Set\-Cookie:.*acabox=([^;]+);.*/\1/p"
}
cookie="acabox=$(get_cookie); __utma=221195784.43393818.1460058666.1460058666.1460068143.2; __utmc=221195784; __utmz=221195784.1460058666.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=221195784.11.10.1460068143; __utmt=1"
getVoice() {
text="ISO=$1"
len=$(echo -n "$text" | wc -m)
result=$(curl -s --insecure -XPOST \
-H 'Host: acapela-box.com'\
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0'\
-H 'Accept: text/html, */*; q=0.01'\
-H 'Accept-Language: en-US,en;q=0.5'\
-H 'Accept-Encoding: gzip, deflate, br'\
-H 'Referer: https://acapela-box.com/AcaBox/index.php'\
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'\
-H 'X-Requested-With: XMLHttpRequest'\
-H 'Content-Length: '$len\
-H 'Cookie: '"$cookie"\
-H 'Connection: keep-alive' \
-d "$text" 'https://acapela-box.com/AcaBox/filtervoices.php')
echo -n "$result"
}
getAcapella() {
vct=$3
spd=$4
frmt=$5
words=$(urlencode "$1") #$1
voice="$2"
text="text=%5Cvct%3D$vct%5C%20%5Cspd%3D$spd%5C%20$words&voice=$voice&listen=1&format=$frmt&codecMP3=1&spd=$spd&vct=$vct"
len=$(echo -n "$text" | wc -m)
url=$(curl -s --insecure -XPOST \
-H 'Host: acapela-box.com'\
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0'\
-H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5'\
-H 'Accept-Encoding: gzip, deflate, br'\
-H 'Referer: https://acapela-box.com/AcaBox/index.php'\
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'\
-H 'X-Requested-With: XMLHttpRequest'\
-H 'Content-Length: '$len\
-H 'Cookie: '"$cookie"\
-H 'Connection: keep-alive'\
-d "$text" 'https://acapela-box.com/AcaBox/dovaas.php') # | sed -r 's/.*"snd_url":"([^"]+)".*/\1/;s/\\//g')
echo -n $url
}
argv=( "$@" )
argc=${#argv[@]}
args=()
args[2]="antoinefromafar22k"
args[3]=100
args[4]=180
args[5]="WAV 22kHz"
args[6]="show_url"
i=0
arg=1
while [ "$i" -lt "$argc" ]; do
case "${argv[$i]}" in
\-\-reload|\-r)
cookie_gen
echo "Cookie regenerated."
exit 0
;;
\-\-help|\-h)
cat <<EOF
AcapelaBox CLI v4.1 - Use acapela-box.com from the command line.
Developped by mure-r_c (LazyShpee), 31/7/2016
Usage $0 [options] <text>
$0 [options] <-f filename|--file filename>
$0 <-l|--list> <ISO country code>
Where options are:
-r, --cookie Regenerates the cookie, use this if no response is given.
-v, --voice Specify voice (default:antoinefromafar22k)
-o, --output Specify output file for download action
-a, --action Specify an action in
- url, show_url: shows the url (default)
- play, mpv: plays the sound using mpv
- stdout, curl: prints the sound to stdout using curl
- wget, download, dl: downloads to file,
can specify a name with -o
-S, --shaping Specify a voice shaping (default:180)
-s, --speed Specify a voice speed (default:100)
EOF
exit 0
;;
\-\-list|\-l)
arg=9
;;
\-\-file|\-f)
arg=8
;;
\-\-output|\-o)
arg=7
;;
\-\-action|\-a)
arg=6
;;
\-\-format|\-f)
arg=5
;;
\-\-shaping|\-S)
arg=4
;;
\-\-speed|\-s)
arg=3
;;
\-\-voice|\-v)
arg=2
;;
*)
args["$arg"]="${argv[$i]}"
arg=1
;;
esac
let "i++"
done
if [ ! -z "${args[9]}" ];
then
result=$(getVoice "${args[9]}")
if [[ $result == *"ISO not"* ]];
then
echo "$result"
echo "ISO code not valid."
exit 1
fi
list=$(echo "$result" | sed -nr 's/.*data-id="([^"]+)".*"/\t\1/gp;s/.*value="[^"]+">([^<]+)<.*/- \1/gp')
echo "$list" | sed 'N;
s/\(.*\)\n\(.*\)/\2\
\1/'
exit 0
fi
if [ ! -z "${args[8]}" ];
then
if [ -f "${args[8]}" ];
then
args[1]=$(cat "${args[8]}")
else
echo "No such file: ${args[8]}"
fi
fi
if [ -z "${args[1]}" ];
then
echo "I need some text to say some things"
exit 1
fi
result="$(getAcapella "${args[1]}" "${args[2]}" "${args[3]}" "${args[4]}" "${args[5]}")"
ok=$(echo "$result" | sed -r 's/.*"res":"([^"]+)".*/\1/')
if [ "$ok" = "NOK" ];
then
echo "Something went wrong, check your parameters."
exit 1
fi
url=$(echo "$result" | sed -r 's/.*"snd_url":"([^"]+)".*/\1/;s/\\//g')
case "${args[6]}" in
show_url|url)
echo $url
;;
stdout|curl)
curl $url
;;
download|dl|wget)
if [ -z "${args[7]}" ];
then
wget $url
else
wget $url -O "${args[7]}"
fi
;;
play|mpv)
mpv $url
;;
*)
echo "Wrong action given."
;;
esac
exit 0