From fb5caa0f7eec7d667252eb4f37893ea15dad5036 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 16 Jul 2017 17:50:20 +0200 Subject: [PATCH] add: Functions --- albentohandy | 105 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 87 insertions(+), 18 deletions(-) diff --git a/albentohandy b/albentohandy index c97772c..0cae5e0 100755 --- a/albentohandy +++ b/albentohandy @@ -4,6 +4,78 @@ ### copy to other folder. It works on parallel, you can ### use it in a cluster with Parameter -S. +MakeSymlinksToWork() { + local readonly workdir="$1" + local readonly musicdir="$2" + local readonly albumlist="$3" + + for i in $(cat "$albumlist"); do + cp --recursive --symbolic-link $musicdir/$i $workdir/ + done + +} + +ConvertFlacToMp3() { + local readonly workdir="$1" + local readonly basefile="$2" + local readonly paralleopts="$3" + local readonly scriptdir="$4" + + find $workdir -name '*.flac' | \ + sort | \ + parallel $basefile --will-cite --ungroup --eta --progress --sshlogin $parallelopts $scriptdir/flactomp3v2 {} +} + +CleanupFlacAndCovers() { + local readonly workdir="$1" + + find $workdir -name '*.flac' | \ + sort | \ + xargs rm + find $workdir -name 'cover*' | \ + sort | \ + xargs rm +} + +CleanupWorkDir() { + local readonly workdir="$1" + + printf "cleanup working directory\n\n" + rm --recursive $workdir +} + +CopyWorkDirToDestDir() { + local readonly workdir="$1" + local readonly destdir="$2" + + mkdir --parents $destdir + cp --recursive $workdir/* $destdir +} + +MakeZipFile() { + local readonly workdir="$1" + local zipname="$2" + + if [[ ! $zipname =~ .zip ]]; then + local zipname="${zipname}.zip" + fi + + local readonly curpath=$(pwd) + cd $workdir + 7z a -bd -mmt=off -mm=Copy $curpath/$zipname . + cd $curpath +} + +MakeSha256CheckSum() { + local readonly workdir="$1" + + find $workdir -name '*.mp3' | \ + sort | \ + xargs sha256sum | \ + sed "s=$workdir/==" \ + >> $workdir/sha256sum +} + main() { WORK="$(pwd)/work.$$" # temporary working directory SCRIPTPATH="/usr/bin" # path to flactomp3v2 and notify.sh script @@ -98,9 +170,7 @@ main() { addInfo "

$(cat "$albumlist" | sed 's/$/
/')

" # make symlinks of original flac's in working directory printf "\nPhase %02d of %02d: create symlinks of flac's to working directory %s\n" $((curphase++)) $phase "$WORK" - for i in $(cat "$albumlist"); do - cp --recursive --symbolic-link $MUSICPATH/$i $WORK/ - done + MakeSymlinksToWork "$WORK" "$MUSICPATH" "$albumlist" addInfo "

" currentDate @@ -108,14 +178,15 @@ main() { # convert flac to mp3 # it is the longest phase printf "\nPhase %02d of %02d: flac -> mp3\n" $((curphase++)) $phase - find $WORK -name '*.flac' | sort | parallel $BASEFILE --will-cite --ungroup --eta --progress --sshlogin $parallelopts $SCRIPTPATH/flactomp3v2 {} + + ConvertFlacToMp3 "$WORK" "$BASEFILE" "$parallelopts" "$SCRIPTPATH" + currentDate addInfo "flac -> mp3 finished

" # removing flac and cover.jpg printf "\nPhase %02d of %02d: remove flac's and cover's\n\n" $((curphase++)) $phase - find $WORK -name '*.flac' | sort | xargs rm - find $WORK -name 'cover*' | sort | xargs rm + CleanupFlacAndCovers "$WORK" # create sha256sum in working directory if [ $checksum == true ]; then @@ -123,7 +194,9 @@ main() { currentDate addInfo "create sha256sum is start
" printf "Phase %02d of %02d: create sha256sum\n\n" $((curphase++)) $phase - find $WORK -name '*.mp3' | sort | xargs sha256sum | sed "s=$WORK/==" >> $WORK/sha256sum + + MakeSha256CheckSum "$WORK" + currentDate addInfo "sha256sum is created

" fi @@ -132,16 +205,12 @@ main() { # content of zipfile is content of working directory if [ $mkzip == true ]; then printf "Phase %02d of %02d: create %s\n" $((curphase++)) $phase $zipname - if [[ ! $zipname =~ .zip ]]; then - zipname="${zipname}.zip" - fi addInfo "

" currentDate addInfo "create $zipname start
" - curpath=$(pwd) - cd $WORK - 7z a -bd -mmt=off -mm=Copy $curpath/$zipname . - cd $curpath + + MakeZipFile "$WORK" "$zipname" + printf "\n" currentDate addInfo "$zipname is created

" @@ -153,16 +222,16 @@ main() { addInfo "

" currentDate addInfo "copy from $WORK to $dest start
" - mkdir --parents $dest - cp --recursive $WORK/* $dest + + CopyWorkDirToDestDir "$WORK" "$dest" + currentDate addInfo "copy from $WORK to $dest finished

" fi # delete the working directory if ( [ $mkzip == true ] || [ $cptodest == true ] ) && [ $removework == true ]; then - printf "cleanup working directory\n\n" - rm --recursive $WORK + CleanupWorkDir "$WORK" fi addInfo "

" -- 2.47.3