Last active
August 19, 2017 18:25
-
-
Save dragonee/26b27350c2e3dc0ca75ba364f0199a2d to your computer and use it in GitHub Desktop.
A command to convert album with separate FLAC files and import it to iTunes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adds three functions to your Bash terminal: | |
# flac2mp3 DIRECTORY - converts a directory with .flac files to .mp3 format | |
# itunesadd DIRECTORY - moves MP3 files to iTunes "Add Automatically" folder | |
# flac2itunes DIRECTORY - converts files to mp3 and adds them to iTunes in one step | |
# | |
# options can be modified below | |
# requires flac2mp3.pl from https://github.com/robinbowes/flac2mp3 | |
export FLAC2MP3_APP="/Users/dragonee/Kod/flac2mp3/flac2mp3.pl" | |
export FLAC2MP3_OPTIONS="--processes=5 --preset=320" | |
export FLAC2MP3_ITUNES="/Users/dragonee/Music/iTunes/iTunes Media/Automatically Add to iTunes.localized/" | |
flac2mp3() { | |
if [ -z "$1" ]; then | |
echo "Usage: flac2mp3 SOURCE_DIR [TARGET_DIR]" | |
echo "" | |
echo "If TARGET_DIR is not provided, I will try to substitute FLAC" | |
echo "in the source filename to MP3 with fallback to appending [MP3] at the end." | |
echo "" | |
echo "I'm using these options: $FLAC2MP3_OPTIONS" | |
return 1 | |
fi | |
SOURCE_DIR="$1" | |
if [ -z "$2" ]; then | |
target_dirname=$(dirname "$1") | |
target_basename=$(basename "$1") | |
if [ "$target_basename" == "${target_basename/FLAC/MP3}" ]; then | |
TARGET_DIR="$target_dirname/$target_basename [MP3]" | |
else | |
TARGET_DIR="$target_dirname/${target_basename/FLAC/MP3}" | |
fi | |
else | |
TARGET_DIR="$2" | |
fi | |
"$FLAC2MP3_APP" $FLAC2MP3_OPTIONS "$SOURCE_DIR" "$TARGET_DIR" | |
__="$TARGET_DIR" | |
} | |
itunesadd() { | |
if [ -z "$1" ]; then | |
echo "Usage: itunesadd SOURCE_DIR" | |
fi | |
mv "$1" "$FLAC2MP3_ITUNES" | |
} | |
flac2itunes() { | |
flac2mp3 "$1" "$2" | |
itunesadd "$__" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment