This repository has been archived by the owner on Apr 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 174
/
interactiveAAXtoMP3
159 lines (136 loc) · 6.06 KB
/
interactiveAAXtoMP3
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
#!/usr/bin/env bash
# ===Note for contributors========================================================================================================================
# This script interactively asks the user for the options to call AAXtoMP3 with. This first version does not include all options of AAXtoMP3
# since I tried to keep the dialog short, but I added an --advanced option, which is unused right now, but might be used in the future to add
# more options which only show up if explicitely wanted.
# If you want to add functionality please consider, whether the functionality you add might belong to the advanced options.
# ===Variables====================================================================================================================================
# Help message
help=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n
--advanced More options
--help Print this message\n'
summary="" # This will contain a summary of the options allready set.
call="./AAXtoMP3" # This will contain the call for AAXtoMP3.
advanced=0 # Toggles advanced options on or off.
# ===Options======================================================================================================================================
while true; do
case "$1" in
# Advanced options.
-a | --advanced ) advanced=1; shift ;;
# Command synopsis.
-h | --help ) echo -e "$help"; exit ;;
# Anything else stops command line processing.
* ) break ;;
esac
done
# ===Cross platform compatible use grep and sed===================================================================================================
# ===Detect which annoying version of grep we have===
GREP=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep")
if ! [[ $(type -P "$GREP") ]]; then
echo "$GREP (GNU grep) is not in your PATH"
echo "Without it, this script will break."
echo "On macOS, you may want to try: brew install grep"
exit 1
fi
# ===Detect which annoying version of sed we have===
SED=$(sed --version 2>&1 | $GREP -q GNU && echo "sed" || echo "gsed")
if ! [[ $(type -P "$SED") ]]; then
echo "$SED (GNU sed) is not in your PATH"
echo "Without it, this script will break."
echo "On macOS, you may want to try: brew install gnu-sed"
exit 1
fi
# ===Get options from last time===================================================================================================================
# ===Set default values===
lastcodec="mp3"
lastcompression="4"
lastchapters="yes"
lastauthcode=""
lastloglevel="1"
# ===Get Values from last time===
if [ -f ".interactivesave" ]; then
for ((i=1;i<=$(wc -l .interactivesave | cut -d " " -f 1);i++)) do
line=$(head -$i .interactivesave | tail -1)
case $(echo $line | cut -d " " -f 1 | $SED 's/.$//') in
codec ) lastcodec="$(echo $line | cut -d " " -f 2)";;
compression ) lastcompression="$(echo $line | cut -d " " -f 2)";;
chapters ) lastchapters="$(echo $line | cut -d " " -f 2)";;
authcode ) lastauthcode="$(echo $line | cut -d " " -f 2)";;
loglevel ) lastloglevel="$(echo $line | cut -d " " -f 2)";;
* ) rm .interactivesave; exit 1;;
esac
done
fi
# ===Get options for AAXtoMP3=====================================================================================================================
# ===Codec===
while true; do
clear;
read -e -p "codec (mp3/m4a/m4b/flac/aac/opus): " -i "$lastcodec" codec
case "$codec" in
mp3 ) summary="$summary""codec: $codec"; call="$call -e:mp3"; break;;
m4a ) summary="$summary""codec: $codec"; call="$call -e:m4a"; break;;
m4b ) summary="$summary""codec: $codec"; call="$call -e:m4b"; break;;
flac ) summary="$summary""codec: $codec"; call="$call --flac"; break;;
aac ) summary="$summary""codec: $codec"; call="$call --aac"; break;;
opus ) summary="$summary""codec: $codec"; call="$call --opus"; break;;
esac
done
# ===Compression===
while true; do
clear; echo -e "$summary"
case "$codec" in
mp3 ) maxlevel=9;;
flac ) maxlevel=12;;
opus ) maxlevel=10;;
* ) break;;
esac
read -e -p "compression level (0-$maxlevel): " -i "$lastcompression" compression
if [[ $compression =~ ^[0-9]+$ ]] && [[ "$compression" -ge "0" ]] && [[ "$compression" -le "$maxlevel" ]]; then
summary="$summary""\ncompression level: $compression"
call="$call --level $compression"
break
fi
done
# ===Chapters===
while true; do
clear; echo -e "$summary"
read -e -p "chapters (yes/no/chapternumber to continue with): " -i "$lastchapters" chapters
case "$chapters" in
^[0-9]+$ ) summary="$summary""\nchapters: $chapters"; call="$call -c --continue ${chapters}"; break;;
yes ) summary="$summary""\nchapters: $chapters"; call="$call -c"; break;;
no ) summary="$summary""\nchapters: $chapters"; call="$call -s"; break;;
esac
done
# ===Authcode===
if ! [ -r .authcode ] || [ -r ~/.authcode ]; then
clear; echo -e "$summary"
read -e -p "Authcode: " -i "$lastauthcode" authcode
summary="$summary""\nauthcode: $authcode"
call="$call -A $authcode"
fi
# ===Loglevel===
while true; do
clear; echo -e "$summary"
read -e -p "loglevel (0/1/2/3): " -i "$lastloglevel" loglevel
if [[ $loglevel =~ ^[0-9]+$ ]] && [[ "$loglevel" -ge "0" ]] && [[ "$loglevel" -le "3" ]]; then
summary="$summary""\nloglevel: $loglevel"
call="$call -l $loglevel"
break
fi
done
# ===File===
clear; echo -e "$summary"
read -p "aax-file: " file
file="${file%\'}" #remove suffix ' if file is given via drag'n'drop
file="${file#\'}" #remove prefix ' if file is given via drag'n'drop
savefile="$summary"
summary="$summary""\naax-file: $file"
call="$call $(echo $file | $SED "s;~;$HOME;")"
# ===Summerize chosen options and call AAXtoMP3===================================================================================================
# ===Summary===
clear; echo -e "$summary\n"
echo -e "$call\n"
# ===Save chosen options===
echo -e $savefile | $SED "s;\ level:;:;" > .interactivesave
# ===Call AAXtoMP3===
$call