mirror of
https://github.com/KrumpetPirate/AAXtoMP3.git
synced 2024-11-17 18:58:58 +01:00
Merge branch 'master' of github.com:fabh2o/AAXtoMP3 into all-in-one
This commit is contained in:
commit
64713e23ea
26
AAXtoMP3
26
AAXtoMP3
@ -610,7 +610,7 @@ do
|
||||
|
||||
# Display the total length of the audiobook in format hh:mm:ss
|
||||
# 10#$var force base-10 interpretation. By default it's base-8, so values like 08 or 09 are not octal numbers
|
||||
total_length="$(ffprobe -v error -activation_bytes "${auth_code}" -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ${aax_file} | cut -d . -f 1)"
|
||||
total_length="$(ffprobe -v error -activation_bytes "${auth_code}" -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${aax_file}" | cut -d . -f 1)"
|
||||
hours="$((total_length/3600))"
|
||||
if [ "$((hours<10))" = "1" ]; then hours="0$hours"; fi
|
||||
minutes="$((total_length/60-60*10#$hours))"
|
||||
@ -681,11 +681,10 @@ do
|
||||
</dev/null ffmpeg -loglevel error -activation_bytes "${auth_code}" -i "${aax_file}" -an -codec:v copy "${cover_file}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# -----
|
||||
# OK now spit the file if that's what you want.
|
||||
# If we want multiple file we take the big mp3 and split it by chapter.
|
||||
# Not all audio encodings make sense with multiple chapter outputs. See options section
|
||||
# for more detail
|
||||
# If mode=chaptered, split the big converted file by chapter and remove it afterwards.
|
||||
# Not all audio encodings make sense with multiple chapter outputs (see options section)
|
||||
if [ "${mode}" == "chaptered" ]; then
|
||||
# Playlist m3u support
|
||||
playlist_file="${output_directory}/${currentFileNameScheme}.m3u"
|
||||
@ -755,6 +754,17 @@ do
|
||||
chapter_codec="copy"
|
||||
fi
|
||||
|
||||
#Since there seems to be a bug in some older versions of ffmpeg, which makes, that -ss and -to
|
||||
#have to be apllied to the output file, this makes, that -ss and -to get applied on the input for
|
||||
#ffmpeg version 4+ and on the output for all older versions.
|
||||
split_input=""
|
||||
split_output=""
|
||||
if [ "$(($(ffmpeg -version | $SED -E 's/[^0-9]*([0-9]).*/\1/g;1q') > 3))" = "1" ]; then
|
||||
split_input="-ss ${chapter_start%?} -to ${chapter_end}"
|
||||
else
|
||||
split_output="-ss ${chapter_start%?} -to ${chapter_end}"
|
||||
fi
|
||||
|
||||
# Big Long chapter debug
|
||||
debug_vars "Chapter Variables:" cover_file chapter_start chapter_end chapternum chapter chapterNameScheme chapter_title chapter_file
|
||||
if [ "$((${continueAt} > ${chapternum}))" = "0" ]; then
|
||||
@ -765,11 +775,11 @@ do
|
||||
fi
|
||||
</dev/null ffmpeg -loglevel quiet \
|
||||
-nostats \
|
||||
-ss "${chapter_start%?}" \
|
||||
-to "${chapter_end}" \
|
||||
${split_input} \
|
||||
-i "${output_file}" \
|
||||
-i "${cover_file}" \
|
||||
${extra_crop_cover} \
|
||||
${split_output} \
|
||||
-map 0:0 \
|
||||
-map 1:0 \
|
||||
-acodec ${chapter_codec} \
|
||||
@ -809,7 +819,7 @@ do
|
||||
# ----
|
||||
# ffmpeg seems to copy only chapter position, not chapter names.
|
||||
if [[ ${container} == "mp4" && $(type -P mp4chaps) ]]; then
|
||||
ffprobe -i "${aax_file}" -print_format csv -show_chapters 2>/dev/null | awk -F "," '{printf "CHAPTER%02d=%02d:%02d:%02.3f\nCHAPTER%02dNAME=%s\n", NR, $5/60/60, $5/60%60, $5%60, NR, $8}' > "${output_directory}/${fileNameScheme}.chapters.txt"
|
||||
ffprobe -i "${aax_file}" -print_format csv -show_chapters 2>/dev/null | awk -F "," '{printf "CHAPTER%02d=%02d:%02d:%02.3f\nCHAPTER%02dNAME=%s\n", NR, $5/60/60, $5/60%60, $5%60, NR, $8}' > "${output_directory}/${currentFileNameScheme}.chapters.txt"
|
||||
mp4chaps -i "${output_file}"
|
||||
fi
|
||||
fi
|
||||
|
12
README.md
12
README.md
@ -32,10 +32,14 @@ Thanks to kbabioch, this script has also been packaged in the [AUR](https://aur.
|
||||
```
|
||||
bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level <COMPRESSIONLEVEL>] [-c|--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [-A|--authcode <AUTHCODE>] [-n|--no-clobber] [-t|--target_dir <PATH>] [-C|--complete_dir <PATH>] [-V|--validate] [-d|--debug] [-h|--help] [--continue <CHAPTERNUMBER>] <AAX INPUT_FILES>...
|
||||
```
|
||||
or if you want to get guided through the options
|
||||
```
|
||||
bash interactiveAAXtoMP3 [-a|--advanced] [-h|--help]
|
||||
```
|
||||
|
||||
* **<AAX INPUT_FILES>**... are considered input file(s), useful for batching!
|
||||
|
||||
## Options
|
||||
## Options for AAXtoMP3
|
||||
* **-f** or **--flac** Flac Encoding and as default produces a single file.
|
||||
* **-o** or **--opus** Ogg/Opus Encoding defaults to multiple file output by chapter. The extension is .ogg
|
||||
* **-a** or **--aac** AAC Encoding and produce a m4a single files output.
|
||||
@ -59,6 +63,12 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level <COMPRESS
|
||||
* **--chapter-naming-scheme <STRING>** Use a custom chapter naming scheme, with variables. See [below](#custom-naming-scheme) for more info.
|
||||
* **--use-audible-cli-data** Use additional data got with mkb79/audible-cli. See [below](#audible-cli-integration) for more infos.
|
||||
|
||||
## Options for interactiveAAXtoMP3
|
||||
* **-a** or **--advanced** Get more options to choose. Not used right now.
|
||||
* **-h** or **--help** Get a help prompt.
|
||||
This script presents you the options you chose last time as default.
|
||||
When you get asked for the aax-file you may just drag'n'drop it to the terminal.
|
||||
|
||||
### [AUTHCODE]
|
||||
**Your** Audible auth code (it won't correctly decode otherwise) (required).
|
||||
|
||||
|
159
interactiveAAXtoMP3
Normal file
159
interactiveAAXtoMP3
Normal file
@ -0,0 +1,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
|
Loading…
Reference in New Issue
Block a user