~attente/rhythmbox/rhythmbox

« back to all changes in this revision

Viewing changes to debian/patches/00git_musicbrainz5.patch

  • Committer: Jeremy Bicha
  • Date: 2012-11-07 01:52:30 UTC
  • Revision ID: jbicha@ubuntu.com-20121107015230-trp2j7b9udunr9ep
* New upstream release (LP: #1060601)
* debian/control.in:
  - Bump minimum glib, gtk, totem-plparser, clutter, and clutter-gst
  - Drop no longer needed musicbrainz dependency
* Refreshed 09_keywords.patch
* Updated 11_fix_cd_pausing.patch with fix from git
* Dropped patches applied in new version:
  - 00git_musicbrainz5.patch
  - 08_CVE-2012-3355.patch
  - dont_free_consumed_floating_gvariant.patch
  - git_scale_click.patch
  - git_crash_during_monitor.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From 33074fa366a502e9b2106e44754c8ae9e9d4881b Mon Sep 17 00:00:00 2001
2
 
From: Robert Ancell <robert.ancell@canonical.com>
3
 
Date: Thu, 7 Jun 2012 15:18:32 +1200
4
 
Subject: [PATCH] audiocd: Add support for musicbrainz5
5
 
 
6
 
---
7
 
 configure.ac                               |   17 +-
8
 
 plugins/audiocd/Makefile.am                |    8 +
9
 
 plugins/audiocd/sj-metadata-getter.c       |    6 +
10
 
 plugins/audiocd/sj-metadata-musicbrainz5.c |  619 ++++++++++++++++++++++++++++
11
 
 plugins/audiocd/sj-metadata-musicbrainz5.h |   56 +++
12
 
 5 files changed, 703 insertions(+), 3 deletions(-)
13
 
 create mode 100644 plugins/audiocd/sj-metadata-musicbrainz5.c
14
 
 create mode 100644 plugins/audiocd/sj-metadata-musicbrainz5.h
15
 
 
16
 
diff --git a/configure.ac b/configure.ac
17
 
index 33efca8..c68c629 100644
18
 
--- a/configure.ac
19
 
+++ b/configure.ac
20
 
@@ -51,6 +51,7 @@ GLIB_REQS=2.28.0
21
 
 LIBGPOD_REQS=0.6
22
 
 MUSICBRAINZ3_REQS=3.0.2
23
 
 MUSICBRAINZ4_REQS=4.0.0
24
 
+MUSICBRAINZ5_REQS=5.0.0
25
 
 TOTEM_PLPARSER_REQS=2.32.1
26
 
 VALA_REQS=0.9.4
27
 
 AVAHI_REQS=0.6
28
 
@@ -355,10 +356,14 @@ if test x"$enable_musicbrainz" != "xno"; then
29
 
        AC_SUBST(MUSICBRAINZ3_CFLAGS)
30
 
        AC_SUBST(MUSICBRAINZ3_LIBS)
31
 
 
32
 
-       PKG_CHECK_MODULES(MUSICBRAINZ4, libmusicbrainz4 >= $MUSICBRAINZ4_REQS gconf-2.0, [have_musicbrainz4=yes], [have_musicbrainz4=no])
33
 
+       PKG_CHECK_MODULES(MUSICBRAINZ4, libmusicbrainz4 >= $MUSICBRAINZ4_REQS libdiscid gconf-2.0, [have_musicbrainz4=yes], [have_musicbrainz4=no])
34
 
        AC_SUBST(MUSICBRAINZ4_CFLAGS)
35
 
        AC_SUBST(MUSICBRAINZ4_LIBS)
36
 
 
37
 
+       PKG_CHECK_MODULES(MUSICBRAINZ5, libmusicbrainz5 >= $MUSICBRAINZ5_REQS libdiscid gconf-2.0, [have_musicbrainz5=yes], [have_musicbrainz5=no])
38
 
+       AC_SUBST(MUSICBRAINZ5_CFLAGS)
39
 
+       AC_SUBST(MUSICBRAINZ5_LIBS)
40
 
+
41
 
        if test x"$have_musicbrainz3" = xyes; then
42
 
                oldlibs=$LIBS
43
 
                LIBS="$LIBS $MUSICBRAINZ3_LIBS"
44
 
@@ -374,16 +379,22 @@ if test x"$enable_musicbrainz" != "xno"; then
45
 
                have_sj_metadata_getter=yes
46
 
        fi
47
 
 
48
 
+       if test x"$have_musicbrainz5" = xyes; then
49
 
+               AC_DEFINE([HAVE_MUSICBRAINZ5], 1, [Whether libmusicbrainz5 is available])
50
 
+               have_sj_metadata_getter=yes
51
 
+       fi
52
 
+
53
 
        if test x"$have_sj_metadata_getter" = xyes; then
54
 
                AC_DEFINE([HAVE_SJ_METADATA_GETTER], 1, [Whether to use the sound-juicer metadata getter code])
55
 
        else
56
 
                if test x"$enable_musicbrainz" = xyes; then
57
 
-                       AC_MSG_ERROR([MusicBrainz requested, but neither libmusicbrainz3 nor libmusicbrainz4 are available])
58
 
+                       AC_MSG_ERROR([MusicBrainz requested, but neither libmusicbrainz3, libmusicbrainz4 nor libmusicbrainz5 are available])
59
 
                fi
60
 
        fi
61
 
 fi
62
 
 AM_CONDITIONAL([HAVE_MUSICBRAINZ3], [test "x$have_musicbrainz3" = "xyes"])
63
 
 AM_CONDITIONAL([HAVE_MUSICBRAINZ4], [test "x$have_musicbrainz4" = "xyes"])
64
 
+AM_CONDITIONAL([HAVE_MUSICBRAINZ5], [test "x$have_musicbrainz5" = "xyes"])
65
 
 AM_CONDITIONAL([HAVE_SJ_METADATA_GETTER], [test "x$have_sj_metadata_getter" = "xyes"])
66
 
 
67
 
 AC_PATH_XTRA
68
 
@@ -900,7 +911,7 @@ else
69
 
        AC_MSG_NOTICE([** Multimedia keys support is enabled])
70
 
 fi
71
 
 
72
 
-if test x"$have_musicbrainz3" = "xyes"; then
73
 
+if test x"$have_sj_metadata_getter" = "xyes"; then
74
 
        AC_MSG_NOTICE([** MusicBrainz support is enabled])
75
 
 else
76
 
        AC_MSG_NOTICE([   MusicBrainz support is disabled])
77
 
diff --git a/plugins/audiocd/Makefile.am b/plugins/audiocd/Makefile.am
78
 
index e757d2d..473b9d6 100644
79
 
--- a/plugins/audiocd/Makefile.am
80
 
+++ b/plugins/audiocd/Makefile.am
81
 
@@ -50,6 +50,10 @@ if HAVE_MUSICBRAINZ4
82
 
 libaudiocd_la_LIBADD +=$(MUSICBRAINZ4_LIBS)
83
 
 INCLUDES += $(MUSICBRAINZ4_CFLAGS)
84
 
 endif
85
 
+if HAVE_MUSICBRAINZ5
86
 
+libaudiocd_la_LIBADD +=$(MUSICBRAINZ5_LIBS)
87
 
+INCLUDES += $(MUSICBRAINZ5_CFLAGS)
88
 
+endif
89
 
 
90
 
 libaudiocd_la_LIBADD += $(NULL)
91
 
 
92
 
@@ -77,6 +81,7 @@ SJ_FILES =                                                                    \
93
 
        sj-metadata-getter.c sj-metadata-getter.h                               \
94
 
        sj-metadata-musicbrainz3.c sj-metadata-musicbrainz3.h                   \
95
 
        sj-metadata-musicbrainz4.c sj-metadata-musicbrainz4.h                   \
96
 
+       sj-metadata-musicbrainz5.c sj-metadata-musicbrainz5.h                   \
97
 
        sj-structures.c sj-structures.h                                         \
98
 
        sj-metadata-marshal.list
99
 
 
100
 
@@ -101,6 +106,9 @@ endif
101
 
 if HAVE_MUSICBRAINZ4
102
 
 libaudiocd_la_SOURCES += sj-metadata-musicbrainz4.c sj-metadata-musicbrainz4.h
103
 
 endif
104
 
+if HAVE_MUSICBRAINZ5
105
 
+libaudiocd_la_SOURCES += sj-metadata-musicbrainz5.c sj-metadata-musicbrainz5.h
106
 
+endif
107
 
 
108
 
 MARSHALFILES += sj-metadata-marshal.h sj-metadata-marshal.c
109
 
 
110
 
diff --git a/plugins/audiocd/sj-metadata-getter.c b/plugins/audiocd/sj-metadata-getter.c
111
 
index cfc447d..80b4b0b 100644
112
 
--- a/plugins/audiocd/sj-metadata-getter.c
113
 
+++ b/plugins/audiocd/sj-metadata-getter.c
114
 
@@ -26,6 +26,9 @@
115
 
 #include "sj-metadata-getter.h"
116
 
 #include "sj-metadata-marshal.h"
117
 
 #include "sj-metadata.h"
118
 
+#ifdef HAVE_MUSICBRAINZ5
119
 
+#include "sj-metadata-musicbrainz5.h"
120
 
+#endif /* HAVE_MUSICBRAINZ5 */
121
 
 #ifdef HAVE_MUSICBRAINZ4
122
 
 #include "sj-metadata-musicbrainz4.h"
123
 
 #endif /* HAVE_MUSICBRAINZ4 */
124
 
@@ -178,6 +181,9 @@ lookup_cd (SjMetadataGetter *mdg)
125
 
   GError *error = NULL;
126
 
   gboolean found = FALSE;
127
 
   GType types[] = {
128
 
+#ifdef HAVE_MUSICBRAINZ5
129
 
+    SJ_TYPE_METADATA_MUSICBRAINZ5,
130
 
+#endif /* HAVE_MUSICBRAINZ5 */
131
 
 #ifdef HAVE_MUSICBRAINZ4
132
 
     SJ_TYPE_METADATA_MUSICBRAINZ4,
133
 
 #endif /* HAVE_MUSICBRAINZ4 */
134
 
diff --git a/plugins/audiocd/sj-metadata-musicbrainz5.c b/plugins/audiocd/sj-metadata-musicbrainz5.c
135
 
new file mode 100644
136
 
index 0000000..ab1fec7
137
 
--- /dev/null
138
 
+++ b/plugins/audiocd/sj-metadata-musicbrainz5.c
139
 
@@ -0,0 +1,619 @@
140
 
+/*
141
 
+ * sj-metadata-musicbrainz5.c
142
 
+ * Copyright (C) 2008 Ross Burton <ross@burtonini.com>
143
 
+ * Copyright (C) 2008 Bastien Nocera <hadess@hadess.net>
144
 
+ * Copyright (C) 2011 Christophe Fergeau <cfergeau@redhat.com>
145
 
+ * Copyright (C) 2012 Robert Ancell <robert.ancell@canonical.com>
146
 
+ *
147
 
+ * This library is free software; you can redistribute it and/or
148
 
+ * modify it under the terms of the GNU Library General Public
149
 
+ * License as published by the Free Software Foundation; either
150
 
+ * version 2 of the License, or (at your option) any later version.
151
 
+ *
152
 
+ * This library is distributed in the hope that it will be useful,
153
 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
154
 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
155
 
+ * Library General Public License for more details.
156
 
+ *
157
 
+ * You should have received a copy of the GNU Library General Public
158
 
+ * License along with this library; if not, write to the
159
 
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
160
 
+ * Boston, MA 02111-1307, USA.
161
 
+ */
162
 
+
163
 
+#ifdef HAVE_CONFIG_H
164
 
+#include "config.h"
165
 
+#endif /* HAVE_CONFIG_H */
166
 
+
167
 
+#include <string.h>
168
 
+#include <stdlib.h>
169
 
+#include <glib.h>
170
 
+#include <glib-object.h>
171
 
+#include <gconf/gconf-client.h>
172
 
+#include <discid/discid.h>
173
 
+#include <musicbrainz5/mb5_c.h>
174
 
+
175
 
+#include "sj-metadata-musicbrainz5.h"
176
 
+#include "sj-structures.h"
177
 
+#include "sj-error.h"
178
 
+
179
 
+#define GET(field, function, obj) {                                            \
180
 
+       function (obj, buffer, sizeof (buffer));                                \
181
 
+       if (field)                                                              \
182
 
+               g_free (field);                                                 \
183
 
+       if (*buffer == '\0')                                                    \
184
 
+               field = NULL;                                                   \
185
 
+       else                                                                    \
186
 
+               field = g_strdup (buffer);                                      \
187
 
+}
188
 
+
189
 
+#define GCONF_MUSICBRAINZ_SERVER "/apps/sound-juicer/musicbrainz_server"
190
 
+#define GCONF_PROXY_USE_PROXY "/system/http_proxy/use_http_proxy"
191
 
+#define GCONF_PROXY_HOST "/system/http_proxy/host"
192
 
+#define GCONF_PROXY_PORT "/system/http_proxy/port"
193
 
+#define GCONF_PROXY_USE_AUTHENTICATION "/system/http_proxy/use_authentication"
194
 
+#define GCONF_PROXY_USERNAME "/system/http_proxy/authentication_user"
195
 
+#define GCONF_PROXY_PASSWORD "/system/http_proxy/authentication_password"
196
 
+#define SJ_MUSICBRAINZ_USER_AGENT "libjuicer-"VERSION
197
 
+
198
 
+typedef struct {
199
 
+  Mb5Query mb;
200
 
+  DiscId *disc;
201
 
+  char *cdrom;
202
 
+  /* Proxy */
203
 
+  char *http_proxy;
204
 
+  int http_proxy_port;
205
 
+} SjMetadataMusicbrainz5Private;
206
 
+
207
 
+#define GET_PRIVATE(o)  \
208
 
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), SJ_TYPE_METADATA_MUSICBRAINZ5, SjMetadataMusicbrainz5Private))
209
 
+
210
 
+enum {
211
 
+  PROP_0,
212
 
+  PROP_DEVICE,
213
 
+  PROP_USE_PROXY,
214
 
+  PROP_PROXY_HOST,
215
 
+  PROP_PROXY_PORT,
216
 
+};
217
 
+
218
 
+static void metadata_interface_init (gpointer g_iface, gpointer iface_data);
219
 
+
220
 
+G_DEFINE_TYPE_WITH_CODE (SjMetadataMusicbrainz5,
221
 
+                         sj_metadata_musicbrainz5,
222
 
+                         G_TYPE_OBJECT,
223
 
+                         G_IMPLEMENT_INTERFACE (SJ_TYPE_METADATA,
224
 
+                                                metadata_interface_init));
225
 
+
226
 
+
227
 
+/*
228
 
+ * Private methods
229
 
+ */
230
 
+#ifdef DUMP_DETAILS
231
 
+static void
232
 
+sj_mb5_album_details_dump (AlbumDetails *details)
233
 
+{
234
 
+  if (details->country)
235
 
+    g_print ("Country: %s\n", details->country);
236
 
+  if (details->type)
237
 
+    g_print ("Type: %s\n", details->type);
238
 
+  if (details->lyrics_url)
239
 
+    g_print ("Lyrics URL: %s\n", details->lyrics_url);
240
 
+}
241
 
