diferentiated between a log and debug message

This commit is contained in:
upuv 2018-05-19 21:29:20 +10:00
parent ccfaf07021
commit e69b212982

View File

@ -9,7 +9,13 @@ extension=mp3
mode=chaptered mode=chaptered
auth_code= auth_code=
targetdir= targetdir=
DEBUG=0
# -----
# Code tip Do not have any scritp above this point that calls a function or a binary. If you do
# the $1 will no longer be a ARGV element. So you should only do basic variable setting above here.
#
# Process the command line options. This allows for un-ordered options. Sorta like a getops style
while true; do while true; do
case "$1" in case "$1" in
-f | --flac ) codec=flac; extension=flac; mode=single ; shift ;; -f | --flac ) codec=flac; extension=flac; mode=single ; shift ;;
@ -18,13 +24,14 @@ while true; do
-s | --single ) mode=single; shift ;; -s | --single ) mode=single; shift ;;
-t | --target_dir ) targetdir="$2"; shift 2 ;; -t | --target_dir ) targetdir="$2"; shift 2 ;;
-A | --authcode ) auth_code="$2"; shift 2 ;; -A | --authcode ) auth_code="$2"; shift 2 ;;
-d | --debug ) DEBUG=1; shift ;; # Not so secret flag for debug output. to use in code [ $DEBUG == 1 ] && sample=2 -d | --debug ) DEBUG=1; shift ;;
-h | --help ) printf "$usage" $0 ; exit ;; -h | --help ) printf "$usage" $0 ; exit ;;
-- ) shift; break ;; -- ) shift; break ;;
* ) break ;; * ) break ;;
esac esac
done done
# Empty argv means we have nothing to do so lets bark some help.
if [ "$#" -eq 0 ]; then if [ "$#" -eq 0 ]; then
printf "$usage" $0 printf "$usage" $0
exit 1 exit 1
@ -43,6 +50,7 @@ if ! [[ $(type -P "$GREP") ]]; then
exit 1 exit 1
fi fi
# -----
# Obtain the authcode from either the command line, local directory or home directory. # Obtain the authcode from either the command line, local directory or home directory.
if [ -z $auth_code ]; then if [ -z $auth_code ]; then
if [ -r .authcode ]; then if [ -r .authcode ]; then
@ -57,6 +65,7 @@ if [ -z $auth_code ]; then
exit 1 exit 1
fi fi
# -----
# Check the target dir for if set if it is writable # Check the target dir for if set if it is writable
if [[ ! -w "${targetdir}" || ! -d "${targetdir}" ]] ; then if [[ ! -w "${targetdir}" || ! -d "${targetdir}" ]] ; then
echo "ERROR Target Directory is not writable: \"$targetdir\"" echo "ERROR Target Directory is not writable: \"$targetdir\""
@ -67,7 +76,15 @@ fi
# ======================================================================== # ========================================================================
# Utility Functions # Utility Functions
# debug
debug() { debug() {
if [ $DEBUG == 1 ] ; then
echo "$(date "+%F %T%z") DEBUG ${1}"
fi
}
# log
log() {
echo "$(date "+%F %T%z") ${1}" echo "$(date "+%F %T%z") ${1}"
} }
@ -99,7 +116,7 @@ normalize_whitespace() {
# Main Transcode Loop # Main Transcode Loop
for path for path
do do
debug "Decoding ${path} with auth code ${auth_code}..." log "Decoding ${path} with auth code ${auth_code}..."
# Check for Presense of Audiobook # Check for Presense of Audiobook
if [[ ! -r "${path}" ]] ; then if [[ ! -r "${path}" ]] ; then
@ -122,23 +139,23 @@ do
# This is the primary transcode. All the heavy lifting is here. # This is the primary transcode. All the heavy lifting is here.
</dev/null ffmpeg -loglevel error -stats -activation_bytes "${auth_code}" -i "${path}" -vn -codec:a "${codec}" -ab "$(get_bitrate)k" -map_metadata -1 -metadata title="${title}" -metadata artist="${artist}" -metadata album_artist="$(get_metadata_value album_artist)" -metadata album="$(get_metadata_value album)" -metadata date="$(get_metadata_value date)" -metadata track="1/1" -metadata genre="${genre}" -metadata copyright="$(get_metadata_value copyright)" "${full_file_path}" </dev/null ffmpeg -loglevel error -stats -activation_bytes "${auth_code}" -i "${path}" -vn -codec:a "${codec}" -ab "$(get_bitrate)k" -map_metadata -1 -metadata title="${title}" -metadata artist="${artist}" -metadata album_artist="$(get_metadata_value album_artist)" -metadata album="$(get_metadata_value album)" -metadata date="$(get_metadata_value date)" -metadata track="1/1" -metadata genre="${genre}" -metadata copyright="$(get_metadata_value copyright)" "${full_file_path}"
debug "Created ${full_file_path}." log "Created ${full_file_path}."
# Grab the cover art if available. # Grab the cover art if available.
cover_path="${output_directory}/cover.jpg" cover_path="${output_directory}/cover.jpg"
debug "Extracting cover into ${cover_path}..." log "Extracting cover into ${cover_path}..."
</dev/null ffmpeg -loglevel error -activation_bytes "${auth_code}" -i "${path}" -an -codec:v copy "${cover_path}" </dev/null ffmpeg -loglevel error -activation_bytes "${auth_code}" -i "${path}" -an -codec:v copy "${cover_path}"
# If we want multiple file we take the big mp3 and split it by chapter. # If we want multiple file we take the big mp3 and split it by chapter.
if [ "${mode}" == "chaptered" ]; then if [ "${mode}" == "chaptered" ]; then
# Playlist m3u support # Playlist m3u support
playlist_file="${output_directory}/${title}.m3u" playlist_file="${output_directory}/${title}.m3u"
debug "Creating PlayList ${title}.m3u" log "Creating PlayList ${title}.m3u"
echo '#EXTM3U' > "${playlist_file}" echo '#EXTM3U' > "${playlist_file}"
chaptercount=$($GREP -Pc "Chapter.*start.*end" $metadata_file) chaptercount=$($GREP -Pc "Chapter.*start.*end" $metadata_file)
debug "Extracting ${chaptercount} chapter files from ${full_file_path}..." log "Extracting ${chaptercount} chapter files from ${full_file_path}..."
chapternum=1 chapternum=1
while read -r -u9 first _ _ start _ end while read -r -u9 first _ _ start _ end
@ -169,9 +186,9 @@ do
fi fi
done 9< "$metadata_file" done 9< "$metadata_file"
rm "${full_file_path}" rm "${full_file_path}"
debug "Done creating chapters. Chaptered files contained in ${output_directory}." log "Done creating chapters. Chaptered files contained in ${output_directory}."
fi fi
debug "Done." log "Done. ${title}"
rm "${metadata_file}" rm "${metadata_file}"
done done