Compare commits

...

5 Commits

1 changed files with 26 additions and 19 deletions

View File

@ -7,6 +7,7 @@ source="-"
dest="-"
convert=false
verbose=2
bitrate=192
help=false
temp="/tmp/converted"
convertart=false
@ -37,17 +38,17 @@ CheckDeps() {
# Check EyeD3
if [[ $convertart == true && ! $(eyeD3 --version 2>/dev/null) ]]; then
VerboseOutput 5 "\`eyeD3 --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"
VerboseOutput 5 "Sorry, It seems that eyeD3 is not installed on your system"
VerboseOutput 5 "Please install eyeD3 from your repositories and make sure it is available in your \$PATH"
VerboseOutput 5 "Otherwise disable albumart conversion"
ExecTime
exit 1
fi
# Check Imagemagick
# Check ImageMagick
if [[ $convertart == true && ! $(convert --version 2>/dev/null) ]]; then
VerboseOutput 5 "\`convert --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"
VerboseOutput 5 "Sorry, It seems that ImageMagick is not installed on your system"
VerboseOutput 5 "Please install ImageMagick from your repositories and make sure it is available in your \$PATH"
VerboseOutput 5 "Otherwise disable albumart conversion"
ExecTime
exit 1
@ -58,8 +59,8 @@ CheckDeps() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=s:d:t:cav::h
LONGOPTS=source:,dest:,temp:,convert,convert-art,verbose::,help
OPTIONS=s:d:t:cab:v::h
LONGOPTS=source:,dest:,temp:,convert,convert-art,bitrate:,verbose::,help
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -111,6 +112,10 @@ GetOptions() {
convertart=true
shift
;;
-b|--bitrate)
bitrate="$2"
shift 2
;;
--)
shift
break
@ -148,7 +153,8 @@ Usage() {
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 " -a, --convert-art Convert files before syncing"
echo " -a, --convert-art Convert album-art before syncing"
echo " -b, --bitrate When converting use this bitrate"
echo " -v, --verbose <0-6> Set log level (default: 2)"
echo " -h, --help Display this help text"
echo ""
@ -206,13 +212,14 @@ CreateFileList() {
sourcepath="${1/\[/\\\[}/*"
sourcepath="${sourcepath/\]/\\\]}"
for file in $sourcepath; do
relfile="${file#"$1/"}"
if [[ -d "${1}/$relfile" ]]; then
origfile="${file#"$1/"}"
relfile=$(echo ${origfile} | sed -e 's/\(\.\)*$//g')
if [[ -d "${1}/$origfile" ]]; then
newdir="${3}/$relfile"
newdir=${newdir#"/"}
VerboseOutput 1 "Entering $newdir"
CreateFileList "${1}/$relfile" "${2}/$relfile" "$newdir"
elif [[ ! -f "${2}/$relfile" || "${1}/$relfile" -nt "${2}/$relfile" ]]; then
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}"
fi
@ -242,15 +249,15 @@ ConvertFiles() {
mkdir -p "$temp/${line%/*}";
fi;
if [[ ! -f "$temp/$line" || "${source}/$line" -nt "$temp/$line" ]]; then
lame -b 192 $source/$line $temp/$line 1>/dev/null 2>/dev/null
lame -b ${bitrate} $source/$line $temp/$line 1>/dev/null 2>/dev/null
VerboseOutput 2 "Converted: $line"
if [[ $convertart == true ]]; then
mkdir "$temp/$line-images/"
eyeD3 --write-images "$temp/$line-images/" "$temp/$line"
convert "$temp/$line-images/FRONT_COVER.jpg" -resize 200x200 "$temp/$line-images/FRONT_COVER.jpg"
eyeD3 --remove-all-images "$temp/$line"
eyeD3 --add-image "$temp/$line-images/FRONT_COVER.jpg:FRONT_COVER" "$temp/$line"
VerboseOutput 2 "Converted cover art: $temp/$line"
mkdir -p "$temp/$line-images/"
eyeD3 --write-images "$temp/$line-images/" "$temp/$line" 1>/dev/null 2>/dev/null
convert "$temp/$line-images/FRONT_COVER.*" -resize 200x200 "$temp/$line-images/FRONT_COVER.jpg" 1>/dev/null 2>/dev/null
eyeD3 --remove-all-images "$temp/$line" 1>/dev/null 2>/dev/null
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"
fi
else