Skip to content

Extend c.Add to include position and extend both c.Add and c.AddID to include relative position... #91

@iconoclasthero

Description

@iconoclasthero
// 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)
}

The protocol accepts both an absolute and a relative position for both add and addid. Both are unavailable in c.Add and the latter is unavailable in c.Addid.

add {URI} [POSITION]
Adds the file URI to the playlist (directories add recursively). URI can also be a single file.

The position parameter is the same as in addid. 10

Clients that are connected via local socket may add arbitrary local files (URI is an absolute path). Example:

add "/home/foo/Music/bar.ogg"

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).

The relative-to-current positional facility would be nice to have but as I pointed out in #90 there's no way to add recursively with addid so there's therefore no way to add recursively at a position in gompd which is a significant limitation in utility.

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