Added some more output

This commit is contained in:
Jeroen De Meerleer 2019-03-16 18:31:17 +01:00
parent f44bfd0ef9
commit 72d8a2dcff
1 changed files with 48 additions and 5 deletions

View File

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