/** * itdb_photodb_parse: * @mp: mountpoint of the iPod * @error: will contain the error description when an error occured. * * Parses the photo database of an iPod mounted at @mp. * * Return value: the imported PhotoDB or NULL in case of an error. **/ Itdb_PhotoDB *itdb_photodb_parse (const gchar *mp, GError **error) { gchar *photos_dir; Itdb_PhotoDB *photodb = NULL; photos_dir = itdb_get_photos_dir (mp); if (!photos_dir) { error_no_photos_dir (mp, error); return NULL; } g_free (photos_dir); photodb = itdb_photodb_new (); itdb_device_set_mountpoint (photodb->device, mp); ipod_parse_photo_db (photodb); /* if photodb is empty, create a valid photodb including the main Photo Library album */ if (!photodb->photos && !photodb->photoalbums) { itdb_photodb_free (photodb); photodb = itdb_photodb_create (mp); } return photodb; }
static int do_list (int argc, char **argv) { GError *error = NULL; Itdb_PhotoDB *db; GList *gl_album; if (argc != 3) { g_print (_("Insufficient number of command line arguments.\n")); usage (argc, argv); return 1; } db = itdb_photodb_parse (argv[2], &error); if (db == NULL) { if (error) { g_print (_("Error reading iPod photo database (%s).\n"), error->message); g_error_free (error); error = NULL; } else { g_print (_("Error reading iPod photo database.\n")); } return 1; } for (gl_album=db->photoalbums; gl_album; gl_album=gl_album->next) { GList *gl_photo; Itdb_PhotoAlbum *album = gl_album->data; g_return_val_if_fail (album, 1); g_print ("%s: ", album->name?album->name:_("<Unnamed>")); for (gl_photo=album->members; gl_photo; gl_photo=gl_photo->next) { Itdb_Artwork *photo = gl_photo->data; g_return_val_if_fail (photo, 1); g_print ("%d ", photo->id); } if (g_list_length (album->members) > 0) { g_print ("\n"); } else { g_print (_("<No members>\n")); } } itdb_photodb_free (db); return 0; }
static int do_dump (int argc, char **argv) { GError *error = NULL; Itdb_PhotoDB *db; if (argc != 4) { g_print (_("Wrong number of command line arguments.\n")); usage (argc, argv); return 1; } if (!g_file_test (argv[3], G_FILE_TEST_EXISTS)) { if (mkdir (argv[3], 0777) == -1) { g_print (_("Error creating '%s' (mkdir)\n"), argv[3]); return 1; } } if (!g_file_test (argv[3], G_FILE_TEST_IS_DIR)) { g_print (_("Error: '%s' is not a directory\n"), argv[3]); return 1; } db = itdb_photodb_parse (argv[2], &error); if (db == NULL) { if (error) { g_print (_("Error reading iPod photo database (%s).\n"), error->message); g_error_free (error); error = NULL; } else { g_print (_("Error reading iPod photo database.\n")); } return 1; } dump_albums (db, argv[3]); itdb_photodb_free (db); return 0; }
static int do_remove (int argc, char **argv) { GError *error = NULL; Itdb_PhotoDB *db; Itdb_PhotoAlbum *album = NULL; if (argc < 4) { g_print (_("Insufficient number of command line arguments.\n")); usage (argc, argv); return 1; } db = itdb_photodb_parse (argv[2], &error); if (db == NULL) { if (error) { g_print (_("Error reading iPod photo database (%s).\n"), error->message); g_error_free (error); error = NULL; } else { g_print (_("Error reading iPod photo database.\n")); } return 1; } /* Find specified photoalbum */ if (strcmp (argv[3], "NULL") != 0) { album = itdb_photodb_photoalbum_by_name (db, argv[3]); if (!album) { g_print (_("Specified album '%s' not found. Aborting.\n"), argv[3]); itdb_photodb_free (db); return 1; } } if (argc == 4) { /* Remove photoalbum altogether, but preserve pics */ if (album == NULL) { g_print (_("Cannot remove Photo Library playlist. Aborting.\n")); itdb_photodb_free (db); return 1; } itdb_photodb_photoalbum_remove (db, album, FALSE); } else { /* Remove specified pictures */ int i; for (i=4; i<argc; ++i) { Itdb_Artwork *photo; guint32 id; id = g_strtod (argv[i], NULL); photo = get_photo_by_id (db, id); if (photo == NULL) { g_print (_("Warning: could not find photo with ID <%d>. Skipping...\n"), id); } else { itdb_photodb_remove_photo (db, album, photo); } } } itdb_photodb_write (db, NULL); itdb_photodb_free (db); return 0; }
static int do_add (int argc, char **argv) { GError *error = NULL; Itdb_PhotoAlbum *album = NULL; Itdb_PhotoDB *db; gint i; if (argc < 4) { g_print (_("Insufficient number of command line arguments.\n")); usage (argc, argv); return 1; } db = itdb_photodb_parse (argv[2], &error); if (db == NULL) { if (error) { g_print (_("Error reading iPod photo database (%s).\nWill attempt to create a new database.\n"), error->message); g_error_free (error); error = NULL; } else { g_print (_("Error reading iPod photo database, will attempt to create a new database\n")); } db = itdb_photodb_create (argv[2]); } /* Find or create specified photoalbum */ if (strcmp (argv[3], "NULL") != 0) { album = itdb_photodb_photoalbum_by_name (db, argv[3]); if (!album) { album = itdb_photodb_photoalbum_create (db, argv[3], -1); } } for (i=4; i<argc; ++i) { Itdb_Artwork *photo; photo = itdb_photodb_add_photo (db, argv[i], -1, GDK_PIXBUF_ROTATE_NONE, &error); if (photo == NULL) { if (error) { g_print (_("Error adding photo (%s) to photo database: %s\n"), argv[i], error->message); g_error_free (error); error = NULL; } } else { if (album) { itdb_photodb_photoalbum_add_photo (db, album, photo, -1); } } } itdb_photodb_write (db, NULL); itdb_photodb_free (db); return 0; }