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

Fix playlist names that start with a number

Open janpieper opened this issue 9 years ago • 0 comments

Example

require "ruby-mpd"

mpd = MPD.new
mpd.connect

begin
  playlist = MPD::Playlist.new(mpd, "70s")
  playlist.add("http://us1.internet-radio.com:8180/listen.pls")
  mpd.playlists.first.destroy
ensure
  mpd.disconnect
end

Error

/home/jan/.rvm/gems/ruby-2.3.0/gems/ruby-mpd-0.3.3/lib/ruby-mpd.rb:274:in `handle_server_response': [rm] No such playlist (MPD::NotFound)
        from /home/jan/.rvm/gems/ruby-2.3.0/gems/ruby-mpd-0.3.3/lib/ruby-mpd.rb:196:in `block in send_command'
        from /home/jan/.rvm/gems/ruby-2.3.0/gems/ruby-mpd-0.3.3/lib/ruby-mpd.rb:191:in `synchronize'
        from /home/jan/.rvm/gems/ruby-2.3.0/gems/ruby-mpd-0.3.3/lib/ruby-mpd.rb:191:in `send_command'
        from /home/jan/.rvm/gems/ruby-2.3.0/gems/ruby-mpd-0.3.3/lib/ruby-mpd/playlist.rb:96:in `destroy'
        from mpd.rb:9:in `<main>'

Problem

It seems like the playlist key has two different meanings.

  1. playlist id
  2. playlist name

The problem is handled in the code, but only the case if a playlist name starts with a character, not if the playlist name starts with a number. If a string starts with a number and you call #to_i on it, ruby will only use the leading numbers and transforms them to an integer value.

require "pp"
require "ruby-mpd"

mpd = MPD.new
mpd.connect

begin
  playlist = MPD::Playlist.new(mpd, "70s")
  playlist.add("http://us1.internet-radio.com:8180/listen.pls")
  pp mpd.playlists.map(&:name)
ensure
  mpd.disconnect
end

Expected Output

["70s"]

Actual Output

["70"]

janpieper avatar Mar 24 '16 14:03 janpieper