Minor changes to satisfy shellcheck

This commit is contained in:
Nathaniel Landau
2016-02-09 17:18:26 -05:00
parent 321b0e3bb3
commit 4f33a18cb1
2 changed files with 36 additions and 36 deletions

View File

@@ -198,7 +198,7 @@ function mainScript() {
extension="$(echo "${extension}" | tr '[:upper:]' '[:lower:]')" # Lowercase the extension if needed extension="$(echo "${extension}" | tr '[:upper:]' '[:lower:]')" # Lowercase the extension if needed
# See if the extension is in the specified extension mappings # See if the extension is in the specified extension mappings
if [[ ! "${videoTypes[*]}" =~ "${extension}" ]] && [[ ! "${audioTypes[*]}" =~ "${extension}" ]]; then if [[ ! "${videoTypes[*]}" =~ ${extension} ]] && [[ ! "${audioTypes[*]}" =~ ${extension} ]]; then
error "The extension of '${extension} ' was not recognized." error "The extension of '${extension} ' was not recognized."
die "We don't know what to do with ${fileToTest}." die "We don't know what to do with ${fileToTest}."
fi fi
@@ -207,7 +207,7 @@ function mainScript() {
function convertToFormat() { function convertToFormat() {
# Do things on video files # Do things on video files
if [[ "${videoTypes[*]}" =~ "${file##*.}" ]]; then if [[ "${videoTypes[*]}" =~ ${file##*.} ]]; then
# if you wanted a default target format for a specific input format, # if you wanted a default target format for a specific input format,
# you would put it here. # you would put it here.
# Set the default video conversion format to mp4 # Set the default video conversion format to mp4
@@ -218,7 +218,7 @@ function mainScript() {
fi fi
# Do things on audio files # Do things on audio files
if [[ "${audioTypes[*]}" =~ "${file##*.}" ]]; then if [[ "${audioTypes[*]}" =~ ${file##*.} ]]; then
# Ensure a user sets an output format since we don't have a default. # Ensure a user sets an output format since we don't have a default.
if [[ -z ${userOutput} ]]; then if [[ -z ${userOutput} ]]; then
@@ -309,11 +309,11 @@ function mainScript() {
fi fi
# Increase loop count # Increase loop count
ii=$[$ii+1] ii=$((ii+1))
done done
# Error Handling for video files # Error Handling for video files
if [[ "${videoTypes[*]}" =~ "${file##*.}" ]]; then if [[ "${videoTypes[*]}" =~ ${file##*.} ]]; then
if [ "${videoFoundFlag}" = "false" ]; then if [ "${videoFoundFlag}" = "false" ]; then
warning "Missing video stream for '${file}'." warning "Missing video stream for '${file}'."
seek_confirmation "Inspect the file with ffprobe?" seek_confirmation "Inspect the file with ffprobe?"
@@ -328,7 +328,7 @@ function mainScript() {
fi fi
# Error Handling for audio files # Error Handling for audio files
if [[ "${audioTypes[*]}" =~ "${file##*.}" ]]; then if [[ "${audioTypes[*]}" =~ ${file##*.} ]]; then
if [ "${audioFoundFlag}" = "false" ]; then if [ "${audioFoundFlag}" = "false" ]; then
warning "Missing audio stream for '${file}'." warning "Missing audio stream for '${file}'."
seek_confirmation "Inspect the file with ffprobe?" seek_confirmation "Inspect the file with ffprobe?"
@@ -352,14 +352,14 @@ function mainScript() {
################################################################ ################################################################
# Pick the best aac audio encoder # Pick the best aac audio encoder
if $(ffmpeg -version | grep enable-libfdk-aac >/dev/null); then if ffmpeg -version | grep enable-libfdk-aac >/dev/null; then
aacEncoder="libfdk_aac" aacEncoder="libfdk_aac"
else else
aacencoder="libfaac" aacEncoder="libfaac"
fi fi
supportedAudioCodecs=(aac ac3 eac3) supportedAudioCodecs=(aac ac3 eac3)
if [[ "${supportedAudioCodecs[*]}" =~ "${audioCodec}" ]]; then if [[ "${supportedAudioCodecs[*]}" =~ ${audioCodec} ]]; then
videoAudioCommand="-c:a copy" videoAudioCommand="-c:a copy"
else else
videoAudioCommand="-c:a ${aacEncoder} -b:a 160k" videoAudioCommand="-c:a ${aacEncoder} -b:a 160k"
@@ -435,7 +435,7 @@ function mainScript() {
userWidth=$(echo ${videoSize} | cut -f1 -dx) userWidth=$(echo ${videoSize} | cut -f1 -dx)
userHeight=$(echo ${videoSize} | cut -f2 -dx) userHeight=$(echo ${videoSize} | cut -f2 -dx)
if [ "${userWidth}" -gt "${videoWidth}" ] || [ "${userHeight}" -gt "${videoHeight}" ]; then if [ "${userWidth}" -gt "${videoWidth}" ] || [ "${userHeight}" -gt "${videoHeight}" ]; then
seek_confirmation "Upscale "${file}" to "${videoSize}"? It is already "${videoWidth}"x"${videoHeight}"." seek_confirmation "Upscale ${file} to ${videoSize}? It is already ${videoWidth}x${videoHeight}."
if is_not_confirmed; then if is_not_confirmed; then
continue continue
fi fi
@@ -450,7 +450,7 @@ function mainScript() {
# #################################### # ####################################
if is_not_empty "${height}"; then if is_not_empty "${height}"; then
if [ "${height}" -gt "${videoHeight}" ]; then if [ "${height}" -gt "${videoHeight}" ]; then
seek_confirmation "Upscale "${file}" to height "${height}"? It is already "${videoWidth}"x"${videoHeight}"." seek_confirmation "Upscale ${file} to height ${height}? It is already ${videoWidth}x${videoHeight}."
if is_not_confirmed; then if is_not_confirmed; then
continue continue
fi fi
@@ -459,7 +459,7 @@ function mainScript() {
fi fi
if is_not_empty "${width}"; then if is_not_empty "${width}"; then
if [ "${width}" -gt "${videoWidth}" ]; then if [ "${width}" -gt "${videoWidth}" ]; then
seek_confirmation "Upscale "${file}" to width "${width}"? It is already "${videoWidth}"x"${videoHeight}"." seek_confirmation "Upscale ${file} to width ${width}? It is already ${videoWidth}x${videoHeight}."
if is_not_confirmed; then if is_not_confirmed; then
continue continue
fi fi
@@ -478,7 +478,7 @@ function mainScript() {
# Don't convert to self if no other options set # Don't convert to self if no other options set
if [[ -z ${height} && -z ${width} && -z ${videoSize} && ${downsize720} == "0" && "${outputFormat}" == "${file##*.}" ]]; then if [[ -z ${height} && -z ${width} && -z ${videoSize} && ${downsize720} == "0" && "${outputFormat}" == "${file##*.}" ]]; then
error "Can't convert a '"${file##*.}"' file to itself. Skipping ${file}" error "Can't convert a '${file##*.}' file to itself. Skipping ${file}"
continue continue
fi fi
} }
@@ -519,7 +519,7 @@ function mainScript() {
elif [[ "${userOutput,,}" == "aac" || "${userOutput,,}" == "m4a" ]]; then elif [[ "${userOutput,,}" == "aac" || "${userOutput,,}" == "m4a" ]]; then
outputFormat="m4a" outputFormat="m4a"
# Pick the best aac audio encoder # Pick the best aac audio encoder
if $(ffmpeg -version | grep enable-libfdk-aac >/dev/null); then if ffmpeg -version | grep enable-libfdk-aac >/dev/null; then
# set variable bit rate to '5', the highest unless we are doing spoken word # set variable bit rate to '5', the highest unless we are doing spoken word
if ${spokenWord}; then if ${spokenWord}; then
aacEncoder='libfdk_aac' aacEncoder='libfdk_aac'
@@ -537,7 +537,7 @@ function mainScript() {
fi fi
elif [[ "${userOutput,,}" == "mp3" ]]; then elif [[ "${userOutput,,}" == "mp3" ]]; then
# Can we convert to mp3? Do we have an ffmpeg encoder? # Can we convert to mp3? Do we have an ffmpeg encoder?
if $(ffmpeg -version | grep enable-libmp3lame >/dev/null); then if ffmpeg -version | grep enable-libmp3lame >/dev/null; then
mp3Encoder='libmp3lame' mp3Encoder='libmp3lame'
# else # else
# warning "No workable ffmpeg mp3 encoder. Skipping ${f}..." # warning "No workable ffmpeg mp3 encoder. Skipping ${f}..."
@@ -562,7 +562,7 @@ function mainScript() {
# need high fidelity or stereo so we make them mono and low bit-rate. # need high fidelity or stereo so we make them mono and low bit-rate.
# Pick the best aac audio encoder # Pick the best aac audio encoder
if $(ffmpeg -version | grep enable-libfdk-aac >/dev/null); then if ffmpeg -version | grep enable-libfdk-aac >/dev/null; then
# set variable bit rate to '5', the highest # set variable bit rate to '5', the highest
aacEncoder="libfdk_aac ${monoConversion} -f m4a" aacEncoder="libfdk_aac ${monoConversion} -f m4a"
else else
@@ -662,17 +662,17 @@ function mainScript() {
verbose "Running XLD commands for audio. No FFMPEG." verbose "Running XLD commands for audio. No FFMPEG."
# Respect --safe flag. # Respect --safe flag.
if [[ "${safeRun}" == "1" ]]; then if [[ "${safeRun}" == "1" ]]; then
notice "xld -o "${output}" ${audioConvertCommand} "${file}"" notice "xld -o "${output} ${audioConvertCommand} ${file}
else else
verbose "xld -o "${output}" ${audioConvertCommand} "${file}"" verbose "xld -o ${output} ${audioConvertCommand} ${file}"
xld -o "${output}" ${audioConvertCommand} "${file}" xld -o "${output}" "${audioConvertCommand}" "${file}"
fi fi
else # Use ffmpeg when XLD is set to 0 else # Use ffmpeg when XLD is set to 0
# Respect --safe flag. # Respect --safe flag.
if [[ "${safeRun}" == "1" ]]; then if [[ "${safeRun}" == "1" ]]; then
notice "ffmpeg -i "${file}" ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} "${output}" ${ffquiet}" notice "ffmpeg -i ${file} ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} ${output} ${ffquiet}"
else else
verbose "ffmpeg -i "${file}" ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} "${output}" ${ffquiet}" verbose "ffmpeg -i ${file} ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} ${output} ${ffquiet}"
ffmpeg -i "${file}" ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} "${output}" ${ffquiet} ffmpeg -i "${file}" ${videoResize} ${videoCommand} ${videoAudioCommand} ${audioConvertCommand} "${output}" ${ffquiet}
fi fi
fi fi

View File

@@ -39,10 +39,10 @@ function safeExit() {
# Outputs each line in a variable named $result # Outputs each line in a variable named $result
# ------------------------------------------------------ # ------------------------------------------------------
function readFile() { function readFile() {
unset ${result} unset "${result}"
while read result while read result
do do
echo ${result} echo "${result}"
done < "$1" done < "$1"
} }
@@ -220,14 +220,14 @@ function is_not_empty() {
# ------------------------------------------------------ # ------------------------------------------------------
function type_exists() { function type_exists() {
if [ $(type -P "$1") ]; then if [ "$(type -P "$1")" ]; then
return 0 return 0
fi fi
return 1 return 1
} }
function type_not_exists() { function type_not_exists() {
if [ ! $(type -P "$1") ]; then if [ ! "$(type -P "$1")" ]; then
return 0 return 0
fi fi
return 1 return 1
@@ -334,7 +334,7 @@ function unmountDrive() {
function help () { function help () {
echo "" 1>&2 echo "" 1>&2
input " ${@}" 1>&2 input " $@" 1>&2
if [ -n "${usage}" ]; then # print usage information if available if [ -n "${usage}" ]; then # print usage information if available
echo " ${usage}" 1>&2 echo " ${usage}" 1>&2
fi fi
@@ -401,9 +401,9 @@ function pauseScript() {
function in_array() { function in_array() {
# Determine if a value is in an array. # Determine if a value is in an array.
# Usage: in_array [VALUE] [ARRAY] # Usage: in_array [VALUE] [ARRAY]
local value=$1; shift local value="$1"; shift
for item in "$@"; do for arrayItem in "$@"; do
[[ $item == $value ]] && return 0 [[ "${arrayItem}" == "${value}" ]] && return 0
done done
return 1 return 1
} }
@@ -483,7 +483,7 @@ squeeze_lines() {
# ----------------------------------- # -----------------------------------
progressBar() { progressBar() {
if [[ ${quiet} = "true" ]] || [ ${quiet} == "1" ]; then if [[ "${quiet}" = "true" ]] || [ "${quiet}" == "1" ]; then
return return
fi fi
@@ -495,7 +495,7 @@ progressBar() {
if ${verbose}; then return; fi if ${verbose}; then return; fi
# Reset the count # Reset the count
if [ -z ${progressBarProgress} ]; then if [ -z "${progressBarProgress}" ]; then
progressBarProgress=0 progressBarProgress=0
fi fi
@@ -508,11 +508,11 @@ progressBar() {
tput civis tput civis
trap 'tput cnorm; exit 1' SIGINT trap 'tput cnorm; exit 1' SIGINT
if [ ! ${progressBarProgress} -eq $(( $1 - 1 )) ]; then if [ ! "${progressBarProgress}" -eq $(( $1 - 1 )) ]; then
# Compute the percentage. # Compute the percentage.
perc=$(( ${progressBarProgress} * 100 / $1 )) perc=$(( progressBarProgress * 100 / $1 ))
# Compute the number of blocks to represent the percentage. # Compute the number of blocks to represent the percentage.
num=$(( ${progressBarProgress} * $width / $1 )) num=$(( progressBarProgress * width / $1 ))
# Create the progress bar string. # Create the progress bar string.
bar= bar=
if [ ${num} -gt 0 ]; then if [ ${num} -gt 0 ]; then
@@ -521,7 +521,7 @@ progressBar() {
# Print the progress bar. # Print the progress bar.
progressBarLine=$(printf "%s [%-${width}s] (%d%%)" "Running Process" "${bar}" "${perc}") progressBarLine=$(printf "%s [%-${width}s] (%d%%)" "Running Process" "${bar}" "${perc}")
echo -en "${progressBarLine}\r" echo -en "${progressBarLine}\r"
progressBarProgress=$[${progressBarProgress}+1] progressBarProgress=$(( progressBarProgress + 1 ))
else else
# Clear the progress bar when complete # Clear the progress bar when complete
echo -ne "${width}%\033[0K\r" echo -ne "${width}%\033[0K\r"
@@ -552,7 +552,7 @@ urlencode() {
for (( i = 0; i < length; i++ )); do for (( i = 0; i < length; i++ )); do
local c="${1:i:1}" local c="${1:i:1}"
case $c in case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;; [a-zA-Z0-9.~_-]) printf "%s" "$c" ;;
*) printf '%%%02X' "'$c" *) printf '%%%02X' "'$c"
esac esac
done done