Pages

Saturday 9 June 2007

PutPinfInItsPlace: An iTunes Plus fixer for Nokia mobile phones

I have a Mac.
I have iTunes.
I have a Nokia E61.

So you would think... perfect! Everything is wonderful now that iTunes Plus is out, but...

As is described by following the link above, there is an incompatibility between iTunes and Nokia mobile phones (and potentially other devices on and beyond the Symbian platform).

Update #1: A means of syncing these files to the phone.
Update #2: I have uploaded a version of PutPinfInItsPlace that is compatible with Mac OS X Panther 10.3.9/Java 1.4. Everyone should be covered now, sorry about that.
Update #3: An alternative option for doing the conversion on the phone instead is now available. (Hint: I prefer it this way.)

While there is a simple workaround, again described in the link, which involves re-wrapping the iTunes Plus file in a new AAC file, I wasn't happy with that so I kept investigating.

Turns out there is a single byte that makes all of the difference to such devices, as is borne out by the output of Atomic Parsley (v0.9.0, http://atomicparsley.sourceforge.net):
An iTunes Plus song has the following apparent structure:
...
Atom stsd @ 450 of size: 32871, ends @ 33321
Atom mp4a @ 466 of size: 32855, ends @ 33321
Atom esds @ 502 of size: 51, ends @ 553
Atom pinf @ 553 of size: 32768, ends @ 33321 ~
Atom stts @ 33321 of size: 24, ends @ 33345
...
~ denotes an unknown atom

Whereas the re-wrapped container (that works on the devices) has the following structure:
...
Atom stsd @ 442 of size: 32871, ends @ 33313
Atom mp4a @ 458 of size: 32855, ends @ 33313
Atom esds @ 494 of size: 32819, ends @ 33313
Atom stts @ 33313 of size: 24, ends @ 33337
...

Note that the unknown atom pinf (that's where your iTunes account information appears to be by the way) doesn't appear in the QuickTime Pro-containered file.

I tried to trivially strip out the pinf atom using Atomic Parsley, but no joy, and this is seemingly a red herring - as a hex editor examination of the files will attest to. The re-wrapped version of the file still has my account name in it, yet it doesn't cause the device to baulk!
The only difference in that area of the file is one byte - it's in the size of the esds atom. It appears that QuickTime Pro writes the pinf atom out as a child of esds (and Atomic Parsley and other tools don't parse the file that deeply to care), whereas the iTunes Store/iTunes 7.2 writes the pinf atom out as a sibling instead. It is only this difference (not any metadata) that prevents the file from playing on my phone.
Note that changing this byte means iTunes 7.2 no longer sees the file as a "Purchased AAC audio file", instead Get Info reports simply an "AAC audio file" kind. The Account Name is still visible.

So on to fixing this. You can simply find the byte (get a hex editor, I used the free 0xED - http://www.macupdate.com/0xED) which is in the atom size field immediately before 'esds' appears) and change it to include the pinf size. But this would obviously get tedious.

I've already got 27 iTunes Plus songs and I'm bound to get more, so to help me and you out, here's a very simple tool to change the byte for you.

I named it "PutPinfInItsPlace" since the problem is a misplaced pinf atom (smart hey?). This is a Java application, purely so that iTunes Windows and iTunes Mac users can use it (Windows users - install Java from http://www.java.com).

It will accept a list of files either on the command line, or if no files are given, it will ask you for them with a simple file chooser window. You can select as many files as you like at a time.

It will first back up your file as is in the same folder (renaming it to song name.purchased.m4a), and it won't continue if it can't back up your song, so it should be safe to use.

Then it will walk through the file looking for the misplaced pinf atom, copying the file out as it goes, changing the byte when it finds it then finishing off the file. Messages will let you know of its progress.

You can use the file directly on your iTunes Music folder because the tool preserves the original file names and metadata so iTunes should keep your ratings. If the conversion is successful you can manually delete or move the backups away.

There is more information on the tool in the README.txt file, and I'd appreciate some success or failure comments here. Thanks!

I hope this information (so someone can fix the issue or make a better tool) and tool is useful in the meantime.

You can download the tool from the link on http://geocities.ws/jking_ok/blog.html.



Update 12/08/2010: Changed link to GeoCities mirror.

16 comments:

  1. Awesome work! I've mirrored the file on my site too just in case the Geocities account gets hammered :)

    Regards,
    Shane.

    ReplyDelete
  2. The perl CPAN module Audio::M4P::Quicktime has been updated to cover the new iTunes Plus mp4a atom variant, and I have informed the author of Atomic Parsley of the nature of these changes, so I suspect an updated version of Atomic Parsley will fix your problem soon.

    --Bill

    ReplyDelete
  3. Hi
    I could not believe I still could not have my tunes on my N95 having paid more to "upgrade" them, so was pleased to see your fix. Unfortunately the java app "could not be launched".
    I have Ti Powerbook running os10.3.9

    ReplyDelete
  4. Sorry I left Panther behind. The problem is you need Java 1.5 installed (from Apple) which wasn't officially released for Panther.

    Either wait until I have a Panther-ready version (about a day) or follow these instructions to install Java 1.5 on Panther.

    ReplyDelete
  5. @pfree.ad:
    I have now uploaded a Panther-compatible version for you.

    ReplyDelete
  6. Thanks Joshua,
    I've run the app and I now have 2 copies of the files in my itunes folder (one .purchaced.m4a one just .m4a) but only the purchaced version shows up in itunes. I this normal?
    I'll tranfer the .m4a versions to my phone and see if they play on N95.

    ReplyDelete
  7. That sounds about right. I don't touch the iTunes library, so if it detects the old version as the one in the library, you can manually swap them over by re-importing them (you'll need to do that if you follow along with my Nokia Media Transfer stuff).

    ReplyDelete
  8. While I know it wasn't said it would, it does not fix the files so they play on the xbox 360...

    ReplyDelete
  9. I downloaded the .jar file and it won't work on my N95, it advises that's an invalid jar file? Am I doing something wrong as the comments on here indicate the conversion is done prior to adding them to the phone?

    ReplyDelete
  10. Hi anonymous:

    You're right you CAN'T run the jar on the phone -- you need to run it on the computer before copying the files.

    But I'll let you in on a secret: I'm close to version that will run on the phone without touching iTunes at all :-)

    ReplyDelete
  11. Thank-you SOOO much for this -- I was halfway through a heart attack when Google pointed me to your site. Now my iTunes Plus actually work as advertised!

    I did a little write-up on my own blog:

    http://preview.tinyurl.com/2fg66y

    ... So hopefully even more fame and fortune will be coming your way :-)

    ReplyDelete
  12. Sorry if I am being a bit silly here but when I try to launch the app it tries to install it to the phone. I have JRE installed - any hints?

    ReplyDelete
  13. Anon, yes it does NOT run on the phone. I'm guessing you are running Windows and have PC Suite or other software that thinks all .jar files are meant for the phone.

    A workaround for this would be to run it from the Command Prompt -- click Start, Run... type cmd and click Run.

    From there, change to where the .jar file is (for example, the Desktop) using the cd command and then run java -jar PutPinfInItsPlace.jar.

    If Java isn't found, that means it is not in your PATH. A shortcut to try would be typing %JAVA_HOME%\bin\java instead.

    ReplyDelete
  14. Does saving audio in Fission do the trick?

    http://www.macworld.com/article/58287/2007/06/unwateritunesplus.html

    ReplyDelete
  15. I've been trying this to get MPA files working with a new Nokia E55, which just skips over the files instead of playing them , but the application doesn't work, it doesn't seem to want to read the files:

    tom$: PutPinfInItsPlace tom$ java -jar PutPinfInItsPlace.jar
    java.io.IOException: Short read from source file!
    at PutPinfInItsPlace.main(PutPinfInItsPlace.java:121)


    tom$ PutPinfInItsPlace tom$ java -jar PutPinfInItsPlace.jar
    java.lang.IllegalArgumentException
    at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:505)
    at PutPinfInItsPlace.main(PutPinfInItsPlace.java:119)


    I'm running Mac OS X 10.6.4 - any ideas?

    Can you tell me what your application is doing? I might be able to whip some code up myself to fix my files...

    I can give you the AtomicParsely output if you want it..

    ReplyDelete