mirror of
https://github.com/KrumpetPirate/AAXtoMP3.git
synced 2024-11-18 03:08:57 +01:00
validate_extra_files final touchs, mediainfo get only useful infos,
save chapter infos from audible-cli json, publisher tag, cover crop, real track title
This commit is contained in:
parent
5f390b4f59
commit
047d7eb6f3
60
AAXtoMP3
60
AAXtoMP3
@ -324,7 +324,7 @@ validate_aax() {
|
||||
}
|
||||
|
||||
validate_extra_files() {
|
||||
local extra_media_file # extra_title extra_chapter_file
|
||||
local extra_media_file extra_find_command
|
||||
extra_media_file="$1"
|
||||
# Bash trick to delete, non greedy, from the end up until the first '-'
|
||||
extra_title="${extra_media_file%-*}"
|
||||
@ -334,24 +334,25 @@ validate_extra_files() {
|
||||
# AAX file: BookTitle-LC_128_44100_stereo.aax
|
||||
# Cover file: BookTitle_(1215).jpg
|
||||
# Chapter file: BookTitle-chapters.json
|
||||
|
||||
# Chapter
|
||||
extra_chapter_file="${extra_title}-chapters.json"
|
||||
|
||||
# Cover
|
||||
extra_dirname="$(dirname "${extra_media_file}")"
|
||||
extra_find_command='find "${extra_dirname}" -maxdepth 1 -regex ".*/${extra_title}_([0-9]+)\.jpg"'
|
||||
# We want the output of the find command, we will turn errexit on later
|
||||
set +e errexit
|
||||
extra_cover_file="$(eval ${extra_find_command})"
|
||||
set -e errexit
|
||||
|
||||
debug_vars "Audible-cli variables" extra_media_file extra_title extra_chapter_file extra_cover_file extra_find_command extra_dirname
|
||||
|
||||
# Test for chapter file existence
|
||||
if [[ ! -r "${extra_chapter_file}" ]] ; then
|
||||
log "ERROR File NOT Found: ${extra_chapter_file}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
extra_find_command='find -maxdepth 1 -regex ".*/${extra_title}_([0-9]+)\.jpg"'
|
||||
# extra_cover_file="$(find -maxdepth 1 -regex \".*/${extra_title}_\(\[\0\-\9\]\+\)\\.jpg\")"
|
||||
|
||||
# We want the output of the find command, we will turn errexit on later
|
||||
set +e errexit
|
||||
extra_cover_file="$(eval ${extra_find_command})"
|
||||
set -e errexit
|
||||
|
||||
debug_vars "Audible-cli files" extra_media_file extra_title extra_chapter_file extra_cover_file
|
||||
if [[ "x${extra_cover_file}" == "x" ]] ; then
|
||||
log "ERROR Cover File NOT Found"
|
||||
return 1
|
||||
@ -367,8 +368,29 @@ save_metadata() {
|
||||
media_file="$1"
|
||||
ffprobe -i "$media_file" 2> "$metadata_file"
|
||||
if [[ $(type -P mediainfo) ]]; then
|
||||
echo "Mediainfo data START" >> "$metadata_file"
|
||||
# Mediainfo output is structured like ffprobe, so we append it to the metadata file and then parse it with get_metadata_value()
|
||||
mediainfo "$media_file" >> "$metadata_file"
|
||||
# mediainfo "$media_file" >> "$metadata_file"
|
||||
# Or we only get the data we are intrested in:
|
||||
# Description
|
||||
echo "Track_More :" "$(mediainfo --Inform="General;%Track_More%" "$media_file")" >> "$metadata_file"
|
||||
# Narrator
|
||||
echo "nrt :" "$(mediainfo --Inform="General;%nrt%" "$media_file")" >> "$metadata_file"
|
||||
# Publisher
|
||||
echo "pub :" "$(mediainfo --Inform="General;%pub%" "$media_file")" >> "$metadata_file"
|
||||
echo "Mediainfo data END" >> "$metadata_file"
|
||||
fi
|
||||
if [[ "${audibleCli}" == "1" ]]; then
|
||||
# If we use data we got with audible-cli, we delete conflicting chapter infos
|
||||
$SED -i '/^ Chapter #/d' "${metadata_file}"
|
||||
# Some magic: we parse the .json generated by audible-cli.
|
||||
# to get the output structure like the one generated by ffprobe,
|
||||
# we use some characters (#) as placeholder, add some new lines,
|
||||
# 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 ':' 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)\n\n"' "${extra_chapter_file}" \
|
||||
| tr -d ':' >> "$metadata_file"
|
||||
fi
|
||||
debug "Metadata file $metadata_file"
|
||||
debug_file "$metadata_file"
|
||||
@ -434,6 +456,7 @@ do
|
||||
if [[ $(type -P mediainfo) ]]; then
|
||||
narrator="$(get_metadata_value nrt)"
|
||||
description="$(get_metadata_value Track_More)"
|
||||
publisher="$(get_metadata_value pub)"
|
||||
else
|
||||
narrator=""
|
||||
description=""
|
||||
@ -453,7 +476,7 @@ do
|
||||
# Big long DEBUG output. Fully describes the settings used for transcoding.
|
||||
# Note 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.
|
||||
debug_vars "Book and Variable values" title auth_code mode aax_file container codec bitrate artist album_artist album album_date genre copyright narrator description output_file metadata_file working_directory
|
||||
debug_vars "Book and Variable values" title auth_code mode aax_file container codec bitrate artist album_artist album album_date genre copyright narrator description publisher output_file metadata_file working_directory
|
||||
|
||||
# -----
|
||||
if [ "${continue}" == "0" ]; then
|
||||
@ -478,6 +501,7 @@ do
|
||||
-metadata copyright="${copyright}" \
|
||||
-metadata description="${description}" \
|
||||
-metadata composer="${narrator}" \
|
||||
-metadata publisher="${publisher}" \
|
||||
-f ${container} \
|
||||
"${output_file}"
|
||||
|
||||
@ -495,6 +519,8 @@ do
|
||||
|
||||
# We now set a variable, ${extra_crop_cover}, which contains an additional
|
||||
# ffmpeg flag. It crops the cover so the width and the height is divisible by two.
|
||||
# Since the standard (in the aax file) image resolution is 512, we set the flag
|
||||
# only if we use a custom cover art.
|
||||
extra_crop_cover='-vf crop=trunc(iw/2)*2:trunc(ih/2)*2'
|
||||
else
|
||||
log "Extracting cover into ${cover_file}..."
|
||||
@ -558,7 +584,7 @@ do
|
||||
fi
|
||||
|
||||
# Big Long chapter debug
|
||||
debug_vars "Chapter Variables:" cover_file extra_crop_cover chapter_start chapter_end id3_version_param chapternum chapter_title chapter_file
|
||||
debug_vars "Chapter Variables:" cover_file chapter_start chapter_end id3_version_param chapternum chapter_title chapter_file
|
||||
if [ "$((${continueAt} > ${chapternum}))" = "0" ]; then
|
||||
# Extract chapter by time stamps start and finish of chapter.
|
||||
# This extracts based on time stamps start and end.
|
||||
@ -576,9 +602,9 @@ do
|
||||
-metadata:s:v title="Album cover" \
|
||||
-metadata:s:v comment="Cover (Front)" \
|
||||
-metadata track="${chapternum}" \
|
||||
-metadata title="${chapter_title}" \
|
||||
-metadata:s:a title="${chapter_title}" \
|
||||
-metadata:s:a track="${chapternum}" \
|
||||
-metadata title="${chapter}" \
|
||||
-metadata:s:a title="${chapter}" \
|
||||
-metadata:s:a track="${chapternum}/${chaptercount}" \
|
||||
-map_chapters -1 \
|
||||
-f ${container} \
|
||||
"${chapter_file}"
|
||||
|
Loading…
Reference in New Issue
Block a user