summaryrefslogtreecommitdiffstats
path: root/flactomp3
blob: 1939569e6194dfd4e16dc8ec8dcaf6ad788d3542 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

shopt -s globstar

if (($# < 1)); then
	echo "usage: ${0##*/} <directory>"
	exit
fi

if [[ ! -d $1 ]]; then
	echo "argument must be a directory"
	exit 1
fi

dir=${1%/}
copydir_suffix="_mp3"

# same regex twice, but different replacement pattern
find "$dir" -type f -name '*.flac' -print0 | parallel -0 mkdir -p '{=s#^([^/]+)(.*)/([^/]+)\.flac$#\1'"${copydir_suffix}"'\2#=}'\; ffmpeg -i {} -qscale:a 0 '{=s#^([^/]+)(.*)/([^/]+)\.flac$#\1'"${copydir_suffix}"'\2\3.mp3#=}'