2
* Copyright (C) 2005 Christophe Fergeau
5
* The code contained in this file is free software; you can redistribute
6
* it and/or modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either version
8
* 2.1 of the License, or (at your option) any later version.
10
* This file is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this code; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* iTunes and iPod are trademarks of Apple
21
* This product is not supported/written/published by Apple!
30
/*#include "ipod-db-parser.h"*/
32
#define ITUNESDB_MAX_SIZE 10 * 1024 * 1024
35
unsigned char header_id[4];
39
typedef struct _MHeader MHeader;
42
unsigned char header_id[4];
45
unsigned char padding[];
48
typedef struct _MhlHeader MhlHeader;
51
typedef struct _MhbdHeader MhbdHeader;
52
typedef struct _ArtworkDB_MhsdHeader ArtworkDB_MhsdHeader;
53
/*typedef struct _MhsdHeader MhsdHeader;*/
54
typedef struct _MhltHeader MhltHeader;
55
typedef struct _MhlpHeader MhlpHeader;
56
typedef struct _MhypHeader MhypHeader;
57
typedef struct _MhipHeader MhipHeader;
58
typedef struct _MhitHeader MhitHeader;
59
typedef struct _ArtworkDB_MhodHeader ArtworkDB_MhodHeader;
60
/*typedef struct _MhodHeader MhodHeader;*/
61
typedef struct _MhfdHeader MhfdHeader;
62
typedef struct _MhliHeader MhliHeader;
63
typedef struct _MhiiHeader MhiiHeader;
64
typedef struct _MhniHeader MhniHeader;
65
typedef struct _MhlaHeader MhlaHeader;
66
typedef struct _MhbaHeader MhbaHeader;
67
typedef struct _MhlfHeader MhlfHeader;
68
typedef struct _MhifHeader MhifHeader;
69
typedef struct _MhiaHeader MhiaHeader;
71
typedef struct _MhitHeader471 MhitHeader471;
72
/* MHOD typedef mess */
73
typedef struct _ArtworkDB_MhodHeaderArtworkType3 ArtworkDB_MhodHeaderArtworkType3;
74
typedef struct _MhodHeaderString MhodHeaderString;
75
typedef struct _MhodHeaderArtworkType1 MhodHeaderArtworkType1;
76
/* typedef struct _MhodHeaderArtworkType3 MhodHeaderArtworkType3; */
77
typedef struct _MhodHeaderSmartPlaylistData MhodHeaderSmartPlaylistData;
78
typedef struct _MhodHeaderSmartPlaylistRuleString MhodHeaderSmartPlaylistRuleString;
79
typedef struct _MhodHeaderSmartPlaylistRuleNonString MhodHeaderSmartPlaylistRuleNonString;
80
typedef struct _MhodHeaderSmartPlaylistRule MhodHeaderSmartPlaylistRule;
83
unsigned char header_id[4];
91
unsigned char padding[];
96
MHSD_PLAYLIST_LIST = 2
99
enum MhsdPhotoIndexType {
105
struct _ArtworkDB_MhsdHeader {
106
unsigned char header_id[4];
109
/* Strangely, the following field is only 16 bits long in the
110
* ArtworkDB (it's definitely 32 bits in the iTunesDB). This
111
* could well be an error with the first generation of mobile
112
* phones with iPod support).
116
unsigned char padding[];
119
struct _iTunesDB_MhsdHeader {
120
unsigned char header_id[4];
124
unsigned char padding[];
127
unsigned char header_id[4];
130
unsigned char padding[];
134
unsigned char header_id[4];
136
gint32 num_playlists;
137
unsigned char padding[];
141
unsigned char header_id[4];
152
unsigned char padding[];
156
unsigned char header_id[4];
160
gint32 correlation_id;
164
unsigned char padding[];
167
/* MHIT header as written by iTunes 4.7.1, the added fields (from unknown17 to
168
* the end of the struct) are pretty useless, so we don't use this struct
170
struct _MhitHeader471 {
171
unsigned char header_id[4];
178
/* FIXME: endianness issue with the order of the 3 fields above ? */
189
/* FIXME: endianness issue with the order of the 2 fields above ? */
202
gint32 last_modified;
203
gint32 bookmark_time;
205
/* FIXME: endianness issue with the order of the 5 fields above ? */
209
gint16 artwork_count;
239
unsigned char padding[];
243
unsigned char header_id[4];
250
/* FIXME: endianness issue with the order of the 3 fields above ? */
261
/* FIXME: endianness issue with the order of the 2 fields above ? */
274
gint32 last_modified;
275
gint32 bookmark_time;
277
/* FIXME: endianness issue with the order of the 5 fields above ? */
281
gint16 artwork_count;
290
unsigned char padding[];
294
MHOD_ENCODING_UTF16 = 0,
295
MHOD_ENCODING_UTF8 = 1
300
MHOD_TYPE_LOCATION = 2,
302
MHOD_TYPE_ARTIST = 4,
304
MHOD_TYPE_FILETYPE = 6,
305
MHOD_TYPE_EQ_SETTING = 7,
306
MHOD_TYPE_COMMENT = 8,
307
MHOD_TYPE_COMPOSER = 12,
308
MHOD_TYPE_GROUPING = 13,
309
MHOD_TYPE_SMART_PLAYLIST_DATA = 50,
310
MHOD_TYPE_SMART_PLAYLIST_RULES = 51,
311
MHOD_TYPE_LIBRARY_PLAYLIST_INDEX = 52,
316
unsigned char header_id[4];
324
struct _ArtworkDB_MhodHeader {
325
unsigned char header_id[4];
328
/* Strangely, the following field is only 16 bits long in the
329
* ArtworkDB (it's definitely 32 bits in the iTunesDB). This
330
* could well be an error with the first generation of mobile
331
* phones with iPod support).
339
struct _MhodHeaderString {
340
unsigned char header_id[4];
343
gint32 type; /* < 50 */
348
gint32 unknown3; /* It was thought that this was string encoding:
349
* 0 == UTF-16, 1 == UTF-8, however, recent iTunesDB
350
* files have had this set to 1 even with UTF-16 strings.
351
* Therefore this is definitely incorrect, and the
352
* correct meaning has not yet been discovered yet. */
354
unsigned char string[];
357
enum MhodArtworkType {
358
MHOD_ARTWORK_TYPE_ALBUM_NAME = 1, /* string: album name (in the Photo Database) */
359
MHOD_ARTWORK_TYPE_THUMBNAIL = 2, /* container: thumbnail image */
360
MHOD_ARTWORK_TYPE_FILE_NAME = 3, /* string: file name */
361
MHOD_ARTWORK_TYPE_IMAGE = 5 /* container: full resolution image (in the Photo Database) */
364
struct _MhodHeaderArtworkType1 {
365
unsigned char header_id[4];
374
gint32 unknown3; /* might be the string encoding */
375
gint32 unknown4; /* always zero? */
376
unsigned char string[];
379
struct _MhodHeaderArtworkType3 {
380
unsigned char header_id[4];
384
gint16 padding; /* high byte is padding length (0-3) */
393
struct _ArtworkDB_MhodHeaderArtworkType3 {
394
unsigned char header_id[4];
403
gint8 mhod_version; /* 0,1: string is UTF8, 2: string is
413
MHOD_LIMIT_MINUTES = 1,
414
MHOD_LIMIT_MEGABYTES = 2,
415
MHOD_LIMIT_SONGS = 3,
416
MHOD_LIMIT_HOURS = 4,
417
MHOD_LIMIT_GIGABYTES = 5
420
enum MhodLimitSortType {
421
MHOD_LIMIT_SORT_RANDOM = 0x02,
422
MHOD_LIMIT_SORT_SONG_NAME = 0x03,
423
MHOD_LIMIT_SORT_ALBUM = 0x04,
424
MHOD_LIMIT_SORT_ARTIST = 0x05,
425
MHOD_LIMIT_SORT_GENRE = 0x07,
426
MHOD_LIMIT_SORT_MOST_RECENTLY_ADDED = 0x10,
427
MHOD_LIMIT_SORT_MOST_OFTEN_PLAYED = 0x14,
428
MHOD_LIMIT_SORT_MOST_RECENTLY_PLAYED = 0x15,
429
MHOD_LIMIT_SORT_HIGHEST_RATING = 0x17
432
struct _MhodHeaderSmartPlaylistData {
433
unsigned char header_id[4];
436
gint32 type; /* 50 */
446
gchar match_checked_only;
447
gchar reverse_limit_sort;
448
unsigned char padding[];
452
enum MhodSmartPlaylistRuleFieldType {
453
MHOD_FIELD_SONG_NAME = 0x02,
454
MHOD_FIELD_ALBUM = 0x03,
455
MHOD_FIELD_ARTIST = 0x04,
456
MHOD_FIELD_BITRATE = 0x05,
457
MHOD_FIELD_SAMPLE_RATE = 0x06,
458
MHOD_FIELD_YEAR = 0x07,
459
MHOD_FIELD_GENRE = 0x08,
460
MHOD_FIELD_KIND = 0x09,
461
MHOD_FIELD_DATE_MODIFIED = 0x0a,
462
MHOD_FIELD_TRACK_NUMBER = 0x0b,
463
MHOD_FIELD_SIZE = 0x0c,
464
MHOD_FIELD_TIME = 0x0d,
465
MHOD_FIELD_COMMENT = 0x0e,
466
MHOD_FIELD_DATE_ADDED = 0x10,
467
MHOD_FIELD_COMPOSER = 0x12,
468
MHOD_FIELD_PLAY_COUNT = 0x16,
469
MHOD_FIELD_LAST_PLAYED = 0x17,
470
MHOD_FIELD_DISC_NUMBER = 0x18,
471
MHOD_FIELD_RATING = 0x19,
472
MHOD_FIELD_COMPILATION = 0x1f,
473
MHOD_FIELD_BPM = 0x23,
474
MHOD_FIELD_GROUPING = 0x27,
475
MHOD_FIELD_PLAYLIST = 0x28
478
enum MhodSmartPlaylistRuleAction {
479
MHOD_RULE_IS = 1 << 0,
480
MHOD_RULE_CONTAINS = 1 << 1,
481
MHOD_RULE_BEGINS_WITH = 1 << 2,
482
MHOD_RULE_ENDS_WITH = 1 << 3,
483
MHOD_RULE_GREATER_THAN = 1 << 4,
484
MHOD_RULE_GREATER_THAN_OR_EQUAL_TO = 1 << 5,
485
MHOD_RULE_LESS_THAN = 1 << 6,
486
MHOD_RULE_LESS_THAN_OR_EQUAL_TO = 1 << 7,
487
MHOD_RULE_IN_THE_RANGE = 1 << 8,
488
MHOD_RULE_IS_THE_LAST = 1 << 9,
489
MHOD_RULE_NOT = 1 << 24,
490
MHOD_RULE_STRING = 1 << 25
494
struct _MhodHeaderSmartPlaylistRuleString {
495
/* Big endian fields */
503
struct _MhodHeaderSmartPlaylistRuleNonString {
504
/* Big endian fields */
518
struct _MhodHeaderSmartPlaylistRule {
519
unsigned char header_id[4];
522
gint32 type; /* 51 */
526
/* Fields stored in big-endian from there */
528
gint32 number_of_rules;
529
gint32 rules_operator;
532
MhodHeaderSmartPlaylistRuleString rule_string;
533
MhodHeaderSmartPlaylistRuleNonString rule_non_string;
540
unsigned char header_id[4];
558
unsigned char padding[];
562
unsigned char header_id[4];
565
unsigned char padding[];
569
unsigned char header_id[4];
579
gint32 digitised_date;
580
gint32 orig_img_size;
581
unsigned char padding[];
582
} __attribute__((__packed__));
583
/* I we don't put the 'packed' attribute above, some 64 bit systems
584
* will pad the 64 bit integer to be aligned to an 8-byte boundary.
585
* Hopefully there won't be any systems around that crash when
586
* accessing 64 bit integers not aligned to 8-byte boundaries. */
590
unsigned char header_id[4];
594
gint32 correlation_id;
597
gint16 vertical_padding;
598
gint16 horizontal_padding;
601
unsigned char padding[];
605
unsigned char header_id[4];
608
unsigned char padding[];
612
unsigned char header_id[4];
615
gint32 num_mhods; /* number of Data Objects in the List, probably always 1 */
616
gint32 num_mhias; /* number of pictures in the album */
617
gint32 playlist_id; /* starts out at $64 and increments by 1 */
618
gint32 unknown2; /* unknown, seems to be always 0 */
619
gint16 unknown3; /* unknown, seems to be always 0 */
621
/* FIXME: not sure if I have these right; iPod doesn't seem to listen to them */
626
guint8 transition_direction;
627
gint32 slide_duration;
628
gint32 transition_duration;
632
gint32 prev_playlist_id; /* the id of the previous playlist */
633
unsigned char padding[];
637
unsigned char header_id[4];
640
unsigned char padding[];
644
unsigned char header_id[4];
648
gint32 correlation_id;
650
unsigned char padding[];
654
unsigned char header_id[4];
656
gint32 total_len; /* probably the size of the header and all child records;
657
* as there aren't any child records this is equal to header length */
658
gint32 unknown1; /* seems to be zero */
659
gint32 image_id; /* the id of the mhii record this mhia refers to */
660
unsigned char padding[];
664
#endif /* PARSE_DB_H */