[gnome-music/wip/mschraal/core: 95/118] Add grl dleyna source (POC)



commit 9a84b612e476967c1f99e776298d8b7aedc4f31f
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Jun 23 00:18:25 2019 +0200

    Add grl dleyna source (POC)
    
    Prove it is possible to add other sources as proper browsable.
    Show dleyna artist query names in the artist view, I know too
    little upnp to make it more at this time.

 gnomemusic/coregrilo.py                     |  9 ++-
 gnomemusic/grilowrappers/grldleynasource.py | 90 +++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index e65b5e13..7478830b 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -5,9 +5,9 @@ from gi.repository import Grl, GObject
 from gnomemusic import log
 from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.coresong import CoreSong
+from gnomemusic.grilowrappers.grldleynasource import GrlDLeynaSource
 from gnomemusic.grilowrappers.grltrackersource import GrlTrackerSource
 
-
 class CoreGrilo(GObject.GObject):
 
     def __repr__(self):
@@ -42,13 +42,18 @@ class CoreGrilo(GObject.GObject):
         self._registry.connect('source-removed', self._on_source_removed)
 
     def _on_source_added(self, registry, source):
-        print(source.props.source_id)
+        print("SOURCE", source.props.source_id[:10])
         if source.props.source_id == "grl-tracker-source":
             self._tracker_source = GrlTrackerSource(
                 source, self._hash, self._model, self._albums_model,
                 self._artists_model, self._coremodel, self._coreselection)
             # self._tracker_source = source
             print(self._tracker_source, "added")
+        elif source.props.source_id[:10] == "grl-dleyna":
+            self._dleyna_source = GrlDLeynaSource(
+                source, self._hash, self._model, self._albums_model,
+                self._artists_model, self._coremodel, self._coreselection)
+            print(self._dleyna_source, "added")
 
     def _on_source_removed(self, registry, source):
         print("removed,", source.props.source_id)
diff --git a/gnomemusic/grilowrappers/grldleynasource.py b/gnomemusic/grilowrappers/grldleynasource.py
new file mode 100644
index 00000000..7e060218
--- /dev/null
+++ b/gnomemusic/grilowrappers/grldleynasource.py
@@ -0,0 +1,90 @@
+import gi
+gi.require_version('Grl', '0.3')
+from gi.repository import Grl, GObject
+
+from gnomemusic.corealbum import CoreAlbum
+from gnomemusic.coreartist import CoreArtist
+from gnomemusic.coresong import CoreSong
+
+
+class GrlDLeynaSource(GObject.GObject):
+
+    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_COMPOSER,
+        Grl.METADATA_KEY_DURATION,
+        Grl.METADATA_KEY_FAVOURITE,
+        Grl.METADATA_KEY_ID,
+        Grl.METADATA_KEY_LYRICS,
+        Grl.METADATA_KEY_PLAY_COUNT,
+        Grl.METADATA_KEY_THUMBNAIL,
+        Grl.METADATA_KEY_TITLE,
+        Grl.METADATA_KEY_TRACK_NUMBER,
+        Grl.METADATA_KEY_URL
+    ]
+
+    def __repr__(self):
+        return "<GrlDLeynaSource>"
+
+    def __init__(
+            self, source, _hash, model, albums_model, artists_model, coremodel,
+            core_selection):
+        super().__init__()
+
+        self._coremodel = coremodel
+        self._core_selection = core_selection
+        self._source = source
+        self._model = model
+        self._albums_model = albums_model
+        self._album_ids = {}
+        self._artists_model = artists_model
+        self._hash = _hash
+        # self._table = table
+        # Only way to figure out removed items
+        # self._url_table = url_hash
+
+        Grl.init(None)
+
+        self._fast_options = Grl.OperationOptions()
+        self._fast_options.set_resolution_flags(
+            Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY)
+
+        self._full_options = Grl.OperationOptions()
+        self._full_options.set_resolution_flags(
+            Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY)
+
+        # self._initial_fill(self._source)
+        # self._initial_albums_fill(self._source)
+        self._initial_artists_fill(self._source)
+
+        # self._source.connect("content-changed", self._on_content_changed)
+
+    def _initial_artists_fill(self, source):
+        query = """
+        upnp:class derivedfrom 'object.container.person.musicArtist'
+        """.replace('\n', ' ').strip()
+
+        options = self._fast_options.copy()
+
+        source.query(
+            query, self.METADATA_KEYS, options, self._add_to_artists_model)
+
+    def _add_to_artists_model(self, source, op_id, media, user_data, error):
+        if error:
+            print("ERROR", error)
+            return
+
+        if not media:
+            print("NO MEDIA", source, op_id, media, error)
+            return
+
+        artist = CoreArtist(media)
+        artist.props.artist = media.get_title() + " (upnp)"
+        self._artists_model.append(artist)
+        print(
+            "ADDING DLNA ARTIST", media.get_title(), media.get_artist(),
+            media.get_id())


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