void pragha_toolbar_update_playback_progress(PraghaBackend *backend, gpointer user_data) { gint length = 0, newsec = 0; PraghaMusicobject *mobj = NULL; PraghaToolbar *toolbar = user_data; newsec = GST_TIME_AS_SECONDS(pragha_backend_get_current_position(backend)); if (newsec > 0) { mobj = pragha_backend_get_musicobject (backend); length = pragha_musicobject_get_length (mobj); if (length > 0) { pragha_toolbar_update_progress (toolbar, length, newsec); } else { gint nlength = GST_TIME_AS_SECONDS(pragha_backend_get_current_length(backend)); pragha_musicobject_set_length (mobj, nlength); } } }
LIBMTP_track_t * mtp_track_new_from_pragha_musicobject (LIBMTP_mtpdevice_t *mtp_device, PraghaMusicobject *mobj) { LIBMTP_track_t *tr; LIBMTP_filetype_t filetype; gchar *filename; const gchar *mime_type; struct stat sbuf; mime_type = pragha_musicobject_get_mime_type (mobj); if (is_valid_mime(mime_type, mime_flac)) filetype = LIBMTP_FILETYPE_FLAC; else if (is_valid_mime(mime_type, mime_mpeg)) filetype = LIBMTP_FILETYPE_MP3; else if (is_valid_mime(mime_type, mime_ogg)) filetype = LIBMTP_FILETYPE_OGG; else if (is_valid_mime(mime_type, mime_wav)) filetype = LIBMTP_FILETYPE_WAV; else if (is_valid_mime(mime_type, mime_asf)) filetype = LIBMTP_FILETYPE_WMA; else if (is_valid_mime(mime_type, mime_mp4)) filetype = LIBMTP_FILETYPE_MP4; else filetype = LIBMTP_FILETYPE_UNKNOWN; if (filetype == LIBMTP_FILETYPE_UNKNOWN) return NULL; filename = g_strdup(pragha_musicobject_get_file(mobj)); if (g_stat(filename, &sbuf) == -1) { g_free(filename); return NULL; } tr = LIBMTP_new_track_t(); /* Minimun data. */ tr->filesize = (uint64_t) sbuf.st_size; tr->filename = get_display_name(mobj); tr->filetype = filetype; /* Metadata. */ tr->title = g_strdup(pragha_musicobject_get_title(mobj)); tr->artist = g_strdup(pragha_musicobject_get_artist(mobj)); tr->album = g_strdup(pragha_musicobject_get_album(mobj)); tr->duration = (1000 * pragha_musicobject_get_length(mobj)); tr->genre = g_strdup(pragha_musicobject_get_genre (mobj)); tr->date = g_strdup_printf("%d", pragha_musicobject_get_year (mobj)); /* Storage data. */ tr->parent_id = mtp_device->default_music_folder; tr->storage_id = 0; g_free(filename); return tr; }
void pragha_database_add_new_musicobject (PraghaDatabase *database, PraghaMusicobject *mobj) { const gchar *file, *mime_type, *artist, *album, *genre, *comment; gint location_id = 0, mime_type_id = 0, artist_id = 0, album_id = 0, genre_id = 0, year_id = 0, comment_id; if (mobj) { file = pragha_musicobject_get_file (mobj); mime_type = pragha_musicobject_get_mime_type (mobj); artist = pragha_musicobject_get_artist (mobj); album = pragha_musicobject_get_album (mobj); genre = pragha_musicobject_get_genre (mobj); comment = pragha_musicobject_get_comment (mobj); /* Write location */ if ((location_id = pragha_database_find_location (database, file)) == 0) location_id = pragha_database_add_new_location (database, file); /* Write mime_type */ if ((mime_type_id = pragha_database_find_mime_type (database, mime_type)) == 0) mime_type_id = pragha_database_add_new_mime_type (database, mime_type); /* Write artist */ if ((artist_id = pragha_database_find_artist (database, artist)) == 0) artist_id = pragha_database_add_new_artist (database, artist); /* Write album */ if ((album_id = pragha_database_find_album (database, album)) == 0) album_id = pragha_database_add_new_album (database, album); /* Write genre */ if ((genre_id = pragha_database_find_genre (database, genre)) == 0) genre_id = pragha_database_add_new_genre (database, genre); /* Write year */ if ((year_id = pragha_database_find_year (database, pragha_musicobject_get_year (mobj))) == 0) year_id = pragha_database_add_new_year (database, pragha_musicobject_get_year (mobj)); /* Write comment */ if ((comment_id = pragha_database_find_comment (database, comment)) == 0) comment_id = pragha_database_add_new_comment (database, comment); /* Write track */ pragha_database_add_new_track (database, location_id, mime_type_id, artist_id, album_id, genre_id, year_id, comment_id, pragha_musicobject_get_track_no (mobj), pragha_musicobject_get_length (mobj), pragha_musicobject_get_channels (mobj), pragha_musicobject_get_bitrate (mobj), pragha_musicobject_get_samplerate (mobj), pragha_musicobject_get_title (mobj)); } }