X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Fmeta.py;h=d589051e3d0461aff175cb0841319fe61eb2672c;hb=9ec2e9036e1f0fe67e8ddd7e8fb7f91a2e86cd62;hp=6fb6a0e60a3a86f14c2a180bb24e6043e7cf2127;hpb=100239e6cc68450278f0f5c4e8077b587af5218e;p=mpd-sima.git diff --git a/sima/lib/meta.py b/sima/lib/meta.py index 6fb6a0e..d589051 100644 --- a/sima/lib/meta.py +++ b/sima/lib/meta.py @@ -36,6 +36,33 @@ class Meta: return self.mbid == other.mbid return SimaStr(str(self)) == SimaStr(str(other)) + def __hash__(self): + if self.mbid is not None: + return hash(self.mbid) + else: + return id(self) + + +class Album(Meta): + __hash__ = Meta.__hash__ + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + def __eq__(self, other): + """ + Perform mbid equality test if present, + else fallback on self.name equality + """ + if hasattr(other, 'mbid'): + if other.mbid and self.mbid: + return self.mbid == other.mbid + return str(self) == str(other) + + @property + def album(self): + return self.name + class Artist(Meta):