From: kaliko Date: Sat, 8 Oct 2016 10:26:52 +0000 (+0200) Subject: Changed tracks equality test X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=refs%2Fheads%2Ftrack_equality;p=mpd-sima.git Changed tracks equality test Equality is not anymore based on file attribute only. Now it compares artist/title between tracks --- diff --git a/doc/Changelog b/doc/Changelog index d5106ed..a8f1e14 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -5,6 +5,9 @@ MPD_sima v0.15.0 * Add option to prevent single & repeat mode to disable queuing (Closes #19) * Honor MPC password/host format on command line option 'host' * Fixed fuzzy search for short artist names + * Changed tracks equality test + Equality is not anymore based on file attribute only. + Now it compares artist/title between tracks -- kaliko jack UNRELEASED diff --git a/sima/lib/track.py b/sima/lib/track.py index e4740bf..f6385d3 100644 --- a/sima/lib/track.py +++ b/sima/lib/track.py @@ -34,7 +34,8 @@ class Track: :param int time: duration in second, defaults to 0 :param int pos: position in queue, defaults to -1 :param str title|artist|album: defaults to "" - :param str musicbrainz_artistid|musicbrainz_albumartistid: MusicBrainz IDs, defaults to ``None`` + :param str musicbrainz_artistid: MusicBrainz IDs, defaults to ``None`` + :param str musicbrainz_albumartistid: MusicBrainz IDs, defaults to ``None`` """ def __init__(self, file=None, time=0, pos=-1, **kwargs): @@ -93,6 +94,10 @@ class Track: return Track(time=self.time - other.time) def __hash__(self): + if self.musicbrainz_artistid and self.title: + return hash(self.musicbrainz_artistid + self.title) + if self.artist and self.title: + return hash(self.artist + self.title) if self.file: return hash(self.file) else: diff --git a/tests/test_track.py b/tests/test_track.py index 62eb306..37ab3b0 100644 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -42,4 +42,22 @@ class TestTrackObject(unittest.TestCase): trk = Track(artist='track_artist') self.assertEqual(trk.Artist.name, 'track_artist') +class TestTrackObjectEquality(unittest.TestCase): + + def test_identity(self): + trk0 = Track(file='/foo/bar', + musicbrainz_artistid='d8e7e3e2-49ab-4f7c-b148-fc946d521f99', + title='Crazy') + trk1 = Track(file='/foo/bar/baz', + musicbrainz_artistid='d8e7e3e2-49ab-4f7c-b148-fc946d521f99', + title='Crazy') + self.assertTrue(trk1 == trk0, 'different files same artist/title should be equal') + trk0 = Track(file='/foo/bar', + musicbrainz_artistid='d8e7e3e2-49ab-4f7c-b148-fc946d521f88', + title='Crazy') + trk1 = Track(file='/foo/bar/baz', + musicbrainz_artistid='d8e7e3e2-49ab-4f7c-b148-fc946d521f99', + title='Crazy') + self.assertTrue(trk1 != trk0, 'different files same title different artist should not be equal') + # vim: ai ts=4 sw=4 sts=4 expandtab