From: Bastian Dehn Date: Tue, 17 Jan 2017 20:41:00 +0000 (+0100) Subject: change: bash conventionen X-Git-Tag: v1.0.0^2~115 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=5681f6a5943548c31658363bfb7d72285ddefdad;p=albentohandy.git change: bash conventionen syntax better read remove: file extensions --- diff --git a/Makefile b/Makefile index de646e5..8fe9b70 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,10 @@ MANPATH=/usr/share/man/de/man1 BINPATH=/usr/bin install: - cp albentohandy.sh $(BINPATH)/albentohandy.sh - chmod 755 $(BINPATH)/albentohandy.sh - cp flactomp3v2.sh $(BINPATH)/flactomp3v2.sh - chmod 755 $(BINPATH)/flactomp3v2.sh + cp albentohandy $(BINPATH)/albentohandy + chmod 755 $(BINPATH)/albentohandy + cp flactomp3v2 $(BINPATH)/flactomp3v2 + chmod 755 $(BINPATH)/flactomp3v2 cp man/albentohandy.1 $(MANPATH)/albentohandy.1 cp notify.sh $(BINPATH)/notify.sh chmod 755 $(BINPATH)/notify.sh @@ -15,8 +15,8 @@ install: cp man/flactomp3v2.conf.1 $(MANPATH)/flactomp3v2.conf.1 gzip $(MANPATH)/flactomp3v2.conf.1 uninstall: - rm $(BINPATH)/albentohandy.sh - rm $(BINPATH)/flactomp3v2.sh + rm $(BINPATH)/albentohandy + rm $(BINPATH)/flactomp3v2 rm $(BINPATH)/notify.sh rm $(MANPATH)/albentohandy.1.gz rm $(MANPATH)/albentohandy.conf.1.gz diff --git a/albentohandy b/albentohandy new file mode 100755 index 0000000..98d8fd3 --- /dev/null +++ b/albentohandy @@ -0,0 +1,169 @@ +#!/bin/bash + +work="$(pwd)/work.$$" # temporary working directory +scriptpath="/usr/bin" # path to flactomp3v2 and notify.sh script +musicpath="/tmp/musikpath" # flac collection directory + +# check exist config and scripts +# .albentohandy.conf: set scriptpath and musicpath +if [ -f $HOME/.albentohandy.conf ]; then + source $HOME/.albentohandy.conf +else + printf "\nERROR\n%s/.albentohandy.conf does not exists\n" $HOME + exit 1 +fi +# flactomp3v2: convert flac's to mp3 +if [ ! -f $scriptpath/flactomp3v2 ]; then + printf "\nERROR\nflactomp3v2 do not found in %s\n" $scriptpath + exit 1 +fi +# notify.sh: functions send email +if [ ! -f $scriptpath/notify.sh ]; then + printf "\nERROR\nnotify.sh do not found in %s\n" $scriptpath + exit 1 +else + source $scriptpath/notify.sh +fi + +# set defaults +albumlist="albumlist" +parallelopts=":" +curphase=1 +phase=3 +checksum=false +mkzip=false +removework=false +cptodest=false + +# in cluster you have to same bitrate and +# stereo mode of mp3's on every pc. +# read more about basefile in man parallel +if [ -f $HOME/.flactomp3v2.conf ]; then + BASEFILE="--basefile $HOME/.flactomp3v2.conf --cleanup" +fi + +# read parameters +while getopts ":ci:m:S::rw:z:" optname; do + case "$optname" in + "c") + checksum=true + ((phase++)) + ;; + "i") + albumlist="$OPTARG" + ;; + "m") + cptodest=true + dest="$OPTARG" + ((phase++)) + ;; + "S") + parallelopts="$OPTARG" + ;; + "r") + removework=true + ;; + "w") + work="$OPTARG" + ;; + "z") + mkzip=true + zipname="$OPTARG" + ((phase++)) + ;; + esac +done + +# check albumlist is set +if [ ! -f "$albumlist" ]; then + printf "\nalbumlist does not exists\n\n" + exit +fi + +# create working directory +if [ ! -d $work ]; then + mkdir $work +fi + +openMail +addInfo "

