commit 24d179066856e1bd7138edfe00679f816ceb0037
Author: Christophe Fergeau <[email protected]>
Date: Sat Oct 17 15:58:59 2009 +0200
rework mhia/mhla writing to include more information
This additional information contains an SQL ID which will be used when
writing
sqlite databases for the iphone.
src/itdb.h | 1 -
src/itdb_itunesdb.c | 58 ++++++++++++++++++++++++++++++++------------------
2 files changed, 37 insertions(+), 22 deletions(-)
---
diff --git a/src/itdb.h b/src/itdb.h
index edf4ca6..7ee5af3 100644
--- a/src/itdb.h
+++ b/src/itdb.h
@@ -1664,7 +1664,6 @@ struct _Itdb_Track
/* (gtkpod note: don't forget to add fields read from the file to
* copy_new_info() in file.c!) */
-
/* ------------------------------------------------------------ *\
*
* Error codes
diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c
index 0d50bee..09d3a39 100644
--- a/src/itdb_itunesdb.c
+++ b/src/itdb_itunesdb.c
@@ -4458,11 +4458,18 @@ static void mk_mhod (FExport *fexp, MHODData *mhod)
}
}
+struct _Itdb_Item_Id {
+ guint32 id;
+ guint64 sql_id;
+};
+typedef struct _Itdb_Item_Id Itdb_Item_Id;
+
static void mk_mhia (gpointer key, gpointer value, gpointer user_data)
{
FExport *fexp;
WContents *cts;
Itdb_Track *track;
+ Itdb_Item_Id *id;
MHODData mhod;
guint mhod_num;
gulong mhia_seek;
@@ -4470,6 +4477,9 @@ static void mk_mhia (gpointer key, gpointer value,
gpointer user_data)
track = (Itdb_Track *)key;
g_return_if_fail (track != NULL);
+ id = (Itdb_Item_Id *)value;
+ g_return_if_fail (id != NULL);
+
fexp = (FExport *)user_data;
g_return_if_fail (fexp);
g_return_if_fail (fexp->wcontents);
@@ -4477,15 +4487,13 @@ static void mk_mhia (gpointer key, gpointer value,
gpointer user_data)
mhia_seek = cts->pos;
put_header (cts, "mhia"); /* header */
- put32lint (cts, 92); /* size of header */
+ put32lint (cts, 88); /* size of header */
put32lint (cts, -1); /* total size -> later */
put32lint (cts, 2); /* number of children mhods */
- put16lint (cts, 0); /* unknown */
- put16lint (cts, GPOINTER_TO_UINT (value)); /* album id */
- put32lint (cts, 0); /* unknown */
- put32lint (cts, 0); /* unknown */
+ put32lint (cts, id->id); /* album id */
+ put64lint (cts, id->sql_id); /* id used in the sqlite DB */
put32lint (cts, 2); /* unknown */
- put32_n0 (cts, 15); /* padding */
+ put32_n0 (cts, 14); /* padding */
mhod.valid = TRUE;
mhod_num = 0;
@@ -5277,19 +5285,16 @@ static void wcontents_free (WContents *cts)
}
}
-
-static guint itdb_track_hash (gconstpointer v)
+static guint itdb_album_hash (gconstpointer v)
{
Itdb_Track *track = (Itdb_Track *)v;
if (track->album != NULL) {
return g_str_hash (track->album);
- } else if (track->artist != NULL) {
- return g_str_hash (track->artist);;
}
g_assert_not_reached ();
}
-static gboolean itdb_track_equal (gconstpointer v1, gconstpointer v2)
+static gboolean itdb_album_equal (gconstpointer v1, gconstpointer v2)
{
Itdb_Track *track1 = (Itdb_Track *)v1;
Itdb_Track *track2 = (Itdb_Track *)v2;
@@ -5299,15 +5304,26 @@ static gboolean itdb_track_equal (gconstpointer v1,
gconstpointer v2)
if ((track1->albumartist != NULL) && (track2->albumartist != NULL)) {
return (g_str_equal (track1->album, track2->album)
- && g_str_equal (track1->albumartist, track2->albumartist));
+ && g_str_equal (track1->albumartist, track2->albumartist));
} else if ((track1->artist != NULL) && (track2->artist != NULL)) {
return (g_str_equal (track1->album, track2->album)
- && g_str_equal (track1->artist, track2->artist));
+ && g_str_equal (track1->artist, track2->artist));
} else {
return (g_str_equal (track1->album, track2->album));
}
}
+static void add_new_id (GHashTable *album_ids, Itdb_Track *track, guint
album_id)
+{
+ Itdb_Item_Id *id;
+
+ id = g_new0 (Itdb_Item_Id, 1);
+ id->id = album_id;
+ id->sql_id = ((guint64)g_random_int () << 32) | ((guint64)g_random_int
());
+
+ g_hash_table_insert (album_ids, track, id);
+}
+
/* - reassign the iPod IDs
- make sure the itdb->tracks are in the same order as the mpl
- assign album IDs to write the MHLA
@@ -5347,30 +5363,30 @@ static void prepare_itdb_for_write (FExport *fexp)
fexp->next_id = FIRST_IPOD_ID;
g_assert (fexp->albums == NULL);
- fexp->albums = g_hash_table_new (itdb_track_hash, itdb_track_equal);
+ fexp->albums = g_hash_table_new_full (itdb_album_hash, itdb_album_equal,
+ NULL, g_free);
/* assign unique IDs and create sort keys */
for (gl=itdb->tracks; gl; gl=gl->next)
{
Itdb_Track *track = gl->data;
- guint id;
+ Itdb_Item_Id *id;
g_return_if_fail (track);
track->id = fexp->next_id++;
if (track->album == NULL) {
- /* unknow album name and artist, this entry isn't interesting to
+ /* unknown album name, this entry isn't interesting to
* build the list of all albums on the ipod
*/
continue;
}
/* album ids are used when writing the mhla header */
- id = GPOINTER_TO_UINT (g_hash_table_lookup (fexp->albums, track));
- if (id != 0) {
- track->priv->album_id = id;
+ id = g_hash_table_lookup (fexp->albums, track);
+ if (id != NULL) {
+ track->priv->album_id = id->id;
} else {
- g_hash_table_insert (fexp->albums, track,
- GUINT_TO_POINTER (album_id));
+ add_new_id (fexp->albums, track, album_id);
track->priv->album_id = album_id;
album_id++;
}
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2