ruby-mpd 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -1
- data/README.md +14 -5
- data/Rakefile +7 -1
- data/bin/rspec +16 -0
- data/lib/ruby-mpd.rb +3 -3
- data/lib/ruby-mpd/parser.rb +9 -3
- data/lib/ruby-mpd/playlist.rb +7 -5
- data/lib/ruby-mpd/plugins/controls.rb +1 -1
- data/lib/ruby-mpd/plugins/database.rb +1 -1
- data/lib/ruby-mpd/song.rb +28 -7
- data/lib/ruby-mpd/version.rb +1 -1
- data/ruby-mpd.gemspec +1 -1
- metadata +6 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3d1c4e3976d91cea9da096a4d4c16c3c0cc6a5e4
         | 
| 4 | 
            +
              data.tar.gz: 632f1d4b4928a249c28446b8202aa930dbbce9f5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d30486b01ba069e82431f03b66743f48a6d8c3c943a1a2794c9dcc3543f2d17da5c939717101ccc3595982ebe15850e4011b56cffdd00c01c10e5dec5e13915e
         | 
| 7 | 
            +
              data.tar.gz: 70d07b44d2c8b10d41f249822135d8f74ae638143ab2294affe08ed54db6127b2563f5bb300482e24f1fe31a8ba0d3d8927c6a077eee0d8351390a548a5ae315
         | 
    
        data/.rspec
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,8 @@ | |
| 1 1 | 
             
            # ruby-mpd
         | 