+#else
242
 
+#define sj_mb5_album_details_dump(...)
243
 
+#endif
244
 
+
245
 
+static GList *
246
 
+get_artist_list (Mb5ArtistCredit credit)
247
 
+{
248
 
+  Mb5NameCreditList name_list;
249
 
+  GList *artists;
250
 
+  unsigned int i;
251
 
+  char buffer[512]; /* for the GET macro */
252
 
+
253
 
+  if (credit == NULL)
254
 
+    return NULL;
255
 
+
256
 
+  name_list = mb5_artistcredit_get_namecreditlist (credit);
257
 
+  if (name_list == NULL) {
258
 
+    return NULL;
259
 
+  }
260
 
+
261
 
+  artists = NULL;
262
 
+  for (i = 0; i < mb5_namecredit_list_size (name_list); i++) {
263
 
+    Mb5NameCredit name_credit;
264
 
+    Mb5Artist artist;
265
 
+    ArtistDetails *details;
266
 
+
267
 
+    name_credit = mb5_namecredit_list_item (name_list, i);
268
 
+    details = g_new0 (ArtistDetails, 1);
269
 
+    GET (details->joinphrase, mb5_namecredit_get_joinphrase, name_credit);
270
 
+    artists = g_list_prepend (artists, details);
271
 
+    artist = mb5_namecredit_get_artist (name_credit);
272
 
+    if (!artist) {
273
 
+      g_warning ("no Mb5Artist associated with Mb5NameCredit, falling back to Mb5NameCredit::name");
274
 
+      GET (details->name, mb5_namecredit_get_name, name_credit);
275
 
+      continue;
276
 
+    }
277
 
+
278
 
+    GET (details->id, mb5_artist_get_id, artist);
279
 
+    GET (details->name, mb5_artist_get_name, artist);
280
 
+    GET (details->sortname, mb5_artist_get_sortname, artist);
281
 
+    GET (details->disambiguation, mb5_artist_get_disambiguation, artist);
282
 
+    GET (details->gender, mb5_artist_get_gender, artist);
283
 
+    GET (details->country, mb5_artist_get_country, artist);
284
 
+  }
285
 
+
286
 
+  return g_list_reverse(artists);
287
 
+}
288
 
