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))
40 if self.mbid is not None:
41 return hash(self.mbid)
47 __hash__ = Meta.__hash__
49 def __init__(self, **kwargs):
50 super().__init__(**kwargs)
52 def __eq__(self, other):
54 Perform mbid equality test if present,
55 else fallback on self.name equality
57 if hasattr(other, 'mbid'):
58 if other.mbid and self.mbid:
59 return self.mbid == other.mbid
60 return str(self) == str(other)
69 def __init__(self, **kwargs):
71 super().__init__(**kwargs)
73 def append(self, name):
74 self._aliases.append(name)
78 return self._aliases + [self.name]
80 def __add__(self, other):
81 if isinstance(other, Artist):
82 if self.mbid == other.mbid:
83 res = Artist(**self.__dict__)
84 res._aliases.extend(other.names)
87 raise NotSameArtist('different mbids: {0} and {1}'.format(self, other))
92 def __init__(self, **kwargs):
93 super().__init__(**kwargs)
94 if hasattr(self, 'musicbrainz_artistid'):
95 self.artist = Artist(mbid=self.musicbrainz_artistid,
98 # vim: ai ts=4 sw=4 sts=4 expandtab