| 2 2 |  | 
| 3 | 
            +
            [](https://travis-ci.org/archSeer/ruby-mpd)
         | 
| 4 | 
            +
            [](https://codeclimate.com/github/archSeer/ruby-mpd)
         | 
| 5 | 
            +
             | 
| 3 6 | 
             
            ruby-mpd is a powerful object-oriented client for the  [Music Player Daemon](http://www.musicpd.org), forked from librmpd. librmpd is as of writing outdated by 6 years! This library tries to act as a successor, originally using librmpd as a base, however almost all of the codebase was rewritten. ruby-mpd supports all "modern" MPD features as well as callbacks.
         | 
| 4 7 |  | 
| 5 8 | 
             
            ## MPD Protocol
         | 
| @@ -45,7 +48,7 @@ mpd.disconnect | |
| 45 48 | 
             
            Once connected, you can issue commands to talk to the server.
         | 
| 46 49 |  | 
| 47 50 | 
             
            ```ruby
         | 
| 48 | 
            -
            mpd.connect | 
| 51 | 
            +
            mpd.connect
         | 
| 49 52 | 
             
            mpd.play if mpd.stopped?
         | 
| 50 53 | 
             
            song = mpd.current_song
         | 
| 51 54 | 
             
            puts "Current Song: #{song.artist} - #{song.title}"
         | 
| @@ -178,7 +181,7 @@ end | |
| 178 181 | 
             
            ```
         | 
| 179 182 |  | 
| 180 183 | 
             
            One can also use separate methods or Procs and whatnot, just pass them in as a parameter.
         | 
| 181 | 
            -
             | 
| 184 | 
            +
             | 
| 182 185 | 
             
            ```ruby
         | 
| 183 186 | 
             
            # Using a Proc
         | 
| 184 187 | 
             
            proc = Proc.new { |volume| puts “Volume was set to #{volume}.” }
         | 
| @@ -207,7 +210,7 @@ ruby-mpd supports callbacks for any of the keys returned by `MPD#status`, as wel | |
| 207 210 | 
             
            * *songid*: playlist songid of the current song stopped on or playing.
         | 
| 208 211 | 
             
            * *nextsong*: playlist song number of the next song to be played.
         | 
| 209 212 | 
             
            * *nextsongid*: playlist songid of the next song to be played.
         | 
| 210 | 
            -
            * *time*: Returns two  | 
| 213 | 
            +
            * *time*: Returns two integers, `elapsed` and `total`, Integers representing seconds.
         | 
| 211 214 | 
             
            * *elapsed*: Float, representing total time elapsed within the current song, but with higher accuracy.
         | 
| 212 215 | 
             
            * *bitrate*: instantaneous bitrate in kbps.
         | 
| 213 216 | 
             
            * *xfade*: crossfade in seconds
         | 
| @@ -218,7 +221,7 @@ ruby-mpd supports callbacks for any of the keys returned by `MPD#status`, as wel | |
| 218 221 | 
             
            * *error*: if there is an error, returns message here
         | 
| 219 222 |  | 
| 220 223 | 
             
            * *connection*: Are we connected to the daemon? true or false
         | 
| 221 | 
            -
             | 
| 224 | 
            +
             | 
| 222 225 | 
             
            Note that if the callback returns more than one value, the callback needs more arguments in order to recieve those values:
         | 
| 223 226 |  | 
| 224 227 | 
             
            ```ruby
         | 
| @@ -266,7 +269,13 @@ Idle seems like a possible way to reimplement callbacks; make a separate connect | |
| 266 269 |  | 
| 267 270 | 
             
            ### Tests
         | 
| 268 271 |  | 
| 269 | 
            -
             | 
| 272 | 
            +
            There is the beginings of a test suite, that can be ran with:
         | 
| 273 | 
            +
             | 
| 274 | 
            +
            ```
         | 
| 275 | 
            +
            $ bin/rspec spec/
         | 
| 276 | 
            +
            ```
         | 
| 277 | 
            +
             | 
| 278 | 
            +
            The entire MPD server mock class either needs to be rewritten, or a `mpd.conf` along with a sample database and instructions for a controlled environment needs to be written.
         | 
| 270 279 |  | 
| 271 280 | 
             
            ## TODO list
         | 
| 272 281 |  | 
    
        data/Rakefile
    CHANGED
    
    | @@ -5,6 +5,12 @@ Rake::TestTask.new(:test) do |test| | |
| 5 5 | 
             
              test.verbose = true
         | 
| 6 6 | 
             
            end
         | 
| 7 7 |  | 
| 8 | 
            +
            begin
         | 
| 9 | 
            +
              require 'rspec/core/rake_task'
         | 
| 10 | 
            +
              RSpec::Core::RakeTask.new(:spec)
         | 
| 11 | 
            +
            rescue LoadError
         | 
| 12 | 
            +
            end
         | 
| 13 | 
            +
             | 
| 8 14 | 
             
            desc "Open an irb session preloaded with this API"
         | 
| 9 15 | 
             
            task :console do
         | 
| 10 16 | 
             
              require 'ruby-mpd'
         | 
| @@ -13,4 +19,4 @@ task :console do | |
| 13 19 | 
             
              IRB.start
         | 
| 14 20 | 
             
            end
         | 
| 15 21 |  | 
| 16 | 
            -
            task :default => :test
         | 
| 22 | 
            +
            task :default => [:test, :spec]
         | 
    
        data/bin/rspec
    ADDED
    
    | @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            #
         | 
| 3 | 
            +
            # This file was generated by Bundler.
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # The application 'rspec' is installed as part of a gem, and
         | 
| 6 | 
            +
            # this file is here to facilitate running it.
         | 
| 7 | 
            +
            #
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            require 'pathname'
         | 
| 10 | 
            +
            ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
         | 
| 11 | 
            +
              Pathname.new(__FILE__).realpath)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            require 'rubygems'
         | 
| 14 | 
            +
            require 'bundler/setup'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            load Gem.bin_path('rspec-core', 'rspec')
         | 
    
        data/lib/ruby-mpd.rb
    CHANGED
    
    | @@ -186,11 +186,11 @@ class MPD | |
| 186 186 | 
             
              # @return (see #handle_server_response)
         | 
| 187 187 | 
             
              # @raise [MPDError] if the command failed.
         | 
| 188 188 | 
             
              def send_command(command, *args)
         | 
| 189 | 
            -
                raise ConnectionError, "Not connected to the server!" unless  | 
| 189 | 
            +
                raise ConnectionError, "Not connected to the server!" unless socket
         | 
| 190 190 |  | 
| 191 191 | 
             
                @mutex.synchronize do
         | 
| 192 192 | 
             
                  begin
         | 
| 193 | 
            -
                     | 
| 193 | 
            +
                    socket.puts convert_command(command, *args)
         | 
| 194 194 | 
             
                    response = handle_server_response
         | 
| 195 195 | 
             
                    return parse_response(command, response)
         | 
| 196 196 | 
             
                  rescue Errno::EPIPE
         | 
| @@ -253,7 +253,7 @@ private | |
| 253 253 | 
             
              def handle_server_response
         | 
| 254 254 | 
             
                msg = ''
         | 
| 255 255 | 
             
                while true
         | 
| 256 | 
            -
                  case line =  | 
| 256 | 
            +
                  case line = socket.gets
         | 
| 257 257 | 
             
                  when "OK\n", nil
         | 
| 258 258 | 
             
                    break
         | 
| 259 259 | 
             
                  when /^ACK/
         | 
    
        data/lib/ruby-mpd/parser.rb
    CHANGED
    
    | @@ -4,7 +4,7 @@ class MPD | |
| 4 4 | 
             
              # Parser module, being able to parse messages to and from the MPD daemon format.
         | 
| 5 5 | 
             
              # @todo There are several parser hacks. Time is an array in status and a normal
         | 
| 6 6 | 
             
              #   string in MPD::Song, so we do`@time = options.delete(:time) { [nil] }.first`
         | 
| 7 | 
            -
              #   to hack the array return. Playlist names are strings, whilst in status it's | 
| 7 | 
            +
              #   to hack the array return. Playlist names are strings, whilst in status it's
         | 
| 8 8 | 
             
              #   and int, so we parse it as an int if it's parsed as non-zero (if it's 0 it's a string)
         | 
| 9 9 | 
             
              #   and to fix numeric name playlists (123.m3u), we convert the name to_s inside
         | 
| 10 10 | 
             
              #   MPD::Playlist too.
         | 
| @@ -73,7 +73,13 @@ class MPD | |
| 73 73 | 
             
                    Time.at(value.to_i)
         | 
| 74 74 | 
             
                  elsif key == :"last-modified"
         | 
| 75 75 | 
             
                    Time.iso8601(value)
         | 
| 76 | 
            -
                  elsif  | 
| 76 | 
            +
                  elsif key == :time
         | 
| 77 | 
            +
                    if value.include?(':')
         | 
| 78 | 
            +
                      value.split(':').map(&:to_i)
         | 
| 79 | 
            +
                    else
         | 
| 80 | 
            +
                      [nil, value.to_i]
         | 
| 81 | 
            +
                    end
         | 
| 82 | 
            +
                  elsif key == :audio
         | 
| 77 83 | 
             
                    value.split(':').map(&:to_i)
         | 
| 78 84 | 
             
                  else
         | 
| 79 85 | 
             
                    value.force_encoding('UTF-8')
         | 
| @@ -114,7 +120,7 @@ class MPD | |
| 114 120 |  | 
| 115 121 | 
             
                # Remove lines which we don't want.
         | 
| 116 122 | 
             
                def filter_lines(string, filter)
         | 
| 117 | 
            -
                  string.lines.reject {|line| line =~ /(#{filter.join('|')}):/}.join
         | 
| 123 | 
            +
                  string.lines.reject {|line| line =~ /(#{filter.join('|')}):/i}.join
         | 
| 118 124 | 
             
                end
         | 
| 119 125 |  | 
| 120 126 | 
             
                # Make chunks from string.
         | 
    
        data/lib/ruby-mpd/playlist.rb
    CHANGED
    
    | @@ -25,14 +25,16 @@ class MPD | |
| 25 25 | 
             
                # @return [Array<MPD::Song>] songs in the playlist.
         | 
| 26 26 | 
             
                def songs
         | 
| 27 27 | 
             
                  result = @mpd.send_command(:listplaylistinfo, @name)
         | 
| 28 | 
            -
                   | 
| 29 | 
            -
                     | 
| 30 | 
            -
             | 
| 31 | 
            -
                     | 
| 28 | 
            +
                  result.map do |hash|
         | 
| 29 | 
            +
                    if hash[:file] && !hash[:file].match(/^(https?:\/\/)?/)[0].empty?
         | 
| 30 | 
            +
                      Song.new(@mpd, {:file => hash[:file], :time => [0]})
         | 
| 31 | 
            +
                    else
         | 
| 32 | 
            +
                      Song.new(@mpd, hash)
         | 
| 33 | 
            +
                    end
         | 
| 32 34 | 
             
                  end
         | 
| 33 35 | 
             
                rescue TypeError
         | 
| 34 36 | 
             
                  puts "Files inside Playlist '#{@name}' do not exist!"
         | 
| 35 | 
            -
                  return  | 
| 37 | 
            +
                  return []
         | 
| 36 38 | 
             
                rescue NotFound
         | 
| 37 39 | 
             
                  return [] # we rescue in the case the playlist doesn't exist.
         | 
| 38 40 | 
             
                end
         | 
    
        data/lib/ruby-mpd/song.rb
    CHANGED
    
    | @@ -10,7 +10,7 @@ class MPD::Song | |
| 10 10 | 
             
              def initialize(mpd, options)
         | 
| 11 11 | 
             
                @mpd = mpd
         | 
| 12 12 | 
             
                @data = {} # allowed fields are @types + :file
         | 
| 13 | 
            -
                @time = options.delete(:time)  | 
| 13 | 
            +
                @time = options.delete(:time) # an array of 2 items where last is time
         | 
| 14 14 | 
             
                @file = options.delete(:file)
         | 
| 15 15 | 
             
                @title = options.delete(:title)
         | 
| 16 16 | 
             
                @artist = options.delete(:artist)
         | 
| @@ -19,23 +19,42 @@ class MPD::Song | |
| 19 19 | 
             
                @data.merge! options
         | 
| 20 20 | 
             
              end
         | 
| 21 21 |  | 
| 22 | 
            -
              # Two songs are the same when they  | 
| 22 | 
            +
              # Two songs are the same when they share the same hash.
         | 
| 23 23 | 
             
              def ==(another)
         | 
| 24 | 
            -
                 | 
| 24 | 
            +
                to_h == another.to_h
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              def to_h
         | 
| 28 | 
            +
                {
         | 
| 29 | 
            +
                  time: @time,
         | 
| 30 | 
            +
                  file: @file,
         | 
| 31 | 
            +
                  title: @title,
         | 
| 32 | 
            +
                  artist: @artist,
         | 
| 33 | 
            +
                  album: @album,
         | 
| 34 | 
            +
                  albumartist: @albumartist
         | 
| 35 | 
            +
                }.merge(@data)
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              def elapsed
         | 
| 39 | 
            +
                @time.first
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              def track_length
         | 
| 43 | 
            +
                @time.last
         | 
| 25 44 | 
             
              end
         | 
| 26 45 |  | 
| 27 46 | 
             
              # @return [String] A formatted representation of the song length ("1:02")
         | 
| 28 47 | 
             
              def length
         | 
| 29 | 
            -
                return '--:--' if  | 
| 30 | 
            -
                "#{ | 
| 48 | 
            +
                return '--:--' if track_length.nil?
         | 
| 49 | 
            +
                "#{track_length / 60}:#{"%02d" % (track_length % 60)}"
         | 
| 31 50 | 
             
              end
         | 
| 32 | 
            -
             | 
| 51 | 
            +
             | 
| 33 52 | 
             
              # Retrieve "comments" metadata from a file and cache it in the object.
         | 
| 34 53 | 
             
              #
         | 
| 35 54 | 
             
              # @return [Hash] Key value pairs from "comments" metadata on a file.
         | 
| 36 55 | 
             
              # @return [Boolean] True if comments are empty
         | 
| 37 56 | 
             
              def comments
         | 
| 38 | 
            -
             | 
| 57 | 
            +
                @comments ||= @mpd.send_command :readcomments, @file
         | 
| 39 58 | 
             
              end
         | 
| 40 59 |  | 
| 41 60 | 
             
              # Pass any unknown calls over to the data hash.
         | 
| @@ -49,4 +68,6 @@ class MPD::Song | |
| 49 68 | 
             
                  raise NoMethodError, "#{m}"
         | 
| 50 69 | 
             
                end
         | 
| 51 70 | 
             
              end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              alias :eql? :==
         | 
| 52 73 | 
             
            end
         | 
    
        data/lib/ruby-mpd/version.rb
    CHANGED
    
    
    
        data/ruby-mpd.gemspec
    CHANGED
    
    | @@ -7,7 +7,7 @@ Gem::Specification.new do |spec| | |
| 7 7 | 
             
              spec.name          = "ruby-mpd"
         | 
| 8 8 | 
             
              spec.version       = MPD::VERSION
         | 
| 9 9 | 
             
              spec.authors       = ["Blaž Hrastnik"]
         | 
| 10 | 
            -
              spec.email         = [" | 
| 10 | 
            +
              spec.email         = ["blaz@mxxn.io"]
         | 
| 11 11 |  | 
| 12 12 | 
             
              spec.summary       = "Modern client library for MPD"
         | 
| 13 13 | 
             
              spec.description   = "A powerful, modern and feature complete library for the Music Player Daemon"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ruby-mpd
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Blaž Hrastnik
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-07-22 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -69,18 +69,21 @@ dependencies: | |
| 69 69 | 
             
            description: A powerful, modern and feature complete library for the Music Player
         | 
| 70 70 | 
             
              Daemon
         | 
| 71 71 | 
             
            email:
         | 
| 72 | 
            -
            -  | 
| 72 | 
            +
            - blaz@mxxn.io
         | 
| 73 73 | 
             
            executables: []
         | 
| 74 74 | 
             
            extensions: []
         | 
| 75 75 | 
             
            extra_rdoc_files: []
         | 
| 76 76 | 
             
            files:
         | 
| 77 77 | 
             
            - ".gitignore"
         | 
| 78 | 
            +
            - ".rspec"
         | 
| 79 | 
            +
            - ".travis.yml"
         | 
| 78 80 | 
             
            - COPYING
         | 
| 79 81 | 
             
            - Gemfile
         | 
| 80 82 | 
             
            - LICENSE.txt
         | 
| 81 83 | 
             
            - README.md
         | 
| 82 84 | 
             
            - Rakefile
         | 
| 83 85 | 
             
            - bin/console
         | 
| 86 | 
            +
            - bin/rspec
         | 
| 84 87 | 
             
            - bin/setup
         | 
| 85 88 | 
             
            - lib/ruby-mpd.rb
         | 
| 86 89 | 
             
            - lib/ruby-mpd/exceptions.rb
         |