Skip to content

Instantly share code, notes, and snippets.

@mmrwoods
Last active December 23, 2015 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmrwoods/6614376 to your computer and use it in GitHub Desktop.
Save mmrwoods/6614376 to your computer and use it in GitHub Desktop.
Burn a rekordbox export to an MP3 CD
#!/bin/bash
# Burns a rekordbox export to an MP3 CD compatible with older CDJs.
#
# Copies mp3, m4a and wav audio files from export volume to a single CD,
# converting to constant bit rate mp3 compatible with older CDJs and other
# non-pioneer CD players as required.
#
# Will explode if files won't fit onto a single CD. Yup, I know this is shit.
#
# Requires OSX with ffmpeg and mediainfo (both can be installed via homebrew).
volname="Rekordbox"
dmgfile="/tmp/rekordbox.dmg"
heading() {
printf "\n\e[32m$1...\e[0m\n"
}
info() {
printf "\e[34m$1\e[0m\n"
}
run_cmd() {
printf "\e[33m$1\e[0m\n"
eval $1
}
# verify arguments...
if test "$1" == ""; then
echo "Usage: $0 path-to-rekordbox-export-volume"
exit 1
fi
if ! test -d "$1"; then
echo "$1 is not a directory, exiting..."
exit 1
fi
if ! test -f "$1/._PIONEER"; then
echo "$1 does not contain a rekordbox export, exiting..."
exit 1
fi
if ! test -d "$1/Contents"; then
echo "$1 has no contents, exiting..."
exit 1
fi
# create and mount disk image
heading "Creating and mounting temporary disk image"
if test -d "/Volumes/$volname"; then
echo "Unmounting existing volume..."
run_cmd "hdiutil unmount \"/Volumes/$volname\""
fi
if test -f $dmgfile; then
echo "Deleting existing dmg file..."
run_cmd "rm -rf $dmgfile"
fi
run_cmd "hdiutil create -fs HFS+ -volname \"$volname\" -size 650m $dmgfile"
run_cmd "hdiutil mount $dmgfile"
# copy files to root path on disk image, converting to constant bit rate mp3 as required
heading "Copying and converting audio files"
find "$1/Contents" -type f -not -name ".*" | grep -i ".\(mp3\|m4a\|wav\)" | while read file; do
filename=${file##*/}
ext=${filename##*.}
dest="/Volumes/$volname/${filename%$ext}mp3"
heading "$filename"
case $(echo $ext | tr 'A-Z' 'a-z' | tr -d "\n") in
mp3)
if $(mediainfo "$file" | grep -i "Bit rate.*Variable" 2>&1 > /dev/null); then
info "Convert from variable to constant bit rate mp3"
run_cmd "ffmpeg -v warning -y -i \"$file\" -ab 192k \"$dest\" < /dev/null"
else
info "Copy file"
run_cmd "cp \"$file\" \"$dest\""
fi
;;
m4a)
info "Convert m4a to mp3"
# TODO: convert with same bitrate rather than hard-coded 192k
run_cmd "ffmpeg -v warning -y -i \"$file\" -ab 192k \"$dest\" < /dev/null"
;;
wav)
info "Convert wav to mp3"
run_cmd "ffmpeg -v warning -y -i \"$file\" -ab 320k \"$dest\" < /dev/null"
;;
esac
info "Check for errors"
run_cmd "mp3check --cut-junk-start --cut-junk-end --fix-headers \"$dest\""
done
# unmount the volume and burn the image
heading "Burning disk image to CD"
run_cmd "drutil burn \"/Volumes/$volname\""
if test $? -ne 0; then
echo "Burn failed, exiting..."
exit 1
fi
# cleanup
heading "Cleaning up"
run_cmd "hdiutil unmount \"/Volumes/$volname\""
run_cmd "rm -rf $dmgfile"
@luisbrauer
Copy link

hi, how can i use this code to really execute it and burn cds with rekorbox information?

@mmrwoods
Copy link
Author

Hi Luis,

It's been a while since I used this because I no longer have rekordbox installed, so the terminology here might be slightly wrong, but the script expects you to create a playlist in rekordbox and then export the playlist to a usb key (or any other mounted disk image). Once you've done this, you can run the script, providing the path to the mounted volume as the only argument. e.g.

$ ./rekordbox2mp3cd /Volumes/USBKEY/

Before you can run the script, you obviously need to make it executable, which you can do using chmod:

$ chmod +x rekordbox2mp3cd

And you also need to ensure that ffmpeg and mediainfo have been installed. Assuming you are using homebrew for package management in OSX, this should be as simple as:

$ brew install ffmpeg mediainfo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment