[goobox] Ported to libmusicbrainz 3
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goobox] Ported to libmusicbrainz 3
- Date: Sat, 4 Jun 2011 20:42:41 +0000 (UTC)
commit ed0f3512809c0ffe867b22a8b936fe4d44d9535c
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Jun 4 19:46:08 2011 +0200
Ported to libmusicbrainz 3
configure.ac | 5 +-
data/ui/properties.ui | 2 +-
src/album-info.c | 112 +++++++++++++-------------
src/dlg-properties.c | 185 ++++++++++++++++++++++---------------------
src/goo-player.c | 118 ++++++++++++++++-----------
src/metadata.c | 213 +++++++++++++++++++++++++++++--------------------
src/metadata.h | 5 +-
7 files changed, 355 insertions(+), 285 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4976022..67381ad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,7 @@ GLIB_REQUIRED=2.28
GTK_REQUIRED=3.0.0
GSTREAMER_REQUIRED=0.10.12
LIBNOTIFY_REQUIRED=0.4.3
-LIBMUSICBRAINZ_REQUIRED=2.1.0
+LIBMUSICBRAINZ3_REQUIRED=3.0.0
dnl ===========================================================================
@@ -33,7 +33,8 @@ PKG_CHECK_MODULES(GOO, [
gtk+-3.0 >= $GTK_REQUIRED
gstreamer-0.10 >= $GSTREAMER_REQUIRED
libbrasero-media3
- libmusicbrainz >= $LIBMUSICBRAINZ_REQUIRED
+ libmusicbrainz3 >= $LIBMUSICBRAINZ3_REQUIRED
+ libdiscid
unique-3.0
])
AC_SUBST(GOO_CFLAGS)
diff --git a/data/ui/properties.ui b/data/ui/properties.ui
index b28d921..83aaf21 100644
--- a/data/ui/properties.ui
+++ b/data/ui/properties.ui
@@ -344,7 +344,7 @@
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
- <object class="GtkImage" id="image2">
+ <object class="GtkImage" id="info_icon">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-dialog-warning</property>
diff --git a/src/album-info.c b/src/album-info.c
index 10c3bc8..7effa35 100644
--- a/src/album-info.c
+++ b/src/album-info.c
@@ -26,6 +26,7 @@
#include "album-info.h"
#include "glib-utils.h"
#include "gth-user-dir.h"
+#include "track-info.h"
#define MBI_VARIOUS_ARTIST_ID "89ad4ac3-39f7-470e-963a-56509c546377"
@@ -44,7 +45,7 @@ album_info_new (void)
album_info_set_title (album, NULL);
album_info_set_artist (album, NULL, NULL);
album_info_set_tracks (album, NULL);
-
+
return album;
}
@@ -68,12 +69,12 @@ GType
album_info_get_type (void)
{
static GType type = 0;
-
+
if (type == 0)
- type = g_boxed_type_register_static ("AlbumInfo",
+ type = g_boxed_type_register_static ("AlbumInfo",
(GBoxedCopyFunc) album_info_copy,
(GBoxedFreeFunc) album_info_free);
-
+
return type;
}
@@ -108,9 +109,9 @@ album_info_copy (AlbumInfo *src)
album_info_set_genre (dest, src->genre);
album_info_set_asin (dest, src->asin);
album_info_set_release_date (dest, src->release_date);
- dest->various_artist = src->various_artist;
+ dest->various_artist = src->various_artist;
album_info_set_tracks (dest, src->tracks);
-
+
return dest;
}
@@ -121,7 +122,7 @@ album_info_set_id (AlbumInfo *album,
{
if (album->id == id)
return;
-
+
g_free (album->id);
if (id != NULL)
album->id = g_strdup (id);
@@ -139,10 +140,10 @@ album_info_set_title (AlbumInfo *album,
album->title = NULL /*g_strdup (_("Unknown Album"))*/;
return;
}
-
+
if (album->title == title)
return;
-
+
g_free (album->title);
album->title = g_strdup (title);
}
@@ -160,15 +161,15 @@ album_info_set_artist (AlbumInfo *album,
album->artist_id = NULL;
return;
}
-
+
if (album->artist == artist)
return;
-
+
g_free (album->artist);
g_free (album->artist_id);
-
+
album->various_artist = (artist_id != NULL) && (strcmp (artist_id, MBI_VARIOUS_ARTIST_ID) == 0);
- if (artist != NULL)
+ if (artist != NULL)
album->artist = g_strdup (artist);
else if (album->various_artist)
album->artist = g_strdup (_("Various"));
@@ -180,18 +181,18 @@ album_info_set_artist (AlbumInfo *album,
}
-void
+void
album_info_set_genre (AlbumInfo *album,
const char *genre)
{
if (album->genre == genre)
return;
-
+
g_free (album->genre);
album->genre = NULL;
-
+
if (genre != NULL)
- album->genre = g_strdup (genre);
+ album->genre = g_strdup (genre);
}
@@ -201,20 +202,20 @@ album_info_set_asin (AlbumInfo *album,
{
if (album->asin == asin)
return;
-
+
g_free (album->asin);
album->asin = NULL;
-
+
if (asin != NULL)
album->asin = g_strdup (asin);
}
-void
+void
album_info_set_release_date (AlbumInfo *album,
GDate *date)
{
- if ((date != NULL) && (g_date_valid (date)))
+ if ((date != NULL) && (g_date_valid (date)))
g_date_set_julian (album->release_date, g_date_get_julian (date));
else
g_date_clear (album->release_date, 1);
@@ -226,18 +227,21 @@ album_info_set_tracks (AlbumInfo *album,
GList *tracks)
{
GList *scan;
-
+
if (album->tracks == tracks)
return;
-
+
track_list_free (album->tracks);
album->tracks = track_list_dup (tracks);
-
+
album->n_tracks = 0;
album->total_length = 0;
for (scan = album->tracks; scan; scan = scan->next) {
TrackInfo *track = scan->data;
-
+
+ if ((album->artist != NULL) && (track->artist == NULL))
+ track_info_set_artist (track, album->artist, album->artist_id);
+
album->n_tracks++;
album->total_length += track->length;
}
@@ -252,15 +256,15 @@ album_info_get_track (AlbumInfo *album,
for (scan = album->tracks; scan; scan = scan->next) {
TrackInfo *track = scan->data;
-
+
if (track->number == track_number)
return track_info_copy (track);
}
- return NULL;
+ return NULL;
}
-
-
+
+
void
album_info_copy_metadata (AlbumInfo *to_album,
AlbumInfo *from_album)
@@ -275,13 +279,13 @@ album_info_copy_metadata (AlbumInfo *to_album,
album_info_set_asin (to_album, from_album->asin);
album_info_set_release_date (to_album, from_album->release_date);
- for (scan_to = to_album->tracks, scan_from = from_album->tracks;
- scan_to && scan_from;
+ for (scan_to = to_album->tracks, scan_from = from_album->tracks;
+ scan_to && scan_from;
scan_to = scan_to->next, scan_from = scan_from->next)
{
TrackInfo *to_track = scan_to->data;
TrackInfo *from_track = scan_from->data;
-
+
track_info_copy_metadata (to_track, from_track);
}
}
@@ -307,45 +311,45 @@ album_info_load_from_cache (AlbumInfo *album,
char *s;
int i;
GList *scan;
-
+
path = get_cache_path (album, disc_id);
if (path == NULL)
return FALSE;
-
- f = g_key_file_new ();
+
+ f = g_key_file_new ();
if (! g_key_file_load_from_file (f, path, G_KEY_FILE_NONE, NULL)) {
g_free (path);
g_key_file_free (f);
return FALSE;
}
g_free (path);
-
+
s = g_key_file_get_string (f, "Album", "Title", NULL);
if (s != NULL) {
album_info_set_title (album, s);
g_free (s);
}
-
+
s = g_key_file_get_string (f, "Album", "Artist", NULL);
if (s != NULL) {
album_info_set_artist (album, s, "");
g_free (s);
}
album->various_artist = g_key_file_get_boolean (f, "Album", "VariousArtists", NULL);
-
+
s = g_key_file_get_string (f, "Album", "Genre", NULL);
if (s != NULL) {
album_info_set_genre (album, s);
g_free (s);
}
-
+
s = g_key_file_get_string (f, "Album", "ReleaseDate", NULL);
if (s != NULL) {
int y = 0, m = 0, d = 0;
-
+
if (sscanf (s, "%d/%d/%d", &d, &m, &y) > 0) {
GDate *date;
-
+
date = g_date_new_dmy ((d > 0) ? d : 1, (m > 0) ? m : 1, (y > 0) ? y : 1);
album_info_set_release_date (album, date);
g_date_free (date);
@@ -357,7 +361,7 @@ album_info_load_from_cache (AlbumInfo *album,
for (scan = album->tracks; scan; scan = scan->next) {
TrackInfo *track = scan->data;
char *group;
-
+
group = g_strdup_printf ("Track %d", i);
s = g_key_file_get_string (f, group, "Title", NULL);
if (s != NULL) {
@@ -370,12 +374,12 @@ album_info_load_from_cache (AlbumInfo *album,
g_free (s);
}
g_free (group);
-
+
i++;
}
-
+
g_key_file_free (f);
-
+
return TRUE;
}
@@ -390,9 +394,9 @@ album_info_save_to_cache (AlbumInfo *album,
GError *error = NULL;
int i;
GList *scan;
-
+
f = g_key_file_new ();
-
+
if (album->title != NULL)
g_key_file_set_string (f, "Album", "Title", album->title);
if (album->artist != NULL)
@@ -404,7 +408,7 @@ album_info_save_to_cache (AlbumInfo *album,
g_key_file_set_string (f, "Album", "Asin", album->asin);
if (g_date_valid (album->release_date)) {
char s[64];
-
+
g_date_strftime (s, sizeof(s), "%d/%m/%Y", album->release_date);
g_key_file_set_string (f, "Album", "ReleaseDate", s);
}
@@ -413,24 +417,24 @@ album_info_save_to_cache (AlbumInfo *album,
for (scan = album->tracks; scan; scan = scan->next) {
TrackInfo *track = scan->data;
char *group;
-
+
group = g_strdup_printf ("Track %d", i);
g_key_file_set_string (f, group, "Title", track->title);
if (track->artist != NULL)
g_key_file_set_string (f, group, "Artist", track->artist);
g_free (group);
-
+
i++;
}
-
+
data = g_key_file_to_data (f, &length, &error);
if (data == NULL) {
debug (DEBUG_INFO, "%s\n", error->message);
g_clear_error (&error);
}
- else {
+ else {
char *path;
-
+
path = get_cache_path (album, disc_id);
if (path != NULL) {
char *dir;
@@ -448,7 +452,7 @@ album_info_save_to_cache (AlbumInfo *album,
}
g_free (data);
}
-
+
g_key_file_free (f);
}
diff --git a/src/dlg-properties.c b/src/dlg-properties.c
index de56ecd..7cf0d2a 100644
--- a/src/dlg-properties.c
+++ b/src/dlg-properties.c
@@ -44,7 +44,7 @@ typedef struct {
GooWindow *window;
GtkWidget *dialog;
GtkBuilder *builder;
- GtkListStore *list_store;
+ GtkListStore *list_store;
GtkTreeViewColumn *author_column;
GList *albums;
int n_albums, current_album;
@@ -67,37 +67,37 @@ set_album_from_data (DialogData *data)
AlbumInfo *album;
const char *album_artist;
GtkTreeIter iter;
-
+
album = album_info_copy (goo_window_get_album (data->window));
album_info_set_title (album, gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("title_entry"))));
album_artist = gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("artist_entry")));
album_info_set_artist (album, album_artist, "");
album->various_artist = gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("artist_combobox"))) == 1;
-
+
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("year_checkbutton")))) {
GDate *date;
-
+
date = g_date_new_dmy (1, 1, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("year_spinbutton"))));
album_info_set_release_date (album, date);
g_date_free (date);
}
else {
GDate *date;
-
+
date = g_date_new ();
album_info_set_release_date (album, date);
g_date_free (date);
}
-
+
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (data->list_store), &iter)) {
GList *scan = album->tracks;
TrackInfo *track;
char *title;
char *artist;
-
+
do {
track = scan->data;
- gtk_tree_model_get (GTK_TREE_MODEL (data->list_store),
+ gtk_tree_model_get (GTK_TREE_MODEL (data->list_store),
&iter,
TITLE_COLUMN, &title,
ARTIST_COLUMN, &artist,
@@ -108,16 +108,16 @@ set_album_from_data (DialogData *data)
track_info_set_artist (track, artist, "");
else
track_info_set_artist (track, album_artist, "");
-
+
g_free (title);
g_free (artist);
-
+
scan = scan->next;
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (data->list_store), &iter));
}
goo_player_set_album (goo_window_get_player (data->window), album);
-
+
album_info_unref (album);
}
@@ -144,9 +144,9 @@ set_data_from_album (DialogData *data,
AlbumInfo *album)
{
GList *scan;
-
+
gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("artist_combobox")), album->various_artist ? 1 : 0);
-
+
if (album->title != NULL)
gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("title_entry")), album->title);
if (album->artist != NULL)
@@ -154,7 +154,7 @@ set_data_from_album (DialogData *data,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("year_checkbutton")), g_date_valid (album->release_date));
if (g_date_valid (album->release_date))
gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("year_spinbutton")), g_date_get_year (album->release_date));
- else
+ else
gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("year_spinbutton")), 0);
gtk_list_store_clear (data->list_store);
@@ -178,38 +178,38 @@ show_album (DialogData *data,
int n)
{
char *s;
-
+
if ((n < 0) || (n >= data->n_albums))
return;
data->current_album = n;
-
+
gtk_widget_hide (GET_WIDGET ("info_box"));
gtk_widget_show (GET_WIDGET ("navigation_box"));
-
- s = g_strdup_printf (_("Album %d of %d"), data->current_album + 1, data->n_albums);
+
+ s = g_strdup_printf (_("Album %d of %d"), data->current_album + 1, data->n_albums);
gtk_label_set_text (GTK_LABEL (GET_WIDGET ("album_label")), s);
g_free (s);
-
+
set_data_from_album (data, g_list_nth (data->albums, n)->data);
}
static GList *
-remove_incompatible_albums (GList *albums,
+remove_incompatible_albums (GList *albums,
AlbumInfo *album)
{
GList *scan;
-
+
for (scan = albums; scan; /* nothing */) {
AlbumInfo *album2 = scan->data;
gboolean incompatible = FALSE;
-
+
if (album2->n_tracks != album->n_tracks)
incompatible = TRUE;
-
+
if (incompatible) {
GList *tmp = scan;
-
+
scan = scan->next;
albums = g_list_remove_link (albums, tmp);
album_info_unref (tmp->data);
@@ -218,49 +218,54 @@ remove_incompatible_albums (GList *albums,
else
scan = scan->next;
}
-
+
return albums;
}
static void
-search_cb (GtkWidget *widget,
+search_cb (GtkWidget *widget,
DialogData *data)
{
- musicbrainz_t mb;
- char *mb_args[2];
-
- mb = mb_New ();
- mb_UseUTF8 (mb, TRUE);
- mb_SetDepth (mb, 4);
- /*mb_SetMaxItems(mb, 10);*/
-
- mb_args[0] = (char*) gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("title_entry")));
- mb_args[1] = NULL;
- if (! mb_QueryWithArgs (mb, MBQ_FindAlbumByName, mb_args)) {
- char mb_error[1024];
- char *s;
-
- mb_GetQueryError (mb, mb_error, sizeof (mb_error));
- s = g_strdup_printf (_("Search failed: %s\n"), mb_error);
- gtk_label_set_text (GTK_LABEL (GET_WIDGET ("info_label")), s);
- g_free (s);
- }
- else {
- data->albums = get_album_list (mb);
- data->albums = remove_incompatible_albums (data->albums, goo_window_get_album (data->window));
- data->n_albums = g_list_length (data->albums);
-
- if (data->n_albums == 0) {
- gtk_label_set_text (GTK_LABEL (GET_WIDGET ("info_label")), _("No album found"));
- gtk_widget_show (GET_WIDGET ("info_box"));
- gtk_widget_hide (GET_WIDGET ("navigation_box"));
- }
- else
- show_album (data, 0);
+ MbReleaseFilter filter;
+ MbQuery query;
+ MbResultList list;
+
+ gtk_image_set_from_stock (GTK_IMAGE (GET_WIDGET ("info_icon")), GTK_STOCK_FIND, GTK_ICON_SIZE_BUTTON);
+ gtk_label_set_text (GTK_LABEL (GET_WIDGET ("info_label")), _("Searching disc info..."));
+ gtk_widget_show (GET_WIDGET ("info_box"));
+ gtk_widget_hide (GET_WIDGET ("navigation_box"));
+
+ /*
+ metadata_search_album_by_title (gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("title_entry"))),
+ data->cancellable,
+ G_CALLBACK (search_album_by_title_ready_cb),
+ data);
+ */
+
+ filter = mb_release_filter_new ();
+ mb_release_filter_title (filter, gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("title_entry"))));
+
+ query = mb_query_new (NULL, NULL);
+ list = mb_query_get_releases (query, filter);
+
+ data->albums = get_album_list (list);
+ get_track_info_for_album_list (data->albums);
+ data->albums = remove_incompatible_albums (data->albums, goo_window_get_album (data->window));
+ data->n_albums = g_list_length (data->albums);
+
+ if (data->n_albums == 0) {
+ gtk_image_set_from_stock (GTK_IMAGE (GET_WIDGET ("info_icon")), GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_BUTTON);
+ gtk_label_set_text (GTK_LABEL (GET_WIDGET ("info_label")), _("No album found"));
+ gtk_widget_show (GET_WIDGET ("info_box"));
+ gtk_widget_hide (GET_WIDGET ("navigation_box"));
}
+ else
+ show_album (data, 0);
- mb_Delete (mb);
+ mb_result_list_free (list);
+ mb_query_free (query);
+ mb_release_filter_free (filter);
}
@@ -271,11 +276,11 @@ title_cell_edited_cb (GtkCellRendererText *renderer,
gpointer user_data)
{
DialogData *data = user_data;
- GtkTreePath *t_path;
+ GtkTreePath *t_path;
GtkTreeIter iter;
-
+
t_path = gtk_tree_path_new_from_string (path);
- if (gtk_tree_model_get_iter (GTK_TREE_MODEL (data->list_store), &iter, t_path))
+ if (gtk_tree_model_get_iter (GTK_TREE_MODEL (data->list_store), &iter, t_path))
gtk_list_store_set (data->list_store, &iter,
TITLE_COLUMN, new_text,
-1);
@@ -290,11 +295,11 @@ artist_cell_edited_cb (GtkCellRendererText *renderer,
gpointer user_data)
{
DialogData *data = user_data;
- GtkTreePath *t_path;
+ GtkTreePath *t_path;
GtkTreeIter iter;
-
+
t_path = gtk_tree_path_new_from_string (path);
- if (gtk_tree_model_get_iter (GTK_TREE_MODEL (data->list_store), &iter, t_path))
+ if (gtk_tree_model_get_iter (GTK_TREE_MODEL (data->list_store), &iter, t_path))
gtk_list_store_set (data->list_store, &iter,
ARTIST_COLUMN, new_text,
-1);
@@ -329,70 +334,70 @@ add_columns (DialogData *data,
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
/* Title */
-
+
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (column, _("Title"));
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_resizable (column, TRUE);
gtk_tree_view_column_set_expand (column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, TITLE_COLUMN);
-
+
renderer = gtk_cell_renderer_text_new ();
-
+
g_value_init (&value, PANGO_TYPE_ELLIPSIZE_MODE);
g_value_set_enum (&value, PANGO_ELLIPSIZE_END);
g_object_set_property (G_OBJECT (renderer), "ellipsize", &value);
g_value_unset (&value);
-
+
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, TRUE);
g_object_set_property (G_OBJECT (renderer), "editable", &value);
g_value_unset (&value);
-
- g_signal_connect (G_OBJECT (renderer),
+
+ g_signal_connect (G_OBJECT (renderer),
"edited",
G_CALLBACK (title_cell_edited_cb),
data);
-
+
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_set_attributes (column, renderer,
"text", TITLE_COLUMN,
NULL);
-
+
gtk_tree_view_append_column (treeview, column);
/* Author */
-
+
data->author_column = column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (column, _("Artist"));
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_resizable (column, FALSE);
gtk_tree_view_column_set_expand (column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, ARTIST_COLUMN);
-
+
renderer = gtk_cell_renderer_text_new ();
-
+
g_value_init (&value, PANGO_TYPE_ELLIPSIZE_MODE);
g_value_set_enum (&value, PANGO_ELLIPSIZE_END);
g_object_set_property (G_OBJECT (renderer), "ellipsize", &value);
g_value_unset (&value);
-
+
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, TRUE);
g_object_set_property (G_OBJECT (renderer), "editable", &value);
g_value_unset (&value);
-
- g_signal_connect (G_OBJECT (renderer),
+
+ g_signal_connect (G_OBJECT (renderer),
"edited",
G_CALLBACK (artist_cell_edited_cb),
data);
-
+
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_set_attributes (column, renderer,
"text", ARTIST_COLUMN,
NULL);
-
- gtk_tree_view_append_column (treeview, column);
+
+ gtk_tree_view_append_column (treeview, column);
}
@@ -449,12 +454,12 @@ dlg_properties (GooWindow *window)
{
DialogData *data;
GtkWidget *image;
-
+
if (window->properties_dialog != NULL) {
gtk_window_present (GTK_WINDOW (window->properties_dialog));
return;
}
-
+
data = g_new0 (DialogData, 1);
data->window = window;
data->builder = _gtk_builder_new_from_file ("properties.ui", "");
@@ -465,14 +470,14 @@ dlg_properties (GooWindow *window)
window->properties_dialog = data->dialog;
/* Set widgets data. */
-
+
image = gtk_image_new_from_stock (GOO_STOCK_RESET, GTK_ICON_SIZE_BUTTON);
g_object_set (GET_WIDGET ("undo_button"),
"use_stock", TRUE,
"label", GOO_STOCK_RESET,
"image", image,
NULL);
-
+
data->list_store = gtk_list_store_new (N_COLUMNS,
G_TYPE_INT,
G_TYPE_STRING,
@@ -480,10 +485,10 @@ dlg_properties (GooWindow *window)
G_TYPE_POINTER);
gtk_tree_view_set_model (GTK_TREE_VIEW (GET_WIDGET ("track_treeview")), GTK_TREE_MODEL (data->list_store));
add_columns (data, GTK_TREE_VIEW (GET_WIDGET ("track_treeview")));
-
+
/* Set the signals handlers. */
- g_signal_connect (G_OBJECT (data->dialog),
+ g_signal_connect (G_OBJECT (data->dialog),
"destroy",
G_CALLBACK (dialog_destroy_cb),
data);
@@ -521,14 +526,14 @@ dlg_properties (GooWindow *window)
data);
g_signal_connect (GET_WIDGET ("year_checkbutton"),
"toggled",
- G_CALLBACK (year_checkbutton_toggled_cb),
+ G_CALLBACK (year_checkbutton_toggled_cb),
data);
-
+
/* run dialog. */
gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (window));
gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE);
gtk_widget_show (data->dialog);
-
+
set_data_from_album (data, goo_window_get_album (data->window));
}
diff --git a/src/goo-player.c b/src/goo-player.c
index 050d1d2..6de4a9a 100644
--- a/src/goo-player.c
+++ b/src/goo-player.c
@@ -25,8 +25,8 @@
#include <string.h>
#include <glib/gi18n.h>
#include <gst/gst.h>
-#include <musicbrainz/queries.h>
-#include <musicbrainz/mb_c.h>
+#include <discid/discid.h>
+#include <musicbrainz3/mb_c.h>
#include "goo-player.h"
#include "goo-marshal.h"
#include "glib-utils.h"
@@ -74,6 +74,7 @@ struct _GooPlayerPrivate {
gboolean exiting;
char *rdf;
+ GList *albums;
};
enum {
@@ -348,6 +349,7 @@ goo_player_init (GooPlayer *self)
self->priv->current_track_n = -1;
self->priv->volume_value = 1.0;
self->priv->update_progress_id = 0;
+ self->priv->albums = NULL;
}
@@ -457,6 +459,9 @@ goo_player_set_album (GooPlayer *self,
}
+#if 0
+
+
static void
set_cd_metadata_from_rdf (GooPlayer *self,
char *rdf)
@@ -552,12 +557,15 @@ read_cached_rdf (GooPlayer *self)
}
+#endif
+
+
static int
check_get_cd_metadata (gpointer data)
{
GooPlayer *player = data;
gboolean done, exiting;
- char *rdf;
+ GList *albums;
/* Remove the check. */
@@ -587,15 +595,20 @@ check_get_cd_metadata (gpointer data)
/**/
g_mutex_lock (player->priv->yes_or_no);
- rdf = player->priv->rdf;
- player->priv->rdf = NULL;
+ albums = player->priv->albums;
+ player->priv->albums = NULL;
g_mutex_unlock (player->priv->yes_or_no);
- if (rdf != NULL) {
- set_cd_metadata_from_rdf (player, rdf);
- save_rdf_to_cache (player, rdf);
+ if (albums != NULL) {
+ AlbumInfo *first_album = albums->data;
+
+ /* FIXME: ask the user which album to use if the query
+ * returned more than one album. */
+
+ goo_player_set_album (player, first_album);
album_info_save_to_cache (player->priv->album, player->priv->discid);
- g_free (rdf);
+
+ album_list_free (albums);
}
return FALSE;
@@ -605,27 +618,28 @@ check_get_cd_metadata (gpointer data)
static void *
get_cd_metadata (void *thread_data)
{
- GooPlayer *player = thread_data;
- musicbrainz_t mb;
- char *rdf = NULL;
+ GooPlayer *player = thread_data;
+ MbReleaseFilter filter;
+ MbQuery query;
+ MbResultList list;
- mb = mb_New ();
- mb_UseUTF8 (mb, TRUE);
- if (mb_Query (mb, MBQ_GetCDInfo)) {
- int rdf_len;
+ filter = mb_release_filter_new ();
+ mb_release_filter_disc_id (filter, player->priv->discid);
+ mb_release_filter_limit (filter, 1);
- rdf_len = mb_GetResultRDFLen (mb);
- rdf = g_malloc (rdf_len + 1);
- mb_GetResultRDF (mb, rdf, rdf_len);
- }
- mb_Delete (mb);
+ query = mb_query_new (NULL, NULL);
+ list = mb_query_get_releases (query, filter);
g_mutex_lock (player->priv->yes_or_no);
- g_free (player->priv->rdf);
- player->priv->rdf = rdf;
+ album_list_free (player->priv->albums);
+ player->priv->albums = get_album_list (list);
player->priv->thread = NULL;
g_mutex_unlock (player->priv->yes_or_no);
+ mb_result_list_free (list);
+ mb_query_free (query);
+ mb_release_filter_free (filter);
+
g_thread_exit (NULL);
return NULL;
@@ -638,7 +652,6 @@ check_get_cd_tracks (gpointer data)
GooPlayer *player = data;
gboolean done;
gboolean exiting;
- char *rdf;
/* Remove the check. */
@@ -681,12 +694,12 @@ check_get_cd_tracks (gpointer data)
return FALSE;
}
- rdf = read_cached_rdf (player);
- if (rdf != NULL) {
- set_cd_metadata_from_rdf (player, rdf);
- g_free (rdf);
- return FALSE;
- }
+ /*
+ metadata_get_album_info_from_disc_id (player->priv->discid,
+ data->cancellable,
+ G_CALLBACK (album_info_from_disc_id_ready_cb),
+ data);
+ */
g_mutex_lock (player->priv->yes_or_no);
player->priv->thread = g_thread_create (get_cd_metadata, player, FALSE, NULL);
@@ -701,9 +714,9 @@ check_get_cd_tracks (gpointer data)
static void *
get_cd_tracks (void *thread_data)
{
- GooPlayer *player = thread_data;
- GList *tracks = NULL;
- musicbrainz_t mb;
+ GooPlayer *player = thread_data;
+ GList *tracks = NULL;
+ DiscId *disc;
if (player->priv->pipeline != NULL)
gst_element_set_state (player->priv->pipeline, GST_STATE_PAUSED);
@@ -711,35 +724,35 @@ get_cd_tracks (void *thread_data)
g_free (player->priv->discid);
player->priv->discid = NULL;
- mb = mb_New ();
- mb_UseUTF8 (mb, TRUE);
- mb_SetDevice (mb, (char *) goo_player_get_device (player));
- if (mb_Query (mb, MBQ_GetCDTOC)) {
- char data[256];
- int n_tracks, i;
+ disc = discid_new ();
+ if (discid_read (disc, goo_player_get_device (player))) {
+ int first_track;
+ int last_track;
+ int i;
- mb_GetResultData(mb, MBE_TOCGetCDIndexId, data, sizeof (data));
- player->priv->discid = g_strdup (data);
+ player->priv->discid = g_strdup (discid_get_id (disc));
debug (DEBUG_INFO, "==> [MB] DISC ID: %s\n", player->priv->discid);
- debug (DEBUG_INFO, "==> [MB] FIRST TRACK: %d\n", mb_GetResultInt (mb, MBE_TOCGetFirstTrack));
+ first_track = discid_get_first_track_num (disc);
+ debug (DEBUG_INFO, "==> [MB] FIRST TRACK: %d\n", first_track);
- n_tracks = mb_GetResultInt (mb, MBE_TOCGetLastTrack);
- debug (DEBUG_INFO, "==> [MB] LAST TRACK: %d\n", n_tracks);
+ last_track = discid_get_last_track_num (disc);
+ debug (DEBUG_INFO, "==> [MB] LAST TRACK: %d\n", last_track);
- for (i = 0; i < n_tracks; i++) {
+ for (i = first_track; i <= last_track; i++) {
gint64 from_sector;
gint64 n_sectors;
- from_sector = mb_GetResultInt1 (mb, MBE_TOCGetTrackSectorOffset, i + 2);
- n_sectors = mb_GetResultInt1 (mb, MBE_TOCGetTrackNumSectors, i + 2);
+ from_sector = discid_get_track_offset (disc, i);
+ n_sectors = discid_get_track_length (disc, i);
debug (DEBUG_INFO, "==> [MB] Track %d: [%"G_GINT64_FORMAT", %"G_GINT64_FORMAT"]\n", i, from_sector, from_sector + n_sectors);
- tracks = g_list_prepend (tracks, track_info_new (i, from_sector, from_sector + n_sectors));
+ tracks = g_list_prepend (tracks, track_info_new (i - first_track, from_sector, from_sector + n_sectors));
}
}
- mb_Delete (mb);
+
+ discid_free (disc);
tracks = g_list_reverse (tracks);
album_info_set_tracks (player->priv->album, tracks);
@@ -822,6 +835,13 @@ goo_player_list (GooPlayer *player)
goo_player_set_is_busy (player, TRUE);
create_pipeline (player);
+ /* FIXME
+ metadata_read_cd_info_from_device (goo_player_get_device (player),
+ data->cancellable,
+ G_CALLBACK (cd_info_from_device_ready_cb),
+ data);
+ */
+
g_mutex_lock (player->priv->yes_or_no);
player->priv->thread = g_thread_create (get_cd_tracks, player, FALSE, NULL);
g_mutex_unlock (player->priv->yes_or_no);
diff --git a/src/metadata.c b/src/metadata.c
index d5289e7..47d0f5d 100644
--- a/src/metadata.c
+++ b/src/metadata.c
@@ -22,124 +22,163 @@
#include <config.h>
#include <stdio.h>
-#include <musicbrainz/queries.h>
-#include <musicbrainz/mb_c.h>
+#include <string.h>
+#include <musicbrainz3/mb_c.h>
#include "glib-utils.h"
#include "metadata.h"
#include "album-info.h"
-static AlbumInfo*
-get_album_info (musicbrainz_t mb,
- int n_album)
+static TrackInfo *
+get_track_info (MbTrack mb_track,
+ int n_track)
+{
+ TrackInfo *track;
+ char data[1024];
+ char data2[1024];
+ MbArtist mb_artist;
+
+ track = track_info_new (n_track, 0, 0);
+
+ mb_track_get_title (mb_track, data, 1024);
+ track_info_set_title (track, data);
+
+ debug (DEBUG_INFO, "==> [MB] TRACK %d: %s\n", n_track, data);
+
+ mb_artist = mb_track_get_artist (mb_track);
+ if (mb_artist != NULL) {
+ mb_artist_get_unique_name (mb_artist, data, 1024);
+ mb_artist_get_id (mb_artist, data2, 1024);
+ track_info_set_artist (track, data, data2);
+ }
+
+ return track;
+}
+
+
+static AlbumInfo *
+get_album_info (MbRelease release)
{
AlbumInfo *album;
char data[1024];
- int n_track, n_tracks;
- GList *tracks = NULL;
-
- /*mb_Select (mb, MBS_Rewind);*/
- if (! mb_Select1 (mb, MBS_SelectAlbum, n_album))
- return NULL;
+ int i;
+ MbArtist artist;
+ char data2[1024];
+ GList *tracks = NULL;
+ int n_tracks;
album = album_info_new ();
-
- if (mb_GetResultData (mb, MBE_AlbumGetAlbumId, data, sizeof (data))) {
- char data2[1024];
- mb_GetIDFromURL (mb, data, data2, sizeof (data2));
- debug (DEBUG_INFO, "==> [MB] ALBUM_ID: %s (%s)\n", data, data2);
- album_info_set_id (album, data2);
- }
- else
- return album;
-
- if (mb_GetResultData (mb, MBE_AlbumGetAlbumName, data, sizeof (data))) {
- album_info_set_title (album, data);
- debug (DEBUG_INFO, "==> [MB] ALBUM NAME: %s\n", data);
- }
-
- if (mb_GetResultData (mb, MBE_AlbumGetAmazonAsin, data, sizeof (data))) {
- album_info_set_asin (album, data);
- debug (DEBUG_INFO, "==> [MB] ASIN: %s\n", data);
- }
-
- if (mb_GetResultInt (mb, MBE_AlbumGetNumReleaseDates) >= 1) {
- int y = 0, m = 0, d = 0;
-
- mb_Select1 (mb, MBS_SelectReleaseDate, 1);
-
- mb_GetResultData (mb, MBE_ReleaseGetDate, data, sizeof (data));
+
+ mb_release_get_id (release, data, 1024);
+ debug (DEBUG_INFO, "==> [MB] ALBUM_ID: %s\n", data);
+ album_info_set_id (album, strrchr (data, '/') + 1);
+
+ mb_release_get_title (release, data, 1024);
+ debug (DEBUG_INFO, "==> [MB] ALBUM NAME: %s\n", data);
+ album_info_set_title (album, data);
+
+ mb_release_get_asin (release, data, 1024);
+ debug (DEBUG_INFO, "==> [MB] ASIN: %s\n", data);
+ album_info_set_asin (album, data);
+
+ for (i = 0; i < mb_release_get_num_release_events (release); i++) {
+ MbReleaseEvent event;
+ int y = 0, m = 0, d = 0;
+
+ event = mb_release_get_release_event (release, i);
+ mb_release_event_get_date (event, data, 1024);
debug (DEBUG_INFO, "==> [MB] RELEASE DATE: %s\n", data);
if (sscanf (data, "%d-%d-%d", &y, &m, &d) > 0) {
GDate *date;
-
+
date = g_date_new_dmy ((d > 0) ? d : 1, (m > 0) ? m : 1, (y > 0) ? y : 1);
album_info_set_release_date (album, date);
g_date_free (date);
}
-
- mb_GetResultData (mb, MBE_ReleaseGetCountry, data, sizeof (data));
- debug (DEBUG_INFO, "==> [MB] RELEASE COUNTRY: %s\n", data);
-
- mb_Select (mb, MBS_Back);
- }
-
- if (mb_GetResultData (mb, MBE_AlbumGetAlbumArtistName, data, sizeof (data))) {
- char data2[1024], data3[1024];
-
- mb_GetResultData (mb, MBE_AlbumGetArtistId, data2, sizeof (data2));
- mb_GetIDFromURL (mb, data2, data3, sizeof (data3));
-
- debug (DEBUG_INFO, "==> [MB] ARTIST_ID: %s (%s)\n", data2, data3);
-
- album_info_set_artist (album, data, data3);
}
-
+
+ artist = mb_release_get_artist (release);
+ mb_artist_get_unique_name (artist, data, 1024);
+ mb_artist_get_id (artist, data2, 1024);
+ album_info_set_artist (album, data, data2);
+
tracks = NULL;
- n_tracks = mb_GetResultInt (mb, MBE_AlbumGetNumTracks);
+ n_tracks = mb_release_get_num_tracks (release);
debug (DEBUG_INFO, "==> [MB] N TRACKS: %d\n", n_tracks);
- for (n_track = 1; n_track <= n_tracks; n_track++) {
+ for (i = 0; i < n_tracks; i++) {
+ MbTrack mb_track;
TrackInfo *track;
-
- track = track_info_new (n_track - 1, 0, 0);
+
+ mb_track = mb_release_get_track (release, i);
+ track = get_track_info (mb_track, i);
+ if (album->artist == NULL)
+ album_info_set_artist (album, track->artist, KEEP_PREVIOUS_VALUE);
tracks = g_list_prepend (tracks, track);
-
- if (mb_GetResultData1 (mb, MBE_AlbumGetTrackName, data, sizeof (data), n_track))
- track_info_set_title (track, data);
-
- debug (DEBUG_INFO, "==> [MB] TRACK %d: %s\n", n_track, data);
-
- if (mb_GetResultData1 (mb, MBE_AlbumGetArtistName, data, sizeof (data), n_track)) {
- char data2[1024], data3[1024];
-
- mb_GetResultData1 (mb, MBE_AlbumGetArtistId, data2, sizeof (data2), n_track);
- mb_GetIDFromURL (mb, data2, data3, sizeof (data3));
- track_info_set_artist (track, data, data3);
-
- if (album->artist == NULL)
- album_info_set_artist (album, data, KEEP_PREVIOUS_VALUE);
- }
}
- mb_Select (mb, MBS_Back);
-
+
tracks = g_list_reverse (tracks);
album_info_set_tracks (album, tracks);
-
+
return album;
}
-GList*
-get_album_list (musicbrainz_t mb)
+GList *
+get_album_list (MbResultList list)
{
GList *albums = NULL;
- int n_albums, i;
-
- n_albums = mb_GetResultInt (mb, MBE_GetNumAlbums);
+ int n_albums;
+ int i;
+
+ n_albums = mb_result_list_get_size (list);
g_print ("[MB] Num Albums: %d\n", n_albums);
-
- for (i = 1; i <= n_albums; i++)
- albums = g_list_prepend (albums, get_album_info (mb, i));
-
+
+ for (i = 0; i < n_albums; i++) {
+ MbRelease release;
+
+ release = mb_result_list_get_release (list, i);
+ albums = g_list_prepend (albums, get_album_info (release));
+ }
+
return g_list_reverse (albums);
}
+
+
+void
+get_track_info_for_album_list (GList *albums)
+{
+ GList *scan;
+
+ for (scan = albums; scan; scan = scan->next) {
+ AlbumInfo *album = scan->data;
+ MbTrackFilter filter;
+ GList *tracks;
+ MbQuery query;
+ MbResultList list;
+ int i;
+
+ filter = mb_track_filter_new ();
+ mb_track_filter_release_id (filter, album->id);
+ query = mb_query_new (NULL, NULL);
+ list = mb_query_get_tracks (query, filter);
+
+ tracks = NULL;
+ for (i = 0; i < mb_result_list_get_size (list); i++) {
+ MbTrack mb_track;
+ TrackInfo *track;
+
+ mb_track = mb_result_list_get_track (list, i);
+ track = get_track_info (mb_track, i);
+ if ((album->artist == NULL) && (track->artist != NULL))
+ album_info_set_artist (album, track->artist, KEEP_PREVIOUS_VALUE);
+ tracks = g_list_prepend (tracks, track);
+ }
+
+ tracks = g_list_reverse (tracks);
+ album_info_set_tracks (album, tracks);
+
+ mb_result_list_free (list);
+ mb_query_free (query);
+ mb_track_filter_free (filter);
+ }
+}
diff --git a/src/metadata.h b/src/metadata.h
index 725de33..45526aa 100644
--- a/src/metadata.h
+++ b/src/metadata.h
@@ -24,8 +24,9 @@
#define METADATA_H
#include <glib.h>
-#include <musicbrainz/mb_c.h>
+#include <musicbrainz3/mb_c.h>
-GList* get_album_list (musicbrainz_t mb);
+GList * get_album_list (MbResultList list);
+void get_track_info_for_album_list (GList *albums);
#endif /* METADATA_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]