From 7f1f3df0206e057d30a18251ce600c08f4334f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerome=20K=C3=BCttner?= <12213711+jkuettner@users.noreply.github.com> Date: Sat, 8 Jan 2022 16:38:29 +0100 Subject: [PATCH 1/3] Add possibility to read the series from the audible library --- AAXtoMP3 | 33 ++++++++++++++++++++++++++++++++- README.md | 5 +++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 1fcbc58..5139adb 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -9,7 +9,7 @@ usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ] [--no-clobber] [--target_dir ] [--complete_dir ] [--validate] [--loglevel ] [--keep-author ] [--author ] [--{dir,file,chapter}-naming-scheme ] -[--use-audible-cli-data] [--continue ] {FILES}\n' +[--use-audible-cli-data] [--audible-cli-library-file ] [--continue ] {FILES}\n' codec=libmp3lame # Default encoder. extension=mp3 # Default encoder extension. level=-1 # Compression level. Can be given for mp3, flac and opus. -1 = default/not specified. @@ -35,6 +35,7 @@ audibleCli=0 # Default off, Use additional data gathered from mkb aaxc_key= # Initialize variables, in case we need them in debug_vars aaxc_iv= # Initialize variables, in case we need them in debug_vars ffmpegPath= # Set a custom path, useful for using the updated version that supports aaxc +library_file= # Libraryfile generated by mkb79/audible-cli # ----- # Code tip Do not have any script above this point that calls a function or a binary. If you do @@ -81,6 +82,8 @@ while true; do --continue ) continueAt="$2"; continue=1; shift 2 ;; # Use additional data got with mkb79/audible-cli --use-audible-cli-data ) audibleCli=1; shift ;; + # Path of the library-file, generated by mkb79/audible-cli (audible library export -o ./library.tsv) + -L | --audible-cli-library-file ) library_file="$2"; shift 2 ;; # Compression level --level ) level="$2"; shift 2 ;; # Keep author number n @@ -488,6 +491,15 @@ validate_extra_files() { return 1 fi + # Test for library file + if [[ ! -r "${library_file}" ]] ; then + library_file_exists=0 + debug "library file not found" + else + library_file_exists=1 + debug "library file found" + fi + debug "All expected audible-cli related file are here" } @@ -538,6 +550,21 @@ save_metadata() { "CHAPTER\((.key))=\(((.value.start_offset_ms / (1000*60*60)) %24 | floor | pad(2))):\(((.value.start_offset_ms / (1000*60)) %60 | floor | pad(2))):\(((.value.start_offset_ms / 1000) %60 | floor | pad(2))).\((.value.start_offset_ms % 1000 | pad(3))) CHAPTER\((.key))NAME=\(.value.title)"' "${extra_chapter_file}" > "${tmp_chapter_file}" fi + + # get extra meta data from library.tsv + if [[ "${library_file_exists}" == 1 ]]; then + asin=$(jq -r '.content_metadata.content_reference.asin' "${extra_chapter_file}") + if [[ ! -z "${asin}" ]]; then + lib_entry=$(grep "^${asin}" "${library_file}") + if [[ ! -z "${lib_entry}" ]]; then + series_title=$(echo "${lib_entry}" | awk -F '\t' '{print $6}') + series_sequence=$(echo "${lib_entry}" | awk -F '\t' '{print $7}') + sed -i "/^ Metadata:/a\\ + series : ${series_title}\\ + series_sequence : ${series_sequence}" "${metadata_file}" + fi + fi + fi fi debug "Metadata file $metadata_file" debug_file "$metadata_file" @@ -645,6 +672,8 @@ do album="$(get_metadata_value album)" album_date="$(get_metadata_value date)" copyright="$(get_metadata_value copyright)" + series="$(get_metadata_value series)" + series_sequence="$(get_metadata_value series_sequence)" # Get more tags with mediainfo if [[ $(type -P mediainfo) ]]; then @@ -743,6 +772,8 @@ do -metadata description="${description}" \ -metadata composer="${narrator}" \ -metadata publisher="${publisher}" \ + -metadata series="${series}" \ + -metadata series_sequence="${series_sequence}" \ -f ${container} \ "${output_file}" if [ "$((${loglevel} > 0))" == "1" ]; then diff --git a/README.md b/README.md index a7d8903..c26d84e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ bash interactiveAAXtoMP3 [-a|--advanced] [-h|--help] * **--file-naming-scheme <STRING>** or **-F** Use a custom file naming scheme, with variables. See [below](#custom-naming-scheme) for more info. * **--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 info. Needed for the files in the `aaxc` format. +* **--audible-cli-library-file** or **-L** Path of the library-file, generated by mkb79/audible-cli (`audible library export -o ./library.tsv`). Only available if `--use-audible-cli-data` is set. This file is required to parse additional metadata such as `$series` or `$series_sequence`. * **--ffmpeg-path** Set the ffmpeg/ffprobe binaries folder. Both of them must be executable and in the same folder. ## Options for interactiveAAXtoMP3 @@ -151,6 +152,10 @@ So you can use `--dir-naming-scheme '$(date +%Y)/$artist'`, but using `--file-na * If you want shorter chapter names, use `--chapter-naming-scheme '$(printf %0${#chaptercount}d $chapternum) $chapter'`: only chapter number and chapter name * If you want to append the narrator name to the title, use `--dir-naming-scheme '$genre/$artist/$title-$narrator' --file-naming-scheme '$title-$narrator'` * If you don't want to have the books separated by author, use `--dir-naming-scheme '$genre/$title'` +* To be able to use `$series` or `$series_sequence` in the schemes the following is required: + * `--use-audible-cli-data` is set + * you have pre-generated the library-file via `audible library export -o ./library.tsv` + * you have set the path to the generated library-file via `--audible-cli-library-file ./library.tsv` ### Installing Dependencies. In general, take a look at [command-not-found.com](https://command-not-found.com/) From b87b08ee6af8432d5c3658e24d8a2efd813352af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerome=20K=C3=BCttner?= <12213711+jkuettner@users.noreply.github.com> Date: Sat, 8 Jan 2022 21:13:28 +0100 Subject: [PATCH 2/3] fix continuing for existing files --- AAXtoMP3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 5139adb..3b8cb9f 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -712,7 +712,7 @@ do if [[ "${noclobber}" = "1" ]] && [[ -d "${output_directory}" ]]; then log "Noclobber enabled but directory '${output_directory}' exists. Skipping to avoid overwriting" - rm -f "${metadata_file}" + rm -f "${metadata_file}" "${tmp_chapter_file}" continue fi mkdir -p "${output_directory}" From 5010927559bccb7b4ea5f387b8d49052967970ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerome=20K=C3=BCttner?= <12213711+jkuettner@users.noreply.github.com> Date: Sat, 8 Jan 2022 21:45:03 +0100 Subject: [PATCH 3/3] fix "syntax error in expression" --- AAXtoMP3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 3b8cb9f..2a88bd1 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -801,7 +801,7 @@ do extra_crop_cover='' cover_width=$(ffprobe -i "${cover_file}" 2>&1 | grep -Po "[0-9]+(?=x[0-9]+)") - if [ "$(( ${cover_width} % 2 ))" == "1" ]; then + if (( ${cover_width} % 2 == 1 )); then if [ "$((${loglevel} > 1))" == "1" ]; then log "Cover ${cover_file} has odd width ${cover_width}, setting extra_crop_cover to make even." fi