Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't show duplicated tags as strings '[x, x]' #54

Closed
carnager opened this issue Apr 30, 2015 · 3 comments
Closed

don't show duplicated tags as strings '[x, x]' #54

carnager opened this issue Apr 30, 2015 · 3 comments

Comments

@carnager
Copy link

sometimes tags in mpd protocol can be duplicates of one another.
This esp. happens if one tagged his library using beets.

This is how raw protocol serves those tags:

currentsong
file: ogg/Brandi Carlile/2008 Creep Live/01-Creep.ogg
Last-Modified: 2015-04-30T02:18:24Z
Album: Creep Live
Title: Creep
Track: 1
Artist: Brandi Carlile
Date: 2008
AlbumArtist: Brandi Carlile
Genre: Rock
Track: 1
Time: 273
Pos: 13
Id: 181945
OK

in python-mpd2 the 2 "track" values will be represented as one string value:

>>> print(file['track'])
[1, 1]
>>> type(file['track'])
<class 'str'>

python-mpd2 could check for key:value on parsing and if multi-values for one key are identical simply merge them. Otherwise represent them as a list.

Alternatively represent all duplicate tags as lists, even if all values are identical. Personally I prefer the first option :)

@carnager carnager changed the title duplicate tags should be filtered out don't show duplicated tags as strings '[x, x]' Apr 30, 2015
@mxjeff
Copy link
Collaborator

mxjeff commented Apr 30, 2015

python-mpd was actually exposing multi-value tags as a list, which is fine I think.
I agree with you carnager, python-mpd2 should present them as a list as well.

But I'm not sure this is relevant to to merge duplicated tag values at the module level.
IMHO, the module should not try to infer what I'm expecting and modifies tags.

For instance here is how I handle it in my client:

class Track:
    """
    Track object.
    Instanciate with Player replies.
    """

    def __init__(self, **kwargs):
        self.title = self.artist = self.album = self.albumartist = ''
        self.__dict__.update(**kwargs)
        #  have tags been collapsed?
        self.collapsed_tags = list()
        # Needed for multiple tag values which returns a list instead of a string
        self.collapse_tags()

    def collapse_tags(self):
        """
        Necessary to deal with tags defined multiple times.
        These entries are set as lists instead of strings.
        """
        for tag, value in self.__dict__.items():
            if isinstance(value, list):
                self.collapsed_tags.append(tag)
                self.__dict__.update({tag: ', '.join(set(value))})

@Mic92
Copy link
Owner

Mic92 commented Apr 30, 2015

I could not reproduce your bug. I have added a test here, where it returns a list. I have also tried:

echo "OK MPD 0.19.0\nTrack: file1\nTrack: file2\nOK\n" | nc -v -l localhost 6601
>>> import mpd
>>> c = mpd.MPDClient()
>>> c.connect("localhost", 6601)
>>> print(type(c.currentsong()['track']))
<class 'list'>

@carnager
Copy link
Author

I seriously don't know what i tested last night, but you are right... i guess mark this as invalid :P

@Mic92 Mic92 closed this as completed Apr 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants