Content-Type: multipart/mixed; boundary="=-qog1uC5U0LeV7Ez0LN9N" --=-qog1uC5U0LeV7Ez0LN9N Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Heya, Here are a couple of patches (literrally). itunesdb2-glib2.patch: use glib2, fix typo libipod-more-glib.patch: use glib2, add iPodGetSong* helpers, replace (some) hackish C code with the glib equivalent (usually shorter), make iPod->dbpath actually contain the path to iTunesDB, added some functionality to testprogram.c (lists all the songs in the master playlist). I'll be adding some code to get a tihm_t from a file (so that I can copy a file to the Music folder of the iPod, then get the tihm_t, and add it to the playlist). Comments ? --=20 /Bastien Nocera http://hadess.net Perfection is reached, not when there is no longer anything to add, but when there is no longer anything to take away. Antoine de Saint-Exupery --=-qog1uC5U0LeV7Ez0LN9N Content-Disposition: attachment; filename=itunesdb2-glib2.patch Content-Type: text/x-patch; name=itunesdb2-glib2.patch; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Index: Makefile =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/ipod-on-linux/iTunesDB2/Makefile,v retrieving revision 1.5 diff -u -r1.5 Makefile --- Makefile 6 Oct 2002 08:32:06 -0000 1.5 +++ Makefile 27 Oct 2002 01:26:10 -0000 @@ -6,7 +6,7 @@ =20 CC =3D gcc -g3 AR =3D ar -CFLAGS =3D `glib-config --cflags` -I../hfsplus -I. -DDEBUG +CFLAGS =3D `pkg-config --cflags glib-2.0` -I../hfsplus -I. -DDEBUG DEFINES =3D =20 .c.o: $(HDRS) @@ -19,10 +19,11 @@ ranlib libitunesdb.a =20 list_test: libitunesdb.a list.o - $(CC) `glib-config --libs` list.o -L. -litunesdb -L../hfsplus -lhfsplus -= o list_test + $(CC) -o list_test `pkg-config --libs glib-2.0` list.o -L. -litunesdb =20 ipod_test: ipod_test.o libitunesdb.a - $(CC) `glib-config --libs` ipod_test.o -L. -litunesdb -L../hfsplus -lhfsp= lus -o ipod_test + $(CC) -o ipod_test `pkg-config --libs glib-2.0` ipod_test.o -L. -litunesd= b =20 clean: - rm -f $(OBJS) libitunesdb.a *~ \ No newline at end of file + rm -f $(OBJS) libitunesdb.a *~ + Index: list.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/ipod-on-linux/iTunesDB2/list.c,v retrieving revision 1.14 diff -u -r1.14 list.c --- list.c 6 Oct 2002 19:04:38 -0000 1.14 +++ list.c 27 Oct 2002 01:26:11 -0000 @@ -58,7 +58,7 @@ ret =3D db_sanity_check(itunesdb); =20 if (ret <=3D -20) { - printf ("There is somthing wrong with the loaded database!\n"); + printf ("There is something wrong with the loaded database!\n"); db_free (&itunesdb); exit(1); } else if (ret < 0) { --=-qog1uC5U0LeV7Ez0LN9N Content-Disposition: attachment; filename=libipod-more-glib.patch Content-Type: text/x-patch; name=libipod-more-glib.patch; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Index: Makefile =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/ipod-on-linux/libipod/Makefile,v retrieving revision 1.5 diff -u -r1.5 Makefile --- Makefile 9 Oct 2002 18:49:57 -0000 1.5 +++ Makefile 27 Oct 2002 01:26:50 -0000 @@ -6,10 +6,8 @@ =20 CC =3D gcc -g =20 -IFLAGS =3D -I -I/usr/include \ - -I/usr/include/glib-1.2 \ - -I/usr/lib/glib/include -I. -I../iTunesDB2 -LIBS =3D -L../iTunesDB2 -litunesdb -lid3tag -lz +IFLAGS =3D `pkg-config --cflags glib-2.0` -I. -I../iTunesDB2 +LIBS =3D -L../iTunesDB2 -litunesdb `pkg-config --libs glib-2.0` -lid3tag -= lz =20 .c.o: $(CC) $(IFLAGS) -c $*.c=20 Index: files.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/ipod-on-linux/libipod/files.c,v retrieving revision 1.5 diff -u -r1.5 files.c --- files.c 9 Oct 2002 18:49:57 -0000 1.5 +++ files.c 27 Oct 2002 01:26:51 -0000 @@ -154,7 +154,7 @@ return ret; } =20 -file_t * getSongInfo( tihm_t * tihm ) { +static file_t * getSongInfo( tihm_t * tihm ) { file_t * file; int cnt =3D 0; Unicode unicode; @@ -221,3 +221,70 @@ =20 return head; } + +char * iPodGetSongTitle( tihm_t *song ) +{ + char * title =3D NULL; + int i; + + g_return_val_if_fail (song !=3D NULL, NULL); + + for ( i =3D 0 ; i < song->num_dohm ; i++ ) { + if ( song->dohms[i].type =3D=3D IPOD_TITLE ) { + title =3D ( char * ) g_malloc( song->dohms[i].size ); + unicode_to_char( title, song->dohms[i].data, song->dohms[i].size ); + break; + } + } + + return title; +} + +char * iPodGetSongArtist( tihm_t *song ) +{ + char * artist =3D NULL; + int i; + + g_return_val_if_fail (song !=3D NULL, NULL); + + for ( i =3D 0 ; i < song->num_dohm ; i++ ) { + if ( song->dohms[i].type =3D=3D IPOD_ARTIST ) { + artist =3D ( char * ) g_malloc( song->dohms[i].size ); + unicode_to_char( artist, song->dohms[i].data, song->dohms[i].size ); + break; + } + } + + return g_strdup( artist ); +} + +char * iPodGetSongRealPath( iPod_t * iPod, tihm_t * song ) +{ + char * path =3D NULL, * needle, * fullpath; + int i; + + g_return_val_if_fail (song !=3D NULL, NULL); + + for (i =3D 0 ; i < song->num_dohm ; i++) { + if (song->dohms[i].type =3D=3D IPOD_PATH) { + path =3D ( char * ) g_malloc( song->dohms[i].size ); + unicode_to_char( path, song->dohms[i].data, song->dohms[i].size ); + break; + } + } + + if (path =3D=3D NULL) + return NULL; + + needle =3D strstr (path, ":"); + while (needle !=3D NULL) { + *needle =3D '/'; + needle =3D strstr (path, ":"); + } + + fullpath =3D g_build_filename( G_DIR_SEPARATOR_S, iPod->mount, path, NUL= L ); + g_free (path); + + return fullpath; +} + Index: iPod.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/ipod-on-linux/libipod/iPod.h,v retrieving revision 1.6 diff -u -r1.6 iPod.h --- iPod.h 9 Oct 2002 18:39:21 -0000 1.6 +++ iPod.h 27 Oct 2002 01:26:51 -0000 @@ -2,6 +2,7 @@ #define IPOD_H =20 #include +#include =20 /* Unicode stuff */ struct Unicode { @@ -45,12 +46,19 @@ int iPodCopyFileFrom( iPod_t * iPod, file_t * from, char * to ); =20 /* Playlist functions */ +/* returns a GList of file_t's */ +GList * iPodGetSongList( iPod_t * iPod ); playlist_t * iPodCreatePlaylist( iPod_t * ipod, char * name ); -int iPodRemovePlaylist( iPod_t * ipod, playlist_t * playlist ); -int iPodAddSongToPlaylist( iPod_t * ipod, playlist_t * playlist,=20 +int iPodRemovePlaylist( iPod_t * iPod, playlist_t * playlist ); +int iPodAddSongToPlaylist( iPod_t * iPod, playlist_t * playlist,=20 file_t * song ); -int iPodRemoveSongFromPlaylist( iPod_t * ipod, playlist_t * playlist, +int iPodRemoveSongFromPlaylist( iPod_t * iPod, playlist_t * playlist, file_t * song ); + +/* Helper functions to get some details about the song */ +char * iPodGetSongTitle( tihm_t *song ); +char * iPodGetSongArtist( tihm_t *song ); +char * iPodGetSongRealPath( iPod_t * iPod, tihm_t *song ); =20 /* mp3 stuff (mp3.c) */ tihm_t * getMP3Info( int fd ); Index: iPodOpenClose.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/ipod-on-linux/libipod/iPodOpenClose.c,v retrieving revision 1.5 diff -u -r1.5 iPodOpenClose.c --- iPodOpenClose.c 4 Oct 2002 19:10:38 -0000 1.5 +++ iPodOpenClose.c 27 Oct 2002 01:26:51 -0000 @@ -1,4 +1,5 @@ #define _FILE_OFFSET_BITS 64 +#include #include #include #include @@ -7,6 +8,7 @@ #include #include #include +#include =20 #include #include "iPod.h" @@ -72,7 +74,6 @@ char * checkiTunesDBPath( char * mountdir ) { char * path; int length;=20 - DIR * dir; int file; =20 /* Copy mount point onto path */ @@ -83,47 +84,41 @@ =20 /* Check for iPod_Control */ strcat( path, "/iPod_Control" ); - dir =3D opendir( path ); - if ( dir =3D=3D NULL ) { + if ( g_file_test( path, G_FILE_TEST_IS_DIR ) =3D=3D FALSE ) { return initPath( path, 1 ); } - closedir( dir ); =20 /* Check for iTunes */ strcat( path, "/iTunes" ); - dir =3D opendir( path ); - if ( dir =3D=3D NULL ) { + if ( g_file_test( path, G_FILE_TEST_IS_DIR ) =3D=3D FALSE ) { return initPath( path, 2 ); } - closedir( dir ); =20 return path; } =20 /* Open the iTunesDB file */ -itunesdb_t * openiTunesDB( char * dbpath, char * name ) { +itunesdb_t * openiTunesDB( char * dbpath , char * name ) { itunesdb_t * iTunesDB; - int fd; - =20 int ret; + =20 /* create the database */ iTunesDB =3D (itunesdb_t *) malloc( sizeof( itunesdb_t ) ); - memset( &(iTunesDB), 0, sizeof( itunesdb_t ) ); + memset( iTunesDB, 0, sizeof( itunesdb_t ) ); =20 /* check to see if the file exists */ - fd =3D open( dbpath, O_RDONLY ); - if ( fd <=3D 0 ) { + if ( g_file_test( dbpath, G_FILE_TEST_IS_REGULAR ) =3D=3D FALSE ) { + fprintf( stderr, "Couldn't open %s: %s\n", dbpath, strerror( errno ) )= ; /* if not create a new one */ if ( ( ret =3D db_create( iTunesDB, name, strlen( name ) ) ) !=3D 0 ) = { free( iTunesDB ); - printf( "AM HERE: %d\n", ret ); return NULL; } } else { /* if so load it up */ - close( fd ); - if ( db_load( iTunesDB, dbpath ) !=3D 0 ) { + if ( db_load( iTunesDB, dbpath ) < 0 ) { + fprintf( stderr, "Couldn't load the database (%s)\n", dbpath ); free( iTunesDB ); return NULL; } @@ -139,7 +134,7 @@ iPod_t * iPodOpen( char * device, char * mountdir ) { int returnval; iPod_t * iPod; - char command[256]; + char * command, * path, * name; =20 /* Check if this device is a winpod */ if ( checkIfWinPod( device ) !=3D 0 ) { @@ -147,30 +142,43 @@ } =20 /* Mount the device */ - sprintf( command, "mount %s", mountdir ); + command =3D g_strdup_printf( "mount %s", mountdir ); returnval =3D system( command ); if ( returnval !=3D 0 ) { + g_free( command ); perror( "HELP " ); return NULL; } =20 /* Build iPod structure */ - iPod =3D (iPod_t *)malloc( sizeof( iPod_t ) ); - iPod->mount =3D mountdir; + iPod =3D g_new( iPod_t, 1 ); + iPod->mount =3D g_strdup( mountdir ); iPod->name =3D NULL; =20 /* find iTunesDB file */ - iPod->dbpath =3D checkiTunesDBPath( mountdir ); - if ( iPod->dbpath =3D=3D NULL ) { + path =3D checkiTunesDBPath( mountdir ); + if ( path =3D=3D NULL ) { + fprintf( stderr, "Couldn't find the database\n"); free( iPod ); return NULL; } =20 + name =3D "iPod"; + iPod->dbpath =3D g_build_filename( G_DIR_SEPARATOR_S, path, "iPod", NULL= ); + if ( g_file_test( iPod->dbpath, G_FILE_TEST_IS_REGULAR ) =3D=3D FALSE ) + { + g_free( iPod->dbpath ); + name =3D "iTunesDB"; + iPod->dbpath =3D g_build_filename( G_DIR_SEPARATOR_S, path, + "iTunesDB", NULL ); + } + /* find name of iPod */ - =20 +=20 /* read iPod database in */ - iPod->iTunesDB =3D openiTunesDB( iPod->dbpath, "iPod" ); + iPod->iTunesDB =3D openiTunesDB( iPod->dbpath , name ); if ( iPod->iTunesDB =3D=3D NULL ) { + fprintf( stderr, "Couldn't read the database\n"); free( iPod ); return NULL; } Index: testprogram.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/ipod-on-linux/libipod/testprogram.c,v retrieving revision 1.1 diff -u -r1.1 testprogram.c --- testprogram.c 1 Oct 2002 17:27:28 -0000 1.1 +++ testprogram.c 27 Oct 2002 01:26:51 -0000 @@ -3,9 +3,29 @@ =20 int main() { iPod_t * iPod; - iPod =3D iPodOpen( "/dev/sda", "/mnt/iPod" ); + GList *songs, *list; + iPod =3D iPodOpen( "/dev/sda", "/mnt/ipod" ); if ( iPod =3D=3D NULL ) { printf( "UhOh\n" ); + iPodClose (iPod); + exit (1); } + songs =3D db_song_list ( iPod->iTunesDB ); + list =3D songs; + + while (list !=3D NULL) { + tihm_t *song =3D list->data; + char *title, *artist, *path; + + title =3D iPodGetSongTitle( song ); + artist =3D iPodGetSongArtist( song ); + path =3D iPodGetSongRealPath( iPod, song ); + + g_print ("%s - %s (%s)\n", artist, title, path); + list =3D list->next; + } + + db_song_list_free( songs ); + iPodClose (iPod); return 0; } --=-qog1uC5U0LeV7Ez0LN9N--