mirror of
https://github.com/KrumpetPirate/AAXtoMP3.git
synced 2025-07-01 08:57:31 +02:00
Fixed empty parameter bug
This commit is contained in:
22
AAXtoMP3
22
AAXtoMP3
@ -72,32 +72,33 @@ do
|
|||||||
|
|
||||||
if [[ "$var" = '--flac' ]]
|
if [[ "$var" = '--flac' ]]
|
||||||
then
|
then
|
||||||
flac='--flac'
|
flac='--flac '
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$var" == '--aac' ]]
|
if [[ "$var" == '--aac' ]]
|
||||||
then
|
then
|
||||||
aac='--aac'
|
aac='--aac'
|
||||||
single='--single'
|
single='--single '
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$var" = '--opus' ]]
|
if [[ "$var" = '--opus' ]]
|
||||||
then
|
then
|
||||||
opus='--opus'
|
opus='--opus '
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$var" == '--single' ]]
|
if [[ "$var" == '--single' ]]
|
||||||
then
|
then
|
||||||
single='--single'
|
single='--single '
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$var" in
|
case "$var" in
|
||||||
-a=*|--auth=*)
|
-a=*|--auth=*)
|
||||||
auth="${var#*=}";
|
auth=$(echo $var | cut -d '=' -f 2)
|
||||||
|
shift
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -112,13 +113,6 @@ for dir in $authcodeDirs; do
|
|||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
|
|
||||||
if [ ! -f "$codeFile" ]; then
|
|
||||||
auth_code=$1
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
auth_code=`head -1 "$codeFile"`
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$auth_code" ]; then
|
if [ -z "$auth_code" ]; then
|
||||||
auth_code="$auth";
|
auth_code="$auth";
|
||||||
fi;
|
fi;
|
||||||
@ -142,7 +136,9 @@ metadata_file="${working_directory}/metadata.txt"
|
|||||||
#if [ -z "$multi_thread" ]; then
|
#if [ -z "$multi_thread" ]; then
|
||||||
for path
|
for path
|
||||||
do
|
do
|
||||||
bash AAXtoMP3Worker "${flac}" "${aac}" "${opus}" "${single}" "${path}" "--auth=${auth_code}"
|
echo bash AAXtoMP3Worker "${flac}""${aac}""${opus}""${single}""--auth=${auth_code}" "${path}"
|
||||||
|
bash AAXtoMP3Worker "${flac}" "${aac}" "${opus}" "${single}" "--auth=${auth_code}" "${path}"
|
||||||
|
echo "running away..."
|
||||||
done
|
done
|
||||||
exit 0;
|
exit 0;
|
||||||
#fi;
|
#fi;
|
||||||
|
148
AAXtoMP3Worker
148
AAXtoMP3Worker
@ -58,8 +58,20 @@ if [[ "$1" = '--help' ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
#Iterate over the parameter to find all entered ones
|
|
||||||
|
ParamArray=()
|
||||||
|
#the multithreadcontroller adds whitespaces to the params, they are removed here.
|
||||||
for var in "$@"
|
for var in "$@"
|
||||||
|
do
|
||||||
|
if ! [[ "$var" = '' ]]
|
||||||
|
then
|
||||||
|
ParamArray+=("$var")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
#Iterate over the parameter to find all entered ones
|
||||||
|
for var in "${ParamArray[@]}"
|
||||||
do
|
do
|
||||||
|
|
||||||
if [[ "$var" = '--flac' ]]
|
if [[ "$var" = '--flac' ]]
|
||||||
@ -92,11 +104,11 @@ do
|
|||||||
|
|
||||||
case "$var" in
|
case "$var" in
|
||||||
-a=*|--auth=*)
|
-a=*|--auth=*)
|
||||||
auth="${var#*=}";
|
auth=$(echo $var | cut -d '=' -f 2)
|
||||||
|
shift
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
auth_code="";
|
auth_code="";
|
||||||
for dir in $authcodeDirs; do
|
for dir in $authcodeDirs; do
|
||||||
codeFile="${dir}$authcode";
|
codeFile="${dir}$authcode";
|
||||||
@ -107,10 +119,7 @@ for dir in $authcodeDirs; do
|
|||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
|
|
||||||
if [ ! -f "$codeFile" ]; then
|
if [ -f "$codeFile" ]; then
|
||||||
auth_code=$1
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
auth_code=`head -1 "$codeFile"`
|
auth_code=`head -1 "$codeFile"`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -151,64 +160,71 @@ normalize_whitespace() {
|
|||||||
echo $*
|
echo $*
|
||||||
}
|
}
|
||||||
|
|
||||||
create_path(){
|
alreadys_skipped_to_auth=0
|
||||||
debug "Decoding $1 with auth code $2..."
|
for path in "${ParamArray[@]}"
|
||||||
|
|
||||||
save_metadata "$1"
|
|
||||||
genre=$(get_metadata_value genre)
|
|
||||||
artist=$(get_metadata_value artist)
|
|
||||||
title=$(get_metadata_value title | sed 's/'\:'/'\ -'/g' | xargs -0)
|
|
||||||
output_directory="$(dirname "$1")/${genre}/${artist}/${title}"
|
|
||||||
mkdir -p "${output_directory}"
|
|
||||||
full_file_path="${output_directory}/${title}.${extension}"
|
|
||||||
|
|
||||||
</dev/null ffmpeg -loglevel error -stats -activation_bytes "$2" -i "$1" -vn -codec:a "${codec}" -ab "$(get_bitrate)k" -map_metadata -1 -metadata title="${title}" -metadata artist="${artist}" -metadata album_artist="$(get_metadata_value album_artist)" -metadata album="$(get_metadata_value album)" -metadata date="$(get_metadata_value date)" -metadata track="1/1" -metadata genre="${genre}" -metadata copyright="$(get_metadata_value copyright)" "${full_file_path}"
|
|
||||||
|
|
||||||
debug "Created ${full_file_path}."
|
|
||||||
|
|
||||||
cover_path="${output_directory}/cover.jpg"
|
|
||||||
debug "Extracting cover into ${cover_path}..."
|
|
||||||
</dev/null ffmpeg -loglevel error -activation_bytes "$2" -i "$1" -an -codec:v copy "${cover_path}"
|
|
||||||
|
|
||||||
if [ "${mode}" == "chaptered" ]; then
|
|
||||||
chaptercount=$($GREP -Pc "Chapter.*start.*end" $metadata_file)
|
|
||||||
debug "Extracting ${chaptercount} chapter files from ${full_file_path}..."
|
|
||||||
|
|
||||||
chapternum=1
|
|
||||||
while read -r -u9 first _ _ start _ end
|
|
||||||
do
|
|
||||||
if [[ "${first}" = "Chapter" ]]
|
|
||||||
then
|
|
||||||
read -r -u9 _
|
|
||||||
read -r -u9 _ _ chapter
|
|
||||||
chapter_title="${title} - $(printf %0${#chaptercount}d $chapternum) ${chapter}"
|
|
||||||
chapter_file="${output_directory}/${chapter_title}.${extension}"
|
|
||||||
|
|
||||||
# the ID3 tags must only be specified for *.mp3 files,
|
|
||||||
# the other container formats come with their own
|
|
||||||
# tagging mechanisms.
|
|
||||||
id3_version_param=""
|
|
||||||
if test "${extension}" = "mp3"; then
|
|
||||||
id3_version_param="-id3v2_version 3"
|
|
||||||
fi
|
|
||||||
|
|
||||||
</dev/null ffmpeg -loglevel error -stats -i "${full_file_path}" -i "${cover_path}" -ss "${start%?}" -to "${end}" -map 0:0 -map 1:0 -acodec copy ${id3_version_param} \
|
|
||||||
-metadata:s:v title="Album cover" -metadata:s:v comment="Cover (Front)" -metadata track="${chapternum}" -metadata title="${chapter_title}" \
|
|
||||||
"${chapter_file}"
|
|
||||||
chapternum=$((chapternum + 1 ))
|
|
||||||
fi
|
|
||||||
done 9< "$metadata_file"
|
|
||||||
rm "${full_file_path}"
|
|
||||||
debug "Done creating chapters. Chaptered files contained in ${output_directory}."
|
|
||||||
fi
|
|
||||||
|
|
||||||
debug "Done."
|
|
||||||
rm "${metadata_file}"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for path
|
|
||||||
do
|
do
|
||||||
create_path "${path}" "${auth_code}"
|
if (( $alreadys_skipped_to_auth == 0 ))
|
||||||
|
then
|
||||||
|
case "$path" in -a=*|--auth=*)
|
||||||
|
alreadys_skipped_to_auth=1;
|
||||||
|
continue ;
|
||||||
|
esac
|
||||||
|
continue ;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( $alreadys_skipped_to_auth == 1 ))
|
||||||
|
then
|
||||||
|
debug "Decoding ${path} with auth code ${auth_code}..."
|
||||||
|
|
||||||
|
save_metadata "${path}"
|
||||||
|
genre=$(get_metadata_value genre)
|
||||||
|
artist=$(get_metadata_value artist)
|
||||||
|
title=$(get_metadata_value title | sed 's/'\:'/'\ -'/g' | xargs -0)
|
||||||
|
output_directory="$(dirname "${path}")/${genre}/${artist}/${title}"
|
||||||
|
mkdir -p "${output_directory}"
|
||||||
|
full_file_path="${output_directory}/${title}.${extension}"
|
||||||
|
|
||||||
|
</dev/null ffmpeg -loglevel error -stats -activation_bytes "${auth_code}" -i "${path}" -vn -codec:a "${codec}" -ab "$(get_bitrate)k" -map_metadata -1 -metadata title="${title}" -metadata artist="${artist}" -metadata album_artist="$(get_metadata_value album_artist)" -metadata album="$(get_metadata_value album)" -metadata date="$(get_metadata_value date)" -metadata track="1/1" -metadata genre="${genre}" -metadata copyright="$(get_metadata_value copyright)" "${full_file_path}"
|
||||||
|
|
||||||
|
debug "Created ${full_file_path}."
|
||||||
|
|
||||||
|
cover_path="${output_directory}/cover.jpg"
|
||||||
|
debug "Extracting cover into ${cover_path}..."
|
||||||
|
</dev/null ffmpeg -loglevel error -activation_bytes "${auth_code}" -i "${path}" -an -codec:v copy "${cover_path}"
|
||||||
|
|
||||||
|
if [ "${mode}" == "chaptered" ]; then
|
||||||
|
chaptercount=$($GREP -Pc "Chapter.*start.*end" $metadata_file)
|
||||||
|
debug "Extracting ${chaptercount} chapter files from ${full_file_path}..."
|
||||||
|
|
||||||
|
chapternum=1
|
||||||
|
while read -r -u9 first _ _ start _ end
|
||||||
|
do
|
||||||
|
if [[ "${first}" = "Chapter" ]]
|
||||||
|
then
|
||||||
|
read -r -u9 _
|
||||||
|
read -r -u9 _ _ chapter
|
||||||
|
chapter_title="${title} - $(printf %0${#chaptercount}d $chapternum) ${chapter}"
|
||||||
|
chapter_file="${output_directory}/${chapter_title}.${extension}"
|
||||||
|
|
||||||
|
# the ID3 tags must only be specified for *.mp3 files,
|
||||||
|
# the other container formats come with their own
|
||||||
|
# tagging mechanisms.
|
||||||
|
id3_version_param=""
|
||||||
|
if test "${extension}" = "mp3"; then
|
||||||
|
id3_version_param="-id3v2_version 3"
|
||||||
|
fi
|
||||||
|
|
||||||
|
</dev/null ffmpeg -loglevel error -stats -i "${full_file_path}" -i "${cover_path}" -ss "${start%?}" -to "${end}" -map 0:0 -map 1:0 -acodec copy ${id3_version_param} \
|
||||||
|
-metadata:s:v title="Album cover" -metadata:s:v comment="Cover (Front)" -metadata track="${chapternum}" -metadata title="${chapter_title}" \
|
||||||
|
"${chapter_file}"
|
||||||
|
chapternum=$((chapternum + 1 ))
|
||||||
|
fi
|
||||||
|
done 9< "$metadata_file"
|
||||||
|
rm "${full_file_path}"
|
||||||
|
debug "Done creating chapters. Chaptered files contained in ${output_directory}."
|
||||||
|
fi
|
||||||
|
|
||||||
|
debug "Done."
|
||||||
|
rm "${metadata_file}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
exit 0;
|
|
21
printparams
Normal file
21
printparams
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
#Iterate over the parameter to find all entered ones
|
||||||
|
|
||||||
|
for var in "$@"
|
||||||
|
do
|
||||||
|
if [[ "$var" = '' ]]
|
||||||
|
then
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
i=0;
|
||||||
|
for var in "$@"
|
||||||
|
do
|
||||||
|
echo "$i. $var"
|
||||||
|
i=$((i+1))
|
||||||
|
|
||||||
|
done
|
||||||
|
|
Reference in New Issue
Block a user