Skip to content

Instantly share code, notes, and snippets.

@zacharied
Last active May 9, 2019 23:05
Show Gist options
  • Save zacharied/a3438ac15dd543de255aed314eb244c8 to your computer and use it in GitHub Desktop.
Save zacharied/a3438ac15dd543de255aed314eb244c8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# WARNING Argument parsing here is really dumb, be careful when adding any
# additional flags.
shopt -s nullglob
readonly LIBRARY=/mnt/f/Music
readonly OUTPUT=/mnt/g/MusicTransfer/out
mkdir -v "$OUTPUT" 2>/dev/null
declare -a flacfiles=()
declare -a copyfiles=()
for d in "$LIBRARY"/*; do
basename=${d#$LIBRARY/}
[[ -d "$OUTPUT/$basename" ]] || mkdir -v "$OUTPUT/$basename"
echo "$basename:"
for f in "$d"/*; do
filename=${f##*/}
echo -n $'\t'
if [[ "${f##*.}" == flac ]]; then
echo -n "CONV "
flacfiles+=("$basename/$filename")
else
echo -n "COPY "
copyfiles+=("$basename/$filename")
fi
echo "$filename"
done
done
echo
echo "${#flacfiles[@]} files will be converted."
echo "${#copyfiles[@]} files will be copied."
read -p "Is this okay? [Y/n] " ans
if [[ ! "$ans" =~ [Yy] ]]; then
return
fi
if [[ "$1" != -c ]]; then
printf "%s\0" "${flacfiles[@]}" | parallel --null -P 4 'ffmpeg -i '"$LIBRARY/"'{} -map 0 -map -v -q:a 0 '"$OUTPUT"'/{.}.mp3'
fi
printf "%s\0" "${copyfiles[@]}" | parallel --null -P 4 'cp -r '"$LIBRARY/"'{} '"$OUTPUT/"'{}'
date +%s > .last_convert_date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment