Added flac-support
This commit is contained in:
parent
c50bcb3468
commit
dd6dbd898e
@ -11,6 +11,7 @@ bitrate=192
|
|||||||
help=false
|
help=false
|
||||||
temp="/tmp/converted"
|
temp="/tmp/converted"
|
||||||
convertart=false
|
convertart=false
|
||||||
|
noflac=false
|
||||||
coverartsize=200
|
coverartsize=200
|
||||||
|
|
||||||
CheckDeps() {
|
CheckDeps() {
|
||||||
@ -39,6 +40,17 @@ CheckDeps() {
|
|||||||
fi
|
fi
|
||||||
VerboseOutput 0 "\`lame --version\` succeeded"
|
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
|
# Check EyeD3
|
||||||
if [[ $convertart == true && ! $(eyeD3 --version 2>/dev/null) ]]; then
|
if [[ $convertart == true && ! $(eyeD3 --version 2>/dev/null) ]]; then
|
||||||
VerboseOutput 5 "\`eyeD3 --version\` failed"
|
VerboseOutput 5 "\`eyeD3 --version\` failed"
|
||||||
@ -67,8 +79,8 @@ CheckDeps() {
|
|||||||
GetOptions() {
|
GetOptions() {
|
||||||
|
|
||||||
# https://stackoverflow.com/a/29754866
|
# https://stackoverflow.com/a/29754866
|
||||||
OPTIONS=s:d:t:c::a::v::h
|
OPTIONS=s:d:t:c::a::v::hF
|
||||||
LONGOPTS=source:,dest:,temp:,convert::,resize-art::,verbose::,help
|
LONGOPTS=source:,dest:,temp:,convert::,resize-art::,verbose::,help,no-flac
|
||||||
|
|
||||||
# -use ! and PIPESTATUS to get exit code with errexit set
|
# -use ! and PIPESTATUS to get exit code with errexit set
|
||||||
# -temporarily store output to be able to check for errors
|
# -temporarily store output to be able to check for errors
|
||||||
@ -129,6 +141,12 @@ GetOptions() {
|
|||||||
VerboseOutput 1 "Converted bitrate is ${bitrate}"
|
VerboseOutput 1 "Converted bitrate is ${bitrate}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-F|--no-flac)
|
||||||
|
VerboseOutput 0 "--no-flac given"
|
||||||
|
noflac=true
|
||||||
|
VerboseOutput 1 "FLAC conversion is disabled"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-a|--resize-art)
|
-a|--resize-art)
|
||||||
VerboseOutput 0 "--resize-art given"
|
VerboseOutput 0 "--resize-art given"
|
||||||
convertart=true
|
convertart=true
|
||||||
@ -269,9 +287,11 @@ CreateFileList() {
|
|||||||
ConvertFiles() {
|
ConvertFiles() {
|
||||||
curline=0
|
curline=0
|
||||||
percentage=0
|
percentage=0
|
||||||
while read -r line
|
IFS="
|
||||||
|
";
|
||||||
|
for line in $(cat "/tmp/music-sync-filelist")
|
||||||
do
|
do
|
||||||
|
VerboseOutput 0 "${source}/$line"
|
||||||
if [[ ! -f "${source}/$line" ]]; then
|
if [[ ! -f "${source}/$line" ]]; then
|
||||||
VerboseOutput 5 "Source-file ${source}/$line Unreachable"
|
VerboseOutput 5 "Source-file ${source}/$line Unreachable"
|
||||||
ExecTime
|
ExecTime
|
||||||
@ -289,34 +309,42 @@ ConvertFiles() {
|
|||||||
VerboseOutput 0 "Creating folder $temp/${line%/*}"
|
VerboseOutput 0 "Creating folder $temp/${line%/*}"
|
||||||
mkdir -p "$temp/${line%/*}";
|
mkdir -p "$temp/${line%/*}";
|
||||||
fi;
|
fi;
|
||||||
if [[ ! -f "$temp/$line" || "${source}/$line" -nt "$temp/$line" ]]; then
|
mp3line=$(echo "$line" | sed -e 's/.flac/.mp3/')
|
||||||
VerboseOutput 0 "Converting MP3-file $temp/${line%/*}"
|
if [[ ! -f "$temp/$mp3line" || "${source}/$mp3line" -nt "$temp/$mp3line" ]]; then
|
||||||
lame -b ${bitrate} $source/$line $temp/$line 1>/dev/null 2>/dev/null
|
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
|
if [[ $convertart == true ]]; then
|
||||||
VerboseOutput 0 "Creating folder $temp/$line-images/"
|
VerboseOutput 0 "Creating folder $temp/${mp3line}-images/"
|
||||||
mkdir -p "$temp/$line-images/"
|
mkdir -p "$temp/${mp3line}-images/"
|
||||||
VerboseOutput 0 "Extracted albumart"
|
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"
|
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
|
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/$line" 1>/dev/null 2>/dev/null
|
eyeD3 --remove-all-images "$temp/${mp3line}" 1>/dev/null 2>/dev/null
|
||||||
VerboseOutput 0 "Embedding albumart"
|
VerboseOutput 0 "Embedding albumart"
|
||||||
eyeD3 --add-image "$temp/$line-images/FRONT_COVER.jpg:FRONT_COVER" "$temp/$line" 1>/dev/null 2>/dev/null
|
eyeD3 --add-image "$temp/${mp3line}-images/FRONT_COVER.jpg:FRONT_COVER" "$temp/${mp3line}" 1>/dev/null 2>/dev/null
|
||||||
VerboseOutput 1 "Converted cover art: $line"
|
VerboseOutput 1 "Converted cover art: ${mp3line}"
|
||||||
fi
|
fi
|
||||||
VerboseOutput 2 "Converted: $line"
|
VerboseOutput 2 "Converted: $line"
|
||||||
else
|
else
|
||||||
VerboseOutput 3 "$line already converted"
|
VerboseOutput 3 "$line already converted"
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
done < "/tmp/music-sync-filelist"
|
done
|
||||||
VerboseOutput 2 "Done converting files"
|
VerboseOutput 2 "Done converting files"
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyFiles() {
|
CopyFiles() {
|
||||||
curline=0
|
curline=0
|
||||||
percentage=0
|
percentage=0
|
||||||
while read -r line
|
IFS="
|
||||||
|
";
|
||||||
|
for line in $(cat "/tmp/music-sync-filelist")
|
||||||
do
|
do
|
||||||
if [[ ! -d "$dest" ]]; then
|
if [[ ! -d "$dest" ]]; then
|
||||||
VerboseOutput 5 "Destination unreachable"
|
VerboseOutput 5 "Destination unreachable"
|
||||||
@ -343,11 +371,11 @@ CopyFiles() {
|
|||||||
mkdir -p "$dest/${destline%/*}";
|
mkdir -p "$dest/${destline%/*}";
|
||||||
fi;
|
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"
|
VerboseOutput 2 "Copied: $line"
|
||||||
|
|
||||||
done < "/tmp/music-sync-filelist"
|
done
|
||||||
VerboseOutput 2 "Done copying files"
|
VerboseOutput 2 "Done copying files"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user