ITunesDB/iTunesDB File/Section1

From iPodLinux

(Difference between revisions)
Jump to: navigation, search
(Database Object)
(Playlist)
Line 417: Line 417:
</td></tr>
</td></tr>
<tr>
<tr>
-
<td> 4 </td><td> header length </td><td> 4 </td><td> size of the mhyp header
+
<td> 4 </td><td> header length </td><td> 4 </td><td> size of the mhyp header. For dbversion <= 0x2A (iTunes 9.0.1.8), the size is 0x6C. For dbversion >= 0x2B (iTunes 9.0.2.25), the size is 0x8C.
</td></tr>
</td></tr>
<tr>
<tr>

Revision as of 07:51, 17 November 2009

Contents

Structure

The iTunesDB file consists of a sort of tree structure arranged into a flat file. Each "object" contains a header followed by some other objects. The header contains a couple of size fields that are used to define where the header ends and other objects begin. Here's the basic structure of it:

<mhbd> - This is a database
  <mhsd> - This is a list holder, which holds a mhla
    <mhla> - This holds a list of albums
      <mhia> - This describes a particular Album Item
        <mhod> - These hold strings associated with an album title
        <mhod> - These hold strings associated with an artist name/title
      <mhia> - This is another album. And so on.
        <mhod>...
        <mhod>...
  <mhsd> - This is a list holder, which holds a mhli
    <mhli> - This holds a list of artists
      <mhii> - This describes a particular Artist Item
        <mhod> - These hold strings associated with an artist name
      <mhii> - This is another artist. And so on.
        <mhod>...
      ...
  <mhsd> - This is a list holder, which holds either a mhlt or an mhlp
    <mhlt> - This holds a list of all the songs on the iPod
      <mhit> - This describes a particular song
        <mhod>... - These hold strings associated with a song
        <mhod>... - Things like Artist, Song Title, Album, etc.
      <mhit> - This is another song. And so on.
        <mhod>...
        <mhod>...
      ...
  <mhsd> - Here's the list holder again.. This time, it's holding an mhlp
    <mhlp> - This holds a bunch of playlists. In fact, all the playlists.
      <mhyp> - This is a playlist.
        <mhod>... - These mhods hold info about the playlists like the name of the list.
        <mhip>... - This mhip holds a reference to a particular song on the iPod.
        ...
      <mhyp> - This is another playlist. And so on.
        <mhod>... - Note that the mhods also hold other things for smart playlists
        <mhip>...
        ...
      ...

And so on. What follows is a detailed description of these various headers.

Chunk Encoding

Each chunk of the file is encoded in the follow form:

Chunk Encoding
Offset Field Size Description
0 Chunk Type Identifier 4 A 4-byte string like "mhbd", "mhlt", etc. This identifies what type of chunk is at the current location.
4 End of Type-specific Header 4 This is a little-endian encoded 32b value that points to the end of the chunk-specific header.
8 End of Chunk or Number of Children 4 This is a little-endian encoded 32b value. It either points to the end of the current chunk, or the number of children the current chunk has.

The Chunk Type Identifier is intuitive: it's a 4-byte string letting you know what you're working with.

The End of Type-specific Header tells you where, relative to offset 0, the header section for this chunk ends. The header starts at offset 12 and runs through to the end of the type-specific header.

The End of Chunk or Number of Children is slightly confusing. Usually, it's an "End of Chunk" offset: what the last offset in the current chunk is. That is, it tells you how long this chunk and all its children are. There are two big exceptions to this: "mhlt" and "mhlp" chunks. In both of these, this number is how many top-level children the mhl[pt] chunk has.


Database Object

mhbd format
offset field size value
0 header identifier 4 mhbd
4 header length 4 size of the mhbd header. For dbversion <= 0x15 (iTunes 7.2 and earlier), the length is 0x68. For dbversion >= 0x17 (iTunes 7.3 and later), the size is 0xBC.
8 total length 4 size of the header and all child records (since everything is a child of MHBD, this will always be the size of the entire file)
12 unknown 4 must be 1 on an iPod Classic otherwise the device will reject the iTunesDB. Has always been observed set to 1 on older devices. On an iPhone 3.x and a Nano 5G it's set to 2.
16 version number 4 appears to be a version number of the database type. 0x09 = iTunes 4.2, 0x0a = iTunes 4.5, 0x0b = iTunes 4.7, 0x0c = iTunes 4.71/4.8, 0x0d = iTunes 4.9, 0x0e = iTunes 5, 0x0f = iTunes 6, 0x10 = iTunes 6.0.1(?), 0x11 = iTunes 6.0.2-6.0.4, 0x12 = iTunes 6.0.5., 0x13 = iTunes 7.0, 0x14 = iTunes 7.1, 0x15 = iTunes 7.2, 0x16 = ?, 0x17 = iTunes 7.3.0, 0x18 = iTunes 7.3.1-7.3.2., 0x19 = iTunes 7.4, 0x1A = iTunes 7.5, 0x1B = iTunes 7.6.0, 0x1C = iTunes 7.6.1, 0x1D - iTunes 7.6.2, 0x20 - iTunes 7.7.0, 0x21 - iTunes 7.7.1, 0x23 - iTunes 8.0.0, 0x24 - iTunes 8.0.1, 0x25 - iTunes 8.0.2, 0x26 - iTunes 8.1.0, 0x27 - iTunes 8.1.1, 0x28 - iTunes 8.2.0, 0x29 - iTunes 9.0 (iPhone iTunesDB), 0x2a - iTunes 9.0.1, 0x2b - iTunes 9.0.2.
20 number of children 4 the number of MHSD children. This has been observed to be 2 (iTunes 4.8 and earlier) or 3 (iTunes 4.9 and older), the third being the separate podcast library in iTunes 4.9. Also it has been observed to be 4 (iTunes 7.1, 7.2), 5 (iTunes 7.3), or 6 (iTunes 8). With iTunes 9, it's 7 for an iPhone 3.x and 5 for an iPod classic (it doesn't have the mhsd type 6 and the artist list).
24 id 8 appears to a 64 bit id value for this database. Not checked by the iPod, as far as I can tell.
32 unknown 2 always seems to be 2. Set to 1 on an iPod Classic and an iPod Photo.
34 unknown 4 something found in iTunesDB 8 (0x25) -- a possible value appears to be 0x63029C23
38 unknown 8 Observed in dbversion 0x11 and later. It was thought that this field is used to store some sort of starting point to generate the item's dbid, but this idea was thrown away.
48 hashing scheme 2 Observed in dbversion 0x19 and later, and must be set to 0x01 for the new iPod Nano 3G (video) and iPod Classic if the hash at offset 88 is used. The obscure hash at offset 88 needs to be set as well, then. The same holds true for iPhone/iTouch with firmware version 1.x. For iPhone/iTouch with firmware 2.x this is set to 0x02 (iTunes 8). In this case, the area at offset 88 is zeroed, but the new hash at offset 114 must be filled.
50 unknown 20 Observed in dbversion 0x19 and later for the new iPod Nano 3G (video) and iPod Classics. Meaning unknown so far.
70 language 2 Observed in dbversion 0x13. It looks like this is a language id (langauge of the iTunes interface). For example for English(United States) this field has values 0x65 and 0x6E which is 'en'. The size of the filed might be bigger to distinguish different 'flavors' of a language.
72 library persistent id 8 Observed in dbversion 0x14. This is a 64-bit Persistent ID for this iPod Library. This matches the value of "Library Persistent ID" seen in hex form (as a 16-char hex string) in the drag object XML when dragging a song from an iPod in iTunes.
80 unknown apparently 4 Apparently set to 0x01 in dbversion 0x25 (iTunes 8/iPhone 2.x)
84 unknown apparently 4 Apparently set to 0x0D in dbversion 0x25 (iTunes 8/iPhone 2.x)
88 obscure hash 20 Observed in dbversion 0x19 for iPod Nano 3G (video), iPod Classics and for iPhone/iPod touch with firmware 1.x.
108 unknown 4 unknown; a seemingly valid value is 80 8F FF FF (iTunes 8/iPhone 2.x)
112 unknown 2 unknown; possibly some sort of version number; valid value seems to be 0x02. Must be 0x02 if the hash at position 114 is used, otherwise it can be 0x00
114 iPhone hash 46 hash for iPhone's iTunesDB (0x25/iTunes 8/iPhone 2.x); highly obfuscated
rest of header is zero padded

The Database Object has two to six children depending on iTunes version, which are all Data Sets.

DataSet

