]> kaliko git repositories - mpd-sima.git/blobdiff - sima/lib/meta.py
Some clean-up (pylint audit)
[mpd-sima.git] / sima / lib / meta.py
index 6fb6a0e60a3a86f14c2a180bb24e6043e7cf2127..4e481e64ab4bfd5349569ae61e70fe36dc15060b 100644 (file)
@@ -1,9 +1,31 @@
 # -*- coding: utf-8 -*-
+# Copyright (c) 2013, 2014 Jack Kaliko <kaliko@azylum.org>
+#
+#  This file is part of sima
+#
+#  sima is free software: you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation, either version 3 of the License, or
+#  (at your option) any later version.
+#
+#  sima is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with sima.  If not, see <http://www.gnu.org/licenses/>.
+#
+#
+"""
+Defines some object to handle audio file metadata
+"""
 
 from .simastr import SimaStr
 from .track import Track
 
 class MetaException(Exception):
+    """Generic Meta Exception"""
     pass
 
 class NotSameArtist(MetaException):
@@ -11,6 +33,7 @@ class NotSameArtist(MetaException):
 
 
 class Meta:
+    """Generic Class for Meta object"""
 
     def __init__(self, **kwargs):
         self.name = None
@@ -36,6 +59,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):