ruby-mpd icon indicating copy to clipboard operation
ruby-mpd copied to clipboard

Cannot fetch songs for playlist (TypeError)

Open janpieper opened this issue 9 years ago • 0 comments

Code

require "pp"
require "ruby-mpd"

mpd = MPD.new
mpd.connect

begin
  playlist = MPD::Playlist.new(mpd, "Example")
  playlist.add("http://uk1.internet-radio.com:8106/listen.pls")
  pp playlist.songs
ensure
  mpd.disconnect
end

Output

Files inside Playlist 'Example' do not exist!
[]

I've checked the code and found this implementation of MPD::Playlist#songs:

    # Lists the songs in the playlist. Playlist plugins are supported.
    # @return [Array<MPD::Song>] songs in the playlist.
    def songs
      result = @mpd.send_command(:listplaylistinfo, @name)
      result.map do |hash|
        if hash[:file] && !hash[:file].match(/^(https?:\/\/)?/)[0].empty?
          Song.new(@mpd, {:file => hash[:file], :time => [0]})
        else
          Song.new(@mpd, hash)
        end
      end
    rescue TypeError
      puts "Files inside Playlist '#{@name}' do not exist!"
      return []
    rescue NotFound
      return [] # we rescue in the case the playlist doesn't exist.
    end

The problem is, that result looks like this:

[ "http://uk1.internet-radio.com:8106/listen.pls" ]

But the code requires result to look like this:

[ { :file => "http://uk1.internet-radio.com:8106/listen.pls" } ]

Edit: I am using MPD 0.18.0

janpieper avatar Mar 26 '16 19:03 janpieper