« April 12, 2006 | Main | June 21, 2006 »

May 27, 2006

How iTunes selects the storefront

Following the itmshack: Grab Album Description Text from the iTunes Music Store article on the O’Reilly Mac DevCenter Blog, and on a Friend’s suggestion, and out of personal interest, I tried to figure out how iTunes specifies the storefront (or country) when talking to the iTunes Music Store. Running tcpflow while visiting the Swiss French store gave it away quite quickly: GET /WebObjects/MZStore.woa/wa/viewAlbum?id=154148337&s=143459 HTTP/1.1
X-Apple-Tz: 7200
X-Apple-Store-Front: 143459-2
Referer: http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/storeFront
User-Agent: iTunes/6.0.4 (Macintosh; U; PPC Mac OS X 10.4.6)
Accept-Language: en-us, en;q=0.50
X-Apple-Validation: 661D3B2F-DB90D338EA5BA65F951043499F6627ED
Accept-Encoding: gzip, x-aes-cbc
Connection: close
Host: ax.phobos.apple.com.edgesuite.net

The storefront is selected with the X-Apple-Store-Front HTTP request header. The number can be extracted by Control-clicking an item in iTunes and choosing ‘Copy iTunes Music Store URL’. As we can see, the s query parameter in the URL gives the storefront number:


The additional -2 in the HTTP header selects the language. If it’s omitted, the default language is used (German for the Swiss French store). Here are the values I could identify before I ran out of patience:

1: English
2: English (slightly different texts)
3: French
4: German
5: French (slightly different texts)

You can easily tell curl to add the X-Apple-Store-Front header:

curl --header 'X-Apple-Store-Front: 143459-2' -s 'http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/viewAlbum?id=154148337' | gunzip

Modification of the itmshack script is left as an exercise for the reader (or for the script’s author ;-)).

Do not meddle in the affairs of Coding Ninjas, for they are subtle and quick to anger.