mhsd format
offset field size value
0 header identifier 4 mhsd
4 header length 4 size of the mhsd header
8 total length 4 size of the header and all child records
12 type 4 A type number.
1 = Track list - contains an MHLT
2 = Playlist List - contains an MHLP
3 = Podcast List - optional, probably. Contains an MHLP also.  
This MHLP is basically the same as the full playlist section, 
except it contains the podcasts in a slightly different way. 
See the Playlists section.
4 = Album List, first seen with iTunes 7.1.
5 = New Playlist List with Smart Playlists, first seen with iTunes 7.3.
6 = Unknown; contains an MHLT; can have an empty MHLT but apparently must be there. (Version 0x25)
8 = Artist List, first seen with iTunes 8.
9 = Unknown; contains no known record but instead a possible hash. Seen on 6-Gen iPod Classics at 
the very end of the iTunesDB file. The possible value begins at the end of the header, where 
the internal record should begin. (Version 0x29)
rest of header is zero padded

Depending on the type of Data Set, it will contain either a Track List child or a Playlist List child. Order is not guaranteed. Example files have contained the type 3 MHSD before the type 2 MHSD. In order for the iPod to list podcasts the type 3 Data Set MUST come between the type 1 and type 2 Data Sets.

TrackList

mhlt format
offset field size value
0 header identifier 4 mhlt
4 header length 4 size of the mhlt header
8 number of songs 4 the total number of songs in the Track List
rest of header is zero padded

The Track List has Track Items as its children. The number of Track Items is the same as the number of songs.

Track Item

