Always use ffmpeg

This commit is contained in:
Jeroen De Meerleer 2020-02-09 14:42:20 +01:00
parent dd6dbd898e
commit 535a75b04d

View File

@ -11,7 +11,6 @@ bitrate=192
help=false help=false
temp="/tmp/converted" temp="/tmp/converted"
convertart=false convertart=false
noflac=false
coverartsize=200 coverartsize=200
CheckDeps() { CheckDeps() {
@ -29,23 +28,12 @@ CheckDeps() {
fi fi
if [[ $1 == 1 ]]; then if [[ $1 == 1 ]]; then
# Check lame
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
VerboseOutput 0 "\`lame --version\` succeeded"
# Check ffmpeg # Check ffmpeg
if [[ $noflac == true && ! $(ffmpeg -h 2>/dev/null) ]]; then if [[ $convert == true && ! $(ffmpeg -h 2>/dev/null) ]]; then
VerboseOutput 5 "\`ffmpeg -h\` failed" VerboseOutput 5 "\`ffmpeg -h\` failed"
VerboseOutput 5 "Sorry, It seems that ffmpeg is not installed on your system" 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 "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" VerboseOutput 5 "Otherwise disable conversion"
ExecTime ExecTime
exit 1 exit 1
fi fi
@ -79,8 +67,8 @@ CheckDeps() {
GetOptions() { GetOptions() {
# https://stackoverflow.com/a/29754866 # https://stackoverflow.com/a/29754866
OPTIONS=s:d:t:c::a::v::hF OPTIONS=s:d:t:c::a::v::h
LONGOPTS=source:,dest:,temp:,convert::,resize-art::,verbose::,help,no-flac LONGOPTS=source:,dest:,temp:,convert::,resize-art::,verbose::,help
# -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
@ -141,12 +129,6 @@ 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
@ -265,6 +247,7 @@ CreateFileList() {
for file in $sourcepath; do for file in $sourcepath; do
origfile="${file#"$1/"}" origfile="${file#"$1/"}"
relfile=$(echo ${origfile} | sed -e 's/\(\.\)*$//g') relfile=$(echo ${origfile} | sed -e 's/\(\.\)*$//g')
mp3file=$(echo "${relfile}" | sed -e 's/.flac/.mp3/')
VerboseOutput 0 "Checking ${origfile}" VerboseOutput 0 "Checking ${origfile}"
if [[ -d "${1}/$origfile" ]]; then if [[ -d "${1}/$origfile" ]]; then
VerboseOutput 0 "${origfile} is folder" VerboseOutput 0 "${origfile} is folder"
@ -272,10 +255,11 @@ CreateFileList() {
newdir=${newdir#"/"} newdir=${newdir#"/"}
VerboseOutput 1 "Entering $newdir" VerboseOutput 1 "Entering $newdir"
CreateFileList "${1}/$origfile" "${2}/$relfile" "$newdir" CreateFileList "${1}/$origfile" "${2}/$relfile" "$newdir"
elif [[ "${1}/$origfile" != *".m3u" ]] && [[ ! -f "${2}/$origfile" || "${1}/$origfile" -nt "${2}/$relfile" ]]; then elif [[ "${1}/$origfile" != *".m3u" ]] && [[ "${1}/$origfile" -nt "${2}/$mp3file" ]]; then
echo ${3}/$origfile >> /tmp/music-sync-filelist echo ${3}/$origfile >> /tmp/music-sync-filelist
VerboseOutput 0 "${origfile} is newer in source" VerboseOutput 0 "${origfile} is newer in source"
VerboseOutput 2 "Added: ${3}/${origfile}" VerboseOutput 2 "Added: ${3}/${origfile}"
echo "${1}/$origfile newer then ${2}/$mp3file" >> /tmp/poot.txt
fi fi
if [[ "${1}/$origfile" == *".m3u" ]]; then if [[ "${1}/$origfile" == *".m3u" ]]; then
VerboseOutput 0 "${origfile} is playlist" VerboseOutput 0 "${origfile} is playlist"
@ -311,24 +295,27 @@ ConvertFiles() {
fi; fi;
mp3line=$(echo "$line" | sed -e 's/.flac/.mp3/') mp3line=$(echo "$line" | sed -e 's/.flac/.mp3/')
if [[ ! -f "$temp/$mp3line" || "${source}/$mp3line" -nt "$temp/$mp3line" ]]; then if [[ ! -f "$temp/$mp3line" || "${source}/$mp3line" -nt "$temp/$mp3line" ]]; then
if [[ $line == *".flac" ]]; then if [[ $line != *".mp3" ]]; then
VerboseOutput 0 "Converting FLAC-file $line to mp3" VerboseOutput 3 "${line} will be converted to mp3-file ${mp3line}"
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 fi
VerboseOutput 0 "Converting MP3-file $line"
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
if [[ $convertart == true ]]; then if [[ $convertart == true ]]; then
VerboseOutput 0 "Creating folder $temp/${mp3line}-images/" VerboseOutput 0 "Creating folder $temp/${mp3line}-images/"
mkdir -p "$temp/${mp3line}-images/" mkdir -p "$temp/${mp3line}-images/"
VerboseOutput 0 "Extracted albumart" VerboseOutput 0 "Extracted albumart"
eyeD3 --write-images "$temp/${mp3line}-images/" "$temp/${mp3line}" 1>/dev/null 2>/dev/null eyeD3 --write-images "$temp/${mp3line}-images/" "$temp/${mp3line}" 1>/dev/null 2>/dev/null
frontcovers=(${temp}/${mp3line}-images/FRONT_COVER.*)
if [ -e "$frontcovers" ]; then
VerboseOutput 0 "Converting albumart" VerboseOutput 0 "Converting albumart"
convert "$temp/${mp3line}-images/FRONT_COVER.*" -resize ${coverartsize}x${coverartsize} "$temp/${mp3line}-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/${mp3line}" 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/${mp3line}-images/FRONT_COVER.jpg:FRONT_COVER" "$temp/${mp3line}" 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: ${mp3line}" VerboseOutput 1 "Converted cover art: ${mp3line}"
else
VerboseOutput 4 "No front cover art found for ${mp3line}"
fi
fi fi
VerboseOutput 2 "Converted: $line" VerboseOutput 2 "Converted: $line"
else else
@ -352,8 +339,14 @@ CopyFiles() {
exit 4 exit 4
fi fi
if [[ ! -f "${temp}/$line" ]]; then if [[ $convert == true ]]; then
VerboseOutput 5 "Source-file ${temp}/$line Unreachable" mp3line=$(echo "$line" | sed -e 's/.flac/.mp3/')
else
mp3line=$(echo "$line")
fi
if [[ ! -f "${temp}/$mp3line" ]]; then
VerboseOutput 5 "Source-file ${temp}/$mp3line Unreachable"
ExecTime ExecTime
exit 3 exit 3
fi fi
@ -362,7 +355,7 @@ CopyFiles() {
total=$(cat /tmp/music-sync-filelist | wc -l) total=$(cat /tmp/music-sync-filelist | wc -l)
percentage=$(echo "scale=4;${curline}/${total}" | bc) percentage=$(echo "scale=4;${curline}/${total}" | bc)
percentage=$(echo "scale=2;${percentage}*100" | bc) percentage=$(echo "scale=2;${percentage}*100" | bc)
destline=$(echo $line | sed -e 's/\.*\//\//g') destline=$(echo $mp3line | sed -e 's/\.*\//\//g')
VerboseOutput 1 "Copying: $line" VerboseOutput 1 "Copying: $line"
VerboseOutput 2 "Progress: $curline / $total (${percentage%00}%) Step 2 of 2" VerboseOutput 2 "Progress: $curline / $total (${percentage%00}%) Step 2 of 2"
@ -371,7 +364,7 @@ CopyFiles() {
mkdir -p "$dest/${destline%/*}"; mkdir -p "$dest/${destline%/*}";
fi; fi;
cp -f $temp/$line $dest/${destline/.flac/.mp3} 1>/dev/null 2>/dev/null cp -f $temp/$mp3line $dest/${destline} 1>/dev/null 2>/dev/null
VerboseOutput 2 "Copied: $line" VerboseOutput 2 "Copied: $line"