Add possibility to read the series from the audible library

This commit is contained in:
Jerome Küttner 2022-01-08 16:38:29 +01:00
parent fb56087a72
commit 7f1f3df020
2 changed files with 37 additions and 1 deletions

View File

@ -9,7 +9,7 @@ usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level <COMPRE
[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode <AUTHCODE>] [--no-clobber]
[--target_dir <PATH>] [--complete_dir <PATH>] [--validate] [--loglevel <LOGLEVEL>]
[--keep-author <N>] [--author <AUTHOR>] [--{dir,file,chapter}-naming-scheme <STRING>]
[--use-audible-cli-data] [--continue <CHAPTERNUMBER>] {FILES}\n'
[--use-audible-cli-data] [--audible-cli-library-file <LIBRARY_PATH>] [--continue <CHAPTERNUMBER>] {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

View File

@ -57,6 +57,7 @@ bash interactiveAAXtoMP3 [-a|--advanced] [-h|--help]
* **--file-naming-scheme &lt;STRING&gt;** or **-F** Use a custom file naming scheme, with variables. See [below](#custom-naming-scheme) for more info.
* **--chapter-naming-scheme &lt;STRING&gt;** 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/)