Last active
September 14, 2020 18:34
-
-
Save rms1000watt/d89ee06ff8c4f50c720e85144267de3e to your computer and use it in GitHub Desktop.
Download all your songs from your old iPod to your Mac
This file contains hidden or 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
#!/usr/bin/env bash | |
output_dir=~/Downloads/ipod | |
map_dir="${output_dir}/map" | |
mkdir -p "${map_dir}" &> /dev/null | |
if [[ $(uname -s) != "Darwin" ]]; then | |
echo "ERROR: this only works for OS X" | |
exit 1 | |
fi | |
if ! command -v ffprobe &> /dev/null; then | |
echo "ERROR: ffprobe is not installed" | |
echo " Install ffprobe by running: brew install ffmpeg" | |
exit 1 | |
fi | |
handle_mp3() { | |
mp3=${1} | |
D2=$(dirname "${mp3}") | |
map_name="$(basename "${D2}")-$(basename "${mp3}")" | |
full_map_name="${map_dir}/${map_name}" | |
if [[ -f ${full_map_name} ]]; then | |
echo "Already processed mp3=${mp3}" | |
return | |
fi | |
echo "Handling mp3=${mp3}" | |
ffprobe_out=$(ffprobe "${mp3}" 2>&1) | |
meta_title=$(echo "${ffprobe_out}" | grep "title" | cut -d':' -f2 | sed 's/^ *//g' | sed 's|/|-|g' |head -1) | |
meta_track=$(echo "${ffprobe_out}" | grep "track" | cut -d':' -f2 | sed 's/^ *//g' | sed 's|/|-|g' |head -1) | |
meta_artist=$(echo "${ffprobe_out}" | grep "artist" | cut -d':' -f2 | sed 's/^ *//g' | sed 's|/|-|g' |head -1) | |
meta_album=$(echo "${ffprobe_out}" | grep "album " | cut -d':' -f2 | sed 's/^ *//g' | sed 's|/|-|g' |head -1) | |
filename="${meta_artist}/${meta_album}/${meta_track} - ${meta_title}.mp3" | |
full_filename="${output_dir}/${filename}" | |
album_dir="$(dirname "${full_filename}")" | |
if [[ ! -d ${album_dir} ]]; then | |
if ! mkdir -pv "${album_dir}"; then | |
echo "################ FAILED TO MKDIR [${album_dir}]" | |
return | |
fi | |
fi | |
if [[ -f ${full_filename} ]]; then | |
echo "################ FILE ALREADY EXISTS [${full_filename}]" | |
return | |
fi | |
echo "cp ${mp3} ${full_filename}" | |
if ! cp "${mp3}" "${full_filename}"; then | |
echo "################ FAILED TO COPY [${mp3}] [${full_filename}]... retry later" | |
return | |
fi | |
touch "${full_map_name}" | |
} | |
handle_ipod_control() { | |
dir=${1} | |
echo "Handling ipod_control dir=${dir}" | |
while IFS= read -r -d '' mp3; do | |
handle_mp3 "${mp3}" | |
done < <(find "${dir}/Music" -type f -name '*.mp3' -print0) | |
} | |
main() { | |
while IFS= read -r -d '' dir; do | |
handle_ipod_control "${dir}" | |
done < <(find /Volumes -type d -iname 'iPod_control' -maxdepth 2 -print0) | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment