Skip to content

c.AddID documentation appears to be incorrect #90

@iconoclasthero

Description

@iconoclasthero

the gompd code uses the protocol addid:

// Add adds the file/directory uri to playlist. Directories add recursively.
func (c *Client) Add(uri string) error {
	return c.Command("add %s", uri).OK()
}

// AddID adds the file/directory uri to playlist and returns the identity
// id of the song added. If pos is positive, the song is added to position
// pos.
func (c *Client) AddID(uri string, pos int) (int, error) {
	var cmd *Command
	if pos >= 0 {
		cmd = c.Command("addid %s %d", uri, pos)
	} else {
		cmd = c.Command("addid %s", uri)
	}
	attrs, err := cmd.Attrs()
	if err != nil {
		return -1, err
	}
	tok, ok := attrs["Id"]
	if !ok {
		return -1, textproto.ProtocolError("addid did not return Id")
	}
	return strconv.Atoi(tok)
}

and the documentation specifically states that it "adds the file/directory uri to playlist and returns the identity id of the song added." However, this seems unpossible, first and foremost because it wouldn't be able to return a single int for the songid if a directory with >1 song were to be added. Secondly, from the mpd protocol documentation:

addid {URI} [POSITION]
Adds a song to the playlist (non-recursive) and returns the song id. URI is always a single file or URL. For example:

addid "foo.mp3"
Id: 999
OK

If the second parameter is given, then the song is inserted at the specified position. If the parameter starts with + or -, then it is relative to the current song 8; e.g. +0 inserts right after the current song and -0 inserts right before the current song (i.e. zero songs between the current song and the newly added song).

It specifically states "song" and "non-recursive" and "URI is always a single file or [a single] URL." There's nothing in the gompd code that suggests that it recuses the URI string and even if it did, the int returned would be ambiguous at best.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions