## 2018-09-11 HB9ocq

trace_pfn_out_log() {
    echo "#pfn_out_log#$1 pfn= P${pfn}P"
    echo "#pfn_out_log#$1 out= O${out}O"
    echo "#pfn_out_log#$1 log= L${log}L"
}

trace_i_o_l() {
    echo "#i_o_l#$1 pfn= I${i}I"
    echo "#i_o_l#$1 out= O${o}O"
    echo "#i_o_l#$1 log= L${l}L"
}

convert_pfn_out_log() {
    set -x
    ffmpeg  -i "$pfn"  -acodec libvorbis  "$out"  >  "$log"  2>&1
    set +x
}


do_shasum() {
    sha256sum "$pfn"
}


convert_w_trace() {
    trace_pfn_out_log 1

    if [[ -v pfn ]]
    then
	echo "#";
    else
	echo "#ERR# pfn not set as variable!!!"
	exit -2
    fi
    if [[ -z "$pfn" ]]
    then
	echo "#ERR# pfn has length zero!!!"
	exit -3
    fi
    if [[ -f "$pfn" ]]
    then
	echo "##"
    else
	echo "#ERR# pfn does not name a file!!!"
	exit -4
    fi

    set -x
    # do_shasum   ## OK, WORKS AS EXPECTED :-)
    ffmpeg  -i "$pfn"  -acodec libvorbis  "$out"  >  "$log"  2>&1 ##WTF## FUBARs with variable $pfn 
    set +x
    
    trace_pfn_out_log 2
    du -sk "$pfn" "$out" "$log"
}


while_read() {
    cat wma.pflist  | sort |  while read pfn
    do
	out="${pfn%.wma}.ogg"
	log="${out}.log"
	
	# do_shasum   ## OK, WORKS AS EXPECTED :-)
	convert_w_trace  ##WTF## FUBARs with variable $pfn
        # ffmpeg  -i "$pfn"  -acodec libvorbis  "$out"  >  "$log"  2>&1 ##WTF## FUBARs with variable $pfn 
	
	sync
	pfn="111"
	out="222"
	log="333"
    done
}

array_for() {
    readarray -t  PFNARRY  <  wma.pflist

    for pfn in "${PFNARRY[@]}"
    do
	out="${pfn%.wma}.ogg"
	log="${out}.log"
	
	convert_w_trace ## works as expected :-)
	# do_shasum   ## OK, WORKS AS EXPECTED :-)

	sync
    done
}


# clean from prev. run
find . -iname '*log' -exec rm -v {} \; ; find . -iname '*ogg' -exec rm -v {} \;

# go!
## while_read  ##WTF## FUBARs with variable $pfn
array_for  # works as expected :-)


##EOFILE
