mirror of
https://github.com/KrumpetPirate/AAXtoMP3.git
synced 2025-07-01 08:57:31 +02:00
Refined Parameterparsing
This commit is contained in:
98
AAXtoMP3
98
AAXtoMP3
@ -6,6 +6,7 @@ codec=libmp3lame
|
||||
extension=mp3
|
||||
mode=chaptered
|
||||
authcode=".authcode";
|
||||
auth="";
|
||||
if [ -z ${HOME+x} ] && ! [ -z ${USERPROFILE+x} ]; then HOME="$USERPROFILE"; fi
|
||||
authcodeDirs="${HOME}/ ./"
|
||||
GREP=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep")
|
||||
@ -23,44 +24,77 @@ if ! [[ $(type -P ffmpeg) ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function print_manual(){
|
||||
echo ""
|
||||
echo "Usage: bash AAXtoMP3 [--flac] [--aac] [--opus ] [--single] --auth=AUTHCODE {FILES}"
|
||||
echo " Note that when you enter conflicting parameters, the last one will be the one used."
|
||||
echo " You HAVE to use the equals-sign. You may also use -a=AUTHCODE. But the '=' is mandatory."
|
||||
echo " Everything after the authcode must be a filename to a file which you want to convert"
|
||||
echo ""
|
||||
echo " [--flac]: The flac codec is used in the resulting files. Default is MP3"
|
||||
echo " [--aac]: The aac codec is used in the resulting files. Default is MP3"
|
||||
echo " [--opus]: The opus codec is used in the resulting files. Default is MP3"
|
||||
echo " [--single] : Prevents creation of chapters. Results in a single file."
|
||||
echo " --authcode=XXXXXXXX: Your personal autcode. Everything after this parameter will be used as an inputfile!"
|
||||
echo " {FILES}: Files to convert, seperated by spaces."
|
||||
echo ""
|
||||
}
|
||||
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
echo "Usage: bash AAXtoMP3 [--flac] [--aac] [--opus ] [--single] AUTHCODE {FILES}"
|
||||
echo "Note that any optional flags have to be inputed in order to function correctly."
|
||||
echo "[--flac] : The flac codec is used in the resulting files. Default is MP3"
|
||||
echo "[--aac] : The aac codec is used in the resulting files. Default is MP3"
|
||||
echo "[--opus] : The opus codec is used in the resulting files. Default is MP3"
|
||||
echo "[--single]: Prevents creation of chapters. Results in a single file."
|
||||
exit 1
|
||||
print_manual
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$1" = '--flac' ]]
|
||||
then
|
||||
codec=flac
|
||||
extension=flac
|
||||
shift
|
||||
|
||||
if [[ "$1" = '-h' ]]; then
|
||||
print_manual
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$1" = '--help' ]]; then
|
||||
print_manual
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$1" == '--aac' ]]
|
||||
then
|
||||
codec=copy
|
||||
extension=m4a
|
||||
mode=single
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ "$1" = '--opus' ]]
|
||||
then
|
||||
codec=libopus
|
||||
extension=ogg
|
||||
shift
|
||||
fi
|
||||
#Iterate over the parameter to find all entered ones
|
||||
for var in "$@"
|
||||
do
|
||||
|
||||
if [[ "$var" = '--flac' ]]
|
||||
then
|
||||
codec=flac
|
||||
extension=flac
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ "$var" == '--aac' ]]
|
||||
then
|
||||
codec=copy
|
||||
extension=m4a
|
||||
mode=single
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ "$var" = '--opus' ]]
|
||||
then
|
||||
codec=libopus
|
||||
extension=ogg
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ "$var" == '--single' ]]
|
||||
then
|
||||
mode=single
|
||||
shift
|
||||
fi
|
||||
|
||||
case "$var" in
|
||||
-a=*|--auth=*) echo "found";
|
||||
auth="${var#*=}";
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$1" == '--single' ]]
|
||||
then
|
||||
mode=single
|
||||
shift
|
||||
fi
|
||||
|
||||
auth_code="";
|
||||
for dir in $authcodeDirs; do
|
||||
@ -79,6 +113,10 @@ else
|
||||
auth_code=`head -1 "$codeFile"`
|
||||
fi
|
||||
|
||||
if [ -z "$auth_code" ]; then
|
||||
auth_code="$auth";
|
||||
fi;
|
||||
|
||||
if [ -z "$auth_code" ]; then
|
||||
echo "INFO: Sorry, no authcode provided.";
|
||||
exit 1;
|
||||
|
Reference in New Issue
Block a user