Skip to content

Instantly share code, notes, and snippets.

@adamvr
Created August 22, 2012 20:25
Show Gist options
  • Select an option

  • Save adamvr/3429049 to your computer and use it in GitHub Desktop.

Select an option

Save adamvr/3429049 to your computer and use it in GitHub Desktop.
Extracting music from an iDevice

Introduction

This script is specifically designed for reconstituting mp3s from the silly hash directories iDevices store their music in. It requires that the mp3s have working id3v2 tags, so use something like find . -name '*.mp3 -print0 | xargs -0Ixx id3v2 -C "xx" to convert them if they're in id3v1.

Usage

./extract.sh ~/music /media/IPOD/iPod_Control/Music

Caveats

  • AAC or anything else aren't even considered.
  • Will blindly overwrite any files that share track names with the extracted file
  • Doesn't prepend a track number to the output file - sucks, but it's pretty hard to fix
#!/usr/bin/env bash
source=$1
dest=$2
[ -z $source ] || [ -z $dest ] || exit 1
find "$source" -name '*.mp3' -print0 |
xargs -0Ixx sh -c '
RANDOM=$$
artist=`id3v2 -l "xx" | grep TPE1 | sed "s/^.*): //" | uniq`
album=`id3v2 -l "xx" | grep TALB | sed "s/^.*): //" | uniq`
title=`id3v2 -l "xx" | grep TIT2 | sed "s/^.*): //" | uniq`
artist=${artist:-unknown}
album=${album:-unknown}
title=${title:-unknown$RANDOM}
echo $artist - $album - $title
mkdir -p "$artist/$album"
cp "xx" "$dest/$artist/$album/$title.mp3"
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment