From: kaliko Date: Wed, 4 Nov 2015 09:37:25 +0000 (+0100) Subject: Fixed false warning about wrong MBID format (Closes #6) X-Git-Tag: 0.14.1~9 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=f0912ba70260d43fc4885f6d75c2e83b6fb5a8d1;p=mpd-sima.git Fixed false warning about wrong MBID format (Closes #6) --- diff --git a/sima/client.py b/sima/client.py index c509109..3ae7d92 100644 --- a/sima/client.py +++ b/sima/client.py @@ -136,7 +136,7 @@ class PlayerClient(Player): "search", "sticker find",] track_obj = ['currentsong'] if self._comm in tracks_listing + track_obj: - # pylint: disable=star-args + # pylint: disable=star-args if isinstance(ans, list): return [Track(**track) for track in ans] elif isinstance(ans, dict): @@ -287,7 +287,7 @@ class PlayerClient(Player): kwalbart = {'albumartist':name, 'artist':name} for album in self.list('album', 'albumartist', artist): if album and album not in albums: - albums.append(Album(name=album, **kwalbart)) #pylint: disable=star-args + albums.append(Album(name=album, **kwalbart)) # pylint: disable=star-args for album in self.list('album', 'artist', artist): album_trks = [trk for trk in self.find('album', album)] if 'Various Artists' in [tr.albumartist for tr in album_trks]: diff --git a/sima/lib/meta.py b/sima/lib/meta.py index 2adac13..de9f44f 100644 --- a/sima/lib/meta.py +++ b/sima/lib/meta.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2013, 2014 Jack Kaliko +# Copyright (c) 2013, 2014, 2015 Jack Kaliko # # This file is part of sima # @@ -29,6 +29,9 @@ import logging import re UUID_RE = r'^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$' +# The Track Object is collapsing multiple tags into a single string using this +# separator. It is used then to split back the string to tags list. +SEPARATOR = chr(0x1F) # ASCII Unit Separator def is_uuid4(uuid): regexp = re.compile(UUID_RE, re.IGNORECASE) @@ -146,20 +149,22 @@ class Artist(Meta): "artist" entry: >>> trk = {'artist':'Art Name', >>> 'albumartist': 'Alb Art Name', # optional - >>> 'musicbrainz_artistid': '' , # optional + >>> 'musicbrainz_artistid': '', # optional >>> 'musicbrainz_albumartistid': '', # optional >>> } >>> artobj0 = Artist(**trk) >>> artobj1 = Artist(name='Tool') """ - name = kwargs.get('artist', name).split(', ')[0] - mbid = kwargs.get('musicbrainz_artistid', mbid) + if kwargs.get('artist', False): + name = kwargs.get('artist').split(SEPARATOR)[0] + if kwargs.get('musicbrainz_artistid', False): + mbid = kwargs.get('musicbrainz_artistid').split(SEPARATOR)[0] if (kwargs.get('albumartist', False) and kwargs.get('albumartist') != 'Various Artists'): - name = kwargs.get('albumartist').split(', ')[0] + name = kwargs.get('albumartist').split(SEPARATOR)[0] if (kwargs.get('musicbrainz_albumartistid', False) and kwargs.get('musicbrainz_albumartistid') != '89ad4ac3-39f7-470e-963a-56509c546377'): - mbid = kwargs.get('musicbrainz_albumartistid').split(', ')[0] + mbid = kwargs.get('musicbrainz_albumartistid').split(SEPARATOR)[0] super().__init__(name=name, mbid=mbid) class MetaContainer(Set): diff --git a/sima/lib/track.py b/sima/lib/track.py index 2874a19..4a2e720 100644 --- a/sima/lib/track.py +++ b/sima/lib/track.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009, 2010, 2011, 2013, 2014 Jack Kaliko +# Copyright (c) 2009, 2010, 2011, 2013, 2014, 2015 Jack Kaliko # Copyright (c) 2009 J. Alexander Treuman (Tag collapse method) # Copyright (c) 2008 Rick van Hattem # @@ -23,7 +23,7 @@ import time -from .meta import Artist +from .meta import Artist, SEPARATOR class Track: """ @@ -60,7 +60,7 @@ class Track: continue if isinstance(value, list): self.collapsed_tags.append(tag) - self.__dict__.update({tag: ', '.join(set(value))}) + self.__dict__.update({tag: SEPARATOR.join(set(value))}) def __repr__(self): return '%s(artist="%s", album="%s", title="%s", file="%s")' % ( diff --git a/sima/plugins/core/mpdoptions.py b/sima/plugins/core/mpdoptions.py index 1c4f852..ab5a4cb 100644 --- a/sima/plugins/core/mpdoptions.py +++ b/sima/plugins/core/mpdoptions.py @@ -31,7 +31,7 @@ from ...lib.plugin import Plugin class MpdOptions(Plugin): """ - Deal with MPD options ‑ idle and repeat mode + Deal with MPD options - idle and repeat mode """ def __init__(self, daemon): diff --git a/tests/test_meta.py b/tests/test_meta.py index 071e925..96b4e0d 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -3,7 +3,7 @@ import unittest from sima.lib.meta import Meta, Artist, MetaContainer, is_uuid4 -from sima.lib.meta import WrongUUID4, MetaException +from sima.lib.meta import WrongUUID4, MetaException, SEPARATOR VALID = '110e8100-e29b-41d1-a716-116655250000' @@ -106,7 +106,7 @@ class TestMetaObject(unittest.TestCase): class TestArtistObject(unittest.TestCase): def test_init(self): - artist = {'artist': ', '.join(['Original Name', 'Featuring Nane', 'Feature…']), + artist = {'artist': SEPARATOR.join(['Original Name', 'Featuring Nane', 'Feature…']), 'albumartist': 'Name', 'musicbrainz_artistid': VALID, 'musicbrainz_albumartistid': VALID.replace('11', '22'), @@ -121,6 +121,15 @@ class TestArtistObject(unittest.TestCase): art = Artist(**artist) self.assertTrue(art.name == 'Original Name', art.name) + def test_empty_name(self): + for args in [ + {'mbid':VALID}, + {'name': None}, + {}, + ]: + with self.assertRaises(MetaException, + msg='{} does not raise an except.'.format(args)): + Artist(**args) class TestMetaContainers(unittest.TestCase):