summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorg Schuler <jcsjcs@users.sourceforge.net>2006-11-11 13:44:29 +0000
committerJorg Schuler <jcsjcs@users.sourceforge.net>2006-11-11 13:44:29 +0000
commit2cb1582ee12c459686deaef20647a2d5fa08f403 (patch)
tree1f47311e55dfd966f379d97008a5344408c9da70
parentb261eb62e01147c3e4fb8dd8154bff007d6e15cc (diff)
downloadlibgpod-tmz-2cb1582ee12c459686deaef20647a2d5fa08f403.tar.gz
libgpod-tmz-2cb1582ee12c459686deaef20647a2d5fa08f403.tar.xz
libgpod-tmz-2cb1582ee12c459686deaef20647a2d5fa08f403.zip
* itdb.h: Itdb_Artwork:
- added unk028, unk036 and rating - added digitized_data timestamp - changed creation_date from gint32 to guint32 * db-itunes-parser.h: db-artwork-debug.c: MhiiHeader: - renamed unknown5 to rating - renamed digitised_date to digitized_date for conformity * db-artwork-writer.c (write_mhli): sanity check to avoid access of NULL pointer. (write_mhii): write unk028, rating, unk036, digitized_data * db-artwork_parser.c (parse_mhii): - parse unk028, rating, unk036, digitized data. - unified reading of DB_TYPE_PHOTO and DB_TYPE_ITUNES, got rid of parse_mhod() and parse_mhni(). git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1335 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r--ChangeLog23
-rw-r--r--src/db-artwork-debug.c4
-rw-r--r--src/db-artwork-parser.c196
-rw-r--r--src/db-artwork-writer.c25
-rw-r--r--src/db-itunes-parser.h8
-rw-r--r--src/itdb.h21
6 files changed, 121 insertions, 156 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e4815b..93ca562 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2006-11-11 Jorg Schuler <jcsjcs at users.sourceforge.net>
+
+ * itdb.h: Itdb_Artwork:
+ - added unk028, unk036 and rating
+ - added digitized_data timestamp
+ - changed creation_date from gint32 to guint32
+
+ * db-itunes-parser.h:
+ db-artwork-debug.c: MhiiHeader:
+ - renamed unknown5 to rating
+ - renamed digitised_date to digitized_date for conformity
+
+ * db-artwork-writer.c (write_mhli): sanity check to avoid access
+ of NULL pointer.
+ (write_mhii): write unk028, rating, unk036, digitized_data
+
+ * db-artwork_parser.c (parse_mhii):
+ - parse unk028, rating, unk036, digitized data.
+ - unified reading of DB_TYPE_PHOTO and DB_TYPE_ITUNES, got rid
+ of parse_mhod() and parse_mhni().
+
+
+
2006-11-08 Jorg Schuler <jcsjcs at users.sourceforge.net>
* itdb.h:
diff --git a/src/db-artwork-debug.c b/src/db-artwork-debug.c
index e632db3..664b605 100644
--- a/src/db-artwork-debug.c
+++ b/src/db-artwork-debug.c
@@ -148,10 +148,10 @@ dump_mhii (MhiiHeader *mhii)
g_print ("\tImage ID: %08x\n", GINT_FROM_LE (mhii->image_id));
g_print ("\tSong ID: %016llx\n", GINT64_FROM_LE (mhii->song_id));
g_print ("\tUnknown4: %08x\n", GINT_FROM_LE (mhii->unknown4));
- g_print ("\tUnknown5: %08x\n", GINT_FROM_LE (mhii->unknown5));
+ g_print ("\tRating: %08x\n", GINT_FROM_LE (mhii->rating));
g_print ("\tUnknown6: %08x\n", GINT_FROM_LE (mhii->unknown6));
g_print ("\tOrig Date: %08x\n", GINT_FROM_LE (mhii->orig_date));
- g_print ("\tDigitised Date: %08x\n", GINT_FROM_LE (mhii->digitised_date));
+ g_print ("\tDigitised Date: %08x\n", GINT_FROM_LE (mhii->digitized_date));
g_print ("\tImage size: %d bytes\n", GINT_FROM_LE (mhii->orig_img_size));
}
diff --git a/src/db-artwork-parser.c b/src/db-artwork-parser.c
index 88de265..ecb4ce1 100644
--- a/src/db-artwork-parser.c
+++ b/src/db-artwork-parser.c
@@ -42,7 +42,6 @@
typedef int (*ParseListItem)(DBParseContext *ctx, GError *error);
-#ifndef NOT_DEFINED_DEBUG_ARTWORKDB
static Itdb_Track *
get_song_by_dbid (Itdb_iTunesDB *db, guint64 id)
{
@@ -58,7 +57,6 @@ get_song_by_dbid (Itdb_iTunesDB *db, guint64 id)
}
return NULL;
}
-#endif
static int
@@ -195,42 +193,11 @@ parse_photo_mhni (DBParseContext *ctx, Itdb_Artwork *artwork, GError *error)
}
static int
-parse_mhni (DBParseContext *ctx, iPodSong *song, GError *error)
-{
- MhniHeader *mhni;
- DBParseContext *mhod_ctx;
- Itdb_Thumb *thumb;
-
- mhni = db_parse_context_get_m_header (ctx, MhniHeader, "mhni");
- if (mhni == NULL) {
- return -1;
- }
- db_parse_context_set_total_len (ctx, get_gint32 (mhni->total_len, ctx->byte_order));
- dump_mhni (mhni);
- thumb = ipod_image_new_from_mhni (mhni, ctx->db);
- if (thumb == NULL) {
- return 0;
- }
-
- song->artwork->thumbnails =
- g_list_append (song->artwork->thumbnails, thumb);
-
- mhod_ctx = db_parse_context_get_sub_context (ctx, ctx->header_len);
- if (mhod_ctx == NULL) {
- return -1;
- }
- parse_mhod_3 (mhod_ctx, thumb, error);
- g_free (mhod_ctx);
-
- return 0;
-}
-
-static int
parse_photo_mhod (DBParseContext *ctx, Itdb_Artwork *artwork, GError *error)
{
ArtworkDB_MhodHeader *mhod;
DBParseContext *mhni_ctx;
- int type;
+ gint32 type;
mhod = db_parse_context_get_m_header (ctx, ArtworkDB_MhodHeader, "mhod");
if (mhod == NULL) {
@@ -238,47 +205,6 @@ parse_photo_mhod (DBParseContext *ctx, Itdb_Artwork *artwork, GError *error)
}
db_parse_context_set_total_len (ctx, get_gint32 (mhod->total_len, ctx->byte_order));
- /* The MHODs found in the ArtworkDB and Photo Database files are
- * significantly different than those found in the iTunesDB.
- * For example, the "type" is split like this:
- * - low 3 bytes are actual type;
- * - high byte is padding length of string (0-3).
- */
- type = get_gint16 (mhod->type, ctx->byte_order) & 0x00FFFFFF;
-
- if ( type == MHOD_ARTWORK_TYPE_ALBUM_NAME) {
- dump_mhod_type_1 ((MhodHeaderArtworkType1 *)mhod);
- } else {
- dump_mhod (mhod);
- }
-
- /* if this is a container... */
- if (type == MHOD_ARTWORK_TYPE_THUMBNAIL) {
- mhni_ctx = db_parse_context_get_sub_context (ctx, ctx->header_len);
- if (mhni_ctx == NULL) {
- return -1;
- }
- parse_photo_mhni (mhni_ctx, artwork, NULL);
- g_free (mhni_ctx);
- }
-
- return 0;
-}
-static int
-parse_mhod (DBParseContext *ctx, iPodSong *song, GError *error)
-{
- ArtworkDB_MhodHeader *mhod;
- DBParseContext *mhni_ctx;
- int type;
- gint32 total_len;
-
- mhod = db_parse_context_get_m_header (ctx, ArtworkDB_MhodHeader, "mhod");
- if (mhod == NULL) {
- return -1;
- }
- total_len = get_gint32 (mhod->total_len, ctx->byte_order);
- db_parse_context_set_total_len (ctx, total_len);
-
type = get_gint16 (mhod->type, ctx->byte_order);
if ( type == MHOD_ARTWORK_TYPE_ALBUM_NAME) {
@@ -293,14 +219,12 @@ parse_mhod (DBParseContext *ctx, iPodSong *song, GError *error)
if (mhni_ctx == NULL) {
return -1;
}
- parse_mhni (mhni_ctx, song, NULL);
+ parse_photo_mhni (mhni_ctx, artwork, NULL);
g_free (mhni_ctx);
}
return 0;
}
-
-
static int
parse_mhii (DBParseContext *ctx, GError *error)
{
@@ -308,73 +232,79 @@ parse_mhii (DBParseContext *ctx, GError *error)
DBParseContext *mhod_ctx;
int num_children;
off_t cur_offset;
- iPodSong *song;
+ iPodSong *song = NULL;
Itdb_Artwork *artwork;
Itdb_PhotoDB *photodb;
Itdb_iTunesDB *itunesdb;
+ guint64 dbid;
mhii = db_parse_context_get_m_header (ctx, MhiiHeader, "mhii");
- if (mhii == NULL) {
- return -1;
+ if (mhii == NULL)
+ {
+ return -1;
}
db_parse_context_set_total_len (ctx, get_gint32 (mhii->total_len, ctx->byte_order));
dump_mhii (mhii);
- switch (ctx->db->db_type) {
+ switch (ctx->db->db_type)
+ {
case DB_TYPE_PHOTO:
- artwork = g_new0( Itdb_Artwork, 1 );
- artwork->artwork_size = get_gint32 (mhii->orig_img_size, ctx->byte_order);
- artwork->id = get_gint32 (mhii->image_id, ctx->byte_order);
- artwork->creation_date = itdb_time_mac_to_host( get_gint32 (mhii->digitised_date, ctx->byte_order) );
-
- cur_offset = ctx->header_len;
- mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset);
- num_children = get_gint32 (mhii->num_children, ctx->byte_order);
- while ((num_children > 0) && (mhod_ctx != NULL)) {
- parse_photo_mhod (mhod_ctx, artwork, NULL);
- num_children--;
- cur_offset += mhod_ctx->total_len;
- g_free (mhod_ctx);
- mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset);
- }
- photodb = db_get_photodb (ctx->db);
- g_return_val_if_fail (photodb, -1);
- photodb->photos = g_list_append (photodb->photos,
- artwork);
- break;
+ photodb = db_get_photodb (ctx->db);
+ g_return_val_if_fail (photodb, -1);
+ artwork = g_new0 (Itdb_Artwork, 1);
+ photodb->photos = g_list_append (photodb->photos, artwork);
+ break;
case DB_TYPE_ITUNES:
-#ifdef NOT_DEFINED_DEBUG_ARTWORKDB
- song = NULL;
-#else
- itunesdb = db_get_itunesdb (ctx->db);
- g_return_val_if_fail (itunesdb, -1);
- song = get_song_by_dbid (itunesdb,
- get_gint64 (mhii->song_id,
- ctx->byte_order));
- if (song == NULL) {
- return -1;
- }
- song->artwork->artwork_size = get_gint32 (mhii->orig_img_size, ctx->byte_order);
- if ((song->artwork_size+song->artwork_count) !=
- song->artwork->artwork_size) {
- g_warning (_("iTunesDB and ArtworkDB artwork sizes inconsistent (%d+%d != %d)"), song->artwork_size, song->artwork_count, song->artwork->artwork_size);
- }
- song->artwork->id = get_gint32 (mhii->image_id, ctx->byte_order);
-#endif
-
- cur_offset = ctx->header_len;
- mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset);
- num_children = get_gint32 (mhii->num_children, ctx->byte_order);
- while ((num_children > 0) && (mhod_ctx != NULL)) {
- parse_mhod (mhod_ctx, song, NULL);
- num_children--;
- cur_offset += mhod_ctx->total_len;
- g_free (mhod_ctx);
- mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset);
- }
- break;
+ itunesdb = db_get_itunesdb (ctx->db);
+ g_return_val_if_fail (itunesdb, -1);
+ dbid = get_gint64 (mhii->song_id, ctx->byte_order);
+ song = get_song_by_dbid (itunesdb, dbid);
+ if (song == NULL)
+ {
+ gchar *strval = g_strdup_printf("%" G_GINT64_FORMAT, dbid);
+ g_print (_("Could not find corresponding track (dbid: %s) for artwork entry.\n"), strval);
+ g_free (strval);
+ return -1;
+ }
+ artwork = song->artwork;
+ g_return_val_if_fail (artwork, -1);
+ break;
default:
- g_return_val_if_reached (-1);
+ g_return_val_if_reached (-1);
+ }
+
+ artwork->id = get_gint32 (mhii->image_id, ctx->byte_order);
+ artwork->unk028 = get_gint32 (mhii->unknown4, ctx->byte_order);
+ artwork->rating = get_gint32 (mhii->rating, ctx->byte_order);
+ artwork->unk036 = get_gint32 (mhii->unknown6, ctx->byte_order);
+ artwork->creation_date = get_gint32 (mhii->orig_date, ctx->byte_order);
+ artwork->digitized_date = get_gint32 (mhii->digitized_date,
+ ctx->byte_order);
+ artwork->artwork_size = get_gint32 (mhii->orig_img_size,
+ ctx->byte_order);
+
+ if (song)
+ {
+ if ((song->artwork_size+song->artwork_count) !=
+ artwork->artwork_size)
+ {
+ g_warning (_("iTunesDB and ArtworkDB artwork sizes inconsistent (%d+%d != %d)\n"),
+ song->artwork_size,
+ song->artwork_count,
+ song->artwork->artwork_size);
+ }
+ }
+
+ cur_offset = ctx->header_len;
+ mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset);
+ num_children = get_gint32 (mhii->num_children, ctx->byte_order);
+ while ((num_children > 0) && (mhod_ctx != NULL))
+ {
+ parse_photo_mhod (mhod_ctx, artwork, NULL);
+ num_children--;
+ cur_offset += mhod_ctx->total_len;
+ g_free (mhod_ctx);
+ mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset);
}
return 0;
}
diff --git a/src/db-artwork-writer.c b/src/db-artwork-writer.c
index e80657a..4ac5726 100644
--- a/src/db-artwork-writer.c
+++ b/src/db-artwork-writer.c
@@ -541,23 +541,26 @@ write_mhii (Itdb_DB *db, void *data, iPodBuffer *buffer)
switch( buffer->db_type) {
case DB_TYPE_ITUNES:
song = (Itdb_Track *)data;
+ artwork = song->artwork;
mhii->song_id = get_gint64 (song->dbid, buffer->byte_order);
- mhii->image_id = get_guint32 (song->artwork->id, buffer->byte_order);
- mhii->orig_img_size = get_gint32 (song->artwork->artwork_size,
- buffer->byte_order);
- it = song->artwork->thumbnails;
break;
case DB_TYPE_PHOTO:
artwork = (Itdb_Artwork *)data;
mhii->song_id = get_gint64 (artwork->id + 2, buffer->byte_order);
- mhii->image_id = get_guint32 (artwork->id, buffer->byte_order);
- mhii->orig_date = get_guint32 (itdb_time_host_to_mac( artwork->creation_date )
- , buffer->byte_order);
- mhii->digitised_date = get_guint32 (itdb_time_host_to_mac( artwork->creation_date )
- , buffer->byte_order);
- it = artwork->thumbnails;
break;
+ default:
+ g_return_val_if_reached (-1);
}
+ mhii->image_id = get_guint32 (artwork->id, buffer->byte_order);
+ mhii->unknown4 = get_gint32 (artwork->unk028, buffer->byte_order);
+ mhii->rating = get_gint32 (artwork->rating, buffer->byte_order);
+ mhii->unknown6 = get_gint32 (artwork->unk036, buffer->byte_order);
+ mhii->orig_date = get_guint32 (artwork->creation_date, buffer->byte_order);
+ mhii->digitized_date = get_guint32 (artwork->digitized_date,
+ buffer->byte_order);
+ mhii->orig_img_size = get_gint32 (artwork->artwork_size,
+ buffer->byte_order);
+ it = artwork->thumbnails;
num_children = 0;
while (it != NULL) {
iPodBuffer *sub_buffer;
@@ -628,7 +631,7 @@ write_mhli (Itdb_DB *db, iPodBuffer *buffer )
if (buffer->db_type == DB_TYPE_ITUNES) {
song = (Itdb_Track*)it->data;
- if (song->artwork->id == 0) {
+ if (!song->artwork || (song->artwork->id == 0)) {
it = it->next;
continue;
}
diff --git a/src/db-itunes-parser.h b/src/db-itunes-parser.h
index 423485c..39fab2f 100644
--- a/src/db-itunes-parser.h
+++ b/src/db-itunes-parser.h
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-10-29 19:18:28 jcs>
+/* Time-stamp: <2006-11-11 20:38:32 jcs>
*
* Copyright (C) 2005 Christophe Fergeau
*
@@ -333,7 +333,7 @@ struct _ArtworkDB_MhodHeader {
* phones with iPod support).
*/
gint16 type;
- gint16 unknown014;
+ gint16 unknown014;
gint32 unknown1;
gint32 unknown2;
};
@@ -575,10 +575,10 @@ struct _MhiiHeader {
gint32 image_id;
gint64 song_id;
gint32 unknown4;
- gint32 unknown5;
+ gint32 rating;
gint32 unknown6;
gint32 orig_date;
- gint32 digitised_date;
+ gint32 digitized_date;
gint32 orig_img_size;
unsigned char padding[];
} __attribute__((__packed__));
diff --git a/src/itdb.h b/src/itdb.h
index 0d0db75..b77743a 100644
--- a/src/itdb.h
+++ b/src/itdb.h
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-11-07 20:51:08 jcs>
+/* Time-stamp: <2006-11-11 16:29:02 jcs>
|
| Copyright (C) 2002-2006 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -445,11 +445,20 @@ struct _Itdb_Thumb {
};
struct _Itdb_Artwork {
- GList *thumbnails; /* list of Itdb_Thumbs */
- guint32 artwork_size; /* Size in bytes of the original source image */
- guint32 id; /* Artwork id used by photoalbums, starts at
- * 0x40... libgpod will set this on sync. */
- gint32 creation_date; /* Date the image was created */
+ GList *thumbnails; /* list of Itdb_Thumbs */
+ guint32 id; /* Artwork id used by photoalbums, starts at
+ * 0x40... libgpod will set this on sync. */
+ gint32 unk028;
+ guint32 rating; /* Rating from iPhoto * 20 (PhotoDB only) */
+ gint32 unk036;
+ guint32 creation_date; /* Date the image file was created
+ (creation date of image file (Mac type,
+ PhotoDB only) */
+ guint32 digitized_date;/* Date the image was taken (EXIF
+ information, Mac type, PhotoDB only) */
+ guint32 artwork_size; /* Size in bytes of the original source
+ image (PhotoDB only -- don't touch in
+ case of ArtworkDB!) */
/* below is for use by application */
guint64 usertype;
gpointer userdata;