mirror of
https://github.com/KrumpetPirate/AAXtoMP3.git
synced 2025-07-02 01:07:31 +02:00
Refined Parameterparsing
This commit is contained in:
74
AAXtoMP3
74
AAXtoMP3
@ -6,6 +6,7 @@ codec=libmp3lame
|
|||||||
extension=mp3
|
extension=mp3
|
||||||
mode=chaptered
|
mode=chaptered
|
||||||
authcode=".authcode";
|
authcode=".authcode";
|
||||||
|
auth="";
|
||||||
if [ -z ${HOME+x} ] && ! [ -z ${USERPROFILE+x} ]; then HOME="$USERPROFILE"; fi
|
if [ -z ${HOME+x} ] && ! [ -z ${USERPROFILE+x} ]; then HOME="$USERPROFILE"; fi
|
||||||
authcodeDirs="${HOME}/ ./"
|
authcodeDirs="${HOME}/ ./"
|
||||||
GREP=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep")
|
GREP=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep")
|
||||||
@ -23,44 +24,77 @@ if ! [[ $(type -P ffmpeg) ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
if [ "$#" -eq 0 ]; then
|
||||||
echo "Usage: bash AAXtoMP3 [--flac] [--aac] [--opus ] [--single] AUTHCODE {FILES}"
|
print_manual
|
||||||
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$1" = '--flac' ]]
|
|
||||||
then
|
if [[ "$1" = '-h' ]]; then
|
||||||
|
print_manual
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ "$1" = '--help' ]]; then
|
||||||
|
print_manual
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
#Iterate over the parameter to find all entered ones
|
||||||
|
for var in "$@"
|
||||||
|
do
|
||||||
|
|
||||||
|
if [[ "$var" = '--flac' ]]
|
||||||
|
then
|
||||||
codec=flac
|
codec=flac
|
||||||
extension=flac
|
extension=flac
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$1" == '--aac' ]]
|
if [[ "$var" == '--aac' ]]
|
||||||
then
|
then
|
||||||
codec=copy
|
codec=copy
|
||||||
extension=m4a
|
extension=m4a
|
||||||
mode=single
|
mode=single
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$1" = '--opus' ]]
|
if [[ "$var" = '--opus' ]]
|
||||||
then
|
then
|
||||||
codec=libopus
|
codec=libopus
|
||||||
extension=ogg
|
extension=ogg
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$1" == '--single' ]]
|
if [[ "$var" == '--single' ]]
|
||||||
then
|
then
|
||||||
mode=single
|
mode=single
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
case "$var" in
|
||||||
|
-a=*|--auth=*) echo "found";
|
||||||
|
auth="${var#*=}";
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
auth_code="";
|
auth_code="";
|
||||||
for dir in $authcodeDirs; do
|
for dir in $authcodeDirs; do
|
||||||
@ -79,6 +113,10 @@ else
|
|||||||
auth_code=`head -1 "$codeFile"`
|
auth_code=`head -1 "$codeFile"`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$auth_code" ]; then
|
||||||
|
auth_code="$auth";
|
||||||
|
fi;
|
||||||
|
|
||||||
if [ -z "$auth_code" ]; then
|
if [ -z "$auth_code" ]; then
|
||||||
echo "INFO: Sorry, no authcode provided.";
|
echo "INFO: Sorry, no authcode provided.";
|
||||||
exit 1;
|
exit 1;
|
||||||
|
Reference in New Issue
Block a user