#!/bin/bash
-# work is a directory do symlinked original and convert
+# working directory
work="$(pwd)/work.$$"
-# scriptpath is the path to flactomp3v2.sh script
+# path to flactomp3v2.sh script
scriptpath="/tmp/scripts"
-# musicpath is collection directory
+# collection directory
musicpath="/tmp/musikpath"
+
+# Check exist config and script is exists
+# config file can set scriptpath and musicpath
if [ -f $HOME/.albumtohandy.conf ]
then
source $HOME/.albumtohandy.conf
printf "\nERROR\nflactomp3v2.sh do not found in %s\n" $scriptpath
exit 1
fi
+
+# set defaults
albumlist="albumlist"
parallelopts=":"
curphase=1
removework=false
cptodest=false
+# read parameters
while getopts ":ci:m:S::rz:" optname
do
case "$optname" in
esac
done
+# check albumlist is set
if [ ! -f "$albumlist" ]
then
printf "\nalbumlist does not exists\n\n"
exit
fi
-printf "\nPhase %02d of %02d: create symlinks of flac's to working directory %s\n" $((curphase++)) $phase "$work"
-
+# create working directory
if [ ! -d $work ]
then
mkdir $work
fi
# make symlinks of original flac's
+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 -rs $musicpath/$i $work/
done
+# 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 --eta --progress --noswap -S $parallelopts $scriptpath/flactomp3v2.sh {}
+# 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
printf "Phase %02d of %02d: create sha256sum\n\n" $((curphase++)) $phase
find $work -name '*.mp3' | sort | xargs sha256sum | sed "s=$work/==" >> $work/sha256sum
fi
+
+# make zipfile in the current path
if [ $mkzip == true ]
then
printf "Phase %02d of %02d: create %s\n" $((curphase++)) $phase $zipname
cd $curpath
printf "\n"
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
fi
cp -r $work/* $dest
fi
+
+# delete the working directory
if ( [ $mkzip == true ] || [ $cptodest == true ] ) && [ $removework == true ]
then
printf "cleanup working directory\n\n"