mirror of
https://github.com/KrumpetPirate/AAXtoMP3.git
synced 2025-07-01 00:47:31 +02:00
Bug Fix, added --chaptered, Readme updates.
This commit is contained in:
82
AAXtoMP3
82
AAXtoMP3
@ -5,14 +5,14 @@
|
||||
# Command Line Options
|
||||
|
||||
# Usage Synopsis.
|
||||
usage=$'\nUsage: AAXtoMP3.sh [--flac] [--aac] [--opus ] [--single] [-e:m4a] [-e:m4b]\n[--authcode <AUTHCODE>] [--output_dir <PATH>] {FILES}\n'
|
||||
usage=$'\nUsage: AAXtoMP3.sh [--flac] [--aac] [--opus ] [--single] [--chaptered]\n[-e:m4a] [-e:m4b] [--authcode <AUTHCODE>] [--output_dir <PATH>] {FILES}\n'
|
||||
codec=libmp3lame # Default encoder.
|
||||
extension=mp3 # Default encoder extention.
|
||||
mode=chaptered # Multi file output
|
||||
auth_code= # Required to be set via file or option.
|
||||
targetdir= # Optional output location. Note default is basedir of AAX file.
|
||||
DEBUG=0 # Default off, If set extremely verbose output.
|
||||
container= # Just in case we need to change the container. Used for M4A to M4B
|
||||
container=mp3 # Just in case we need to change the container. Used for M4A to M4B
|
||||
|
||||
# -----
|
||||
# Code tip Do not have any script above this point that calls a function or a binary. If you do
|
||||
@ -22,17 +22,19 @@ container= # Just in case we need to change the container. Use
|
||||
while true; do
|
||||
case "$1" in
|
||||
# Flac encoding
|
||||
-f | --flac ) codec=flac; extension=flac; mode=single ; shift ;;
|
||||
-f | --flac ) codec=flac; extension=flac; mode=single; container=flac; shift ;;
|
||||
# Apple m4a music format.
|
||||
-a | --aac ) codec=copy; extension=m4a; mode=single ; shift ;;
|
||||
-a | --aac ) codec=copy; extension=m4a; mode=single; container=m4a; shift ;;
|
||||
# Ogg Format
|
||||
-o | --opus ) codec=libopus; extension=ogg; shift ;;
|
||||
-o | --opus ) codec=libopus; extension=ogg; container=flac; shift ;;
|
||||
# If appropriate use only a single file output.
|
||||
-s | --single ) mode=single; shift ;;
|
||||
# If appropriate use only a single file output.
|
||||
-c | --chaptered ) mode=chaptered; shift ;;
|
||||
# This is the same as --single option.
|
||||
-e:mp3 ) codec=libmp3lame; extension=mp3; mode=single; shift ;;
|
||||
-e:mp3 ) codec=libmp3lame; extension=mp3; mode=single; container=mp3; shift ;;
|
||||
# Identical to --acc option.
|
||||
-e:m4a ) codec=copy; extension=m4a; mode=single; shift ;;
|
||||
-e:m4a ) codec=copy; extension=m4a; mode=single; container=m4a shift ;;
|
||||
# Similiar to --aac but specific to audio books.
|
||||
-e:m4b ) codec=copy; extension=m4a; mode=single; container=m4b shift ;;
|
||||
# Change the working dir from AAX directory to what you choose.
|
||||
@ -104,10 +106,12 @@ fi
|
||||
|
||||
# -----
|
||||
# Check the target dir for if set if it is writable
|
||||
if [[ ! -w "${targetdir}" || ! -d "${targetdir}" ]] ; then
|
||||
echo "ERROR Target Directory is not writable: \"$targetdir\""
|
||||
echo "$usage"
|
||||
exit 1
|
||||
if [[ "x${targetdir}" != "x" ]]; then
|
||||
if [[ ! -w "${targetdir}" || ! -d "${targetdir}" ]] ; then
|
||||
echo "ERROR Target Directory is not writable: \"$targetdir\""
|
||||
echo "$usage"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# ========================================================================
|
||||
@ -194,12 +198,11 @@ do
|
||||
genre=$(get_metadata_value genre)
|
||||
artist=$(get_metadata_value artist)
|
||||
title=$(get_metadata_value title | sed 's/'\:'/'-'/g' | sed 's/ / /g' | sed 's/- /-/g' | xargs -0)
|
||||
if [ ! -z targetdir ] ; then
|
||||
if [ "x${targetdir}" != "x" ] ; then
|
||||
output_directory="${targetdir}/${genre}/${artist}/${title}"
|
||||
else
|
||||
output_directory="$(dirname "${path}")/${genre}/${artist}/${title}"
|
||||
fi
|
||||
mkdir -p "${output_directory}"
|
||||
full_file_path="${output_directory}/${title}.${extension}"
|
||||
bitrate="$(get_bitrate)k"
|
||||
album_artist="$(get_metadata_value album_artist)"
|
||||
@ -207,6 +210,8 @@ do
|
||||
album_date="$(get_metadata_value date)"
|
||||
copyright="$(get_metadata_value copyright)"
|
||||
|
||||
mkdir -p "${output_directory}"
|
||||
|
||||
# Big long DEBUG output. Fully describes the settings used for transcoding. I could probably do this better.
|
||||
# Not this is a long debug command. It's not critical to operation. It's purely for people debugging
|
||||
# and coders wanting to extend the script.
|
||||
@ -249,7 +254,7 @@ do
|
||||
|
||||
# The formating of the chapters names and the file names.
|
||||
# Chapter names are used in a few place.
|
||||
chapter_title="${title} - $(printf %0${#chaptercount}d $chapternum) ${chapter}"
|
||||
chapter_title="${title}-$(printf %0${#chaptercount}d $chapternum) ${chapter}"
|
||||
chapter_file="${output_directory}/${chapter_title}.${extension}"
|
||||
|
||||
|
||||
@ -266,7 +271,8 @@ do
|
||||
|
||||
# Extract chapter by time stamps start and finish of chapter.
|
||||
# This extracts based on time stamps start and end.
|
||||
</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} \
|
||||
log "Spliting chapter ${chapternum} start:${start%?}(s) end:${end}(s)"
|
||||
</dev/null ffmpeg -loglevel quiet -nostats -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}"
|
||||
|
||||
@ -275,31 +281,45 @@ do
|
||||
# Playlist creation.
|
||||
duration=$(echo "${end} - ${start%?}" | bc)
|
||||
echo "#EXTINF:${duration%.*},${title} - ${chapter}" >> "${playlist_file}"
|
||||
echo "${chapter_title}.${extension}" >> "${playlist_file}"
|
||||
echo "${chapter_title}.${container}" >> "${playlist_file}"
|
||||
chapternum=$((chapternum + 1 ))
|
||||
|
||||
# ----
|
||||
# Add the cover art to m4a and m4b file types.
|
||||
if [[ ${extension} == "m4a" && $(type -P mp4art) ]]; then
|
||||
mp4art -q --add "${cover_path}" "${chapter_file}"
|
||||
log "Added cover art to ${chapter_title}"
|
||||
fi
|
||||
|
||||
# ----
|
||||
# Detect if we are actuall m4b instead of m4a Then rename the file.
|
||||
if [[ ${extension} == "m4a" && ${container}="m4b" ]]; then
|
||||
mv "${chapter_file}" "${chapter_file/.m4a/.m4b}"
|
||||
fi
|
||||
|
||||
fi
|
||||
done 9< "$metadata_file"
|
||||
|
||||
# Clean up of working directoy stuff.
|
||||
rm "${full_file_path}"
|
||||
log "Done creating chapters. Chaptered files contained in ${output_directory}."
|
||||
fi
|
||||
|
||||
# ----
|
||||
# Add the cover art to m4a and m4b file types.
|
||||
if [[ ${extension} == "m4a" && $(type -P mp4art) ]]; then
|
||||
mp4art --add "${cover_path}" "${full_file_path}"
|
||||
log "Added cover art."
|
||||
fi
|
||||
|
||||
# ----
|
||||
# Detect if we are actuall m4b instead of m4a Then rename the file.
|
||||
if [[ ${extension} == "m4a" && ${container}="m4b" ]]; then
|
||||
mv "${full_file_path}" "${full_file_path/.m4a/.m4b}"
|
||||
log "Done creating chapters for ${output_directory}."
|
||||
else
|
||||
# Perform file tasks on output file.
|
||||
# ----
|
||||
# Add the cover art to m4a and m4b file types.
|
||||
if [[ ${extension} == "m4a" && $(type -P mp4art) ]]; then
|
||||
mp4art -q --add "${cover_path}" "${full_file_path}"
|
||||
log "Added cover art to ${title}.${extension}"
|
||||
fi
|
||||
# ----
|
||||
# Detect if we are actuall m4b instead of m4a Then rename the file.
|
||||
if [[ ${extension} == "m4a" && ${container}="m4b" ]]; then
|
||||
mv "${full_file_path}" "${full_file_path/.m4a/.m4b}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
log "Done. ${title}"
|
||||
log "Done ${title}"
|
||||
# Lastly get rid of any extra stuff.
|
||||
rm "${metadata_file}"
|
||||
done
|
||||
|
Reference in New Issue
Block a user