ruby-mpd-client 1.1.0 → 1.2.0
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/.rubocop.yml +11 -0
- data/.travis.yml +1 -1
- data/README.md +20 -10
- data/Rakefile +6 -3
- data/bin/console +2 -2
- data/lib/mpd/commands.rb +16 -15
- data/lib/mpd/commands/abstract.rb +7 -1
- data/lib/mpd/commands/current_playlist_remove.rb +2 -1
- data/lib/mpd/commands/ping.rb +1 -2
- data/lib/mpd/commands/playlist_add.rb +9 -6
- data/lib/mpd/commands/playlist_list.rb +1 -1
- data/lib/mpd/commands/playlist_remove.rb +19 -0
- data/lib/mpd/connection.rb +1 -1
- data/lib/mpd/playlist.rb +4 -11
- data/lib/mpd/version.rb +1 -1
- data/ruby-mpd-client.gemspec +10 -9
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 887c1fa7271770fbfda6447e9366691137365f1d2e7464a7f6d84ad1c3192126
|
4
|
+
data.tar.gz: fb5d196d90b8cb64650dffe92f03063aa7a5e095d03a58adba4c13c12d22e23c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28be28e2ad32e1f3d5d8d5dcbee86f3330ee9e8c68c67ffa7552236d6dddd6eab85797caf46c6ef4cbf9eb5daaa75f4a0bf69c3f21ea34ea92fc05eca40e50f0
|
7
|
+
data.tar.gz: 75e8a8efb06e740a309c541ef02b134b24f805b8d72fd2dc0bd3834b406db25bd248ca5a29e4a473733cd64a5fa87890b1e3e398d013fc57f8535c1551800498
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
# Ruby MPD client
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
[](https://badge.fury.io/rb/ruby-mpd-client)
|
4
|
+
<br />
|
5
|
+
[](https://travis-ci.org/Nondv/ruby-mpd-client) **master**
|
6
|
+
<br />
|
7
|
+
[](https://travis-ci.org/Nondv/ruby-mpd-client) **develop**
|
5
8
|
|
6
9
|
Yet another ruby mpd client.
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
It does not really provide you some object model for interacting with MPD.
|
12
|
+
Mostly it's just collection of MPD commands with different names.
|
10
13
|
|
11
|
-
|
14
|
+
There's `MPD::Connection` wrapper over `Socket`, `MPD::ServerResponse` - string
|
15
|
+
with some useful methods, `MPD::Playlist` - verypoor abstraction over song list
|
16
|
+
and `MPD::Commands` module that contains all implemented commands.
|
17
|
+
|
18
|
+
See on [rubydoc](http://www.rubydoc.info/gems/ruby-mpd-client).
|
12
19
|
|
13
20
|
## Installation
|
14
21
|
|
@@ -18,8 +25,6 @@ gem 'ruby-mpd-client'
|
|
18
25
|
|
19
26
|
## Usage
|
20
27
|
|
21
|
-
It does not do much
|
22
|
-
|
23
28
|
```ruby
|
24
29
|
require 'ruby-mpd-client'
|
25
30
|
|
@@ -37,14 +42,19 @@ MPD::Commands::Next.new(connection: conn).execute
|
|
37
42
|
MPD::Commands::Pause.new(connection: conn).execute
|
38
43
|
```
|
39
44
|
|
40
|
-
For available commands see
|
45
|
+
For available commands see `MPD::Comands` subclasses on
|
46
|
+
[rubydoc.info](http://www.rubydoc.info/github/Nondv/ruby-mpd-client/MPD/Commands).
|
41
47
|
|
42
48
|
## Contributing
|
43
49
|
|
44
|
-
|
50
|
+
I guess your contribution would be a some command implementation or some models
|
51
|
+
better than `MPD::Playlist` and `MPD::Song`. Feel free to create pull requests,
|
52
|
+
issues or contact me.
|
45
53
|
|
54
|
+
[Link to github repo](https://github.com/Nondv/ruby-mpd-client)
|
46
55
|
|
47
56
|
## License
|
48
57
|
|
49
|
-
The gem is available as open source under the terms of the
|
58
|
+
The gem is available as open source under the terms of the
|
59
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
50
60
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
RuboCop::RakeTask.new(:rubocop)
|
5
7
|
|
6
|
-
task :
|
8
|
+
task travis: %i[spec rubocop]
|
9
|
+
task default: :travis
|
data/bin/console
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
4
|
require 'ruby-mpd-client'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
@@ -10,5 +10,5 @@ require 'ruby-mpd-client'
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/lib/mpd/commands.rb
CHANGED
@@ -8,6 +8,10 @@ module MPD
|
|
8
8
|
#
|
9
9
|
# To decrease code amount
|
10
10
|
#
|
11
|
+
# @!macro [attach] define_trivial_command
|
12
|
+
# @!parse
|
13
|
+
# # Sends "$2" to MPD.
|
14
|
+
# class Commands::$1 < Commands::Abstract; end
|
11
15
|
def self.define_trivial_command(class_name, command)
|
12
16
|
klass = Class.new(::MPD::Commands::Abstract) do
|
13
17
|
define_method :execute do
|
@@ -21,6 +25,10 @@ module MPD
|
|
21
25
|
#
|
22
26
|
# To define commands like 'save "whatever this is"'
|
23
27
|
#
|
28
|
+
# @!macro [attach] define_text_argument_command
|
29
|
+
# @!parse
|
30
|
+
# # Sends '$2 "<ARGUMENT>"' to MPD
|
31
|
+
# class Commands::$1 < Commands::Abstract; end
|
24
32
|
def self.define_text_argument_command(class_name, command)
|
25
33
|
klass = Class.new(::MPD::Commands::Abstract) do
|
26
34
|
define_method :execute do |arg|
|
@@ -34,6 +42,13 @@ module MPD
|
|
34
42
|
#
|
35
43
|
# To define commands like "random <1/0>"
|
36
44
|
#
|
45
|
+
# @!macro [attach] define_option_command
|
46
|
+
# @!parse
|
47
|
+
# # Sends '$2 <1/0>' to MPD
|
48
|
+
# class Commands::$1 < Commands::Abstract
|
49
|
+
# # @param state [Boolean]
|
50
|
+
# def execute(state); end
|
51
|
+
# end
|
37
52
|
def self.define_option_command(class_name, command)
|
38
53
|
klass = Class.new(::MPD::Commands::Abstract) do
|
39
54
|
define_method :execute do |state|
|
@@ -44,32 +59,18 @@ module MPD
|
|
44
59
|
const_set(class_name, klass)
|
45
60
|
end
|
46
61
|
|
47
|
-
# @!macro [attach] define_trivial_command
|
48
|
-
# @!parse
|
49
|
-
# # Sends "$2" to MPD.
|
50
|
-
# class Commands::$1; end
|
51
62
|
define_trivial_command('Pause', 'pause 1')
|
52
63
|
define_trivial_command('Stop', 'stop')
|
53
64
|
define_trivial_command('Previous', 'previous')
|
54
65
|
define_trivial_command('Next', 'next')
|
55
66
|
define_trivial_command('CurrentPlaylistClear', 'clear')
|
67
|
+
define_trivial_command('Update', 'update')
|
56
68
|
|
57
|
-
# @!macro [attach] define_text_argument_command
|
58
|
-
# @!parse
|
59
|
-
# # Sends '$2 "<ARGUMENT>"' to MPD
|
60
|
-
# class Commands::$1; end
|
61
69
|
define_text_argument_command 'PlaylistDelete', :rm
|
62
70
|
define_text_argument_command 'PlaylistSave', :save
|
63
71
|
define_text_argument_command 'PlaylistLoad', :load
|
64
72
|
define_text_argument_command 'PlaylistClear', :playlistclear
|
65
73
|
|
66
|
-
# @!macro [attach] define_option_command
|
67
|
-
# @!parse
|
68
|
-
# # Sends '$2 <1/0>' to MPD
|
69
|
-
# class Commands::$1
|
70
|
-
# # @param state [Boolean]
|
71
|
-
# def execute(state); end
|
72
|
-
# end
|
73
74
|
define_option_command 'Consume', 'consume'
|
74
75
|
define_option_command 'Crossfade', 'crossfade'
|
75
76
|
define_option_command 'Random', 'random'
|
@@ -14,7 +14,13 @@ module MPD
|
|
14
14
|
# You can provide you own connection. It should have same
|
15
15
|
#
|
16
16
|
def initialize(connection: nil, host: 'localhost', port: 6600)
|
17
|
-
@connection = connection
|
17
|
+
@connection = if connection
|
18
|
+
connection
|
19
|
+
else
|
20
|
+
Connection.new(host: host, port: port)
|
21
|
+
.tap(&:connect)
|
22
|
+
.tap(&:gets)
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
#
|
@@ -13,7 +13,8 @@ module MPD
|
|
13
13
|
#
|
14
14
|
def execute(position: nil, id: nil)
|
15
15
|
raise(ArgumentError) if position && id || !position && !id
|
16
|
-
|
16
|
+
command = id ? "deleteid #{id}" : "delete #{resolve_range(position)}"
|
17
|
+
exec_command(command)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
data/lib/mpd/commands/ping.rb
CHANGED
@@ -3,17 +3,20 @@ require 'mpd/commands/abstract'
|
|
3
3
|
module MPD
|
4
4
|
module Commands
|
5
5
|
#
|
6
|
-
# Adds song(s) to specific playlist
|
7
|
-
# `songs` is an array of URIs.
|
6
|
+
# Adds song(s) to specific playlist.
|
8
7
|
#
|
9
8
|
class PlaylistAdd < Abstract
|
10
9
|
#
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# @param name [String] playlist name.
|
11
|
+
# @param songs [Array<String>, String] file URIs.
|
13
12
|
#
|
14
13
|
def execute(name, songs)
|
15
|
-
|
16
|
-
|
14
|
+
if songs.is_a?(Array)
|
15
|
+
commands = songs.map { |s| "playlistadd \"#{name}\" \"#{s}\"" }
|
16
|
+
exec_command_list(commands)
|
17
|
+
else
|
18
|
+
exec_command("playlistadd \"#{name}\" \"#{songs}\"")
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mpd/commands/abstract'
|
2
|
+
|
3
|
+
module MPD
|
4
|
+
module Commands
|
5
|
+
#
|
6
|
+
# Removes **one** song from playlist by position.
|
7
|
+
# Uses MPD command "playlistdelete"
|
8
|
+
#
|
9
|
+
class PlaylistRemove < Abstract
|
10
|
+
#
|
11
|
+
# @param name [String] playlist name.
|
12
|
+
# @param position [Integer] song position.
|
13
|
+
#
|
14
|
+
def execute(name, position)
|
15
|
+
exec_command("playlistdelete \"#{name}\" #{position}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/mpd/connection.rb
CHANGED
data/lib/mpd/playlist.rb
CHANGED
@@ -4,18 +4,11 @@ module MPD
|
|
4
4
|
# Array<SongInfo> with some useful methods
|
5
5
|
class Playlist < Array
|
6
6
|
def self.from_response(response)
|
7
|
-
data = []
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
data << info
|
12
|
-
info = {}
|
13
|
-
end
|
14
|
-
|
15
|
-
info[key] = value
|
7
|
+
data = [{}]
|
8
|
+
response.key_value_pairs.each do |k, v|
|
9
|
+
data.push({}) if data.last.key?(k) # next song reached
|
10
|
+
data.last[k] = v
|
16
11
|
end
|
17
|
-
|
18
|
-
data << info
|
19
12
|
new(data)
|
20
13
|
end
|
21
14
|
|
data/lib/mpd/version.rb
CHANGED
data/ruby-mpd-client.gemspec
CHANGED
@@ -1,27 +1,28 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'mpd/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'ruby-mpd-client'
|
8
8
|
spec.version = MPD::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Dmitriy Non']
|
10
|
+
spec.email = ['non.dmitriy@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = 'yet another MPD client on Ruby'
|
13
13
|
spec.homepage = 'https://github.com/Nondv/ruby-mpd-client'
|
14
|
-
spec.license =
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
17
|
f.match(%r{^(test|spec|features)/})
|
18
18
|
end
|
19
19
|
|
20
|
-
spec.bindir =
|
20
|
+
spec.bindir = 'exe'
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
26
|
spec.add_development_dependency 'rspec-its'
|
27
|
+
spec.add_development_dependency 'rubocop', '0.52.0'
|
27
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mpd-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitriy Non
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.52.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.52.0
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- non.dmitriy@gmail.com
|
@@ -60,6 +74,7 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
63
78
|
- ".travis.yml"
|
64
79
|
- Gemfile
|
65
80
|
- LICENSE.txt
|
@@ -80,6 +95,7 @@ files:
|
|
80
95
|
- lib/mpd/commands/playlist_add.rb
|
81
96
|
- lib/mpd/commands/playlist_info.rb
|
82
97
|
- lib/mpd/commands/playlist_list.rb
|
98
|
+
- lib/mpd/commands/playlist_remove.rb
|
83
99
|
- lib/mpd/commands/set_volume.rb
|
84
100
|
- lib/mpd/commands/status.rb
|
85
101
|
- lib/mpd/connection.rb
|