Thursday, August 25, 2005

iTunes 4.9 Music Videos

UPDATE: See this post to learn why the script no longer works with changes to the iTMS content following the release of iTunes 6.0.

Every time a new version of iTunes is released, Apple changes they way iTunes communicates with the iTunes Music Store usually by changing the encryption keys or methods that the results are encoded with. Then we all have to figure out what's changed and someone usually does. First the pages were gziped, then gziped and encoded with aes-cbc (Rijndael-128) using a static key, then gziped and encoded with aes-cbc using a key that was sent in the response. Now the key is also encrypted. So here for your enlightenment and learned review is some code demonstrating the current iTunes 4.9 communication methods. This example retrieves the link to a QuickTime music video file from the URL copied from iTunes. Remember that... with knowledge comes responsibility.

iTunes 4.9 Music Videos · Try it.

7 Comments...

If you don't mind me asking, specifically how does one run this? Thank you.

Posted by Anonymous GQmacguy on August 25, 2005 8:34 PM  

You have to run the scripts from a web-server with PHP installed. Note that php must be built with (or include) the mcrypt functions.

You might also find someone who is hosting the scripts.

Not hosting it here was a personal decision I made. It should suffice that the code is available for review and download. Be responsible...

Posted by Anonymous Benjamin on August 30, 2005 11:59 AM  

Well, it seems that iTMS uses 2 different codes for their videos now.
THis link below works:
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewVideo?b=a&videoId=41142002&videoIndex=2

This one does not:
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewVideo?videoId=994387&videoIndex=2

The only difference in the URLs is the top one has
/viewVideo?b=a&videoId=
and the now urls use just
/viewVideo?videoID=

The key difference I see when choosing the videos is videos that state the size (240x180 for small and 480x360 for large) on the video page.

Are you working on a workaround for this?

The error message says: No x-apple-twofish-key was found in the result.

Posted by Anonymous Tim on September 03, 2005 9:41 PM  

Using the brand new iTunes 5, it works flawlessly. Thanks for the effort!

Posted by Anonymous Hendrik R. on September 07, 2005 2:13 PM  

tim: Your link under "This one does not" seems to work for me. Am I missing something?

hendrik r.: Thanks. iTunes 5.0 seems to be working for me too.

Posted by Anonymous Benjamin on September 07, 2005 5:19 PM  

It is now working for me under iTunes 5.0, so I guess whatever wasn't working for me under 4.9, is now working under 5.0

Thanks!

Posted by Anonymous tim on September 09, 2005 12:27 PM  

At least the german itunes store has still some videos which use static keys. With the following change I can download them as well:

preg_match("/x-apple-twofish-key: (\w+)/", $payload, $twofish);
if (count($twofish) < 2)
{
preg_match("/x-apple-protocol-key: (\w+)/", $payload, $keynum);
if (count($keynum) < 2 or ($keynum[1] != 2 and $keynum[1] != 3))
error("No or invalid x-apple-protocol-key was found in the result.");
$key = array("ip2tOZ+wFMExvmEYINeIlQ==", "mNHiLKoNir1l0UOtJ1pe5w==");
$key = base64_decode($key[$keynum[1]-2]);
}
else
{
$twofish = pack('H*', $twofish[1] );
$key = descramble_twofish_key($twofish);
}

Posted by Anonymous bernhard on September 10, 2005 6:24 AM  

Post a Comment

 · Blog Index