Added posibility to not convert

This commit is contained in:
Jeroen De Meerleer 2018-12-01 18:40:13 +01:00
parent 3d108ecf7f
commit 4aee64d3fe
2 changed files with 39 additions and 19 deletions

View File

@ -15,6 +15,7 @@ Options:
-s, --source <source> The source folder of the music
-d, --dest <destination> The destionation folder of the music
-t, --temp <folder> The temporary cache for converted files (default: /tmp/converted)
-c, --convert Convert files before syncing
-v, --verbose <0-6> Set log level (default: 2)
-h, --help Display this help text

View File

@ -5,11 +5,13 @@ begin=$(date +"%s")
set -o errexit -o pipefail -o noclobber -o nounset
source="-"
dest="-"
convert=false
verbose=2
help=false
temp="/tmp/converted"
CheckDeps() {
if [[ $1 == 0 ]]; then
# Check getopt
! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
@ -19,22 +21,26 @@ CheckDeps() {
ExecTime
exit 1
fi
fi
if [[ $1 == 1 ]]; then
# Check lame
if [[ ! $(lame --version 2>/dev/null) ]]; then
echo $convert
if [[ $convert == true && ! $(lamek --version 2>/dev/null) ]]; then
VerboseOutput 5 "\`lame --version\` failed"
VerboseOutput 5 "Sorry, It seems that lame is not installed on your system"
VerboseOutput 5 "Please install lame from your repositories and make sure it is available in your \$PATH"
ExecTime
exit 1
fi
fi
}
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=s:d:t:v::h
LONGOPTS=source:,dest:,temp:,verbose::,help
OPTIONS=s:d:t:cv::h
LONGOPTS=source:,dest:,temp:,convert,verbose::,help
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -78,6 +84,10 @@ GetOptions() {
temp="$2"
shift 2
;;
-c|--convert)
convert=true
shift
;;
--)
shift
break
@ -114,6 +124,7 @@ Usage() {
echo " -s, --source <source> The source folder of the music"
echo " -d, --dest <destination> The destionation folder of the music"
echo " -t, --temp <folder> The temporary cache for converted files (default: /tmp/converted)"
echo " -c, --convert Convert files before syncing"
echo " -v, --verbose <0-6> Set log level (default: 2)"
echo " -h, --help Display this help text"
echo ""
@ -281,8 +292,9 @@ ExitHandler() {
trap 'ExitHandler' SIGINT
trap 'ErrorHandler $BASH_COMMAND' ERR
CheckDeps
CheckDeps 0
GetOptions $@
CheckDeps 1
if [[ $help == true ]]; then
Usage
exit
@ -296,7 +308,14 @@ if [[ ! -f /tmp/music-sync-filelist ]]; then
CleanUp
exit 0
fi
if [[ $convert == true ]]; then
ConvertFiles
else
if [[ $temp != "/tmp/converted" ]]; then
VerboseOutput 2 "Conversion not enabled. Ignoring cache folder"
fi
temp=$source
fi
CopyFiles
CleanUp
ExecTime