Merge pull request #112 from FreedomBen/no-clobber

Add no-clobber option to CLI
This commit is contained in:
KrumpetPirate 2019-10-01 18:08:35 -04:00 committed by GitHub
commit 9f8cda5899
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 46 deletions

View File

@ -5,7 +5,7 @@
# Command Line Options # Command Line Options
# Usage Synopsis. # Usage Synopsis.
usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--chaptered]\n[-e:mp3] [-e:m4a] [-e:m4b] [--authcode <AUTHCODE>]\n[--target_dir <PATH>] [--complete_dir <PATH>] [--validate]\n{FILES}\n' usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--chaptered]\n[-e:mp3] [-e:m4a] [-e:m4b] [--authcode <AUTHCODE>] [--no-clobber]\n[--target_dir <PATH>] [--complete_dir <PATH>] [--validate]\n{FILES}\n'
codec=libmp3lame # Default encoder. codec=libmp3lame # Default encoder.
extension=mp3 # Default encoder extention. extension=mp3 # Default encoder extention.
mode=chaptered # Multi file output mode=chaptered # Multi file output
@ -45,6 +45,8 @@ while true; do
-C | --complete_dir ) completedir="$2"; shift 2 ;; -C | --complete_dir ) completedir="$2"; shift 2 ;;
# Authorization code associate with the AAX file(s) # Authorization code associate with the AAX file(s)
-A | --authcode ) auth_code="$2"; shift 2 ;; -A | --authcode ) auth_code="$2"; shift 2 ;;
# Don't overwrite the target directory if it already exists
-n | --no-clobber ) noclobber=1; shift ;;
# Extremely verbose output. # Extremely verbose output.
-d | --debug ) DEBUG=1; shift ;; -d | --debug ) DEBUG=1; shift ;;
# Validate ONLY the aax file(s) No transcoding occurs # Validate ONLY the aax file(s) No transcoding occurs
@ -234,7 +236,7 @@ if [[ "x${targetdir}" != "x" ]]; then
fi fi
# ----- # -----
# Check the target dir for if set if it is writable # Check the completed dir for if set if it is writable
if [[ "x${completedir}" != "x" ]]; then if [[ "x${completedir}" != "x" ]]; then
if [[ ! -w "${completedir}" || ! -d "${completedir}" ]] ; then if [[ ! -w "${completedir}" || ! -d "${completedir}" ]] ; then
echo "ERROR Complete Directory does not exist or is not writable: \"$completedir\"" echo "ERROR Complete Directory does not exist or is not writable: \"$completedir\""
@ -283,7 +285,7 @@ validate_aax() {
log "Test 2 SUCCESS: ${media_file}" log "Test 2 SUCCESS: ${media_file}"
fi fi
# This is a big test only performed when the --validate swicth is passed. # This is a big test only performed when the --validate switch is passed.
if [[ "${VALIDATE}" == "1" ]]; then if [[ "${VALIDATE}" == "1" ]]; then
output="$(ffmpeg -hide_banner -activation_bytes ${auth_code} -i "${media_file}" -vn -f null - 2>&1)" output="$(ffmpeg -hide_banner -activation_bytes ${auth_code} -i "${media_file}" -vn -f null - 2>&1)"
if [[ $? != "0" ]] ; then if [[ $? != "0" ]] ; then
@ -360,6 +362,10 @@ do
album_date="$(get_metadata_value date)" album_date="$(get_metadata_value date)"
copyright="$(get_metadata_value copyright)" copyright="$(get_metadata_value copyright)"
if [[ "${noclobber}" = "1" ]] && [[ -d "${output_directory}" ]]; then
log "Noclobber enabled but directory '${output_directory}' exists. Exiting to avoid overwriting"
exit 0
fi
mkdir -p "${output_directory}" mkdir -p "${output_directory}"
# Fancy declaration of which book we are decoding. Including the AUTHCODE. # Fancy declaration of which book we are decoding. Including the AUTHCODE.

View File

@ -29,7 +29,7 @@ Thanks to kbabioch, this script has also been packaged in the [AUR](https://aur.
## Usage(s) ## Usage(s)
``` ```
bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [-c|--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [-A|--authcode <AUTHCODE>] [-t|--target_dir <PATH>] [-C|--complete_dir <PATH>] [-V|--validate] [-d|--debug] [-h|--help] <AAX INPUT_FILES>... bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [-c|--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [-A|--authcode <AUTHCODE>] [-n|--no-clobber] [-t|--target_dir <PATH>] [-C|--complete_dir <PATH>] [-V|--validate] [-d|--debug] [-h|--help] <AAX INPUT_FILES>...
``` ```
* **&lt;AAX INPUT_FILES&gt;**... are considered input file(s), useful for batching! * **&lt;AAX INPUT_FILES&gt;**... are considered input file(s), useful for batching!
@ -39,6 +39,7 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [-c|--chaptered] [
* **-o** or **--opus** Ogg/Opus Encoding defaults to multiple file output by chapter. The extention is .ogg * **-o** or **--opus** Ogg/Opus Encoding defaults to multiple file output by chapter. The extention is .ogg
* **-a** or **--aac** AAC Encoding and produce a m4a single files output. * **-a** or **--aac** AAC Encoding and produce a m4a single files output.
* **-A** or **--authcode &lt;AUTHCODE&gt;** for this execution of the command use the provided &lt;AUTHCODE&gt; to decode the AAX file. * **-A** or **--authcode &lt;AUTHCODE&gt;** for this execution of the command use the provided &lt;AUTHCODE&gt; to decode the AAX file.
* **-n** or **--no-clobber** If set and the target directory already exists, AAXtoMP3 will exit without overwriting anything.
* **-t** or **--target_dir &lt;PATH&gt;** change the default output location to the named &lt;PATH&gt;. Note the default location is ./Audiobook of the directory to which each AAX file resides. * **-t** or **--target_dir &lt;PATH&gt;** change the default output location to the named &lt;PATH&gt;. Note the default location is ./Audiobook of the directory to which each AAX file resides.
* **-C** or **--complete_dir &lt;PATH&gt;** a directory to place aax files after they have been decoded successfully. Note make a back up of your aax files prior to using this option. Just in case something goes wrong. * **-C** or **--complete_dir &lt;PATH&gt;** a directory to place aax files after they have been decoded successfully. Note make a back up of your aax files prior to using this option. Just in case something goes wrong.
* **-V** or **--validate** Perform 2 validation tests on the supplied aax files. This is more extensive than the normal validation as we attempt to transcode the aax file to a null file. This can take a long period of time. However it is useful when inspecting a large set of aax files prior to transcoding. As download errors are common with Audible servers. * **-V** or **--validate** Perform 2 validation tests on the supplied aax files. This is more extensive than the normal validation as we attempt to transcode the aax file to a null file. This can take a long period of time. However it is useful when inspecting a large set of aax files prior to transcoding. As download errors are common with Audible servers.