From 6dc2257a2358877b8d1039791d046cf981e39b9f Mon Sep 17 00:00:00 2001 From: kaliko Date: Wed, 2 Jun 2021 17:41:40 +0200 Subject: [PATCH] Add Album property to Track objects --- sima/lib/meta.py | 3 +++ sima/lib/track.py | 9 ++++++++- tests/test_track.py | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/sima/lib/meta.py b/sima/lib/meta.py index 39b3197..a492d17 100644 --- a/sima/lib/meta.py +++ b/sima/lib/meta.py @@ -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 diff --git a/sima/lib/track.py b/sima/lib/track.py index d83bc63..503008b 100644 --- a/sima/lib/track.py +++ b/sima/lib/track.py @@ -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 diff --git a/tests/test_track.py b/tests/test_track.py index 61d98cb..eb32803 100644 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -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 -- 2.39.5