mirror of
				https://github.com/KrumpetPirate/AAXtoMP3.git
				synced 2025-11-03 20:40:43 +01:00 
			
		
		
		
	Add possibility to read the series from the audible library
This commit is contained in:
		
							
								
								
									
										33
									
								
								AAXtoMP3
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								AAXtoMP3
									
									
									
									
									
								
							@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user