Added option to convert coverart

This commit is contained in:
Jeroen De Meerleer 2018-12-05 15:37:27 +01:00
parent 4aee64d3fe
commit 493cb40ffd
2 changed files with 42 additions and 4 deletions

View File

@ -17,6 +17,7 @@ Options:
-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)
-a, --convert-art Convert files before syncing
-h, --help Display this help text
Log levels:

View File

@ -9,6 +9,7 @@ convert=false
verbose=2
help=false
temp="/tmp/converted"
convertart=false
CheckDeps() {
if [[ $1 == 0 ]]; then
@ -25,11 +26,29 @@ CheckDeps() {
if [[ $1 == 1 ]]; then
# Check lame
echo $convert
if [[ $convert == true && ! $(lamek --version 2>/dev/null) ]]; then
if [[ $convert == true && ! $(lame --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"
VerboseOutput 5 "Otherwise disable conversion"
ExecTime
exit 1
fi
# 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 "Otherwise disable albumart conversion"
ExecTime
exit 1
fi
# 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 "Otherwise disable albumart conversion"
ExecTime
exit 1
fi
@ -39,8 +58,12 @@ CheckDeps() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=s:d:t:cv::h
LONGOPTS=source:,dest:,temp:,convert,verbose::,help
OPTIONS=s:d:t:cav::h
LONGOPTS=source:,dest:,temp:,convert,convert-art,verbose::,help
# Parsing style without -s or -d
source=${*: -2:1}
dest=${*: -1:1}
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -88,6 +111,10 @@ GetOptions() {
convert=true
shift
;;
-a|--convert-art)
convertart=true
shift
;;
--)
shift
break
@ -125,6 +152,7 @@ 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 " -v, --verbose <0-6> Set log level (default: 2)"
echo " -h, --help Display this help text"
echo ""
@ -220,6 +248,15 @@ ConvertFiles() {
if [[ ! -f "$temp/$line" || "${source}/$line" -nt "$temp/$line" ]]; then
lame -b 192 $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"
fi
else
VerboseOutput 3 "$line already converted"
fi;