Added flac-support

This commit is contained in:
Jeroen De Meerleer 2020-02-08 13:50:50 +01:00
parent c50bcb3468
commit dd6dbd898e

View File

@ -11,6 +11,7 @@ bitrate=192
help=false
temp="/tmp/converted"
convertart=false
noflac=false
coverartsize=200
CheckDeps() {
@ -39,6 +40,17 @@ CheckDeps() {
fi
VerboseOutput 0 "\`lame --version\` succeeded"
# Check ffmpeg
if [[ $noflac == true && ! $(ffmpeg -h 2>/dev/null) ]]; then
VerboseOutput 5 "\`ffmpeg -h\` failed"
VerboseOutput 5 "Sorry, It seems that ffmpeg is not installed on your system"
VerboseOutput 5 "Please install ffmpeg from your repositories and make sure it is available in your \$PATH"
VerboseOutput 5 "If you don't have any FLAC-files use --no-flac"
ExecTime
exit 1
fi
VerboseOutput 0 "\`ffmpeg -h\` succeeded"
# Check EyeD3
if [[ $convertart == true && ! $(eyeD3 --version 2>/dev/null) ]]; then
VerboseOutput 5 "\`eyeD3 --version\` failed"
@ -67,8 +79,8 @@ CheckDeps() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=s:d:t:c::a::v::h
LONGOPTS=source:,dest:,temp:,convert::,resize-art::,verbose::,help
OPTIONS=s:d:t:c::a::v::hF
LONGOPTS=source:,dest:,temp:,convert::,resize-art::,verbose::,help,no-flac
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -129,6 +141,12 @@ GetOptions() {
VerboseOutput 1 "Converted bitrate is ${bitrate}"
shift
;;
-F|--no-flac)
VerboseOutput 0 "--no-flac given"
noflac=true
VerboseOutput 1 "FLAC conversion is disabled"
shift
;;
-a|--resize-art)
VerboseOutput 0 "--resize-art given"
convertart=true
@ -269,9 +287,11 @@ CreateFileList() {
ConvertFiles() {
curline=0
percentage=0
while read -r line
IFS="
";
for line in $(cat "/tmp/music-sync-filelist")
do
VerboseOutput 0 "${source}/$line"
if [[ ! -f "${source}/$line" ]]; then
VerboseOutput 5 "Source-file ${source}/$line Unreachable"
ExecTime
@ -289,34 +309,42 @@ ConvertFiles() {
VerboseOutput 0 "Creating folder $temp/${line%/*}"
mkdir -p "$temp/${line%/*}";
fi;
if [[ ! -f "$temp/$line" || "${source}/$line" -nt "$temp/$line" ]]; then
VerboseOutput 0 "Converting MP3-file $temp/${line%/*}"
lame -b ${bitrate} $source/$line $temp/$line 1>/dev/null 2>/dev/null
mp3line=$(echo "$line" | sed -e 's/.flac/.mp3/')
if [[ ! -f "$temp/$mp3line" || "${source}/$mp3line" -nt "$temp/$mp3line" ]]; then
if [[ $line == *".flac" ]]; then
VerboseOutput 0 "Converting FLAC-file $line to mp3"
ffmpeg -y -i "$source/$line" -acodec libmp3lame -map_metadata 0 -id3v2_version 3 -b:a ${bitrate}k "$temp/${mp3line}" 1>/dev/null 2>/dev/null
else
VerboseOutput 0 "Converting MP3-file $line"
lame -b ${bitrate} "$source/$line" "$temp/$mp3line" 1>/dev/null 2>/dev/null
fi
if [[ $convertart == true ]]; then
VerboseOutput 0 "Creating folder $temp/$line-images/"
mkdir -p "$temp/$line-images/"
VerboseOutput 0 "Creating folder $temp/${mp3line}-images/"
mkdir -p "$temp/${mp3line}-images/"
VerboseOutput 0 "Extracted albumart"
eyeD3 --write-images "$temp/$line-images/" "$temp/$line" 1>/dev/null 2>/dev/null
eyeD3 --write-images "$temp/${mp3line}-images/" "$temp/${mp3line}" 1>/dev/null 2>/dev/null
VerboseOutput 0 "Converting albumart"
convert "$temp/$line-images/FRONT_COVER.*" -resize ${coverartsize}x${coverartsize} "$temp/$line-images/FRONT_COVER.jpg" 1>/dev/null 2>/dev/null
eyeD3 --remove-all-images "$temp/$line" 1>/dev/null 2>/dev/null
convert "$temp/${mp3line}-images/FRONT_COVER.*" -resize ${coverartsize}x${coverartsize} "$temp/${mp3line}-images/FRONT_COVER.jpg" 1>/dev/null 2>/dev/null
eyeD3 --remove-all-images "$temp/${mp3line}" 1>/dev/null 2>/dev/null
VerboseOutput 0 "Embedding albumart"
eyeD3 --add-image "$temp/$line-images/FRONT_COVER.jpg:FRONT_COVER" "$temp/$line" 1>/dev/null 2>/dev/null
VerboseOutput 1 "Converted cover art: $line"
eyeD3 --add-image "$temp/${mp3line}-images/FRONT_COVER.jpg:FRONT_COVER" "$temp/${mp3line}" 1>/dev/null 2>/dev/null
VerboseOutput 1 "Converted cover art: ${mp3line}"
fi
VerboseOutput 2 "Converted: $line"
else
VerboseOutput 3 "$line already converted"
fi;
done < "/tmp/music-sync-filelist"
done
VerboseOutput 2 "Done converting files"
}
CopyFiles() {
curline=0
percentage=0
while read -r line
IFS="
";
for line in $(cat "/tmp/music-sync-filelist")
do
if [[ ! -d "$dest" ]]; then
VerboseOutput 5 "Destination unreachable"
@ -343,11 +371,11 @@ CopyFiles() {
mkdir -p "$dest/${destline%/*}";
fi;
cp -f $temp/$line $dest/$destline 1>/dev/null 2>/dev/null
cp -f $temp/$line $dest/${destline/.flac/.mp3} 1>/dev/null 2>/dev/null
VerboseOutput 2 "Copied: $line"
done < "/tmp/music-sync-filelist"
done
VerboseOutput 2 "Done copying files"
}