Skip to content

Cannot fetch songs for playlist (TypeError) #80

@janpieper

Description

@janpieper

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

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