+
289
 
+static void
290
 
+get_artist_info (GList *artists, char **name, char **sortname, char **id)
291
 
+{
292
 
+  GString *artist_name;
293
 
+  GList *it;
294
 
+  unsigned int artist_count;
295
 
+
296
 
+  artist_name = g_string_new (NULL);
297
 
+  artist_count = 0;
298
 
+  for (it = artists; it != NULL; it = it->next) {
299
 
+    ArtistDetails *details = (ArtistDetails *)it->data;
300
 
+    artist_count++;
301
 
+    g_string_append (artist_name, details->name);
302
 
+    if (details->joinphrase != NULL)
303
 
+      g_string_append (artist_name, details->joinphrase);
304
 
+  }
305
 
+
306
 
+  if (artist_count != 1) {
307
 
+      g_warning ("multiple artists");
308
 
+      if (sortname != NULL)
309
 
+        *sortname = NULL;
310
 
+      if (id != NULL)
311
 
+        *id = NULL;
312
 
+  } else {
313
 
+      ArtistDetails *details = (ArtistDetails *)artists->data;
314
 
+      if (sortname != NULL)
315
 
+        *sortname = g_strdup (details->sortname);
316
 
+      if (id != NULL)
317
 
+        *id = g_strdup (details->id);
318
 
+  }
319
 
+
320
 
+  if (name != NULL)
321
 
+    *name = artist_name->str;
322
 
+
323
 
+  g_string_free (artist_name, FALSE);
324
 
+}
325
 
+
326
 
+
327
 
+static void
328
 
+fill_relations (Mb5RelationListList relations, AlbumDetails *album)
329
 
+{
330
 
+  unsigned int i, j;
331
 
+
332
 
+  for (i = 0; i < mb5_relationlist_list_size (relations); i++) {
333
 
+    Mb5RelationList list = mb5_relationlist_list_item (relations, i);
334
 
+    for (j = 0; j < mb5_relation_list_size (list); j++) {
335
 
+      Mb5Relation relation;
336
 
+      char buffer[512]; /* for the GET() macro */
337
 
+      char *type = NULL;
338
 
+
339
 
+      relation = mb5_relation_list_item (list, j);
340
 
+      if (relation == NULL)
341
 
+        continue;
342
 
+
343
 
+      GET (type, mb5_relation_get_type, relation);
344
 
+      if (type == NULL) {
345
 
+        continue;
346
 
+      }
347
 
+      if (g_str_equal (type, "wikipedia")) {
348
 
+        char *wikipedia = NULL;
349
 
+        GET (wikipedia, mb5_relation_get_target, relation);
350
 
+        if (wikipedia != NULL) {
351
 
+            g_free (album->wikipedia);
352
 
+            album->wikipedia = wikipedia;
353
 
+        }
354
 
+      } else if (g_str_equal (type, "discogs")) {
355
 
+        char *discogs = NULL;
356
 
+        GET (discogs, mb5_relation_get_target, relation);
357
 
+        if (discogs != NULL) {
358
 
+            g_free (album->discogs);
359
 
+            album->discogs = discogs;
360
 
+        }
361
 
+      } else if (g_str_equal (type, "lyrics")) {
362
 
+        char *lyrics = NULL;
363
 
+        GET (lyrics, mb5_relation_get_target, relation);
364
 
+        if (lyrics != NULL) {
365
 
+            g_free (album->lyrics_url);
366
 
+            album->lyrics_url = lyrics;
367
 
+        }
368
 
+      }
369
 
+      g_free (type);
370
 
+    }
371
 
+  }
372
 
+}
373
 
