summaryrefslogtreecommitdiff
path: root/libmpd/playlist.rb
blob: 2b40ce460fc589071212dd3f91dea46e09d27112 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env ruby
#
#--
# Copyright 2009 David Vazgenovich Shakaryan <dvshakaryan@gmail.com>
# Distributed under the terms of the GNU General Public License v3.
# See http://www.gnu.org/licenses/gpl.txt for the full license text.
#++
#
# *Author*:: David Vazgenovich Shakaryan
# *License*:: GNU General Public License v3

# Collection of methods related to the playlist.
module MPDPlaylist
  # Adds the specified file to the playlist.
  # Directories add recursively.
  def add(uri)
    return send_request('add "%s"' % uri)
  end

  # Adds the specified file to the playlist and returns the song id.
  # An optional playlist position can be specified.
  def addid(uri, position=nil)
    command = 'addid "%s"' % uri
    command << ' %s' % position if position

    return send_request(command).scan(/(?!Id: )\d+/).first.to_i
  end

  # Deletes a song from the playlist.
  def delete(songpos)
    return send_request('delete %s' % songpos)
  end

  # Clears the playlist.
  def clear
    return send_request('clear')
  end

  # Returns an Array composed of Hashes containing information about the songs
  # in the playlist.
  def playlist
    return split_and_hash(send_request('playlistinfo'))
  end

  # Swaps the positions of the given songs, specified by playlist positions.
  def swap first, second
    return send_request('swap %s %s' % [first, second])
  end

  # Swaps the positions of the given songs, specified by song ids.
  def swapid first, second
    return send_request('swapid %s %s' % [first, second])
  end
end