[grilo-plugins/wip/jfelder/acoustid-duplicates] grl-acoustid: Do not return the same recording multiple times



commit 6cdd96177ea27b3302e6d7061e257cc53474e530
Author: Jean Felder <jfelder src gnome org>
Date:   Fri May 22 22:07:50 2020 +0200

    grl-acoustid: Do not return the same recording multiple times
    
    An AcoustID lookup operation can return multiple results. Each of
    these results can contain multiple MusicBrainz recordings. However, a
    result can contain recordings that are also part of an other result.
    
    As a grilo query operation returns each of these recordings, it means
    that the same recording can be returned multiple times. In other
    words, a query operation can return duplicates.
    
    Fix the issue by storing the recordings that have already been
    found and checking that a result does not contain recordings that have
    already been returned.

 src/lua-factory/sources/grl-acoustid.lua      | 10 ++++++++--
 tests/lua-factory/sources/test_lua_acoustid.c |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/src/lua-factory/sources/grl-acoustid.lua b/src/lua-factory/sources/grl-acoustid.lua
index 36200833..0f3bfffa 100644
--- a/src/lua-factory/sources/grl-acoustid.lua
+++ b/src/lua-factory/sources/grl-acoustid.lua
@@ -99,12 +99,15 @@ end
 
 function get_count(results)
   local count = 0
+  local recordings_found = {}
 
   if results and #results > 0 then
     for _,result in ipairs(results) do
       if result.recordings and #result.recordings > 0 then
         for _,recording in ipairs(result.recordings) do
-          if recording.releasegroups ~= nil then
+          if recording.releasegroups ~= nil and
+             not recordings_found[recording.id] then
+           recordings_found[recording.id] = true
             count = count + #recording.releasegroups
           end
         end
@@ -150,6 +153,7 @@ end
 
 function lookup_cb_query (feed)
   local count
+  local recordings_found = {}
   if not feed then
     grl.callback()
     return
@@ -171,7 +175,9 @@ function lookup_cb_query (feed)
       #result.recordings > 0 then
       for _, recording in ipairs(result.recordings) do
         if recording.releasegroups and
-          #recording.releasegroups > 0 then
+            #recording.releasegroups > 0 and
+           not recordings_found[recording.id] then
+         recordings_found[recording.id] = true
           for _, releasegroup in ipairs(recording.releasegroups) do
             count = count - 1
             media = build_media (recording, releasegroup)
diff --git a/tests/lua-factory/sources/test_lua_acoustid.c b/tests/lua-factory/sources/test_lua_acoustid.c
index 263e0056..bafde834 100644
--- a/tests/lua-factory/sources/test_lua_acoustid.c
+++ b/tests/lua-factory/sources/test_lua_acoustid.c
@@ -82,7 +82,7 @@ test_query_by_fingerprint (void)
                                    options,
                                    &error);
   g_assert_no_error (error);
-  g_assert_cmpint (g_list_length (results), ==, 12);
+  g_assert_cmpint (g_list_length (results), ==, 8);
 
   media = GRL_MEDIA (results->data);
   g_assert_cmpstr (grl_media_get_title (media), ==, "Primavera");


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