Class: MPD::Playlist
- Inherits:
-
Object
- Object
- MPD::Playlist
- Defined in:
- lib/ruby-mpd/playlist.rb
Overview
An object representing an .m3u playlist stored by MPD.
Playlists are stored inside the configured playlist directory. They are addressed with their file name (without the directory and without the .m3u suffix).
Some of the commands described in this section can be used to run playlist plugins instead of the hard-coded simple m3u parser. They can access playlists in the music directory (relative path including the suffix) or remote playlists (absolute URI with a supported scheme).
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#add(uri) ⇒ Boolean
Adds URI to the playlist.
-
#clear ⇒ Boolean
Clears the playlist.
-
#delete(pos) ⇒ Boolean
Deletes song at position POS from the playlist.
-
#destroy ⇒ Boolean
Deletes the playlist from the disk.
-
#initialize(mpd, options) ⇒ Playlist
constructor
A new instance of Playlist.
-
#load(range = nil) ⇒ Boolean
Loads the playlist into the current queue.
-
#move(songid, songpos) ⇒ Boolean
Moves song with SONGID in the playlist to the position SONGPOS.
-
#rename(new_name) ⇒ Boolean
Renames the playlist to
new_name
. -
#searchadd(type, what) ⇒ Boolean
Searches for any song that contains
what
in thetype
field and immediately adds them to the playlist. -
#songs ⇒ Array<MPD::Song>
Lists the songs in the playlist.
Constructor Details
#initialize(mpd, options) ⇒ Playlist
Returns a new instance of Playlist.
18 19 20 21 22 |
# File 'lib/ruby-mpd/playlist.rb', line 18 def initialize(mpd, ) @name = .is_a?(Hash) ? [:playlist].to_s : .to_s # convert to_s in case the parser converted to int @mpd = mpd #@last_modified = options[:'last-modified'] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/ruby-mpd/playlist.rb', line 16 def name @name end |
Instance Method Details
#add(uri) ⇒ Boolean
Adds URI to the playlist.
50 51 52 |
# File 'lib/ruby-mpd/playlist.rb', line 50 def add(uri) @mpd.send_command :playlistadd, @name, uri end |
#clear ⇒ Boolean
Clears the playlist.
68 69 70 |
# File 'lib/ruby-mpd/playlist.rb', line 68 def clear @mpd.send_command :playlistclear, @name end |
#delete(pos) ⇒ Boolean
Deletes song at position POS from the playlist.
74 75 76 |
# File 'lib/ruby-mpd/playlist.rb', line 74 def delete(pos) @mpd.send_command :playlistdelete, @name, pos end |
#destroy ⇒ Boolean
Deletes the playlist from the disk.
93 94 95 |
# File 'lib/ruby-mpd/playlist.rb', line 93 def destroy @mpd.send_command :rm, @name end |
#load(range = nil) ⇒ Boolean
Loads the playlist into the current queue. Playlist plugins are supported.
Since 0.17, a range can be passed to load, to load only a part of the playlist.
44 45 46 |
# File 'lib/ruby-mpd/playlist.rb', line 44 def load(range=nil) @mpd.send_command :load, @name, range end |
#move(songid, songpos) ⇒ Boolean
Moves song with SONGID in the playlist to the position SONGPOS.
80 81 82 |
# File 'lib/ruby-mpd/playlist.rb', line 80 def move(songid, songpos) @mpd.send_command :playlistmove, @name, songid, songpos end |
#rename(new_name) ⇒ Boolean
Renames the playlist to new_name
.
86 87 88 89 |
# File 'lib/ruby-mpd/playlist.rb', line 86 def rename(new_name) @mpd.send_command :rename, @name, new_name @name = new_name end |
#searchadd(type, what) ⇒ Boolean
Searches for any song that contains what
in the type
field and immediately adds them to the playlist. Searches are NOT case sensitive.
62 63 64 |
# File 'lib/ruby-mpd/playlist.rb', line 62 def searchadd(type, what) @mpd.send_command :searchaddpl, @name, type, what end |
#songs ⇒ Array<MPD::Song>
Lists the songs in the playlist. Playlist plugins are supported.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby-mpd/playlist.rb', line 26 def songs result = @mpd.send_command(:listplaylistinfo, @name) if result.to_s =~ URI::regexp Song.new(@mpd, {:file => result, :time => 0}) else result.map {|hash| Song.new(@mpd, hash) } end rescue TypeError puts "Files inside Playlist '#{@name}' do not exist!" return nil rescue NotFound return [] # we rescue in the case the playlist doesn't exist. end |