Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Chaptered usage updates #209

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions AAXtoMP3
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fi

# -----
# Detect if we need mp4art for cover additions to m4a & m4b files.
if [[ "x${container}" == "xmp4" && "x$(type -P mp4art)" == "x" ]]; then
if [[ "x${container}" == "xmp4" && "x$(type -P mp4art)" == "x" && ! "$mode" == "chaptered" ]]; then
echo "WARN mp4art was not found on your env PATH variable"
echo "Without it, this script will not be able to add cover art to"
echo "m4b files. Note if there are no other errors the AAXtoMP3 will"
Expand Down Expand Up @@ -537,8 +537,10 @@ save_metadata() {
# put a ',' after the start value, we calculate the end of each chapter
# as start+length, and we convert (divide) the time stamps from ms to s.
# Then we delete all ':' and '/' since they make a filename invalid.
jq -r '.content_metadata.chapter_info.chapters[] | "Chapter # start: \(.start_offset_ms/1000), end: \((.start_offset_ms+.length_ms)/1000) \n#\n# Title: \(.title)"' "${extra_chapter_file}" \
| $SED 's@[:/]@@g' >> "$metadata_file"
jq -r '.content_metadata.chapter_info.chapters | reduce .[] as $c ([]; if $c.chapters? then .+[$c |
del(.chapters)]+[$c.chapters] else .+[$c] end) | flatten | .[] |
"Chapter # start: \(.start_offset_ms/1000), end: \((.start_offset_ms+.length_ms)/1000) \n#\n# Title: \(.title)"' \
"${extra_chapter_file}" | $SED 's@[:/]@@g' >> "$metadata_file"
# In case we want to use a single file m4b we need to extract the
# chapter titles from the .json generated by audible–cli and store
# them correctly formatted for mp4chaps in a chapter.txt
Expand Down Expand Up @@ -807,8 +809,8 @@ do
fi

extra_crop_cover=''
cover_width=$(ffprobe -i "${cover_file}" 2>&1 | $GREP -Po "[0-9]+(?=x[0-9]+)")
if (( ${cover_width} % 2 == 1 )); then
cover_width=$(ffprobe -i "${cover_file}" 2>&1 | $GREP -Po "[0-9]+(?=x[0-9]+)" | tail -n 1)
if [[ $(($cover_width % 2)) -eq 1 ]]; then
if [ "$((${loglevel} > 1))" == "1" ]; then
log "Cover ${cover_file} has odd width ${cover_width}, setting extra_crop_cover to make even."
fi
Expand Down Expand Up @@ -967,7 +969,7 @@ do
fi
fi

if [ -f "${cover_file}" ]; then
if [[ -f "${cover_file}" && ! "$mode" == "chaptered" ]]; then
log "Adding cover art"
# FFMGEP does not support MPEG-4 containers fully #
if [ "${container}" == "mp4" ] ; then
Expand Down Expand Up @@ -1009,6 +1011,14 @@ do
log "Moving Transcoded ${aax_file} to ${completedir}"
fi
mv "${aax_file}" "${completedir}"
if [[ ${audibleCli} -eq 1 ]]; then
if [ "$((${loglevel} > 0))" == "1" ]; then
log "Moving remaining audible files to ${completedir}"
fi
[[ -f "${aax_file%%-AAX_??_??.aaxc}_\((*)\).jpg" ]] && mv -v "${aax_file%%-AAX_??_??.aaxc}_\((*)\).jpg" "${completedir}"
[[ -f "${aax_file%%.aaxc}.voucher" ]] && mv -v "${aax_file%%.aaxc}.voucher" "${completedir}"
[[ -f "${aax_file%%-AAX_??_??.aaxc}-chapters.json" ]] && mv -v "${aax_file%%-AAX_??_??.aaxc}-chapters.json" "${completedir}"
fi
fi

done