[gnome-music/songeditor-tracker3: 15/32] grilowrappers: Introduce support for acoustid source
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/songeditor-tracker3: 15/32] grilowrappers: Introduce support for acoustid source
- Date: Mon, 25 May 2020 18:33:37 +0000 (UTC)
commit 569be65c9a3ae1d77adebe6a373c3c11ce09eccf
Author: Sumaid Syed <sumaidsyed gmail com>
Date: Sat Nov 23 13:43:12 2019 +0100
grilowrappers: Introduce support for acoustid source
This source enables song authentication based on its fingerprint. It
needs grilo-plugin 0.3.11 or above to support all the metadata keys.
Based on patches by Jean Felder and Marinus Schraal.
gnomemusic/coregrilo.py | 11 ++++
gnomemusic/grilowrappers/grlacoustidwrapper.py | 88 ++++++++++++++++++++++++++
meson.build | 2 +-
3 files changed, 100 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 85133e15..62ce07a7 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -28,6 +28,7 @@ import gi
gi.require_version('Grl', '0.3')
from gi.repository import Grl, GLib, GObject
+from gnomemusic.grilowrappers.grlacoustidwrapper import GrlAcoustIDWrapper
from gnomemusic.grilowrappers.grlchromaprintwrapper import (
GrlChromaprintWrapper)
from gnomemusic.grilowrappers.grlsearchwrapper import GrlSearchWrapper
@@ -50,6 +51,7 @@ class CoreGrilo(GObject.GObject):
"grl-lastfm-cover:2,"
"grl-theaudiodb-cover:1")
+ _acoustid_api_key = "Nb8SVVtH1C"
_theaudiodb_api_key = "195003"
cover_sources = GObject.Property(type=bool, default=False)
@@ -89,6 +91,10 @@ class CoreGrilo(GObject.GObject):
config.set_api_key(self._theaudiodb_api_key)
self._registry.add_config(config)
+ config = Grl.Config.new("grl-lua-factory", "grl-acoustid")
+ config.set_api_key(self._acoustid_api_key)
+ self._registry.add_config(config)
+
self._registry.connect('source-added', self._on_source_added)
self._registry.connect('source-removed', self._on_source_removed)
@@ -181,6 +187,11 @@ class CoreGrilo(GObject.GObject):
wrapper = GrlChromaprintWrapper(source, self._application)
self._mb_wrappers[source.props.source_id] = wrapper
self._log.debug("Adding wrapper {}".format(wrapper))
+ elif (source.props.source_id == "grl-acoustid"
+ and source.props.source_id not in self._mb_wrappers.keys()):
+ wrapper = GrlAcoustIDWrapper(source, self._application)
+ self._mb_wrappers[source.props.source_id] = wrapper
+ self._log.debug("Adding wrapper {}".format(wrapper))
def _on_source_removed(self, registry, source):
# FIXME: Handle removing sources.
diff --git a/gnomemusic/grilowrappers/grlacoustidwrapper.py b/gnomemusic/grilowrappers/grlacoustidwrapper.py
new file mode 100644
index 00000000..4cb8f97a
--- /dev/null
+++ b/gnomemusic/grilowrappers/grlacoustidwrapper.py
@@ -0,0 +1,88 @@
+# Copyright 2020 The GNOME Music developers
+#
+# GNOME Music is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# GNOME Music is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with GNOME Music; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# The GNOME Music authors hereby grant permission for non-GPL compatible
+# GStreamer plugins to be used and distributed together with GStreamer
+# and GNOME Music. This permission is above and beyond the permissions
+# granted by the GPL license by which GNOME Music is covered. If you
+# modify this code, you may extend this exception to your version of the
+# code, but you are not obligated to do so. If you do not wish to do so,
+# delete this exception statement from your version.
+
+import gi
+gi.require_version("Grl", "0.3")
+from gi.repository import Grl, GObject
+
+
+class GrlAcoustIDWrapper(GObject.GObject):
+ """Wrapper for the Grilo AcoustID source.
+ """
+
+ _ACOUSTID_METADATA_KEYS = [
+ Grl.METADATA_KEY_ALBUM,
+ Grl.METADATA_KEY_ALBUM_ARTIST,
+ Grl.METADATA_KEY_ALBUM_DISC_NUMBER,
+ Grl.METADATA_KEY_ARTIST,
+ Grl.METADATA_KEY_CREATION_DATE,
+ Grl.METADATA_KEY_MB_ARTIST_ID,
+ Grl.METADATA_KEY_MB_RECORDING_ID,
+ Grl.METADATA_KEY_MB_RELEASE_GROUP_ID,
+ Grl.METADATA_KEY_MB_RELEASE_ID,
+ Grl.METADATA_KEY_MB_TRACK_ID,
+ Grl.METADATA_KEY_TITLE,
+ Grl.METADATA_KEY_TRACK_NUMBER
+ ]
+
+ def __init__(self, source, application):
+ """Initialize the AcoustID wrapper
+
+ :param Grl.TrackerSource source: The Tracker source to wrap
+ :param Application application: Application object
+ """
+ super().__init__()
+
+ self._source = source
+ self._log = application.props.log
+
+ coregrilo = application.props.coregrilo
+ registry = coregrilo.props.registry
+ self._fingerprint_key = registry.lookup_metadata_key("chromaprint")
+
+ def get_tags(self, coresong, callback):
+ """Retrieve Musicbrainz tag set for the given song
+
+ :param CoreSong coresong: The song to retrieve tags for
+ :param callback: Metadata retrieval callback
+ """
+ options = Grl.OperationOptions()
+ options.set_resolution_flags(Grl.ResolutionFlags.NORMAL)
+
+ query = "duration={}&fingerprint={}".format(
+ str(coresong.props.media.get_duration()),
+ coresong.props.media.get_string(self._fingerprint_key))
+
+ def _acoustid_resolved(source, op_id, media, count, callback, error):
+ if error:
+ self._log.warning(
+ "Error {}: {}".format(error.domain, error.message))
+ callback(None, 0)
+ return
+
+ callback(media, count)
+
+ self._source.query(
+ query, self._ACOUSTID_METADATA_KEYS, options, _acoustid_resolved,
+ callback)
diff --git a/meson.build b/meson.build
index 67193757..f946f8b0 100644
--- a/meson.build
+++ b/meson.build
@@ -47,7 +47,7 @@ dependency('pango', version: '>= 1.44.0')
dependency('pygobject-3.0', version: '>= 3.36.1')
dependency('py3cairo', version: '>= 1.14.0')
dependency('grilo-0.3', version: '>= 0.3.12', fallback: ['grilo', 'libgrl_dep'])
-dependency('grilo-plugins-0.3', version: '>= 0.3.10', fallback: ['grilo-plugins', 'grilo_plugins_dep'])
+dependency('grilo-plugins-0.3', version: '>= 0.3.11', fallback: ['grilo-plugins', 'grilo_plugins_dep'])
subproject('libgd',
default_options: [
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]