[gnome-music/wip/jfelder/songeditor-gtk4: 65/76] coresong: Add support to query musicbrainz tags
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/songeditor-gtk4: 65/76] coresong: Add support to query musicbrainz tags
- Date: Wed, 23 Feb 2022 20:36:45 +0000 (UTC)
commit 120f0f2d34c1b5efc0175ba50ac46537857b9d72
Author: Sumaid Syed <sumaidsyed gmail com>
Date: Sat Nov 23 14:53:17 2019 +0100
coresong: Add support to query musicbrainz tags
The following framework is used:
1. Compute the chromaprint (a fingerprint) of the song with the
chromaprint source
2. Use the chromaprint to identify the song with the acoustid source
gnomemusic/coregrilo.py | 33 +++++++++++++++++++++++++++++++++
gnomemusic/coresong.py | 15 +++++++++++++++
2 files changed, 48 insertions(+)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 82c9cc550..27e25cab8 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -22,7 +22,9 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
+from __future__ import annotations
from typing import Callable, Dict, Optional
+import typing
import weakref
import gi
@@ -35,6 +37,8 @@ from gnomemusic.grilowrappers.grlchromaprintwrapper import (
from gnomemusic.grilowrappers.grlsearchwrapper import GrlSearchWrapper
from gnomemusic.grilowrappers.grltrackerwrapper import GrlTrackerWrapper
from gnomemusic.trackerwrapper import TrackerState, TrackerWrapper
+if typing.TYPE_CHECKING:
+ from gnomemusic.coresong import CoreSong
class CoreGrilo(GObject.GObject):
@@ -347,3 +351,32 @@ class CoreGrilo(GObject.GObject):
if "grl-tracker3-source" in self._wrappers:
self._wrappers["grl-tracker3-source"].create_playlist(
playlist_title, callback)
+
+ def get_chromaprint(
+ self, coresong: CoreSong,
+ callback: CoreGrilo.RESOLVE_CB_TYPE) -> None:
+ """Retrieve the chromaprint for the given CoreSong
+
+ :param CoreSong coresong: The CoreSong to chromaprint
+ :param callback: Metadata retrieval callback
+ """
+ if "grl-chromaprint" not in self._mb_wrappers:
+ callback(None)
+ return
+
+ self._mb_wrappers["grl-chromaprint"].get_chromaprint(
+ coresong, callback)
+
+ def get_tags(
+ self, coresong: CoreSong,
+ callback: CoreGrilo.QUERY_CB_TYPE) -> None:
+ """Retrieve Musicbrainz tags for the given CoreSong
+
+ :param CoreSong coresong: The CoreSong to retrieve tags for
+ :param callback: Metadata retrieval callback
+ """
+ if "grl-acoustid" not in self._mb_wrappers:
+ callback(None, 0)
+ return
+
+ self._mb_wrappers["grl-acoustid"].get_tags(coresong, callback)
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index 585f28e8d..751684e6a 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -187,3 +187,18 @@ class CoreSong(GObject.GObject):
def update_shuffle_pos(self) -> None:
"""Randomizes the shuffle position of this song"""
self.props.shuffle_pos = randint(1, 1_000_000)
+
+ def query_musicbrainz_tags(
+ self, callback: CoreGrilo.QUERY_CB_TYPE) -> None:
+ """Retrieves metadata keys for this CoreSong
+
+ :param callback: Metadata retrieval callback
+ """
+ def chromaprint_retrieved(media: Optional[Grl.Media]) -> None:
+ if media is None:
+ callback(None, 0)
+ return
+
+ self._coregrilo.get_tags(self, callback)
+
+ self._coregrilo.get_chromaprint(self, chromaprint_retrieved)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]