Added some more output

This commit is contained in:
Jeroen De Meerleer 2019-03-16 18:31:17 +01:00
parent f44bfd0ef9
commit 72d8a2dcff

View File

@ -24,6 +24,7 @@ CheckDeps() {
ExecTime ExecTime
exit 1 exit 1
fi fi
VerboseOutput 0 "\`getopt --test\` succeeded"
fi fi
if [[ $1 == 1 ]]; then if [[ $1 == 1 ]]; then
@ -36,6 +37,8 @@ CheckDeps() {
ExecTime ExecTime
exit 1 exit 1
fi fi
VerboseOutput 0 "\`lame --version\` succeeded"
# Check EyeD3 # Check EyeD3
if [[ $convertart == true && ! $(eyeD3 --version 2>/dev/null) ]]; then if [[ $convertart == true && ! $(eyeD3 --version 2>/dev/null) ]]; then
VerboseOutput 5 "\`eyeD3 --version\` failed" VerboseOutput 5 "\`eyeD3 --version\` failed"
@ -45,6 +48,8 @@ CheckDeps() {
ExecTime ExecTime
exit 1 exit 1
fi fi
VerboseOutput 0 "\`eyeD3 --version\` succeeded"
# Check ImageMagick # Check ImageMagick
if [[ $convertart == true && ! $(convert --version 2>/dev/null) ]]; then if [[ $convertart == true && ! $(convert --version 2>/dev/null) ]]; then
VerboseOutput 5 "\`convert --version\` failed" VerboseOutput 5 "\`convert --version\` failed"
@ -54,7 +59,9 @@ CheckDeps() {
ExecTime ExecTime
exit 1 exit 1
fi fi
VerboseOutput 0 "\`convert --version\` succeeded"
fi fi
VerboseOutput 1 "Dependency test OK"
} }
GetOptions() { GetOptions() {
@ -94,27 +101,36 @@ GetOptions() {
shift shift
;; ;;
-s|--source) -s|--source)
VerboseOutput 0 "--source given."
VerboseOutput 1 "Source is ${2}"
source="$2" source="$2"
shift 2 shift 2
;; ;;
-d|--dest) -d|--dest)
VerboseOutput 0 "--dest given."
VerboseOutput 1 "Destination is ${2}"
dest="$2" dest="$2"
shift 2 shift 2
;; ;;
-t|--temp) -t|--temp)
VerboseOutput 0 "--temp given"
VerboseOutput 1 "Tempfolder is ${2}"
temp="$2" temp="$2"
shift 2 shift 2
;; ;;
-c|--convert) -c|--convert)
VerboseOutput 0 "--convert given"
convert=true convert=true
bitrate=192 bitrate=192
if [[ $2 != "" ]]; then if [[ $2 != "" ]]; then
bitrate=${2} bitrate=${2}
shift shift
fi fi
VerboseOutput 1 "Converted bitrate is ${bitrate}"
shift shift
;; ;;
-a|--resize-art) -a|--resize-art)
VerboseOutput 0 "--resize-art given"
convertart=true convertart=true
coverartsize=200 coverartsize=200
if [[ $2 != "" ]]; then if [[ $2 != "" ]]; then
@ -122,6 +138,7 @@ GetOptions() {
shift shift
fi fi
shift shift
VerboseOutput 1 "Album art will ${coverartsize}px wide"
;; ;;
--) --)
shift shift
@ -135,16 +152,26 @@ GetOptions() {
done done
if [[ ! -z "${1+x}" ]]; then if [[ ! -z "${1+x}" ]]; then
if [[ ${source} != "-" ]]; then
VerboseOutput 4 "Source provided twice. Continueing with ${1}"
fi
source="$1" source="$1"
VerboseOutput 1 "Source is ${1}"
fi fi
if [[ ! -z "${2+x}" ]]; then if [[ ! -z "${2+x}" ]]; then
if [[ ${dest} != "-" ]]; then
VerboseOutput 4 "Destination provided twice. Continueing with ${2}"
fi
dest="$2" dest="$2"
VerboseOutput 1 "Destination is ${2}"
fi fi
if [[ $dest == "-" ]] || [[ $source == "-" ]]; then if [[ $dest == "-" ]] || [[ $source == "-" ]]; then
help=true help=true
fi fi
VerboseOutput 1 "Checks OK. Going on"
} }
Usage() { Usage() {
@ -220,15 +247,22 @@ CreateFileList() {
for file in $sourcepath; do for file in $sourcepath; do
origfile="${file#"$1/"}" origfile="${file#"$1/"}"
relfile=$(echo ${origfile} | sed -e 's/\(\.\)*$//g') relfile=$(echo ${origfile} | sed -e 's/\(\.\)*$//g')
VerboseOutput 0 "Checking ${origfile}"
if [[ -d "${1}/$origfile" ]]; then if [[ -d "${1}/$origfile" ]]; then
VerboseOutput 0 "${origfile} is folder"
newdir="${3}/$relfile" newdir="${3}/$relfile"
newdir=${newdir#"/"} newdir=${newdir#"/"}
VerboseOutput 1 "Entering $newdir" VerboseOutput 1 "Entering $newdir"
CreateFileList "${1}/$origfile" "${2}/$relfile" "$newdir" CreateFileList "${1}/$origfile" "${2}/$relfile" "$newdir"
elif [[ "${1}/$origfile" != *".m3u" ]] && [[ ! -f "${2}/$relfile" || "${1}/$origfile" -nt "${2}/$relfile" ]]; then elif [[ "${1}/$origfile" != *".m3u" ]] && [[ ! -f "${2}/$relfile" || "${1}/$origfile" -nt "${2}/$relfile" ]]; then
echo ${3}/$relfile >> /tmp/music-sync-filelist echo ${3}/$relfile >> /tmp/music-sync-filelist
VerboseOutput 2 "Added: ${3}/${relfile}" VerboseOutput 0 "${origfile} is newer in source"
VerboseOutput 1 "Added: ${3}/${origfile}"
fi fi
if [[ "${1}/$origfile" == *".m3u" ]]; then
VerboseOutput 0 "${origfile} is playlist"
fi
done done
} }
@ -252,25 +286,31 @@ ConvertFiles() {
VerboseOutput 2 "Progress: $curline / $total (${percentage%00}%) Step 1 of 2" VerboseOutput 2 "Progress: $curline / $total (${percentage%00}%) Step 1 of 2"
if [[ "$temp/$line" = */* ]]; then if [[ "$temp/$line" = */* ]]; then
VerboseOutput 0 "Creating folder $temp/${line%/*}"
mkdir -p "$temp/${line%/*}"; mkdir -p "$temp/${line%/*}";
fi; fi;
if [[ ! -f "$temp/$line" || "${source}/$line" -nt "$temp/$line" ]]; then if [[ ! -f "$temp/$line" || "${source}/$line" -nt "$temp/$line" ]]; then
VerboseOutput 0 "Converting MP3-file $temp/${line%/*}"
lame -b ${bitrate} $source/$line $temp/$line 1>/dev/null 2>/dev/null lame -b ${bitrate} $source/$line $temp/$line 1>/dev/null 2>/dev/null
VerboseOutput 2 "Converted: $line"
if [[ $convertart == true ]]; then if [[ $convertart == true ]]; then
VerboseOutput 0 "Creating folder $temp/$line-images/"
mkdir -p "$temp/$line-images/" mkdir -p "$temp/$line-images/"
VerboseOutput 0 "Extracted albumart"
eyeD3 --write-images "$temp/$line-images/" "$temp/$line" 1>/dev/null 2>/dev/null eyeD3 --write-images "$temp/$line-images/" "$temp/$line" 1>/dev/null 2>/dev/null
VerboseOutput 0 "Converting albumart"
convert "$temp/$line-images/FRONT_COVER.*" -resize ${coverartsize}x${coverartsize} "$temp/$line-images/FRONT_COVER.jpg" 1>/dev/null 2>/dev/null convert "$temp/$line-images/FRONT_COVER.*" -resize ${coverartsize}x${coverartsize} "$temp/$line-images/FRONT_COVER.jpg" 1>/dev/null 2>/dev/null
eyeD3 --remove-all-images "$temp/$line" 1>/dev/null 2>/dev/null eyeD3 --remove-all-images "$temp/$line" 1>/dev/null 2>/dev/null
VerboseOutput 0 "Embedding albumart"
eyeD3 --add-image "$temp/$line-images/FRONT_COVER.jpg:FRONT_COVER" "$temp/$line" 1>/dev/null 2>/dev/null eyeD3 --add-image "$temp/$line-images/FRONT_COVER.jpg:FRONT_COVER" "$temp/$line" 1>/dev/null 2>/dev/null
VerboseOutput 2 "Converted cover art: $line" VerboseOutput 1 "Converted cover art: $line"
fi fi
VerboseOutput 2 "Converted: $line"
else else
VerboseOutput 3 "$line already converted" VerboseOutput 3 "$line already converted"
fi; fi;
done < "/tmp/music-sync-filelist" done < "/tmp/music-sync-filelist"
VerboseOutput 2 "Done converting files"
} }
CopyFiles() { CopyFiles() {
@ -299,6 +339,7 @@ CopyFiles() {
VerboseOutput 2 "Progress: $curline / $total (${percentage%00}%) Step 2 of 2" VerboseOutput 2 "Progress: $curline / $total (${percentage%00}%) Step 2 of 2"
if [[ "$dest/$line" = */* ]]; then if [[ "$dest/$line" = */* ]]; then
VerboseOutput 0 "Creating folder $dest/${line%/*}"
mkdir -p "$dest/${line%/*}"; mkdir -p "$dest/${line%/*}";
fi; fi;
@ -307,11 +348,13 @@ CopyFiles() {
VerboseOutput 2 "Copied: $line" VerboseOutput 2 "Copied: $line"
done < "/tmp/music-sync-filelist" done < "/tmp/music-sync-filelist"
VerboseOutput 2 "Done copying files"
} }
CleanUp() { CleanUp() {
VerboseOutput 1 "Cleaning Up" VerboseOutput 1 "Cleaning Up"
if [[ -f /tmp/music-sync-filelist ]]; then if [[ -f /tmp/music-sync-filelist ]]; then
VerboseOutput 1 "Removing filelist"
rm "/tmp/music-sync-filelist" rm "/tmp/music-sync-filelist"
fi fi
VerboseOutput 1 "Done" VerboseOutput 1 "Done"