?

Log in

No account? Create an account
Trevor Stone's Journal
Those who can, do. The rest hyperlink.
HOWTO Copy Music from an iPod 
24th-Dec-2006 02:45 am
Trevor baby stare
At some point, my iTunes library location was incorrectly set to the Music folder in my home folder instead of my external hard drive. tamheals downloaded several albums, ripped a few, and we bought six songs from the iTunes store. At a later time, the setting was changed to the correct location on the external hard drive and the files from the Music folder were re-added to iTunes and copied to that path. I therefore had two (in some cases three) entries per song for these albums. One evening I went through and moved the Music files to the trash and deleted them from the iTunes list, making sure I could still play them. A few weeks later, Tam emptied the trash. Suddenly, all of the files I'd deleted were marked as missing from iTunes. Somehow (presumably user error) the files were no longer on the external hard drive.

The iTunes Store (unlike Calabash) only lets you download each purchased song once and advises you that you can burn them to CD. Burning a CD with six unconnected songs hadn't seemed like an important move. This is not a feature which benefits the consumer in any way

Fortunately, most of the deleted files are on Tam's iPod. Unfortunately, the iPod file system is obfuscated. Fortunately, there's a mp3info Ruby gem and I've been reading the Ruby Cookbook. I wrote the following script to go through all the mp3 files on the iPod and print the title, artist, album, track, and file path. I then went through the songs marked missing in iTunes and copied the file names into a text file, munging each line into a copy statement.

The script doesn't work on .m4a (AAC) files since mp3info can't handle them. Several minutes of googling finds only references to an MP4Tag ruby library by Miles Egan. Links to that page produce a 404. Archive.org has the old page, but didn't archive the tarball. The site seems to have been hijacked. If I get ambitious I may try to find an AAC specification and parse the files myself, but I think I'll accomplish the task with a list of songs I'm looking for and grepping each .m4a file.

Update, two hours later: Files purchased from the iTunes Store have a .m4p extension (rather than .m4a), so recovering the MIA purchased songs was a simple as ls -l /Volumes/RhiPod/iTunes_Control/Music/*.m4p and comparing the file modification dates with those iTunes remembered for the missing songs. I also found faad2 and installed it through DarwinPorts. faad2 is a decoder for AAC files and the -i command line option prints a lot of information, including metadata. I ran it on all the .m4a files and saved the output to a textfile which I can process with the flip-flop (..) operator.

#!/usr/bin/ruby

require 'rubygems'
require 'mp3info'
require 'find'

root = ARGV.length > 1 ? ARGV[0] : '/Volumes/RhiPod/iPod_Control/Music/'
Find.find(root) do |path|
    if path.match(/\.mp3/i)
        begin
            Mp3Info.open(path) do |mp3|
                title = mp3.tag.title || ''
                artist = mp3.tag.artist || ''
                album = mp3.tag.album || ''
                track = mp3.tag.tracknum || ''
                #puts %{}
                puts "#{title}\t#{artist}\t#{album}\t#{track}\t#{path}"
            end
        rescue Exception => e
            #msg = %{}
            warn "#{path}: #{e.message}"
            #puts msg
        end
    end
end
Comments 
24th-Dec-2006 09:25 pm (UTC)
If it ever comes up, good to know there are people smarter than me who've cracked this stuff :-)

Supposedly the guy who wrote DeCSS also has a crack to let you copy directly off an iPod nowadays.
This page was loaded Oct 16th 2018, 9:06 am GMT.