" +currentDate +addInfo "albentohandy.sh is started

" +addInfo "

Foldende Alben wurden ausgewählt:

" +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 + +addInfo "

" +currentDate +addInfo "flac -> mp3 start
" +# 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 --eta --progress --noswap --sshlogin $parallelopts $scriptpath/flactomp3v2 {} +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 + +# create sha256sum in working directory +if [ $checksum == true ]; then + addInfo "

" + 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 + currentDate + addInfo "sha256sum is created

" +fi + +# make zipfile in the current path +# 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 + printf "\n" + currentDate + addInfo "$zipname is created

" +fi + +# copy work directory to destination folder +if [ $cptodest == true ]; then + printf "Phase %02d of %02d: copy %s/ to destination %s\n\n" $((curphase++)) $phase $work $dest + addInfo "

" + currentDate + addInfo "copy from $work to $dest start
" + mkdir --parents $dest + cp --recursive $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 +fi + +addInfo "

" +currentDate +addInfo "send email

" +closeMail +sendEmail + +exit 0 diff --git a/albentohandy.sh b/albentohandy.sh deleted file mode 100755 index 245a031..0000000 --- a/albentohandy.sh +++ /dev/null @@ -1,185 +0,0 @@ -#!/bin/bash - -work="$(pwd)/work.$$" # temporary working directory -scriptpath="/usr/bin" # path to flactomp3v2.sh and notify.sh script -musicpath="/tmp/musikpath" # flac collection directory - -# check exist config and scripts -# .albentohandy.conf: set scriptpath and musicpath -if [ -f $HOME/.albentohandy.conf ] -then - source $HOME/.albentohandy.conf -else - printf "\nERROR\n%s/.albentohandy.conf does not exists\n" $HOME - exit 1 -fi -# flactomp3v2.sh: convert flac's to mp3 -if [ ! -f $scriptpath/flactomp3v2.sh ] -then - printf "\nERROR\nflactomp3v2.sh do not found in %s\n" $scriptpath - exit 1 -fi -# notify.sh: functions send email -if [ ! -f $scriptpath/notify.sh ] -then - printf "\nERROR\nnotify.sh do not found in %s\n" $scriptpath - exit 1 -else - source $scriptpath/notify.sh -fi - -# set defaults -albumlist="albumlist" -parallelopts=":" -curphase=1 -phase=3 -checksum=false -mkzip=false -removework=false -cptodest=false - -# in cluster you have to same bitrate and -# stereo mode of mp3's on every pc. -# read more about basefile in man parallel -if [ -f $HOME/.flactomp3v2.conf ] -then - BASEFILE="--basefile $HOME/.flactomp3v2.conf --cleanup" -fi - -# read parameters -while getopts ":ci:m:S::rw:z:" optname -do - case "$optname" in - "c") - checksum=true - ((phase++)) - ;; - "i") - albumlist="$OPTARG" - ;; - "m") - cptodest=true - dest="$OPTARG" - ((phase++)) - ;; - "S") - parallelopts="$OPTARG" - ;; - "r") - removework=true - ;; - "w") - work="$OPTARG" - ;; - "z") - mkzip=true - zipname="$OPTARG" - ((phase++)) - ;; - esac -done - -# check albumlist is set -if [ ! -f "$albumlist" ] -then - printf "\nalbumlist does not exists\n\n" - exit -fi - -# create working directory -if [ ! -d $work ] -then - mkdir $work -fi - -openMail -addInfo "

" -currentDate -addInfo "albentohandy.sh is started

" -addInfo "

Foldende Alben wurden ausgewählt:

" -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 - -addInfo "

" -currentDate -addInfo "flac -> mp3 start
" -# 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 --eta --progress --noswap --sshlogin $parallelopts $scriptpath/flactomp3v2.sh {} -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 - -# create sha256sum in working directory -if [ $checksum == true ] -then - addInfo "

