Now removes .new from filename with --delete flag set

This commit is contained in:
Nathaniel Landau
2015-06-21 11:53:17 -04:00
parent a4f4b8d9b2
commit 5ef114da66

View File

@@ -55,7 +55,7 @@ function trapCleanup() {
# ----------------------------------- # -----------------------------------
quiet=0 quiet=0
printLog=0 printLog=0
verbose=0 verbose=false
force=0 force=0
strict=0 strict=0
debug=0 debug=0
@@ -92,7 +92,7 @@ logFile="$HOME/Library/Logs/${scriptBasename}.log"
# most dependencies can be installed automatically using the package # most dependencies can be installed automatically using the package
# manager 'Homebrew'. # manager 'Homebrew'.
# ----------------------------------- # -----------------------------------
homebrewDependencies=(ffmpeg jq) homebrewDependencies=(ffmpeg jq rename)
function mainScript() { function mainScript() {
############## Begin Script Here ################### ############## Begin Script Here ###################
@@ -111,6 +111,8 @@ function breakLoop() {
} }
function outputDir() { function outputDir() {
if $verbose; then v="-v" ; fi
if [[ -n "${saveDir}" ]]; then if [[ -n "${saveDir}" ]]; then
if [[ -e "${saveDir}" && ! -d "${saveDir}" ]]; then if [[ -e "${saveDir}" && ! -d "${saveDir}" ]]; then
die "${saveDir} exists but is not a directory" die "${saveDir} exists but is not a directory"
@@ -118,7 +120,7 @@ function outputDir() {
if [[ ! -d "${saveDir}" ]]; then if [[ ! -d "${saveDir}" ]]; then
seek_confirmation "${saveDir} does not exist. Create?" seek_confirmation "${saveDir} does not exist. Create?"
if is_confirmed; then if is_confirmed; then
mkdir "${saveDir}" && verbose "mkdir ${saveDir}" mkdir $v "${saveDir}"
else else
die "Can't run without a place to save the files." die "Can't run without a place to save the files."
fi fi
@@ -168,6 +170,8 @@ function doConvert() {
# Set the output name, format, and directory # Set the output name, format, and directory
# ############################################### # ###############################################
if $verbose; then v="-v" ; fi
# Set output filename # Set output filename
output="$(basename "${f%.*}").$outputFormat" && verbose "output="${output}"" output="$(basename "${f%.*}").$outputFormat" && verbose "output="${output}""
@@ -218,9 +222,13 @@ function doConvert() {
verbose "ffmpeg -i "${f}" ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} "${output}" ${ffquiet}" verbose "ffmpeg -i "${f}" ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} "${output}" ${ffquiet}"
ffmpeg -i "${f}" ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} "${output}" ${ffquiet} ffmpeg -i "${f}" ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} "${output}" ${ffquiet}
# delete original if requested # delete original if requested and remove '.new' from new file
if [[ "${deleteOriginal}" == "1" ]]; then if [[ "${deleteOriginal}" == "1" ]]; then
rm -f "${f}" && verbose "Deleting "${f}"" rm -f $v "${f}"
#remove '.new' from filename
for file in *.new.*; do
rename $v 's/.new//g' "${file}"
done
fi fi
fi fi
fi fi
@@ -749,7 +757,7 @@ while [[ $1 = -?* ]]; do
-h|--help) usage >&2; safeExit ;; -h|--help) usage >&2; safeExit ;;
--force) force=1 ;; --force) force=1 ;;
--version) echo "$(basename $0) $version"; safeExit ;; --version) echo "$(basename $0) $version"; safeExit ;;
-v|--verbose) verbose=1 ;; -v|--verbose) verbose=true ;;
-l|--log) printLog=1 ;; -l|--log) printLog=1 ;;
-q|--quiet) quiet=1 ;; -q|--quiet) quiet=1 ;;
-d|--debug) debug=1;; -d|--debug) debug=1;;