Skip to content

Instantly share code, notes, and snippets.

@neofright
Created November 29, 2021 19:09
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 neofright/a9d0abce03f9d0d643756478c9da9f0a to your computer and use it in GitHub Desktop.
Save neofright/a9d0abce03f9d0d643756478c9da9f0a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# set -o nounset
# set -o errexit
########################################################
## Am I running this on my ZFS server or my Macbook?
if [[ $(uname) == "Darwin" ]]
then
music_mount_point="/Volumes/tank"
ipod_mount_point="/Volumes/IPOD"
transflac_path="$HOME/Documents/GitHub/transflac/transflac"
else
music_mount_point="/mnt/tank/data"
ipod_mount_point="/mnt/IPOD"
transflac_path="/mnt/tank/data/Scripts/transflac/transflac"
fi
if [[ ! -d "$ipod_mount_point" ]]; then exit; fi
## The _Gifts folder contains music given to me by friends. I have not split the albums
## into separate FLAC and MP3 folders like I have for the rest of my library.
declare -A flac_dirs
flac_dirs["${music_mount_point}/Music/albums [FLAC]/"]="${ipod_mount_point}/Music/albums [FLAC_XCODE]/"
flac_dirs["${music_mount_point}/Music/_Gifts/"]="${ipod_mount_point}/Music/_Gifts/"
declare -A mp3_dirs
mp3_dirs["${music_mount_point}/Music/albums [MP3]/"]="${ipod_mount_point}/Music/albums [MP3]/"
mp3_dirs["${music_mount_point}/Music/_Gifts/"]="${ipod_mount_point}/Music/_Gifts/"
########################################################
## TRANSCODE FLAC ALBUMS TO OGG
########################################################
for key in "${!flac_dirs[@]}"
do
value="${flac_dirs[$key]}"
"$transflac_path" "$key" "$value" OGG STANDARD
done
########################################################
## RSYNC MP3 ALBUMS
########################################################
function rsync_mp3()
{
rsync \
--recursive \
--times \
--quiet \
--prune-empty-dirs \
--safe-links \
--modify-window=2 \
--delete \
--exclude="*.flac" \
--filter 'protect *.ogg' \
--filter 'protect folder.jpg' \
"$1" \
"$2"
}
printf '\nSyncing mp3 music to iPod...'
for key in "${!mp3_dirs[@]}"
do
value="${mp3_dirs[$key]}"
rsync_mp3 "$key" "$value"
done
printf 'OK\n'
########################################################
## GENERATE M3U PLAYLIST
########################################################
printf '\nCreating updated playlist...'
playlist_file="${ipod_mount_point}/Music/music.m3u"
find \
"${ipod_mount_point}/Music/" \
-type f \
\( -iname "*.mp3" \
-o -iname "*.ogg" \) \
-print | sed "s%$ipod_mount_point/Music/%%g" | sort -t / -k 2 > "$playlist_file"
printf 'OK\n'
########################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment