static gboolean rb_ipod_db_load (RbIpodDb *ipod_db, GMount *mount) { GFile *mount_root; char *mount_path; const Itdb_IpodInfo *info; RbIpodDbPrivate *priv = IPOD_DB_GET_PRIVATE (ipod_db); mount_root = g_mount_get_root (mount); if (mount_root == NULL) { return FALSE; } mount_path = g_file_get_path (mount_root); g_object_unref (mount_root); priv->itdb = itdb_parse (mount_path, NULL); g_free (mount_path); if (priv->itdb == NULL) { return FALSE; } info = itdb_device_get_ipod_info (priv->itdb->device); if (info->ipod_generation == ITDB_IPOD_GENERATION_UNKNOWN || info->ipod_generation == ITDB_IPOD_GENERATION_SHUFFLE_1 || info->ipod_generation == ITDB_IPOD_GENERATION_SHUFFLE_2 || info->ipod_generation == ITDB_IPOD_GENERATION_SHUFFLE_3) { priv->needs_shuffle_db = TRUE; } else { priv->needs_shuffle_db = FALSE; } return TRUE; }
int main (int argc, char **argv) { Itdb_iTunesDB *db; GList *it; GList *covers; int nb_covers; if (argc < 3) { g_print ("Usage: %s mountpoint image-dir\n", argv[0]); return 1; } setlocale (LC_ALL, ""); #if !GLIB_CHECK_VERSION(2, 36, 0) g_type_init (); #endif covers = get_cover_list (argv[2]); if (covers == NULL) { g_print ("Error, %s should be a directory containing pictures\n", argv[2]); return 1; } nb_covers = g_list_length (covers); db = itdb_parse (argv[1], NULL); if (db == NULL) { g_print ("Error reading iPod database\n"); return 1; } for (it = db->tracks; it != NULL; it = it->next) { Itdb_Track *song; const char *coverpath; song = (Itdb_Track*)it->data; itdb_artwork_remove_thumbnails (song->artwork); coverpath = g_list_nth_data (covers, g_random_int_range (0, nb_covers)); itdb_track_set_thumbnails (song, coverpath); /* g_print ("%s - %s - %s gets %s\n", song->artist, song->album, song->title, coverpath);*/ } /* if (db->tracks != NULL) { Itdb_Track *song; const char *coverpath; song = (Itdb_Track *)db->tracks->data; coverpath = g_list_nth_data (covers, g_random_int_range (0, nb_covers)); itdb_track_remove_thumbnail (song); itdb_track_set_thumbnail (song, coverpath); }*/ itdb_write (db, NULL); itdb_free (db); g_list_foreach (covers, (GFunc)g_free, NULL); g_list_free (covers); return 0; }
int main (int argc, char **argv) { Itdb_iTunesDB *db; if (argc < 2) { g_print ("Usage: %s mountpoint\n", argv[0]); return 1; } setlocale (LC_ALL, ""); g_type_init (); db = itdb_parse (argv[1], NULL); if (db == NULL) { g_print ("Error reading iPod database\n"); return 1; } g_print ("========== ArtworkDB ==========\n"); save_thumbnails (db); itdb_free (db); return 0; }
GpodDb::InitResult GpodDb::Load () { const auto& nativePath = QDir::toNativeSeparators (LocalPath_).toUtf8 (); GError *gerr = nullptr; if ((DB_ = itdb_parse (nativePath, &gerr))) return { Result::Success, {} }; if (gerr && gerr->domain == ITDB_FILE_ERROR && gerr->code == ITDB_FILE_ERROR_NOTFOUND) { g_error_free (gerr); return { Result::NotFound, {} }; } QString text; if (gerr) { text = tr ("Error loading iTunes database: %1.") .arg (QString::fromUtf8 (gerr->message)); g_error_free (gerr); } else text = tr ("Error loading iTunes database."); return { Result::OtherError, text }; }
void GPodLoader::LoadDatabase() { int task_id = task_manager_->StartTask(tr("Loading iPod database")); emit TaskStarted(task_id); // Load the iTunes database GError* error = nullptr; Itdb_iTunesDB* db = itdb_parse(QDir::toNativeSeparators(mount_point_).toLocal8Bit(), &error); // Check for errors if (!db) { if (error) { qLog(Error) << "loading database failed:" << error->message; emit Error(QString::fromUtf8(error->message)); g_error_free(error); } else { emit Error(tr("An error occurred loading the iTunes database")); } task_manager_->SetTaskFinished(task_id); return; } // Convert all the tracks from libgpod structs into Song classes const QString prefix = path_prefix_.isEmpty() ? QDir::fromNativeSeparators(mount_point_) : path_prefix_; SongList songs; for (GList* tracks = db->tracks; tracks != nullptr; tracks = tracks->next) { Itdb_Track* track = static_cast<Itdb_Track*>(tracks->data); Song song; song.InitFromItdb(track, prefix); song.set_directory_id(1); if (type_ != Song::Type_Unknown) song.set_filetype(type_); songs << song; } // Need to remove all the existing songs in the database first backend_->DeleteSongs(backend_->FindSongsInDirectory(1)); // Add the songs we've just loaded backend_->AddOrUpdateSongs(songs); moveToThread(original_thread_); task_manager_->SetTaskFinished(task_id); emit LoadFinished(db); }
Itdb_iTunesDB* IpodDeviceHelper::parseItdb( const QString &mountPoint, QString &errorMsg ) { Itdb_iTunesDB *itdb; GError *error = 0; errorMsg.clear(); itdb = itdb_parse( QFile::encodeName( mountPoint ), &error ); if( error ) { if( itdb ) itdb_free( itdb ); itdb = 0; errorMsg = QString::fromUtf8( error->message ); g_error_free( error ); error = 0; } if( !itdb && errorMsg.isEmpty() ) errorMsg = i18n( "Cannot parse iTunes database due to an unreported error." ); return itdb; }