+
374
 
+static void
375
 
+fill_tracks_from_medium (Mb5Medium medium, AlbumDetails *album)
376
 
+{
377
 
+  Mb5TrackList track_list;
378
 
+  GList *tracks;
379
 
+  unsigned int i;
380
 
+  char buffer[512]; /* for the GET() macro */
381
 
+
382
 
+  track_list = mb5_medium_get_tracklist (medium);
383
 
+  if (!track_list)
384
 
+    return;
385
 
+
386
 
+  album->number = mb5_track_list_size (track_list);
387
 
+
388
 
+  tracks = NULL;
389
 
+
390
 
+  for (i = 0; i < mb5_track_list_size (track_list); i++) {
391
 
+    Mb5Track mbt;
392
 
+    Mb5ArtistCredit credit;
393
 
+    Mb5Recording recording;
394
 
+    TrackDetails *track;
395
 
+
396
 
+    mbt = mb5_track_list_item (track_list, i);
397
 
+    if (!mbt)
398
 
+      continue;
399
 
+
400
 
+    track = g_new0 (TrackDetails, 1);
401
 
+
402
 
+    track->album = album;
403
 
+
404
 
+    track->number = mb5_track_get_position (mbt);
405
 
+    recording = mb5_track_get_recording (mbt);
406
 
+    if (recording != NULL) {
407
 
+      GET (track->title, mb5_recording_get_title, recording);
408
 
+      GET (track->track_id, mb5_recording_get_id, recording);
409
 
+      track->duration = mb5_recording_get_length (recording) / 1000;
410
 
+      credit = mb5_recording_get_artistcredit (recording);
411
 
+    } else {
412
 
+      GET (track->title, mb5_track_get_title, mbt);
413
 
+      track->duration = mb5_track_get_length (mbt) / 1000;
414
 
+      credit = mb5_track_get_artistcredit (mbt);
415
 
+    }
416
 
+
417
 
+    if (credit) {
418
 
+      GList *artists;
419
 
+      artists = get_artist_list (credit);
420
 
+      if (artists) {
421
 
+        get_artist_info (artists, &track->artist,
422
 
+                         &track->artist_sortname,
423
 
+                         &track->artist_id);
424
 
+      }
425
 
+      track->artists = artists;
426
 
+    }
427
 
+    if (track->artist == NULL)
428
 
+      track->artist = g_strdup (album->artist);
429
 
+    if (track->artist_sortname == NULL)
430
 
+      track->artist_sortname = g_strdup (album->artist_sortname);
431
 
+    if (track->artist_id == NULL)
432
 
+      track->artist_id = g_strdup (album->artist_id);
433
 
+
434
 
+    tracks = g_list_prepend (tracks, track);
435
 
+  }
436
 
+  album->tracks = g_list_reverse (tracks);
437
 
+}
438
 
+
439
 
+static AlbumDetails *
440
 
+make_album_from_release (Mb5ReleaseGroup group,
441
 
+                         Mb5Release release,
442
 
+                         Mb5Medium medium)
443
 
+{
444
 
+  AlbumDetails *album;
445
 
+  Mb5ArtistCredit credit;
446
 
+  GList *artists;
447
 
+  char *date = NULL;
448
 
+  char buffer[512]; /* for the GET macro */
449
 
+
450
 
+  g_assert (release);
451
 
+  g_return_val_if_fail (medium != NULL, NULL);
452
 
+
453
 
+  album = g_new0 (AlbumDetails, 1);
454
 
+
455
 
+  GET (album->album_id, mb5_release_get_id, release);
456
 
+  GET (album->title, mb5_medium_get_title, medium);
457
 
+  if (album->title == NULL)
458
 
+    GET (album->title, mb5_release_get_title, release);
459
 
+
460
 
+  credit = mb5_release_get_artistcredit (release);
461
 
+
462
 
+  artists = get_artist_list (credit);
463
 
+  if (artists) {
464
 
+    get_artist_info (artists, &album->artist,
465
 
+                     &album->artist_sortname,
466
 
+                     &album->artist_id);
467
 
+  }
468
 
+  album->artists = artists;
469
 
+
470
 
+  GET (date, mb5_release_get_date, release);
471
 
+  album->release_date = sj_metadata_helper_scan_date (date);
472
 
+  g_free (date);
473
 
+
474
 
+  GET (album->asin, mb5_release_get_asin, release);
475
 
+  GET (album->country, mb5_release_get_country, release);
476
 
+  if (group) {
477
 
+    GET (album->type, mb5_releasegroup_get_primarytype, group);
478
 
+    if (g_str_has_suffix (album->type, "Spokenword")
479
 
+        || g_str_has_suffix (album->type, "Interview")
480
 
+        || g_str_has_suffix (album->type, "Audiobook")) {
481
 
+      album->is_spoken_word = TRUE;
482
 
+    }
483
 
+    fill_relations (mb5_releasegroup_get_relationlistlist(group), album);
484
 
+  }
485
 
+
486
 
+  album->disc_number = mb5_medium_get_position (medium);
487
 
+  fill_tracks_from_medium (medium, album);
488
 
+  fill_relations (mb5_release_get_relationlistlist (release), album);
489
 
+
490
 
+  sj_mb5_album_details_dump (album);
491
 
+  return album;
492
 
+}
493
 
+
494
 
+/*
495
 
+ * Virtual methods
496
 
+ */
497
 
+static GList *
498
 
+mb5_list_albums (SjMetadata *metadata, char **url, GError **error)
499
 
+{
500
 
+  SjMetadataMusicbrainz5Private *priv;
501
 
+  GList *albums = NULL;
502
 
+  Mb5ReleaseList releases;
503
 
+  Mb5Release release;
504
 
+  const char *discid = NULL;
505
 
+  char buffer[1025];
506
 
+  int i;
507
 
+  g_return_val_if_fail (SJ_IS_METADATA_MUSICBRAINZ5 (metadata), NULL);
508
 
+
509
 
+  priv = GET_PRIVATE (metadata);
510
 
+
511
 
+  if (sj_metadata_helper_check_media (priv->cdrom, error) == FALSE) {
512
 
+    return NULL;
513
 
+  }
514
 
+
515
 
+  priv->disc = discid_new ();
516
 
+  if (priv->disc == NULL)
517
 
+    return NULL;
518
 
+  if (discid_read (priv->disc, priv->cdrom) == 0)
519
 
+    return NULL;
520
 
+
521
 
+  if (url != NULL)
522
 
+    *url = g_strdup (discid_get_submission_url (priv->disc));
523
 
+
524
 
+  if (g_getenv("MUSICBRAINZ_FORCE_DISC_ID")) {
525
 
+    discid = g_getenv("MUSICBRAINZ_FORCE_DISC_ID");
526
 
+  } else {
527
 
+    discid = discid_get_id (priv->disc);
528
 
+  }
529
 
+
530
 
+  releases = mb5_query_lookup_discid(priv->mb, discid);
531
 
+
532
 
+  if (releases == NULL) {
533
 
+    return NULL;
534
 
+  }
535
 
+
536
 
+  if (mb5_release_list_size (releases) == 0) {
537
 
+    return NULL;
538
 
+  }
539
 
+
540
 
+  for (i = 0; i < mb5_release_list_size (releases); i++) {
541
 
+    AlbumDetails *album;
542
 
+
543
 
+    release = mb5_release_list_item (releases, i);
544
 
+    if (release) {
545
 
+      char *releaseid = NULL;
546
 
+      Mb5Release full_release;
547
 
+
548
 
+      releaseid = NULL;
549
 
+      GET(releaseid, mb5_release_get_id, release);
550
 
+
551
 
+      full_release = mb5_query_lookup_release (priv->mb, releaseid);
552
 
+      g_free (releaseid);
553
 
+      if (full_release) {
554
 
+        Mb5MediumList media;
555
 
+        Mb5Metadata metadata = NULL;
556
 
+        Mb5ReleaseGroup group;
557
 
+        unsigned int j;
558
 
+
559
 
+        group = mb5_release_get_releasegroup (full_release);
560
 
+        if (group) {
561
 
+          /* The release-group information we can extract from the
562
 
+           * lookup_release query doesn't have the url relations for the
563
 
+           * release-group, so run a separate query to get these urls
564
 
+           */
565
 
+          char *releasegroupid = NULL;
566
 
+          char *params_names[] = { "inc" };
567
 
+          char *params_values[] = { "artists url-rels" };
568
 
+
569
 
+          GET (releasegroupid, mb5_releasegroup_get_id, group);
570
 
+          metadata = mb5_query_query (priv->mb, "release-group", releasegroupid, "",
571
 
+                                      1, params_names, params_values);
572
 
+          g_free (releasegroupid);
573
 
+        }
574
 
+
575
 
+        if (metadata && mb5_metadata_get_releasegroup (metadata))
576
 
+          group = mb5_metadata_get_releasegroup (metadata);
577
 
+
578
 
+        media = mb5_release_media_matching_discid (full_release, discid);
579
 
+        for (j = 0; j < mb5_medium_list_size (media); j++) {
580
 
+          Mb5Medium medium;
581
 
+          medium = mb5_medium_list_item (media, j);
582
 
+          if (medium) {
583
 
+            album = make_album_from_release (group, full_release, medium);
584
 
+            album->metadata_source = SOURCE_MUSICBRAINZ;
585
 
+            albums = g_list_append (albums, album);
586
 
+          }
587
 
+        }
588
 
+        mb5_metadata_delete (metadata);
589
 
+        mb5_medium_list_delete (media);
590
 
+        mb5_release_delete (full_release);
591
 
+      }
592
 
+    }
593
 
+  }
594
 
+  mb5_release_list_delete (releases);
595
 
+  return albums;
596
 
+}
597
 
+
598
 
+/*
599
 
+ * GObject methods
600
 
+ */
601
 
+
602
 
+static void
603
 
+metadata_interface_init (gpointer g_iface, gpointer iface_data)
604
 
+{
605
 
+  SjMetadataClass *klass = (SjMetadataClass*)g_iface;
606
 
+
607
 
+  klass->list_albums = mb5_list_albums;
608
 
+}
609
 
+
610
 
+static void
611
 
+sj_metadata_musicbrainz5_init (SjMetadataMusicbrainz5 *self)
612
 
+{
613
 
+  GConfClient *gconf_client;
614
 
+  gchar *server_name;
615
 
+
616
 
+  SjMetadataMusicbrainz5Private *priv;
617
 
+
618
 
+  priv = GET_PRIVATE (self);
619
 
+
620
 
+  gconf_client = gconf_client_get_default ();
621
 
+
622
 
+  server_name = gconf_client_get_string (gconf_client, GCONF_MUSICBRAINZ_SERVER, NULL);
623
 
+
624
 
+  if (server_name && (*server_name == '\0')) {
625
 
+    g_free (server_name);
626
 
+    server_name = NULL;
627
 
+  }
628
 
+
629
 
+  priv->mb = mb5_query_new (SJ_MUSICBRAINZ_USER_AGENT, server_name, 0);
630
 
+  g_free (server_name);
631
 
+
632
 
+
633
 
+  /* Set the HTTP proxy */
634
 
+  if (gconf_client_get_bool (gconf_client, GCONF_PROXY_USE_PROXY, NULL)) {
635
 
+    char *proxy_host;
636
 
+    int port;
637
 
+
638
 
+    proxy_host = gconf_client_get_string (gconf_client, GCONF_PROXY_HOST, NULL);
639
 
+    mb5_query_set_proxyhost (priv->mb, proxy_host);
640
 
+    g_free (proxy_host);
641
 
+
642
 
+    port = gconf_client_get_int (gconf_client, GCONF_PROXY_PORT, NULL);
643
 
+    mb5_query_set_proxyport (priv->mb, port);
644
 
+
645
 
+    if (gconf_client_get_bool (gconf_client, GCONF_PROXY_USE_AUTHENTICATION, NULL)) {
646
 
+      char *username, *password;
647
 
+
648
 
+      username = gconf_client_get_string (gconf_client, GCONF_PROXY_USERNAME, NULL);
649
 
+      mb5_query_set_proxyusername (priv->mb, username);
650
 
+      g_free (username);
651
 
+
652
 
+      password = gconf_client_get_string (gconf_client, GCONF_PROXY_PASSWORD, NULL);
653
 
+      mb5_query_set_proxypassword (priv->mb, password);
654
 
+      g_free (password);
655
 
+    }
656
 
+  }
657
 
+
658
 
+  g_object_unref (gconf_client);
659
 
+}
660
 
+
661
 
+static void
662
 
+sj_metadata_musicbrainz5_get_property (GObject *object, guint property_id,
663
 
+                                       GValue *value, GParamSpec *pspec)
664
 
+{
665
 
+  SjMetadataMusicbrainz5Private *priv = GET_PRIVATE (object);
666
 
+  g_assert (priv);
667
 
+
668
 
+  switch (property_id) {
669
 
+  case PROP_DEVICE:
670
 
+    g_value_set_string (value, priv->cdrom);
671
 
+    break;
672
 
+  case PROP_PROXY_HOST:
673
 
+    g_value_set_string (value, priv->http_proxy);
674
 
+    break;
675
 
+  case PROP_PROXY_PORT:
676
 
+    g_value_set_int (value, priv->http_proxy_port);
677
 
+    break;
678
 
+  default:
679
 
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
680
 
+  }
681
 
+}
682
 
+
683
 
+static void
684
 
+sj_metadata_musicbrainz5_set_property (GObject *object, guint property_id,
685
 
+                                       const GValue *value, GParamSpec *pspec)
686
 
+{
687
 
+  SjMetadataMusicbrainz5Private *priv = GET_PRIVATE (object);
688
 
+  g_assert (priv);
689
 
+
690
 
+  switch (property_id) {
691
 
+  case PROP_DEVICE:
692
 
+    if (priv->cdrom)
693
 
+      g_free (priv->cdrom);
694
 
+    priv->cdrom = g_value_dup_string (value);
695
 
+    break;
696
 
+  case PROP_PROXY_HOST:
697
 
+    if (priv->http_proxy) {
698
 
+      g_free (priv->http_proxy);
699
 
+    }
700
 
+    priv->http_proxy = g_value_dup_string (value);
701
 
+    /* TODO: check this unsets the proxy if NULL, or should we pass "" ? */
702
 
+    mb5_query_set_proxyhost (priv->mb, priv->http_proxy);
703
 
+    break;
704
 
+  case PROP_PROXY_PORT:
705
 
+    priv->http_proxy_port = g_value_get_int (value);
706
 
+    mb5_query_set_proxyport (priv->mb, priv->http_proxy_port);
707
 
+    break;
708
 
+  default:
709
 
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
710
 
+  }
711
 
+}
712
 
+
713
 
+static void
714
 
+sj_metadata_musicbrainz5_finalize (GObject *object)
715
 
+{
716
 
+  SjMetadataMusicbrainz5Private *priv;
717
 
+
718
 
+  priv = GET_PRIVATE (object);
719
 
+
720
 
+  if (priv->mb != NULL) {
721
 
+    mb5_query_delete (priv->mb);
722
 
+    priv->mb = NULL;
723
 
+  }
724
 
+  if (priv->disc != NULL) {
725
 
+      discid_free (priv->disc);
726
 
+      priv->disc = NULL;
727
 
+  }
728
 
+  g_free (priv->cdrom);
729
 
+
730
 
+  G_OBJECT_CLASS (sj_metadata_musicbrainz5_parent_class)->finalize (object);
731
 
+}
732
 
+
733
 
+static void
734
 
+sj_metadata_musicbrainz5_class_init (SjMetadataMusicbrainz5Class *class)
735
 
+{
736
 
+  GObjectClass *object_class = (GObjectClass*)class;
737
 
+
738
 
+  g_type_class_add_private (class, sizeof (SjMetadataMusicbrainz5Private));
739
 
+
740
 
+  object_class->get_property = sj_metadata_musicbrainz5_get_property;
741
 
+  object_class->set_property = sj_metadata_musicbrainz5_set_property;
742
 
+  object_class->finalize = sj_metadata_musicbrainz5_finalize;
743
 
+
744
 
+  g_object_class_override_property (object_class, PROP_DEVICE, "device");
745
 
+  g_object_class_override_property (object_class, PROP_PROXY_HOST, "proxy-host");
746
 
+  g_object_class_override_property (object_class, PROP_PROXY_PORT, "proxy-port");
747
 
+}
748
 
+
749
 
+
750
 
+/*
751
 
+ * Public methods.
752
 
+ */
753
 
+
754
 
+GObject *
755
 
+sj_metadata_musicbrainz5_new (void)
756
 
+{
757
 
+  return g_object_new (SJ_TYPE_METADATA_MUSICBRAINZ5, NULL);
758
 
+}
759
 
diff --git a/plugins/audiocd/sj-metadata-musicbrainz5.h b/plugins/audiocd/sj-metadata-musicbrainz5.h
760
 
new file mode 100644
761
 
index 0000000..3cd4c42
762
 
--- /dev/null
763
 
+++ b/plugins/audiocd/sj-metadata-musicbrainz5.h
764
 
@@ -0,0 +1,56 @@
765
 
+/*
766
 
+ * sj-metadata-musicbrainz5.h
767
 
+ * Copyright (C) 2008 Ross Burton <ross@burtonini.com>
768
 
+ * Copyright (C) 2008 Bastien Nocera <hadess@hadess.net>
769
 
+ *
770
 
+ * This library is free software; you can redistribute it and/or
771
 
+ * modify it under the terms of the GNU Library General Public
772
 
+ * License as published by the Free Software Foundation; either
773
 
+ * version 2 of the License, or (at your option) any later version.
774
 
+ *
775
 
+ * This library is distributed in the hope that it will be useful,
776
 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
777
 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
778
 
+ * Library General Public License for more details.
779
 
+ *
780
 
+ * You should have received a copy of the GNU Library General Public
781
 
+ * License along with this library; if not, write to the
782
 
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
783
 
+ * Boston, MA 02111-1307, USA.
784
 
+ */
785
 
+
786
 
+#ifndef SJ_METADATA_MUSICBRAINZ5_H
787
 
+#define SJ_METADATA_MUSICBRAINZ5_H
788
 
+
789
 
+#include <glib-object.h>
790
 
+#include "sj-metadata.h"
791
 
+
792
 
+G_BEGIN_DECLS
793
 
+
794
 
+#define SJ_TYPE_METADATA_MUSICBRAINZ5           (sj_metadata_musicbrainz5_get_type ())
795
 
+#define SJ_METADATA_MUSICBRAINZ5(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), SJ_TYPE_METADATA_MUSICBRAINZ5, SjMetadataMusicbrainz5))
796
 
+#define SJ_METADATA_MUSICBRAINZ5_CLASS(vtable)  (G_TYPE_CHECK_CLASS_CAST ((vtable), SJ_TYPE_METADATA_MUSICBRAINZ5, SjMetadataMusicbrainz5Class))
797
 
+#define SJ_IS_METADATA_MUSICBRAINZ5(obj)        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SJ_TYPE_METADATA_MUSICBRAINZ5))
798
 
+#define SJ_IS_METADATA_MUSICBRAINZ5_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), SJ_TYPE_METADATA_MUSICBRAINZ5))
799
 
+#define SJ_METADATA_MUSICBRAINZ5_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SJ_TYPE_METADATA_MUSICBRAINZ5, SjMetadataMusicbrainz5Class))
800
 
+
801
 
+typedef struct _SjMetadataMusicbrainz5 SjMetadataMusicbrainz5;
802
 
+typedef struct _SjMetadataMusicbrainz5Class SjMetadataMusicbrainz5Class;
803
 
+
804
 
+struct _SjMetadataMusicbrainz5
805
 
+{
806
 
+  GObject parent;
807
 
+};
808
 
+
809
 
+struct _SjMetadataMusicbrainz5Class
810
 
+{
811
 
+  GObjectClass parent;
812
 
+};
813
 
+
814
 
+GType sj_metadata_musicbrainz5_get_type (void);
815
 
+
816
 
+GObject *sj_metadata_musicbrainz5_new (void);
817
 
+
818
 
+G_END_DECLS
819
 
+
820
 
+#endif /* SJ_METADATA_MUSICBRAINZ5_H */
821
 
1.7.10
822