1 # -*- coding: utf-8 -*-
3 from .simastr import SimaStr
4 from .track import Track
6 class MetaException(Exception):
9 class NotSameArtist(MetaException):
15 def __init__(self, **kwargs):
18 if 'name' not in kwargs:
19 raise MetaException('need at least a "name" argument')
20 self.__dict__.update(kwargs)
23 fmt = '{0}(name="{1.name}", mbid="{1.mbid}")'
24 return fmt.format(self.__class__.__name__, self)
29 def __eq__(self, other):
31 Perform mbid equality test if present,
32 else fallback on fuzzy equality
34 if hasattr(other, 'mbid'):
35 if other.mbid and self.mbid:
36 return self.mbid == other.mbid
37 return SimaStr(str(self)) == SimaStr(str(other))
42 def __init__(self, **kwargs):
44 super().__init__(**kwargs)
46 def append(self, name):
47 self._aliases.append(name)
51 return self._aliases + [self.name]
53 def __add__(self, other):
54 if isinstance(other, Artist):
55 if self.mbid == other.mbid:
56 res = Artist(**self.__dict__)
57 res._aliases.extend(other.names)
60 raise NotSameArtist('different mbids: {0} and {1}'.format(self, other))
65 def __init__(self, **kwargs):
66 super().__init__(**kwargs)
67 if hasattr(self, 'musicbrainz_artistid'):
68 self.artist = Artist(mbid=self.musicbrainz_artistid,
71 # vim: ai ts=4 sw=4 sts=4 expandtab