Skip to content

Fix playlist names that start with a number#78

Open
janpieper wants to merge 3 commits intoarchseer:masterfrom
janpieper:fix-numeric-playlist-names
Open

Fix playlist names that start with a number#78
janpieper wants to merge 3 commits intoarchseer:masterfrom
janpieper:fix-numeric-playlist-names

Conversation

@janpieper
Copy link
Contributor

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"]

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

Successfully merging this pull request may close these issues.

1 participant