Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot fetch songs for playlist (TypeError) #80

Open
janpieper opened this issue Mar 26, 2016 · 0 comments
Open

Cannot fetch songs for playlist (TypeError) #80

janpieper opened this issue Mar 26, 2016 · 0 comments

Comments

@janpieper
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant