[sound-juicer/pwood/wip/fuzzy-toc-matching: 1/5] Add support for multiple parameters in musicbrainz queries



commit 41014e4f0b1092880f31c116c918fd263adb1767
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Sun Jun 25 11:21:09 2017 +0100

    Add support for multiple parameters in musicbrainz queries
    
    This allows us to pass more than just an inc parameter when querying
    musicbrainz, which is needed to do fuzzy toc matching.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788425

 libjuicer/sj-metadata-musicbrainz5.c | 49 +++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 15 deletions(-)
---
diff --git a/libjuicer/sj-metadata-musicbrainz5.c b/libjuicer/sj-metadata-musicbrainz5.c
index b8bc68fa..ae152b8c 100644
--- a/libjuicer/sj-metadata-musicbrainz5.c
+++ b/libjuicer/sj-metadata-musicbrainz5.c
@@ -210,15 +210,16 @@ print_musicbrainz_query_error (SjMetadataMusicbrainz5 *self,
 static gint64 last_query_time;
 
 static Mb5Metadata
-query_musicbrainz (SjMetadataMusicbrainz5  *self,
-                   const char              *entity,
-                   const char              *id,
-                   const char              *includes,
-                   GCancellable            *cancellable,
-                   GError                 **error)
+query_musicbrainz_full (SjMetadataMusicbrainz5  *self,
+                        const char              *entity,
+                        const char              *id,
+                        int                      param_count,
+                        char                   **param_names,
+                        char                   **param_values,
+                        GCancellable            *cancellable,
+                        GError                 **error)
 {
   Mb5Metadata metadata;
-  char *inc, *includes_copy;
   gint64 delay = 4 * G_USEC_PER_SEC;
   int count = 0;
   SjMetadataMusicbrainz5Private *priv = GET_PRIVATE (self);
@@ -226,9 +227,6 @@ query_musicbrainz (SjMetadataMusicbrainz5  *self,
 
   g_info ("Querying %s %s", entity, id);
 
-  inc = g_strdup ("inc");
-  includes_copy = g_strdup (includes);
-
   while (TRUE) {
     if (g_cancellable_set_error_if_cancelled (cancellable, error))
       return NULL;
@@ -239,12 +237,8 @@ query_musicbrainz (SjMetadataMusicbrainz5  *self,
       t = g_get_monotonic_time ();
     }
 
-    if (includes == NULL)
-      metadata = mb5_query_query (priv->mb, entity, id, "",
-                                  0, NULL, NULL);
-    else
       metadata = mb5_query_query (priv->mb, entity, id, "",
-                                  1, &inc, &includes_copy);
+                                  param_count, param_names, param_values);
 
     if (metadata != NULL || ++count == 5 ||
         mb5_query_get_lasthttpcode (priv->mb) != 503)
@@ -264,6 +258,31 @@ query_musicbrainz (SjMetadataMusicbrainz5  *self,
     print_musicbrainz_query_error (self, entity, id);
 
   last_query_time = g_get_monotonic_time ();
+  return metadata;
+}
+
+static Mb5Metadata
+query_musicbrainz (SjMetadataMusicbrainz5  *self,
+                   const char              *entity,
+                   const char              *id,
+                   const char              *includes,
+                   GCancellable            *cancellable,
+                   GError                 **error)
+{
+  Mb5Metadata metadata;
+  char *inc, *includes_copy;
+
+  inc = g_strdup ("inc");
+  includes_copy = g_strdup (includes);
+
+  if (includes == NULL)
+    metadata = query_musicbrainz_full (self, entity, id,
+                                       0, NULL, NULL,
+                                       cancellable, error);
+  else
+    metadata = query_musicbrainz_full (self, entity, id,
+                                       1, &inc, &includes_copy,
+                                       cancellable, error);
   g_free (inc);
   g_free (includes_copy);
   return metadata;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]