1
/* Time-stamp: <2006-09-18 01:33:30 jcs>
3
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
4
| Part of the gtkpod project.
6
| URL: http://www.gtkpod.org/
7
| URL: http://gtkpod.sourceforge.net/
9
| Most of the code in this file has been ported from the perl
10
| script "mktunes.pl" (part of the gnupod-tools collection) written
11
| by Adrian Ulrich <pab at blinkenlights.ch>.
13
| gnupod-tools: http://www.blinkenlights.ch/cgi-bin/fm.pl?get=ipod
15
| The code contained in this file is free software; you can redistribute
16
| it and/or modify it under the terms of the GNU Lesser General Public
17
| License as published by the Free Software Foundation; either version
18
| 2.1 of the License, or (at your option) any later version.
20
| This file is distributed in the hope that it will be useful,
21
| but WITHOUT ANY WARRANTY; without even the implied warranty of
22
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
| Lesser General Public License for more details.
25
| You should have received a copy of the GNU Lesser General Public
26
| License along with this code; if not, write to the Free Software
27
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
| iTunes and iPod are trademarks of Apple
31
| This product is not supported/written/published by Apple!
33
| $Id: itdb.h,v 1.41 2006/09/17 17:14:21 jcsjcs Exp $
36
#ifndef __ITUNESDB_H__
37
#define __ITUNESDB_H__
41
#include <sys/types.h>
47
/* G_GNUC_INTERNAL is defined in glib 2.6 */
48
#ifndef G_GNUC_INTERNAL
49
#define G_GNUC_INTERNAL
52
typedef void (* ItdbUserDataDestroyFunc) (gpointer userdata);
53
typedef gpointer (* ItdbUserDataDuplicateFunc) (gpointer userdata);
55
typedef struct _Itdb_Device Itdb_Device;
56
typedef struct _Itdb_Artwork Itdb_Artwork;
57
typedef struct _Itdb_Thumb Itdb_Thumb;
58
typedef struct _SPLPref SPLPref;
59
typedef struct _SPLRule SPLRule;
60
typedef struct _SPLRules SPLRules;
61
typedef struct _Itdb_iTunesDB Itdb_iTunesDB;
62
typedef struct _Itdb_PhotoDB Itdb_PhotoDB;
63
typedef struct _Itdb_Playlist Itdb_Playlist;
64
typedef struct _Itdb_PhotoAlbum Itdb_PhotoAlbum;
65
typedef struct _Itdb_Track Itdb_Track;
66
typedef struct _Itdb_IpodInfo Itdb_IpodInfo;
69
/* ------------------------------------------------------------ *\
71
* Thumbnail-relevant definitions
73
\* ------------------------------------------------------------ */
75
/* Types of thumbnails in Itdb_Image */
77
ITDB_THUMB_COVER_SMALL,
78
ITDB_THUMB_COVER_LARGE,
79
ITDB_THUMB_PHOTO_SMALL,
80
ITDB_THUMB_PHOTO_LARGE,
81
ITDB_THUMB_PHOTO_FULL_SCREEN,
82
ITDB_THUMB_PHOTO_TV_SCREEN
86
/* The Itdb_Thumb structure can represent two slightly different
89
a) a thumbnail before it's transferred to the iPod.
93
width and height, if unequal 0, will indicate the size on the
94
iPod. width and height are set the first time a pixbuf is
95
requested for this thumbnail.
97
type is set according to the type this thumbnail represents
99
filename point to a 'real' image file OR image_data and
100
image_data_len are set.
102
b) a thumbnail (big or small) stored on a database in the iPod. In
103
these cases, id corresponds to the ID originally used in the
104
database, filename points to a .ithmb file on the iPod
109
guchar *image_data; /* holds the thumbnail data of
110
non-transfered thumbnails when
112
gsize image_data_len; /* length of data */
117
gint16 horizontal_padding;
118
gint16 vertical_padding;
121
struct _Itdb_Artwork {
122
GList *thumbnails; /* list of Itdb_Thumbs */
123
guint32 artwork_size; /* Size in bytes of the original source image */
124
guint32 id; /* Artwork id used by photoalbums, starts at
125
* 0x40... libgpod will set this on sync. */
126
gint32 creation_date; /* Date the image was created */
127
/* below is for use by application */
130
/* function called to duplicate userdata */
131
ItdbUserDataDuplicateFunc userdata_duplicate;
132
/* function called to free userdata */
133
ItdbUserDataDestroyFunc userdata_destroy;
137
/* ------------------------------------------------------------ *\
139
* iPod model-relevant definitions
141
\* ------------------------------------------------------------ */
144
ITDB_IPOD_GENERATION_UNKNOWN,
145
ITDB_IPOD_GENERATION_FIRST,
146
ITDB_IPOD_GENERATION_SECOND,
147
ITDB_IPOD_GENERATION_THIRD,
148
ITDB_IPOD_GENERATION_FOURTH,
149
ITDB_IPOD_GENERATION_FIFTH,
150
ITDB_IPOD_GENERATION_SIXTH,
151
ITDB_IPOD_GENERATION_MOBILE
152
} Itdb_IpodGeneration;
155
ITDB_IPOD_MODEL_INVALID,
156
ITDB_IPOD_MODEL_UNKNOWN,
157
ITDB_IPOD_MODEL_COLOR,
158
ITDB_IPOD_MODEL_COLOR_U2,
159
ITDB_IPOD_MODEL_REGULAR,
160
ITDB_IPOD_MODEL_REGULAR_U2,
161
ITDB_IPOD_MODEL_MINI,
162
ITDB_IPOD_MODEL_MINI_BLUE,
163
ITDB_IPOD_MODEL_MINI_PINK,
164
ITDB_IPOD_MODEL_MINI_GREEN,
165
ITDB_IPOD_MODEL_MINI_GOLD,
166
ITDB_IPOD_MODEL_SHUFFLE,
167
ITDB_IPOD_MODEL_NANO_WHITE,
168
ITDB_IPOD_MODEL_NANO_BLACK,
169
ITDB_IPOD_MODEL_VIDEO_WHITE,
170
ITDB_IPOD_MODEL_VIDEO_BLACK,
171
ITDB_IPOD_MODEL_MOBILE_1,
172
ITDB_IPOD_MODEL_VIDEO_U2,
173
ITDB_IPOD_MODEL_NANO_SILVER,
174
ITDB_IPOD_MODEL_NANO_BLUE,
175
ITDB_IPOD_MODEL_NANO_GREEN,
176
ITDB_IPOD_MODEL_NANO_PINK
179
struct _Itdb_IpodInfo {
180
/* model_number is abbreviated: if the first character is not
181
numeric, it is ommited. e.g. "MA350 -> A350", "M9829 -> 9829" */
182
const gchar *model_number;
183
const double capacity; /* in GB */
184
const Itdb_IpodModel ipod_model;
185
const Itdb_IpodGeneration ipod_generation;
186
/* Number of music (Fnn) dirs created by iTunes. The exact
187
number seems to be version dependent. Therefore, the
188
numbers here represent a mixture of reported values and
189
common sense. Note: this number does not necessarily
190
represent the number of dirs present on a particular
191
iPod. It is used when setting up a new iPod from
193
const guint musicdirs;
197
/* ------------------------------------------------------------ *\
199
* Smart Playlists (Rules)
201
\* ------------------------------------------------------------ */
204
/* Most of the knowledge about smart playlists has been provided by
205
Samuel "Otto" Wood (sam dot wood at gmail dot com) who let me dig
206
in his impressive C++ class. Contact him for a complete
207
copy. Further, all enums and #defines below, SPLRule, SPLRules, and
208
SPLPref may also be used under a FreeBSD license. */
210
#define SPL_STRING_MAXLEN 255
212
/* Definitions for smart playlists */
213
enum { /* types for match_operator */
214
SPLMATCH_AND = 0, /* AND rule - all of the rules must be true in
215
order for the combined rule to be applied */
216
SPLMATCH_OR = 1 /* OR rule */
219
/* Limit Types.. like limit playlist to 100 minutes or to 100 songs */
221
LIMITTYPE_MINUTES = 0x01,
223
LIMITTYPE_SONGS = 0x03,
224
LIMITTYPE_HOURS = 0x04,
228
/* Limit Sorts.. Like which songs to pick when using a limit type
229
Special note: the values for LIMITSORT_LEAST_RECENTLY_ADDED,
230
LIMITSORT_LEAST_OFTEN_PLAYED, LIMITSORT_LEAST_RECENTLY_PLAYED, and
231
LIMITSORT_LOWEST_RATING are really 0x10, 0x14, 0x15, 0x17, with the
232
'limitsort_opposite' flag set. This is the same value as the
233
"positive" value (i.e. LIMITSORT_LEAST_RECENTLY_ADDED), and is
234
really very terribly awfully weird, so we map the values to iPodDB
235
specific values with the high bit set.
237
On writing, we check the high bit and write the limitsort_opposite
238
from that. That way, we don't have to deal with programs using the
239
class needing to set the wrong limit and then make it into the
240
"opposite", which would be frickin' annoying. */
242
LIMITSORT_RANDOM = 0x02,
243
LIMITSORT_SONG_NAME = 0x03,
244
LIMITSORT_ALBUM = 0x04,
245
LIMITSORT_ARTIST = 0x05,
246
LIMITSORT_GENRE = 0x07,
247
LIMITSORT_MOST_RECENTLY_ADDED = 0x10,
248
LIMITSORT_LEAST_RECENTLY_ADDED = 0x80000010, /* See note above */
249
LIMITSORT_MOST_OFTEN_PLAYED = 0x14,
250
LIMITSORT_LEAST_OFTEN_PLAYED = 0x80000014, /* See note above */
251
LIMITSORT_MOST_RECENTLY_PLAYED = 0x15,
252
LIMITSORT_LEAST_RECENTLY_PLAYED = 0x80000015,/* See note above */
253
LIMITSORT_HIGHEST_RATING = 0x17,
254
LIMITSORT_LOWEST_RATING = 0x80000017, /* See note above */
257
/* Smartlist Actions - Used in the rules.
258
Note by Otto (Samuel Wood):
259
really this is a bitmapped field...
261
bit 0 = "string" values if set, "int" values if not set
262
bit 1 = "not", or to negate the check.
264
bit 0 = simple "IS" query
269
bit 5 = unknown, but probably greater than or equal to
271
bit 7 = unknown, but probably less than or equal to
272
bit 8 = a range selection
273
bit 9 = "in the last"
276
SPLACTION_IS_INT = 0x00000001, /* "Is Set" in iTunes */
277
SPLACTION_IS_GREATER_THAN = 0x00000010, /* "Is After" in iTunes */
278
SPLACTION_IS_LESS_THAN = 0x00000040, /* "Is Before" in iTunes */
279
SPLACTION_IS_IN_THE_RANGE = 0x00000100,
280
SPLACTION_IS_IN_THE_LAST = 0x00000200,
282
SPLACTION_IS_STRING = 0x01000001,
283
SPLACTION_CONTAINS = 0x01000002,
284
SPLACTION_STARTS_WITH = 0x01000004,
285
SPLACTION_ENDS_WITH = 0x01000008,
287
SPLACTION_IS_NOT_INT = 0x02000001, /* "Is Not Set" in iTunes */
289
/* Note: Not available in iTunes 4.5 (untested on iPod) */
290
SPLACTION_IS_NOT_GREATER_THAN = 0x02000010,
291
/* Note: Not available in iTunes 4.5 (untested on iPod) */
292
SPLACTION_IS_NOT_LESS_THAN = 0x02000040,
293
/* Note: Not available in iTunes 4.5 (seems to work on iPod) */
294
SPLACTION_IS_NOT_IN_THE_RANGE = 0x02000100,
296
SPLACTION_IS_NOT_IN_THE_LAST = 0x02000200,
297
SPLACTION_IS_NOT = 0x03000001,
298
SPLACTION_DOES_NOT_CONTAIN = 0x03000002,
300
/* Note: Not available in iTunes 4.5 (seems to work on iPod) */
301
SPLACTION_DOES_NOT_START_WITH = 0x03000004,
302
/* Note: Not available in iTunes 4.5 (seems to work on iPod) */
303
SPLACTION_DOES_NOT_END_WITH = 0x03000008,
331
/* These are to pass to AddRule() when you need a unit for the two "in
332
the last" action types Or, in theory, you can use any time
333
range... iTunes might not like it, but the iPod shouldn't care. */
335
SPLACTION_LAST_DAYS_VALUE = 86400, /* nr of secs in 24 hours */
336
SPLACTION_LAST_WEEKS_VALUE = 604800, /* nr of secs in 7 days */
337
SPLACTION_LAST_MONTHS_VALUE = 2628000,/* nr of secs in 30.4167
342
// Hey, why limit ourselves to what iTunes can do? If the iPod can deal with it, excellent!
343
#define SPLACTION_LAST_HOURS_VALUE 3600 // number of seconds in 1 hour
344
#define SPLACTION_LAST_MINUTES_VALUE 60 // number of seconds in 1 minute
345
#define SPLACTION_LAST_YEARS_VALUE 31536000 // number of seconds in 365 days
347
/* fun ones.. Near as I can tell, all of these work. It's open like that. :)*/
348
#define SPLACTION_LAST_LUNARCYCLE_VALUE 2551443 // a "lunar cycle" is the time it takes the moon to circle the earth
349
#define SPLACTION_LAST_SIDEREAL_DAY 86164 // a "sidereal day" is time in one revolution of earth on its axis
350
#define SPLACTION_LAST_SWATCH_BEAT 86 // a "swatch beat" is 1/1000th of a day.. search for "internet time" on google
351
#define SPLACTION_LAST_MOMENT 90 // a "moment" is 1/40th of an hour, or 1.5 minutes
352
#define SPLACTION_LAST_OSTENT 600 // an "ostent" is 1/10th of an hour, or 6 minutes
353
#define SPLACTION_LAST_FORTNIGHT 1209600 // a "fortnight" is 14 days
354
#define SPLACTION_LAST_VINAL 1728000 // a "vinal" is 20 days
355
#define SPLACTION_LAST_QUARTER 7889231 // a "quarter" is a quarter year
356
#define SPLACTION_LAST_SOLAR_YEAR 31556926 // a "solar year" is the time it takes the earth to go around the sun
357
#define SPLACTION_LAST_SIDEREAL_YEAR 31558150 // a "sidereal year" is the time it takes the earth to reach the same point in space again, compared to the stars
360
/* Smartlist fields - Used for rules. */
362
SPLFIELD_SONG_NAME = 0x02, /* String */
363
SPLFIELD_ALBUM = 0x03, /* String */
364
SPLFIELD_ARTIST = 0x04, /* String */
365
SPLFIELD_BITRATE = 0x05, /* Int (e.g. from/to = 128) */
366
SPLFIELD_SAMPLE_RATE = 0x06, /* Int (e.g. from/to = 44100) */
367
SPLFIELD_YEAR = 0x07, /* Int (e.g. from/to = 2004) */
368
SPLFIELD_GENRE = 0x08, /* String */
369
SPLFIELD_KIND = 0x09, /* String */
370
SPLFIELD_DATE_MODIFIED = 0x0a,/* Int/Mac Timestamp (e.g. from/to =
371
bcf93280 == is before 6/19/2004)*/
372
SPLFIELD_TRACKNUMBER = 0x0b, /* Int (e.g. from = 1, to = 2) */
373
SPLFIELD_SIZE = 0x0c, /* Int (e.g. from/to = 0x00600000
375
SPLFIELD_TIME = 0x0d, /* Int (e.g. from/to = 83999 for
377
SPLFIELD_COMMENT = 0x0e, /* String */
378
SPLFIELD_DATE_ADDED = 0x10, /* Int/Mac Timestamp (e.g. from/to =
379
bcfa83ff == is after 6/19/2004) */
380
SPLFIELD_COMPOSER = 0x12, /* String */
381
SPLFIELD_PLAYCOUNT = 0x16, /* Int (e.g. from/to = 1) */
382
SPLFIELD_LAST_PLAYED = 0x17, /* Int/Mac Timestamp (e.g. from =
383
bcfa83ff (6/19/2004) to =
384
0xbcfbd57f (6/20/2004)) */
385
SPLFIELD_DISC_NUMBER = 0x18, /* Int (e.g. from/to = 1) */
386
SPLFIELD_RATING = 0x19, /* Int/Stars Rating (e.g. from/to =
388
SPLFIELD_COMPILATION = 0x1f, /* Int (e.g. is set ->
389
SPLACTION_IS_INT/from=1,
391
SPLACTION_IS_NOT_INT/from=1) */
392
SPLFIELD_BPM = 0x23, /* Int (e.g. from/to = 60) */
393
SPLFIELD_GROUPING = 0x27, /* String */
394
SPLFIELD_PLAYLIST = 0x28, /* XXX - Unknown...not parsed
395
correctly...from/to = 0xb6fbad5f
396
for * "Purchased Music". Extra
397
data after * "to"... */
400
#define SPLDATE_IDENTIFIER (G_GINT64_CONSTANT (0x2dae2dae2dae2daeU))
402
/* Maximum string length that iTunes writes to the database */
403
#define SPL_MAXSTRINGLENGTH 255
407
guint8 liveupdate; /* "live Updating" check box */
408
guint8 checkrules; /* "Match X of the following
409
conditions" check box */
410
guint8 checklimits; /* "Limit To..." check box */
411
guint32 limittype; /* See types defined above */
412
guint32 limitsort; /* See types defined above */
413
guint32 limitvalue; /* The value typed next to "Limit
415
guint8 matchcheckedonly; /* "Match only checked songs" check
423
gchar *string; /* data in UTF8 */
424
/* from and to are pretty stupid.. if it's a date type of field,
426
value = 0x2dae2dae2dae2dae,
427
date = some number, like 2 or -2
428
units = unit in seconds, like 604800 = a week
429
but if this is actually some kind of integer comparison, like
430
rating = 60 (3 stars)
431
value = the value we care about
451
guint32 match_operator; /* "All" (logical AND): SPLMATCH_AND,
452
"Any" (logical OR): SPLMATCH_OR */
458
/* ------------------------------------------------------------ *\
460
* iTunesDB, Playlists, Tracks
462
\* ------------------------------------------------------------ */
464
/* one star is how much (track->rating) */
465
#define ITDB_RATING_STEP 20
471
Itdb_Device *device;/* iPod device info */
472
/* below is for use by application */
475
/* function called to duplicate userdata */
476
ItdbUserDataDuplicateFunc userdata_duplicate;
477
/* function called to free userdata */
478
ItdbUserDataDestroyFunc userdata_destroy;
481
struct _Itdb_iTunesDB
485
gchar *filename; /* filename of iTunesDB */
486
Itdb_Device *device;/* iPod device info */
489
/* below is for use by application */
492
/* function called to duplicate userdata */
493
ItdbUserDataDuplicateFunc userdata_duplicate;
494
/* function called to free userdata */
495
ItdbUserDataDestroyFunc userdata_destroy;
498
struct _Itdb_PhotoAlbum
500
gchar *name; /* name of photoalbum in UTF8 */
501
GList *members; /* photos in album (Track *) */
502
gint num_images; /* number of photos in album */
503
gint master; /* 0x01 for master, 0x00 otherwise */
506
/* below is for use by application */
509
/* function called to duplicate userdata */
510
ItdbUserDataDuplicateFunc userdata_duplicate;
511
/* function called to free userdata */
512
ItdbUserDataDestroyFunc userdata_destroy;
515
struct _Itdb_Playlist
517
Itdb_iTunesDB *itdb; /* pointer to iTunesDB (for convenience) */
518
gchar *name; /* name of playlist in UTF8 */
519
guint8 type; /* ITDB_PL_TYPE_NORM/_MPL */
520
guint8 flag1; /* unknown, usually set to 0 */
521
guint8 flag2; /* unknown, always set to 0 */
522
guint8 flag3; /* unknown, always set to 0 */
523
gint num; /* number of tracks in playlist */
524
GList *members; /* tracks in playlist (Track *) */
525
gboolean is_spl; /* smart playlist? */
526
guint32 timestamp; /* some timestamp */
527
guint64 id; /* playlist ID */
528
guint32 mhodcount; /* This appears to be the number of string
529
MHODs (type < 50) associated with this
530
playlist (typically 0x01). Doesn't seem
531
to be signficant unless you include Type
532
52 MHODs. libgpod sets this to 1 when
534
guint16 libmhodcount; /* The number of Type 52 MHODs associated
535
with this playlist. If you don't create
536
Type 52 MHODs, this can be
537
zero. Otherwise, if you have Type 52
538
MHODs associated with this playlist and
539
set this to zero, no songs appear on the
540
iPod. jcsjcs: with iTunes 4.9 this seems
541
to be set to 1 even without any Type 52
542
MHODs present. libgpod sets this to 1
544
guint32 sortorder; /* How to sort playlist -- see below */
545
guint32 podcastflag; /* ITDB_PL_FLAG_NORM/_PODCAST */
546
SPLPref splpref; /* smart playlist prefs */
547
SPLRules splrules; /* rules for smart playlists */
548
/* below is for use by application */
551
/* function called to duplicate userdata */
552
ItdbUserDataDuplicateFunc userdata_duplicate;
553
/* function called to free userdata */
554
ItdbUserDataDestroyFunc userdata_destroy;
561
1 - playlist order (manual sort order)
584
24 - release date (I guess, it's the value for the "Podcasts" list)
594
/* ITDB_PSO_UNKNOWN = 2, */
600
ITDB_PSO_FILETYPE = 8,
601
ITDB_PSO_TIME_MODIFIED = 9,
602
ITDB_PSO_TRACK_NR = 10,
604
ITDB_PSO_TIME = 12, /* ? */
606
ITDB_PSO_SAMPLERATE = 14,
607
ITDB_PSO_COMMENT = 15,
608
ITDB_PSO_TIME_ADDED = 16,
609
ITDB_PSO_EQUALIZER = 17, /* ? */
610
ITDB_PSO_COMPOSER = 18,
611
/* ITDB_PSO_UNKNOWN = 19, */
612
ITDB_PSO_PLAYCOUNT = 20,
613
ITDB_PSO_TIME_PLAYED = 21,
615
ITDB_PSO_RATING = 23,
616
ITDB_PSO_RELEASE_DATE = 24, /* used by podcasts */
618
ITDB_PSO_GROUPING = 26,
619
ITDB_PSO_CATEGORY = 27,
620
ITDB_PSO_DESCRIPTION = 28
621
} ItdbPlaylistSortOrder;
624
/* some of the descriptive comments below are copied verbatim from
625
http://ipodlinux.org/ITunesDB.
626
http://ipodlinux.org/ITunesDB is the best source for information
627
about the iTunesDB and related files. */
630
Itdb_iTunesDB *itdb; /* pointer to iTunesDB (for convenience) */
631
gchar *title; /* title (utf8) */
632
gchar *ipod_path; /* name of file on iPod: uses ":"
634
gchar *album; /* album (utf8) */
635
gchar *artist; /* artist (utf8) */
636
gchar *genre; /* genre (utf8) */
637
gchar *filetype; /* eg. "MP3-File"...(utf8)*/
638
gchar *comment; /* comment (utf8) */
639
gchar *category; /* Category for podcast */
640
gchar *composer; /* Composer (utf8) */
641
gchar *grouping; /* ? (utf8) */
642
gchar *description; /* see note for MHOD_ID in itdb_itunesdb.c */
643
gchar *podcasturl; /* see note for MHOD_ID in itdb_itunesdb.c */
644
gchar *podcastrss; /* see note for MHOD_ID in itdb_itunesdb.c */
645
gchar *chapterdata; /* see note for MHOD_ID in itdb_itunesdb.c */
646
gchar *subtitle; /* see note for MHOD_ID in itdb_itunesdb.c */
647
guint32 id; /* unique ID of track */
648
gint32 size; /* size of file in bytes */
649
gint32 tracklen; /* Length of track in ms */
650
gint32 cd_nr; /* CD number */
651
gint32 cds; /* number of CDs */
652
gint32 track_nr; /* track number */
653
gint32 tracks; /* number of tracks */
654
gint32 bitrate; /* bitrate */
655
guint16 samplerate; /* samplerate (CD: 44100) */
656
guint16 samplerate_low; /* in the iTunesDB the samplerate is
657
multiplied by 0x10000 -- these are the
658
lower 16 bit, which are usually 0 */
659
gint32 year; /* year */
660
gint32 volume; /* volume adjustment */
661
guint32 soundcheck; /* volume adjustment "soundcheck" */
662
guint32 time_added; /* time when added (Mac type) */
663
guint32 time_played; /* time of last play (Mac type) */
664
guint32 time_modified; /* time of last modification (Mac type)*/
665
guint32 bookmark_time; /* bookmark set for (AudioBook) in ms */
666
guint32 rating; /* star rating (stars * RATING_STEP (20)) */
667
guint32 playcount; /* number of times track was played */
668
guint32 playcount2; /* Also stores the play count of the
669
song. Don't know if it ever differs
670
from the above value. During sync itdb
671
sets playcount2 to the same value as
673
guint32 recent_playcount; /* times track was played since last sync */
674
gboolean transferred; /* has file been transferred to iPod? */
675
gint16 BPM; /* supposed to vary the playback speed */
676
guint8 app_rating; /* star rating set by appl. (not
677
* iPod). If the rating set on the iPod
678
and the rating field above differ, the
679
original rating is copied here and the
680
new rating is stored above. */
681
guint8 type1; /* CBR MP3s and AAC are 0x00, VBR MP3s are
683
guint8 type2; /* MP3s are 0x01, AAC are 0x00 */
688
guint64 dbid; /* unique database ID */
689
guint32 drm_userid; /* Apple Store/Audible User ID (for DRM'ed
690
files only, set to 0 otherwise). */
691
guint32 visible; /* If this value is 1, the song is visible
692
on the iPod. All other values cause
693
the file to be hidden. */
694
guint32 filetype_marker; /* This appears to always be 0 on hard
695
drive based iPods, but for the
696
iTunesDB that is written to an iPod
697
Shuffle, iTunes 4.7.1 writes out the
698
file's type as an ANSI string(!). For
699
example, a MP3 file has a filetype of
700
0x4d503320 -> 0x4d = 'M', 0x50 = 'P',
701
0x33 = '3', 0x20 = <space>. (set to
702
the filename extension by itdb when
703
copying track to iPod)*/
704
guint16 artwork_count; /* The number of album artwork items
705
associated with this song. libgpod
706
updates this value when syncing */
707
guint32 artwork_size; /* The total size of artwork (in bytes)
708
attached to this song, when it is
709
converted to JPEG format. Observed in
710
iPodDB version 0x0b and with an iPod
711
Photo. libgpod updates this value when
713
float samplerate2; /* The sample rate of the song expressed
714
as an IEEE 32 bit floating point
715
number. It's uncertain why this is
716
here. itdb will set this when adding
719
guint16 unk126; /* unknown, but always seems to be 0xffff for
720
MP3/AAC songs, 0x0 for uncompressed songs
721
(like WAVE format), 0x1 for Audible. itdb
722
will try to set this when adding a new track */
723
guint32 unk132; /* unknown */
724
guint32 time_released;/* date/time added to music store? definitely a
725
timestamp, always appears to be a time of
726
0700 GMT. For podcasts: release date as
727
displayed next to the title in the Podcast
729
guint16 unk144; /* unknown, but MP3 songs appear to be always
730
0x000c, AAC songs are always 0x0033, Audible
731
files are 0x0029, WAV files are 0x0. itdb
732
will attempt to set this value when adding a
734
guint16 unk146; /* unknown, but appears to be 1 if played at
735
least once in iTunes and 0 otherwise. */
736
guint32 unk148; /* unknown - used for Apple Store DRM songs
737
(always 0x01010100?), zero otherwise */
738
guint32 unk152; /* unknown */
739
guint32 unk156, unk160;
740
guint8 has_artwork; /* 0x01: artwork is present. 0x02: no artwork is
741
present for this track (used by the iPod to
742
decide whether to display Artwork or not) */
743
guint8 skip_when_shuffling;/* "Skip when shuffling" when set to
744
0x01, set to 0x00 otherwise. .m4b and .aa
745
files always seem to be skipped when
746
shuffling, however */
747
guint8 remember_playback_position;/* "Remember playback position"
748
when set to 0x01, set to 0x00 otherwise. .m4b
749
and .aa files always seem to remember the
750
playback position, however. */
751
guint8 flag4; /* Used for podcasts, 0x00 otherwise. If set to
752
0x01 the "Now Playing" page will show
753
Title/Album, when set to 0x00 it will also
754
show the Artist. When set to 0x02 a sub-page
755
(middle button) with further information
756
about the track will be shown. */
757
guint64 dbid2; /* not clear. if not set, itdb will set this to
758
the same value as dbid when adding a track */
759
guint8 lyrics_flag; /* set to 0x01 if lyrics are present in MP3 tag
760
("ULST"), 0x00 otherwise */
761
guint8 movie_flag; /* set to 0x01 if it's a movie file, 0x00
763
guint8 mark_unplayed; /* A value of 0x02 marks a podcast as unplayed
764
on the iPod (bullet) once played it is set to
765
0x01. Non-podcasts have this set to 0x01. */
766
guint8 unk179; /* unknown (always 0x00 so far) */
767
guint32 unk180, unk184;
768
guint32 samplecount;/* Number of samples in the song. First observed
769
in dbversion 0x0d, and only for AAC and WAV
770
files (not MP3?!?). */
771
guint32 unk192, unk196, unk200;
772
guint32 unk204; /* unknown - added in dbversion 0x0c, first
773
values observed in 0x0d. Observed to be 0x0
775
guint32 unk208, unk212, unk216, unk220, unk224;
776
guint32 unk228, unk232, unk236, unk240;
778
/* Chapter data: defines where the chapter stops are in the track,
779
as well as what info should be displayed for each section of
780
the track. Until it can be parsed and interpreted, the
781
chapterdata will just be read as a block and written back on
782
sync. This will be changed at a later time */
783
void *chapterdata_raw;
784
guint32 chapterdata_raw_length;
786
/* This is for Cover Art support */
787
struct _Itdb_Artwork *artwork;
789
/* below is for use by application */
792
/* function called to duplicate userdata */
793
ItdbUserDataDuplicateFunc userdata_duplicate;
794
/* function called to free userdata */
795
ItdbUserDataDestroyFunc userdata_destroy;
797
/* (gtkpod note: don't forget to add fields read from the file to
798
* copy_new_info() in file.c!) */
801
/* ------------------------------------------------------------ *\
805
\* ------------------------------------------------------------ */
808
ITDB_FILE_ERROR_SEEK, /* file corrupt: illegal seek occured */
809
ITDB_FILE_ERROR_CORRUPT, /* file corrupt */
810
ITDB_FILE_ERROR_NOTFOUND, /* file not found */
811
ITDB_FILE_ERROR_RENAME, /* file could not be renamed */
812
ITDB_FILE_ERROR_ITDB_CORRUPT /* iTunesDB in memory corrupt */
817
#define ITDB_FILE_ERROR itdb_file_error_quark ()
818
GQuark itdb_file_error_quark (void);
821
/* ------------------------------------------------------------ *\
825
\* ------------------------------------------------------------ */
827
/* functions for reading/writing database, general itdb functions */
828
Itdb_iTunesDB *itdb_parse (const gchar *mp, GError **error);
829
Itdb_iTunesDB *itdb_parse_file (const gchar *filename, GError **error);
830
gboolean itdb_write (Itdb_iTunesDB *db, GError **error);
831
gboolean itdb_write_file (Itdb_iTunesDB *itdb, const gchar *filename,
833
gboolean itdb_shuffle_write (Itdb_iTunesDB *itdb, GError **error);
834
gboolean itdb_shuffle_write_file (Itdb_iTunesDB *itdb,
835
const gchar *filename, GError **error);
836
Itdb_iTunesDB *itdb_new (void);
837
void itdb_free (Itdb_iTunesDB *itdb);
838
Itdb_iTunesDB *itdb_duplicate (Itdb_iTunesDB *itdb); /* not implemented */
839
guint32 itdb_tracks_number (Itdb_iTunesDB *itdb);
840
guint32 itdb_tracks_number_nontransferred (Itdb_iTunesDB *itdb);
841
guint32 itdb_playlists_number (Itdb_iTunesDB *itdb);
843
/* general file functions */
844
gint itdb_musicdirs_number (Itdb_iTunesDB *itdb);
845
gchar *itdb_resolve_path (const gchar *root,
846
const gchar * const * components);
847
gboolean itdb_rename_files (const gchar *mp, GError **error);
848
gboolean itdb_cp_track_to_ipod (Itdb_Track *track,
849
gchar *filename, GError **error);
850
gboolean itdb_cp (const gchar *from_file, const gchar *to_file,
852
void itdb_filename_fs2ipod (gchar *filename);
853
void itdb_filename_ipod2fs (gchar *ipod_file);
854
gchar *itdb_filename_on_ipod (Itdb_Track *track);
855
void itdb_set_mountpoint (Itdb_iTunesDB *itdb, const gchar *mp);
856
const gchar *itdb_get_mountpoint (Itdb_iTunesDB *itdb);
857
gchar *itdb_get_control_dir (const gchar *mountpoint);
858
gchar *itdb_get_itunes_dir (const gchar *mountpoint);
859
gchar *itdb_get_music_dir (const gchar *mountpoint);
860
gchar *itdb_get_artwork_dir (const gchar *mountpoint);
861
gchar *itdb_get_photos_dir (const gchar *mountpoint);
862
gchar *itdb_get_photos_thumb_dir (const gchar *mountpoint);
863
gchar *itdb_get_device_dir (const gchar *mountpoint);
864
gchar *itdb_get_itunesdb_path (const gchar *mountpoint);
865
gchar *itdb_get_itunessd_path (const gchar *mountpoint);
866
gchar *itdb_get_artworkdb_path (const gchar *mountpoint);
867
gchar *itdb_get_photodb_path (const gchar *mountpoint);
868
gchar *itdb_get_path (const gchar *dir, const gchar *file);
870
/* itdb_device functions */
871
Itdb_Device *itdb_device_new (void);
872
void itdb_device_free (Itdb_Device *device);
873
void itdb_device_set_mountpoint (Itdb_Device *device, const gchar *mp);
874
gboolean itdb_device_read_sysinfo (Itdb_Device *device);
875
gboolean itdb_device_write_sysinfo (Itdb_Device *device, GError **error);
876
gchar *itdb_device_get_sysinfo (Itdb_Device *device, const gchar *field);
877
void itdb_device_set_sysinfo (Itdb_Device *device,
878
const gchar *field, const gchar *value);
879
const Itdb_IpodInfo *itdb_device_get_ipod_info (Itdb_Device *device);
880
const Itdb_IpodInfo *itdb_info_get_ipod_info_table (void);
881
const gchar *itdb_info_get_ipod_model_name_string (Itdb_IpodModel model);
882
const gchar *itdb_info_get_ipod_generation_string (Itdb_IpodGeneration generation);
884
/* track functions */
885
Itdb_Track *itdb_track_new (void);
886
void itdb_track_free (Itdb_Track *track);
887
void itdb_track_add (Itdb_iTunesDB *itdb, Itdb_Track *track, gint32 pos);
888
void itdb_track_remove (Itdb_Track *track);
889
void itdb_track_unlink (Itdb_Track *track);
890
Itdb_Track *itdb_track_duplicate (Itdb_Track *tr);
891
Itdb_Track *itdb_track_by_id (Itdb_iTunesDB *itdb, guint32 id);
892
GTree *itdb_track_id_tree_create (Itdb_iTunesDB *itdb);
893
void itdb_track_id_tree_destroy (GTree *idtree);
894
Itdb_Track *itdb_track_id_tree_by_id (GTree *idtree, guint32 id);
896
/* playlist functions */
897
Itdb_Playlist *itdb_playlist_new (const gchar *title, gboolean spl);
898
void itdb_playlist_free (Itdb_Playlist *pl);
899
void itdb_playlist_add (Itdb_iTunesDB *itdb, Itdb_Playlist *pl, gint32 pos);
900
void itdb_playlist_move (Itdb_Playlist *pl, guint32 pos);
901
void itdb_playlist_remove (Itdb_Playlist *pl);
902
void itdb_playlist_unlink (Itdb_Playlist *pl);
903
Itdb_Playlist *itdb_playlist_duplicate (Itdb_Playlist *pl);
904
gboolean itdb_playlist_exists (Itdb_iTunesDB *itdb, Itdb_Playlist *pl);
905
void itdb_playlist_add_track (Itdb_Playlist *pl,
906
Itdb_Track *track, gint32 pos);
907
Itdb_Playlist *itdb_playlist_by_id (Itdb_iTunesDB *itdb, guint64 id);
908
Itdb_Playlist *itdb_playlist_by_nr (Itdb_iTunesDB *itdb, guint32 num);
909
Itdb_Playlist *itdb_playlist_by_name (Itdb_iTunesDB *itdb, gchar *name);
910
gboolean itdb_playlist_contains_track (Itdb_Playlist *pl, Itdb_Track *track);
911
guint32 itdb_playlist_contain_track_number (Itdb_Track *tr);
912
void itdb_playlist_remove_track (Itdb_Playlist *pl, Itdb_Track *track);
913
guint32 itdb_playlist_tracks_number (Itdb_Playlist *pl);
914
void itdb_playlist_randomize (Itdb_Playlist *pl);
916
/* playlist functions for master playlist */
917
Itdb_Playlist *itdb_playlist_mpl (Itdb_iTunesDB *itdb);
918
gboolean itdb_playlist_is_mpl (Itdb_Playlist *pl);
919
void itdb_playlist_set_mpl (Itdb_Playlist *pl);
921
/* playlist functions for podcasts playlist */
922
Itdb_Playlist *itdb_playlist_podcasts (Itdb_iTunesDB *itdb);
923
gboolean itdb_playlist_is_podcasts (Itdb_Playlist *pl);
924
void itdb_playlist_set_podcasts (Itdb_Playlist *pl);
926
/* smart playlist functions */
927
SPLFieldType itdb_splr_get_field_type (const SPLRule *splr);
928
SPLActionType itdb_splr_get_action_type (const SPLRule *splr);
929
void itdb_splr_validate (SPLRule *splr);
930
void itdb_splr_remove (Itdb_Playlist *pl, SPLRule *splr);
931
SPLRule *itdb_splr_new (void);
932
void itdb_splr_add (Itdb_Playlist *pl, SPLRule *splr, gint pos);
933
SPLRule *itdb_splr_add_new (Itdb_Playlist *pl, gint pos);
934
void itdb_spl_copy_rules (Itdb_Playlist *dest, Itdb_Playlist *src);
935
gboolean itdb_splr_eval (SPLRule *splr, Itdb_Track *track);
936
void itdb_spl_update (Itdb_Playlist *spl);
937
void itdb_spl_update_all (Itdb_iTunesDB *itdb);
938
void itdb_spl_update_live (Itdb_iTunesDB *itdb);
940
/* thumbnails functions */
942
gboolean itdb_track_set_thumbnails (Itdb_Track *track,
943
const gchar *filename);
944
gboolean itdb_track_set_thumbnails_from_data (Itdb_Track *track,
945
const guchar *image_data,
946
gsize image_data_len);
947
void itdb_track_remove_thumbnails (Itdb_Track *track);
949
/* photoalbum functions */
950
Itdb_PhotoDB *itdb_photodb_parse (const gchar *mp, GError **error);
951
gboolean itdb_photodb_add_photo (Itdb_PhotoDB *db,
952
const gchar *albumname,
953
const gchar *filename);
954
gboolean itdb_photodb_add_photo_from_data (Itdb_PhotoDB *db,
955
const gchar *albumname,
956
const guchar *image_data,
957
gsize image_data_len);
958
Itdb_PhotoAlbum *itdb_photodb_photoalbum_new (Itdb_PhotoDB *db,
959
const gchar *album_name);
960
Itdb_PhotoDB *itdb_photodb_new (void);
961
void itdb_photodb_free (Itdb_PhotoDB *photodb);
962
gboolean itdb_photodb_write (Itdb_PhotoDB *db, GError **error);
963
void itdb_photodb_photoalbum_free (Itdb_PhotoAlbum *pa);
964
gboolean itdb_photodb_remove_photo (Itdb_PhotoDB *db,
965
const gint photo_id );
967
/* itdb_artwork_... */
968
Itdb_Artwork *itdb_artwork_new (void);
969
Itdb_Artwork *itdb_artwork_duplicate (Itdb_Artwork *artwork);
970
void itdb_artwork_free (Itdb_Artwork *artwork);
971
Itdb_Thumb *itdb_artwork_get_thumb_by_type (Itdb_Artwork *artwork,
973
gboolean itdb_artwork_add_thumbnail (Itdb_Artwork *artwork,
975
const gchar *filename);
976
gboolean itdb_artwork_add_thumbnail_from_data (Itdb_Artwork *artwork,
978
const guchar *image_data,
979
gsize image_data_len);
980
void itdb_artwork_remove_thumbnail (Itdb_Artwork *artwork,
982
void itdb_artwork_remove_thumbnails (Itdb_Artwork *artwork);
984
/* the following funciton returns a pointer to a GdkPixbuf if
985
gdk-pixbuf is installed -- a NULL pointer otherwise. */
986
gpointer itdb_thumb_get_gdk_pixbuf (Itdb_Device *device,
988
Itdb_Thumb *itdb_thumb_duplicate (Itdb_Thumb *thumb);
989
void itdb_thumb_free (Itdb_Thumb *thumb);
990
Itdb_Thumb *itdb_thumb_new (void);
991
gchar *itdb_thumb_get_filename (Itdb_Device *device, Itdb_Thumb *thumb);
994
guint64 itdb_time_get_mac_time (void);
995
time_t itdb_time_mac_to_host (guint64 mactime);
996
guint64 itdb_time_host_to_mac (time_t time);
998
/* Initialise a blank ipod */
999
gboolean itdb_init_ipod (const gchar *mountpoint,
1000
const gchar *model_number,
1001
const gchar *ipod_name,