</tr>
mhit format
offset field size value
0 header identifier 4 mhit
4 header length 4 size of the mhit header. For dbversion <= 0x0b (iTunes 4.7 and earlier), the length is 0x9c. For dbversion >= 0x0c (iTunes 4.71 and later), the size is 0xf4. For dbversion = 0x12 (iTunes 6.0.5), 0x13 (iTunes 7.0) the size is 0x148. For dbversion >= 0x14 (iTunes 7.1) the size is 0x184. For dbversion >= 0x1b (iTunes 7.6), the size is 0x01b4. For dbversion >= 0x20 (iTunes 7.7.0), the size is 0x0208. For dbversion >= 0x23 (iTunes 8.0.0), the size is 0x0248.
8 total length 4 size of the header and all child records
12 number of strings 4 number of strings (mhods) that are children of this mhit
16 unique id 4 unique ID for a track (referenced in playlists)
20 visible 4 If this value is 1, the song is visible on the iPod. All other values cause the file to be hidden. Was previously known as unk1.
24 filetype 4 This appears to always be 0 on 1st through 4th generation hard drive-based iPods. For the iTunesDB that is written to the 5th generation iPod (iPod Video) and the iPod Shuffle, iTunes 4.7.1 (and greater) writes out the file's type as an ANSI string padded with spaces. For example, an MP3 file has a filetype of 0x4d503320 -> 0x4d = 'M', 0x50 = 'P', 0x33 = '3', 0x20 = <space>. AAC is 0x41414320 & "new" AAC which is used by iTunes 7, M4A, is 0x4D344120. Protected AAC files (purchased from iTunes Store) are M4P = 0x4D345020. MP4 video files = 0x4D503420. Was previously known as unk2. This really is an integer field and is reversed in iTunesDB used in mobile phones with reversed endianess.
28 type1 1 CBR MP3s are type 0x00, VBR MP3s are type 0x01, AAC are type 0x00
29 type2 1 CBR MP3s are type 0x01, VBR MP3s are type 0x01, AAC are type 0x00 (type1 and type2 used to be one 2 byte field, but by it doesn't get reversed in the reversed endian iTunesDB for mobile phones, so it must be two fields).
30 compilation flag 1 1 if the flag is on, 0 if the flag is off
31 stars/rating 1 the rating of the track * 20. Note that the iPod does not update this value here when you change the rating. See the Play Counts file for more information.
32 last modified time 4 last modified time of the track
36 size 4 size of the track, in bytes
40 length 4 length of the track, in milliseconds
44 track number 4 the track number of the track (the 9 in 9/15)
48 total tracks 4 the total number of tracks on this album (the 15 in 9/15)
52 year 4 year of the track
56 bitrate 4 bitrate of the track (ie, 128, 320, etc)
60 sample rate 4 sample rate of the track (ie. 44100) multiplied by 0x10000.
64 volume 4 Volume adjustment field. This is a value from -255 to 255 that will be applied to the track on playback. If you adjust the volume slider in iTunes track info screen, this is what you are adjusting.
68 start time 4 time, in milliseconds, that the song will start playing at
72 stop time 4 time, in milliseconds, that the song will stop playing at
76 soundcheck 4 The SoundCheck value to apply to the song, when SoundCheck is switched on in the iPod settings. The value to put in this field can be determined by the equation: X = 1000 * 10 ^ (-.1 * Y) where Y is the adjustment value in dB and X is the value that goes into the SoundCheck field. The value 0 is special, the equation is not used and it is treated as "no Soundcheck" (basically the same as the value 1000). This equation works perfectly well with ReplayGain derived data instead of the iTunes SoundCheck derived information.
80 play count 4 play count of the song. Note that the iPod does not update this value here. See the Play Counts file for more information.
84 play count 2 4 play count of the song since the last sync. Used to sync play count information back to iTunes. See the Play Counts file for more information.
88 last played time 4 time the song was last played. Note that the iPod does not update this value here. See the Play Counts file for more information.
92 disc number 4 disc number, for multi disc sets
96 total discs 4 total number of discs, for multi disc sets.
100 userid 4 Apple Store/Audible User ID (for DRM'ed files only, set to 0 otherwise). Previously known as unk5.
104 date added 4 date added to the iPod or iTunes (not certain which)
108 bookmark time 4 the point, in milliseconds, that the track will start playing back at. This is used for AudioBook filetypes (.AA and .M4B) based on the file extension. Note that there is also a bookmark value in the play counts file that will be set by the iPod and can be used instead of this value. See the Play Counts file for more information.
112 dbid 8 Unique 64 bit value that identifies this song across the databases on the iPod. For example, this id joins an iTunesDB mhit with a ArtworkDB mhii. iTunes appears to randomly create this value for a newly formatted iPod, then increments it by 1 for each additional song added. Previously known as unk7 and unk8.
120 checked 1 0 if the track is checked, 1 if it is not (in iTunes)
121 application rating 1 This is the rating that the song had before it was last changed, sorta. If you sync iTunes and the iPod, and they have different (new) ratings, the rating from iTunes will go here and the iPod rating will take precedence and go into the normal rating field. I'm uncertain what exactly this is for, but it's always set to what the iTunes rating is before each sync.
122 BPM 2 the BPM of the track
124 artwork count 2 The number of album artwork items put into the tags of this song. Even if you don't put any artwork items into the tags of the song, this value must at least be 1 for the iPod to display any artwork stored in the ithmb files.
126 unk9 2 unknown, but always seems to be 0xffff for MP3/AAC songs, 0x0 for uncompressed songs (like WAVE format), 0x1 for Audible
128 artwork size 4 The total size of artwork (in bytes) attached to this song (i.e. put into the song as tags). Observed in iPodDB version 0x0b and with an iPod Photo as well as with iPodDB version 0x0d and an iPod Nano.
132 unk11 4 unknown
136 sample rate 2 4 The sample rate of the song expressed as an IEEE 32 bit floating point number. It's uncertain why this is here.
140 date released 4 date/time added to music store? For podcasts this corresponds to the release date as displayed to the right of the podcast title. Formerly known as unk13.
144 unk14/1 2 unknown, but MPEG-1 Layer-3 songs appear to be always 0x000c, MPEG-2 Layer 3 songs (extrem low bitrate) appear to be 0x0016, MPEG-2.5 Layer 3 songs are 0x0020, AAC songs are always 0x0033, Audible files are 0x0029, WAV files are 0x0000.
146 explicit flag 2 If this flag is set to 1, the track is shown as explicit content in iTunes. Otherwise set this flag to 0. Was previously known as unk14/2.
148 unk15 4 unknown - used for Apple Store DRM songs (always 0x01010100?), zero otherwise
152 unk16 4 unknown
156 Skip Count 4 Number of times the track has been skipped. Formerly unknown 17 (added in dbversion 0x0c)
160 Last Skipped 4 Date/time last skipped. Formerly unknown 18 (added in dbversion 0x0c)
164 has_artwork 1 added in dbversion 0xd. Seems to be set to 0x02 for tracks without associated artwork (even if artwork is present, it will not be shown on the iPod) and 0x01 for tracks with associated artwork.
165 skip_when_shuffling 1 sets "Skip When Shuffling" when set to 0x1 (added in dbversion 0xd, formerly known as flag2)
166 remember_playback_position 1 sets "Remember Playback Position" when set to 0x1 (added in dbversion 0xd). Note that Protected AAC files (.m4b extension) and Audible files (.aa extension) do not set this flag or the previous one (skip_when_shuffling), and yet are always bookmarkable and are never included in the song shuffle. To determine if a file is bookmarkable, therefore, check the file type first. If it's not an .m4b or .aa, then check this flag in iTunesDB. (Formerly known as flag3)
167 flag4 1 some kind of "Podcast" flag (added in dbversion 0xd)? When this flag is set to 0x1 then the "Now playing" page will not show the artist name, but only title and album. When additionally has_artwork is 0x2 then there will be a new sub-page on the "Now playing" page with information about the podcast/song. If the track item is a kind of podcast then this flag must be set to 0x1 or 0x2, otherwise this flag must be set to 0x0. If this flag do not follow this, it might be removed from iTunesDB when user change there iPod to sync podcasts/songs in iTunes.
168 dbid2 8 Until dbversion 0x12, same data as dbid above (added in dbversion 0x0c). Since 0x12, this field value differs from the dbid one.
176 lyrics flag 1 set to 0x01 if lyrics are stored in the MP3 tags ("USLT"), 0 otherwise.
177 movie file flag 1 if 0x1, it is a movie file. Otherwise, it is an audio file.
178 played_mark 1 added in dbversion 0x0c, first values observed in 0x0d. Observed to be 0x01 for non-podcasts. With podcasts, a value of 0x02 marks this track with a bullet as 'not played' on the iPod, irrespective of the value of play count above. A value of 0x01 removes the bullet. Formerly known as unk20.
179 unk17 1 unknown - added in dbversion 0x0c. So far always 0.
180 unk21 4 unknown (added in dbversion 0x0c)
184 pregap 4 Number of samples of silence before the songs starts (for gapless playback).
188 sample count 8 Number of samples in the song (for gapless playback).
196 unk25 4 unknown (added in dbversion 0x0c)
200 postgap 4 Number of samples of silence at the end of the song (for gapless playback).
204 unk27 4 unknown - added in dbversion 0x0c, first values observed in 0x0d. Appears to be 0x1 for files encoded using the MP3 encoder, 0x0 otherwise.
208 Media Type 4 (formerly known as unk28; added in dbversion 0x0c). It seems that this field denotes the type of the file on (e.g.) the 5g video iPod. It must be set to 0x00000001 for audio files, and set to 0x00000002 for video files. If set to 0x00, the files show up in both, the audio menus ("Songs", "Artists", etc.) and the video menus ("Movies", "Music Videos", etc.). It appears to be set to 0x20 for music videos, and if set to 0x60 the file shows up in "TV Shows" rather than "Movies".

The following list summarizes all observed types:

  • 0x00 00 00 00 - Audio/Video
  • 0x00 00 00 01 - Audio
  • 0x00 00 00 02 - Video
  • 0x00 00 00 04 - Podcast
  • 0x00 00 00 06 - Video Podcast
  • 0x00 00 00 08 - Audiobook
  • 0x00 00 00 20 - Music Video
  • 0x00 00 00 40 - TV Show (shows up ONLY in TV Shows
  • 0x00 00 00 60 - TV Show (shows up in the Music lists as well)

Caution: Even if a track is marked as "Audiobook" here (value 0x08), it will not show up in the "Audiobooks" menu on the iPod. Only *.aa and *.m4b are shown there by recent firmwares. One proven exception: On the nano they show if they have the correct media type set here and the MHIT also has a chapter data mhod!

212 season number 4 the season number of the track, for TV shows only. Previously known as unk29. (added in dbversion 0x0c)
216 episode number 4 the episode number of the track, for TV shows only - although not displayed on the iPod, the episodes are sorted by episode number. Previously known as unk30. (added in dbversion 0x0c)
220 unk31 4 unknown (added in dbversion 0x0c). Has something to do with protected files - set to 0x0 for non-protected files.
224 unk32 4 unknown (added in dbversion 0x0c)
228 unk33 4 unknown (added in dbversion 0x0c)
232 unk34 4 unknown (added in dbversion 0x0c)
236 unk35 4 unknown (added in dbversion 0x0c)
240 unk36 4 unknown (added in dbversion 0x0c)
244 unk37 4 unknown (added in dbversion 0x13)
248 gaplessData 4 The size in bytes from first Synch Frame (which is usually the XING frame that includes the LAME tag) until the 8th before the last frame. The gapless playback does not work for MP3 files if this is set to zero. Maybe the iPod prepares the next track when rest 8 frames in the actual track. For AAC tracks, this may be zero. (added in dbversion 0x13)
252 unk38 4 unknown (added in dbversion 0x0c)
256 gaplessTrackFlag 2 if 1, this track has gapless playback data (added in dbversion 0x13)
258 gaplessAlbumFlag 2 if 1, this track does not use crossfading in iTunes (added in dbversion 0x13)
260 unk39 20 Appears to be a hash, not checked by the iPod
280 unk40 4 unknown (seen set to 0xbf)
284 unk41 4 unknown
288 AlbumID 4 album id from the album list
352 mhii-link 4 Setting this offset to != 0 triggers the 'Right-Pane-Artwork-Slideshow' on late 2007 iPods (3g Nano) and causes the iPod to use this value to do artwork lookups (dbid_1 will be ignored!). This value should be set to the id of the corresponding ArtworkDB mhii (Offset 16)
480 ArtistID 4 artist id from the artist list
The rest of the mhit is zero padded.

The MHIT is followed by several Data Objects which have string types. At minimum, it must have a Location type MHOD, in order to tell the iPod where the file is located on the iPod itself. It always has a FileType MHOD as well, although it's not totally necessary.

Playlist List

mhlp format
offset field size value
0 header identifier 4 mhlp
4 header length 4 size of the mhlp header
8 number of playlists 4 the number of playlists on the iPod. This includes the Library playlist.
rest of header is zero padded

The Playlist List has all the playlists as its children. The very first playlist *must* be the Library playlist. This is a normal playlist, but it has the special "hidden" bit set in it, and it contains all the songs on the iPod (in no particular order).

Playlist

mhyp format
offset field size value
0 header identifier 4 mhyp
4 header length 4 size of the mhyp header. For dbversion <= 0x2A (iTunes 9.0.1.8), the size is 0x6C. For dbversion >= 0x2B (iTunes 9.0.2.25), the size is 0x8C.
8 total length 4 size of the header and all child records
12 Data Object Child Count 4 number of Data Objects in the List
16 Playlist Item Count 4 number of Playlist Items in the List
20 Is Master Playlist flag 1 1 if the playlist is the Master (Library) playlist, 0 if it is not. Only the Master (Library) Playlist should have a 1 here.
21 unk 3 Probably three more flags, the first of which has been observed to have been set to 1 for some playlists.
24 timestamp 4 time of the playlists creation
28 persistent playlist ID 8 a unique, randomly generated ID for the playlist
36 unk3 4 Always zero?
40 String MHOD Count 2 This appears to be the number of string MHODs (type < 50) associated with this playlist (typically 0x01). Doesn't seem to be signficant unless you include Type 52 MHODs. Formerly known as unk4.
42 Podcast Flag 1 This is set to 0 on normal playlists and to 1 for the Podcast playlist. If set to 1, the playlist will not be shown under 'Playlists' on the iPod, but as 'Podcasts' under the Music menu.. The actual title of the Playlist does not matter. If more than one playlist is set to 1, they don't show up at all. They also don't show up if you set this to 1 on one playlist and 2 on the other. Please note that podcast playlists are organized slightly different than ordinary playlists (see below).
43 Group Flag 1 This is set to 0 on normal playlists and to 1 for a grouping playlist which is a new feature of iTunes 7. If set to 1, this playlist will show up as a toplevel folder on the iPod, if you hit the center button you will get a list of included playlists. Unclear so far: How are the included playlists determined? MHOD 100?
44 List Sort Order 4 The field that the playlist will be sorted by. See list below.
rest of header is zero padded

The structure of the Playlists are different than most others. Each Playlist looks like this, conceptually:

   <mhyp>
      <mhod type=1>Playlist Name</mhod>
      <mhod type=50>Smart Playlist Info</mhod> (optional)
      <mhod type=51>Smart Playlist Rules</mhod> (optional)
      ...
      <mhip>Playlist Item</mhip>
             <mhod type=100>Position Indicator</mhod>
      <mhip>Playlist Item</mhip>
             <mhod type=100>Position Indicator</mhod>
      ...
   </mhyp>

The point being that these are all considered in the MHYP for the size calculations. However, in the "Data Object" child count, ONLY those MHODs that come before the first MHIP are counted. The "position indicators" are children of the MHIPs (older firmwares had a bug in this respect).


List Sort Order

1 - playlist order (manual sort order)
2 - ???
3 - songtitle
4 - album
5 - artist
6 - bitrate
7 - genre
8 - kind
9 - date modified
10 - track number
11 - size
12 - time
13 - year
14 - sample rate
15 - comment
16 - date added
17 - equalizer
18 - composer
19 - ???
20 - play count
21 - last played
22 - disc number
23 - my rating
24 - release date (I guess, it's the value for the "Podcasts" list)
25 - BPM
26 - grouping
27 - category
28 - description
29 - show
30 - season
31 - episode number

Podcasts

The podcasts playlist is organized slightly differently, in the Type 3 MHSD. For example:

mhyp (MHODs: 2, MHIPs: 5, hidden: 0, list sort order: 0x18)
  mhod (type: 1, string: 'Podcasts')
  mhod (type: 100)
  mhip (MHODs: 1, groupflag: 256, groupid: 8232, trackid: 0, timestamp: 0, groupref: 0)
    mhod (type: 1, string: 'Example podcast')
  mhip (MHODs: 1, groupflag: 0, groupid: 8233, trackid: 8230, timestamp: 3206828281, groupref: 8232)
    mhod (type: 100)
  mhip (MHODs: 1, groupflag: 0, groupid: 8234, trackid: 8226, timestamp: 3206828379, groupref: 8232)
    mhod (type: 100)
  mhip (MHODs: 1, groupflag: 0, groupid: 8235, trackid: 8228, timestamp: 3206828327, groupref: 8232)
    mhod (type: 100)
  mhip (MHODs: 1, groupflag: 0, groupid: 8236, trackid: 8224, timestamp: 3206828394, groupref: 8232)
    mhod (type: 100)

The first mhip (probably identified by groupflag==256) contains the name of a podcast which will then appear as a submenu of the Podcasts menu on the iPod. The other mhips (which reference the episodes in that podcast) seem to use the groupref field to link to their 'parent' mhip (using the groupid field). At the same time the groupids of the episodes are unique as well, but don't seem to be used anywhere else.

Playlist Item

mhip format
offset field size value
0 header identifier 4 mhip
4 header length 4 size of the mhip header
8 total length 4 size of the header and all child records
12 Data Object Child Count 4 number of mhod following this Playlist Item (always 1 so far)
16 Podcast Grouping Flag 2 Formerly unk1. 0x0 = normal file. 0x100 = Podcast Group. Podcast Groups will be followed by a single child, an MHOD type 1 string, which specifies the name of the Podcast Group. They will also have a 0 (zero) for the Track ID. This field used to be some kind of correlation ID or something, but this may have been a bug. In any case, the old way breaks iPods now, and this should be set to zero on all normal songs.
18 unk4 1 0 or 1 in iTunes 7.2.
19 unk5 1 0 or 8 in iTunes 7.2.
20 Group ID (?) 4 Formerly unk2. A unique ID for the track. It appears it is made sure that this ID does not correspond to any real track ID. Doesn't seem to correlate to anything, but other bits reference it. See Podcast Grouping Reference below.
24 track ID 4 the ID number of the track in the track list. See Track Item for more info
28 timestamp 4 some kind of time stamp, possibly time the song was added to the playlist
32 Podcast Grouping Reference 4 Formerly unk3. This is the parent group that this podcast should be listed under. It should be zero the rest of the time.
36 unk4 4 Always zero?
40 unk5 4 Always zero?
44 unk6 8 Some id? Introduced with DB version 0x1C = iTunes 7.6.1?
rest of header is zero padded

For purposes of size calculations, Playlist Items have no children. However, every Playlist Item is invariably followed by a Data Object of type 100, which contains nothing but a number that is used to order/sort the playlist. See the Playlist description above for more information.

Please note that starting with iTunes 4.9 (mhbd file version number 0x0d) the Type 100 MHOD following the Playlist Item is considered a child of the Playlist Item and is included into the size calculation. The old behaviour was probably a bug in iTunes.