Merge pull request #189 from jkuettner/feature/audible-library-series

Add optional possibility to extract the series from the audible library
This commit is contained in:
Krumpet Pirate 2022-01-09 08:47:22 -05:00 committed by GitHub
commit d5e32478c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 3 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] [--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode <AUTHCODE>] [--no-clobber]
[--target_dir <PATH>] [--complete_dir <PATH>] [--validate] [--loglevel <LOGLEVEL>] [--target_dir <PATH>] [--complete_dir <PATH>] [--validate] [--loglevel <LOGLEVEL>]
[--keep-author <N>] [--author <AUTHOR>] [--{dir,file,chapter}-naming-scheme <STRING>] [--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. codec=libmp3lame # Default encoder.
extension=mp3 # Default encoder extension. extension=mp3 # Default encoder extension.
level=-1 # Compression level. Can be given for mp3, flac and opus. -1 = default/not specified. 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_key= # Initialize variables, in case we need them in debug_vars
aaxc_iv= # 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 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 # 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 ;; --continue ) continueAt="$2"; continue=1; shift 2 ;;
# Use additional data got with mkb79/audible-cli # Use additional data got with mkb79/audible-cli
--use-audible-cli-data ) audibleCli=1; shift ;; --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 # Compression level
--level ) level="$2"; shift 2 ;; --level ) level="$2"; shift 2 ;;
# Keep author number n # Keep author number n
@ -488,6 +491,15 @@ validate_extra_files() {
return 1 return 1
fi 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" 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))=\(((.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}" CHAPTER\((.key))NAME=\(.value.title)"' "${extra_chapter_file}" > "${tmp_chapter_file}"
fi 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 fi
debug "Metadata file $metadata_file" debug "Metadata file $metadata_file"
debug_file "$metadata_file" debug_file "$metadata_file"
@ -645,6 +672,8 @@ do
album="$(get_metadata_value album)" album="$(get_metadata_value album)"
album_date="$(get_metadata_value date)" album_date="$(get_metadata_value date)"
copyright="$(get_metadata_value copyright)" copyright="$(get_metadata_value copyright)"
series="$(get_metadata_value series)"
series_sequence="$(get_metadata_value series_sequence)"
# Get more tags with mediainfo # Get more tags with mediainfo
if [[ $(type -P mediainfo) ]]; then if [[ $(type -P mediainfo) ]]; then
@ -683,7 +712,7 @@ do
if [[ "${noclobber}" = "1" ]] && [[ -d "${output_directory}" ]]; then if [[ "${noclobber}" = "1" ]] && [[ -d "${output_directory}" ]]; then
log "Noclobber enabled but directory '${output_directory}' exists. Skipping to avoid overwriting" log "Noclobber enabled but directory '${output_directory}' exists. Skipping to avoid overwriting"
rm -f "${metadata_file}" rm -f "${metadata_file}" "${tmp_chapter_file}"
continue continue
fi fi
mkdir -p "${output_directory}" mkdir -p "${output_directory}"
@ -743,6 +772,8 @@ do
-metadata description="${description}" \ -metadata description="${description}" \
-metadata composer="${narrator}" \ -metadata composer="${narrator}" \
-metadata publisher="${publisher}" \ -metadata publisher="${publisher}" \
-metadata series="${series}" \
-metadata series_sequence="${series_sequence}" \
-f ${container} \ -f ${container} \
"${output_file}" "${output_file}"
if [ "$((${loglevel} > 0))" == "1" ]; then if [ "$((${loglevel} > 0))" == "1" ]; then
@ -770,7 +801,7 @@ do
extra_crop_cover='' extra_crop_cover=''
cover_width=$(ffprobe -i "${cover_file}" 2>&1 | grep -Po "[0-9]+(?=x[0-9]+)") 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 if [ "$((${loglevel} > 1))" == "1" ]; then
log "Cover ${cover_file} has odd width ${cover_width}, setting extra_crop_cover to make even." log "Cover ${cover_file} has odd width ${cover_width}, setting extra_crop_cover to make even."
fi fi

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. * **--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. * **--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. * **--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. * **--ffmpeg-path** Set the ffmpeg/ffprobe binaries folder. Both of them must be executable and in the same folder.
## Options for interactiveAAXtoMP3 ## 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 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 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'` * 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. ### Installing Dependencies.
In general, take a look at [command-not-found.com](https://command-not-found.com/) In general, take a look at [command-not-found.com](https://command-not-found.com/)