From 9a674d01273b0dc7c3266ba35576bdcdf33c1a55 Mon Sep 17 00:00:00 2001 From: fabh2o Date: Tue, 2 Feb 2021 10:53:10 +0100 Subject: [PATCH] Use mediainfo to parse additional metadata --- AAXtoMP3 | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index e74c28d..b651c5e 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -213,6 +213,18 @@ if [[ "x${container}" == "xmp4" && "x$(type -P mp4chaps)" == "x" ]]; then echo "Ubuntu: sudo apt-get install mp4v2-utils" fi +# ----- +# Detect if we need mediainfo for adding description and narrator +if [[ "x$(type -P mediainfo)" == "x" ]]; then + echo "WARN mediainfo was not found on your env PATH variable" + echo "Without it, this script will not be able to add the narrator" + echo "and description tags. Note if there are no other errors the AAXtoMP3" + echo "will continue. However no such tags will be added to the output." + echo "INSTALL:" + echo "MacOS: brew install mediainfo" + echo "Ubuntu: sudo apt-get install mediainfo" +fi + # ----- # Obtain the authcode from either the command line, local directory or home directory. # See Readme.md for details on how to acquire your personal authcode for your personal @@ -314,6 +326,10 @@ save_metadata() { local media_file media_file="$1" ffprobe -i "$media_file" 2> "$metadata_file" + if [[ $(type -P mediainfo) ]]; then + # 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" + fi debug "Metadata file $metadata_file" debug_file "$metadata_file" } @@ -368,6 +384,14 @@ do album="$(get_metadata_value album)" album_date="$(get_metadata_value date)" copyright="$(get_metadata_value copyright)" + # Get more tags with mediainfo + if [[ $(type -P mediainfo) ]]; then + narrator="$(get_metadata_value nrt)" + description="$(get_metadata_value Track_More)" + else + narrator="" + description="" + fi if [[ "${noclobber}" = "1" ]] && [[ -d "${output_directory}" ]]; then log "Noclobber enabled but directory '${output_directory}' exists. Exiting to avoid overwriting" @@ -383,14 +407,33 @@ 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 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 output_file metadata_file working_directory # ----- if [ "${continue}" == "0" ]; then # This is the main work horse command. This is the primary transcoder. # This is the primary transcode. All the heavy lifting is here. debug 'ffmpeg -loglevel error -stats -activation_bytes "${auth_code}" -i "${aax_file}" -vn -codec:a "${codec}" -ab ${bitrate} -map_metadata -1 -metadata title="${title}" -metadata artist="${artist}" -metadata album_artist="${album_artist}" -metadata album="${album}" -metadata date="${album_date}" -metadata track="1/1" -metadata genre="${genre}" -metadata copyright="${copyright}" "${output_file}"' -