" - 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 - currentDate - addInfo "sha256sum is created

" -fi - -# make zipfile in the current path -# 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 - printf "\n" - currentDate - addInfo "$zipname is created

" -fi - -# copy work directory to destination folder -if [ $cptodest == true ] -then - printf "Phase %02d of %02d: copy %s/ to destination %s\n\n" $((curphase++)) $phase $work $dest - addInfo "

" - currentDate - addInfo "copy from $work to $dest start
" - if [ ! -d $dest ] - then - mkdir --parents $dest - fi - cp -r $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 -fi - -addInfo "

" -currentDate -addInfo "send email

" -closeMail -sendEmail - -exit 0 diff --git a/flactomp3v2 b/flactomp3v2 new file mode 100755 index 0000000..5dd73c5 --- /dev/null +++ b/flactomp3v2 @@ -0,0 +1,48 @@ +#!/bin/bash + +# Default options +BITRATE=192 +MODE="j" + +# check config exists +# config .flactomp3v2.conf can set BITRATE and MODE +if [ -f $HOME/.flactomp3v2.conf ]; then + source $HOME/.flactomp3v2.conf +fi + +INPUTFILE=$1 +OUTPUTFILE="${INPUTFILE[@]/%flac/mp3}" # give output correct extension + +# get the tags from flac file +ARTIST=$(metaflac "$INPUTFILE" --show-tag=ARTIST | sed s/.*=//g) +TITLE=$(metaflac "$INPUTFILE" --show-tag=TITLE | sed s/.*=//g) +ALBUM=$(metaflac "$INPUTFILE" --show-tag=ALBUM | sed s/.*=//g) +GENRE=$(metaflac "$INPUTFILE" --show-tag=GENRE | sed s/.*=//g) +TRACKNUMBER=$(metaflac "$INPUTFILE" --show-tag=TRACKNUMBER | sed s/.*=//g) +DATE=$(metaflac "$INPUTFILE" --show-tag=DATE | sed s/.*=//g) +RRL=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_REFERENCE_LOUDNESS | sed s/.*=//g) +RTG=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_TRACK_GAIN | sed s/.*=//g) +RTP=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_TRACK_PEAK | sed s/.*=//g) +RAG=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_ALBUM_GAIN | sed s/.*=//g) +RAP=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_ALBUM_PEAK | sed s/.*=//g) + +# ID3v2.3 tagging with cover and without cover +eyed3Command="eyeD3 --v2 --to-v2.3 \ +--artist=\"$ARTIST\" --title=\"$TITLE\" --album=\"$ALBUM\" --genre=\"${GENRE:-12}\" \ +--track=\"${TRACKNUMBER:-0}\" --year=\"$DATE\" \ +--set-user-text-frame=\"REPLAYGAIN_REFERENCE_LOUDNESS:$RRL\" \ +--set-user-text-frame=\"REPLAYGAIN_TRACK_GAIN:$RTG\" \ +--set-user-text-frame=\"REPLAYGAIN_TRACK_PEAK:$RTP\" \ +--set-user-text-frame=\"REPLAYGAIN_ALBUM_GAIN:$RAG\" \ +--set-user-text-frame=\"REPLAYGAIN_ALBUM_PEAK:$RAP\"" +if [ -f ${INPUTFILE%/*}/cover.jpg ]; then + eyed3Command+=" --add-image=\"${INPUTFILE%/*}/cover.jpg\":FRONT_COVER" +fi +eyed3Command+=" --no-tagging-time-frame \ +\"$OUTPUTFILE\" > /dev/null 2>&1" + +# stream flac into the lame encoder +nice --adjustment=2 flac --silent --stdout --decode "$INPUTFILE" | nice --adjustment=3 lame --silent -b $BITRATE -m $MODE --noreplaygain - "$OUTPUTFILE" +eval $eyed3Command + +exit 0 diff --git a/flactomp3v2.sh b/flactomp3v2.sh deleted file mode 100755 index f16c721..0000000 --- a/flactomp3v2.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -# Default options -BITRATE=192 -MODE="j" - -# check config exists -# config .flactomp3v2.conf can set BITRATE and MODE -if [ -f $HOME/.flactomp3v2.conf ] -then - source $HOME/.flactomp3v2.conf -fi - -INPUTFILE=$1 -OUTPUTFILE="${INPUTFILE[@]/%flac/mp3}" # give output correct extension - -# get the tags from flac file -ARTIST=$(metaflac "$INPUTFILE" --show-tag=ARTIST | sed s/.*=//g) -TITLE=$(metaflac "$INPUTFILE" --show-tag=TITLE | sed s/.*=//g) -ALBUM=$(metaflac "$INPUTFILE" --show-tag=ALBUM | sed s/.*=//g) -GENRE=$(metaflac "$INPUTFILE" --show-tag=GENRE | sed s/.*=//g) -TRACKNUMBER=$(metaflac "$INPUTFILE" --show-tag=TRACKNUMBER | sed s/.*=//g) -DATE=$(metaflac "$INPUTFILE" --show-tag=DATE | sed s/.*=//g) -RRL=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_REFERENCE_LOUDNESS | sed s/.*=//g) -RTG=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_TRACK_GAIN | sed s/.*=//g) -RTP=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_TRACK_PEAK | sed s/.*=//g) -RAG=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_ALBUM_GAIN | sed s/.*=//g) -RAP=$(metaflac "$INPUTFILE" --show-tag=REPLAYGAIN_ALBUM_PEAK | sed s/.*=//g) - -# ID3v2.3 tagging with cover and without cover -eyed3Command="eyeD3 --v2 --to-v2.3 \ ---artist=\"$ARTIST\" --title=\"$TITLE\" --album=\"$ALBUM\" --genre=\"${GENRE:-12}\" \ ---track=\"${TRACKNUMBER:-0}\" --year=\"$DATE\" \ ---set-user-text-frame=\"REPLAYGAIN_REFERENCE_LOUDNESS:$RRL\" \ ---set-user-text-frame=\"REPLAYGAIN_TRACK_GAIN:$RTG\" \ ---set-user-text-frame=\"REPLAYGAIN_TRACK_PEAK:$RTP\" \ ---set-user-text-frame=\"REPLAYGAIN_ALBUM_GAIN:$RAG\" \ ---set-user-text-frame=\"REPLAYGAIN_ALBUM_PEAK:$RAP\"" -if [ -f ${INPUTFILE%/*}/cover.jpg ] -then - eyed3Command+=" --add-image=\"${INPUTFILE%/*}/cover.jpg\":FRONT_COVER" -fi -eyed3Command+=" --no-tagging-time-frame \ -\"$OUTPUTFILE\" > /dev/null 2>&1" - -# stream flac into the lame encoder -nice --adjustment=2 flac --silent --stdout --decode "$INPUTFILE" | nice --adjustment=3 lame --silent -b $BITRATE -m $MODE --noreplaygain - "$OUTPUTFILE" -eval $eyed3Command - -exit 0 diff --git a/notify.sh b/notify.sh index fefbe15..aab8d13 100755 --- a/notify.sh +++ b/notify.sh @@ -7,8 +7,7 @@ MESSAGE="" # load all parameters to sendemail over smtp # NOTIFY; FROMADDRESS; TOADDRESS; STMP; SMPTUSERNAME; SMTPPASSWORD(base64) -if [ ! -f $HOME/.albentohandy.conf ] -then +if [ ! -f $HOME/.albentohandy.conf ]; then printf "\nERROR\n.albentohandy.conf does not exist\n" exit 1 else @@ -18,8 +17,7 @@ fi # send email to notify user sendEmail() { -if [ $NOTIFY == true ] -then +if [ $NOTIFY == true ]; then sendemail -f $FROMADDRESS -t $TOADDRESS \ -s $SMTP -xu $SMTPUSERNAME -xp $(echo $SMTPPASSWORD | base64 --decode) -o tls=yes \ -u "albentohandy" -o message-content-type=html -m "$MESSAGE"