diff --git a/music-sync.sh b/music-sync.sh index 730d2d6..c2a8cf1 100755 --- a/music-sync.sh +++ b/music-sync.sh @@ -11,7 +11,6 @@ bitrate=192 help=false temp="/tmp/converted" convertart=false -noflac=false coverartsize=200 CheckDeps() { @@ -29,23 +28,12 @@ CheckDeps() { fi 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 - 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 "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" + VerboseOutput 5 "Otherwise disable conversion" ExecTime exit 1 fi @@ -79,8 +67,8 @@ CheckDeps() { GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS=s:d:t:c::a::v::hF - LONGOPTS=source:,dest:,temp:,convert::,resize-art::,verbose::,help,no-flac + OPTIONS=s:d:t:c::a::v::h + LONGOPTS=source:,dest:,temp:,convert::,resize-art::,verbose::,help # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -141,12 +129,6 @@ 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 @@ -265,6 +247,7 @@ CreateFileList() { for file in $sourcepath; do origfile="${file#"$1/"}" relfile=$(echo ${origfile} | sed -e 's/\(\.\)*$//g') + mp3file=$(echo "${relfile}" | sed -e 's/.flac/.mp3/') VerboseOutput 0 "Checking ${origfile}" if [[ -d "${1}/$origfile" ]]; then VerboseOutput 0 "${origfile} is folder" @@ -272,10 +255,11 @@ CreateFileList() { newdir=${newdir#"/"} VerboseOutput 1 "Entering $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 VerboseOutput 0 "${origfile} is newer in source" VerboseOutput 2 "Added: ${3}/${origfile}" + echo "${1}/$origfile newer then ${2}/$mp3file" >> /tmp/poot.txt fi if [[ "${1}/$origfile" == *".m3u" ]]; then VerboseOutput 0 "${origfile} is playlist" @@ -311,24 +295,27 @@ ConvertFiles() { fi; 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 + if [[ $line != *".mp3" ]]; then + VerboseOutput 3 "${line} will be converted to mp3-file ${mp3line}" 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 VerboseOutput 0 "Creating folder $temp/${mp3line}-images/" mkdir -p "$temp/${mp3line}-images/" VerboseOutput 0 "Extracted albumart" eyeD3 --write-images "$temp/${mp3line}-images/" "$temp/${mp3line}" 1>/dev/null 2>/dev/null - 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 - eyeD3 --remove-all-images "$temp/${mp3line}" 1>/dev/null 2>/dev/null - VerboseOutput 0 "Embedding albumart" - 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}" + frontcovers=(${temp}/${mp3line}-images/FRONT_COVER.*) + if [ -e "$frontcovers" ]; then + 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 + eyeD3 --remove-all-images "$temp/${mp3line}" 1>/dev/null 2>/dev/null + VerboseOutput 0 "Embedding albumart" + 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}" + else + VerboseOutput 4 "No front cover art found for ${mp3line}" + fi fi VerboseOutput 2 "Converted: $line" else @@ -352,8 +339,14 @@ CopyFiles() { exit 4 fi - if [[ ! -f "${temp}/$line" ]]; then - VerboseOutput 5 "Source-file ${temp}/$line Unreachable" + if [[ $convert == true ]]; then + 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 exit 3 fi @@ -362,7 +355,7 @@ CopyFiles() { total=$(cat /tmp/music-sync-filelist | wc -l) percentage=$(echo "scale=4;${curline}/${total}" | 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 2 "Progress: $curline / $total (${percentage%00}%) Step 2 of 2" @@ -371,7 +364,7 @@ CopyFiles() { mkdir -p "$dest/${destline%/*}"; 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"