]> kaliko git repositories - mpd-sima.git/commitdiff
Add Album property to Track objects
authorkaliko <kaliko@azylum.org>
Wed, 2 Jun 2021 15:41:40 +0000 (17:41 +0200)
committerkaliko <kaliko@azylum.org>
Wed, 2 Jun 2021 15:41:40 +0000 (17:41 +0200)
sima/lib/meta.py
sima/lib/track.py
tests/test_track.py

index 39b3197573c9e78456cdcbbfaf8f5854d90f18ae..a492d17ed60e7ac3749216cf4245eb96bb39c227 100644 (file)
@@ -56,6 +56,7 @@ def mbidfilter(func):
         func(*args, **kwargs)
     return wrapper
 
+
 def serialize(func):
     def wrapper(*args, **kwargs):
         ans = func(*args, **kwargs)
@@ -182,6 +183,8 @@ class Album(Meta):
 
     @mbidfilter
     def __init__(self, name=None, mbid=None, **kwargs):
+        if kwargs.get('musicbrainz_albumid', False):
+            mbid = kwargs.get('musicbrainz_albumid').split(SEPARATOR)[0]
         super().__init__(name=name, mbid=mbid, **kwargs)
 
     @property
index d83bc6346c76e72184d7355558a4e19351430510..503008b6b1a5a844a58b4538c404421dba394589 100644 (file)
@@ -23,7 +23,7 @@
 
 import time
 
-from .meta import Artist, SEPARATOR
+from .meta import Artist, Album, SEPARATOR
 
 class Track:
     """
@@ -149,5 +149,12 @@ class Track:
             return Artist(name='[unknown]', **self.__dict__)
         return Artist(**self.__dict__)
 
+    @property
+    def Album(self):
+        """Get the :class:`sima.lib.meta.Album` associated to this track"""
+        if not self.album:
+            return Album(name='[unknown]', **self.__dict__)
+        return Album(name=self.album, **self.__dict__)
+
 # VIM MODLINE
 # vim: ai ts=4 sw=4 sts=4 expandtab
index 61d98cb5daaf4661a11dc221bfa1b753c8fb8607..eb3280380a560cfe441f199a321431de0d2e7f78 100644 (file)
@@ -51,4 +51,14 @@ class TestTrackObject(unittest.TestCase):
         trk = Track(**{'artist': 'Devolt', 'genre': 'Punk '})
         self.assertEqual(trk.genres, ['Punk'])
 
+    def test_artist_object(self):
+        trk = Track(**DEVOLT)
+        self.assertEqual(trk.Artist.name, DEVOLT['artist'])
+        self.assertEqual(trk.Artist.mbid, DEVOLT['musicbrainz_artistid'])
+
+    def test_album_object(self):
+        trk = Track(**DEVOLT)
+        self.assertEqual(trk.Album.name, DEVOLT['album'])
+        self.assertEqual(trk.Album.mbid, DEVOLT['musicbrainz_albumid'])
+
 # vim: ai ts=4 sw=4 sts=4 expandtab