Skip to main content
Fixed the mkdir line, by doing a Perl seach/replace!
Source Link

So I kept playing with this script, and it felt like I was aiming at a moving target. I wasn't keeping super close track of my changes and what-not, so there may have been other issues going on.

However, I think I've fixed my script to work correctly.

The goal of this script, is to take an arbitrary source directory, that contains *.flac and *.jpg files, create an identical directory structure at the destination, then re-encode all the *.flac files in that source, and write the *.mp3 in the destination directory. Finally, copy all the *.jpg (cover art) in the source directory to the corresponding destination directory. Use GNU parallel as much as possible.

TL;DR - Convert a FLAC directory tree, to an MP3 directory tree, using parallel.

Here's what I finally came up with

#!/bin/sh
SOURCE=$1
DEST=$2
find $SOURCE -type f -name '*.flac' -printf "%h\n" | uniq | parallel --dry-run mkdir -p $DEST{=s:$SOURCE:$DEST:g=}
find $SOURCE -type f -name '*.flac' -printf "%P\n" | parallel --dry-run ffmpeg -loglevel info -i $SOURCE{} -codec:a libmp3lame -qscale:a 3 $DEST{.}.mp3
find $SOURCE -type f -name '*.jpg' -printf "%P\n" | parallel --dry-run cp $SOURCE{} $DEST{}

It seems to work, at least for the --dry-run output, as above. Feel free to (re-)use this.

So I kept playing with this script, and it felt like I was aiming at a moving target. I wasn't keeping super close track of my changes and what-not, so there may have been other issues going on.

However, I think I've fixed my script to work correctly.

The goal of this script, is to take an arbitrary source directory, that contains *.flac and *.jpg files, create an identical directory structure at the destination, then re-encode all the *.flac files in that source, and write the *.mp3 in the destination directory. Finally, copy all the *.jpg (cover art) in the source directory to the corresponding destination directory. Use GNU parallel as much as possible.

TL;DR - Convert a FLAC directory tree, to an MP3 directory tree, using parallel.

Here's what I finally came up with

#!/bin/sh
SOURCE=$1
DEST=$2
find $SOURCE -type f -name '*.flac' -printf "%h\n" | uniq | parallel --dry-run mkdir -p $DEST{}
find $SOURCE -type f -name '*.flac' -printf "%P\n" | parallel --dry-run ffmpeg -loglevel info -i $SOURCE{} -codec:a libmp3lame -qscale:a 3 $DEST{.}.mp3
find $SOURCE -type f -name '*.jpg' -printf "%P\n" | parallel --dry-run cp $SOURCE{} $DEST{}

It seems to work, at least for the --dry-run output, as above. Feel free to (re-)use this.

So I kept playing with this script, and it felt like I was aiming at a moving target. I wasn't keeping super close track of my changes and what-not, so there may have been other issues going on.

However, I think I've fixed my script to work correctly.

The goal of this script, is to take an arbitrary source directory, that contains *.flac and *.jpg files, create an identical directory structure at the destination, then re-encode all the *.flac files in that source, and write the *.mp3 in the destination directory. Finally, copy all the *.jpg (cover art) in the source directory to the corresponding destination directory. Use GNU parallel as much as possible.

TL;DR - Convert a FLAC directory tree, to an MP3 directory tree, using parallel.

Here's what I finally came up with

#!/bin/sh
SOURCE=$1
DEST=$2
find $SOURCE -type f -name '*.flac' -printf "%h\n" | uniq | parallel --dry-run mkdir -p {=s:$SOURCE:$DEST:g=}
find $SOURCE -type f -name '*.flac' -printf "%P\n" | parallel --dry-run ffmpeg -loglevel info -i $SOURCE{} -codec:a libmp3lame -qscale:a 3 $DEST{.}.mp3
find $SOURCE -type f -name '*.jpg' -printf "%P\n" | parallel --dry-run cp $SOURCE{} $DEST{}

It seems to work, at least for the --dry-run output, as above. Feel free to (re-)use this.

Source Link

So I kept playing with this script, and it felt like I was aiming at a moving target. I wasn't keeping super close track of my changes and what-not, so there may have been other issues going on.

However, I think I've fixed my script to work correctly.

The goal of this script, is to take an arbitrary source directory, that contains *.flac and *.jpg files, create an identical directory structure at the destination, then re-encode all the *.flac files in that source, and write the *.mp3 in the destination directory. Finally, copy all the *.jpg (cover art) in the source directory to the corresponding destination directory. Use GNU parallel as much as possible.

TL;DR - Convert a FLAC directory tree, to an MP3 directory tree, using parallel.

Here's what I finally came up with

#!/bin/sh
SOURCE=$1
DEST=$2
find $SOURCE -type f -name '*.flac' -printf "%h\n" | uniq | parallel --dry-run mkdir -p $DEST{}
find $SOURCE -type f -name '*.flac' -printf "%P\n" | parallel --dry-run ffmpeg -loglevel info -i $SOURCE{} -codec:a libmp3lame -qscale:a 3 $DEST{.}.mp3
find $SOURCE -type f -name '*.jpg' -printf "%P\n" | parallel --dry-run cp $SOURCE{} $DEST{}

It seems to work, at least for the --dry-run output, as above. Feel free to (re-)use this.