o-mpd_client 0.2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # MPD::Client
2
+
3
+ [![Build Status](https://badgen.net/travis/mamantoha/mpd_client)](https://travis-ci.org/mamantoha/mpd_client)
4
+ [![Gem Version](https://badge.fury.io/rb/mpd_client.svg)](https://badge.fury.io/rb/mpd_client)
5
+
6
+ Yet another Music Player Daemon (MPD) client library written entirely in Ruby.
7
+ `mpd_client` is a Ruby port of the [python-mpd](https://github.com/Mic92/python-mpd2) library.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application `Gemfile`:
12
+
13
+ ```ruby
14
+ gem 'mpd_client'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```console
20
+ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```console
26
+ gem install mpd_client
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ All functionality is contained in the `MPD::Client` class. Creating an instance of this class is as simple as:
32
+
33
+ ```ruby
34
+ require 'mpd_client'
35
+
36
+ client = MPD::Client.new
37
+ ```
38
+
39
+ Once you have an instance of the `MPD::Client` class, start by connecting to the server:
40
+
41
+ ```ruby
42
+ client.connect('localhost', 6600)
43
+ ```
44
+
45
+ or Unix domain socket
46
+
47
+ ```ruby
48
+ client.connect('/var/run/mpd/socket')
49
+ ```
50
+
51
+ The client library can be used as follows:
52
+
53
+ ```ruby
54
+ puts client.mpd_version # print the mpd version
55
+ puts client.search('title', 'ruby') # print the result of the command 'search title ruby'
56
+ client.close # send the close command
57
+ client.disconect # disconnect from the server
58
+ ```
59
+
60
+ Command lists are also supported using `command_list_ok_begin` and `command_list_end`:
61
+
62
+ ```ruby
63
+ client.command_list_ok_begin # start a command list
64
+ client.update # insert the update command into the list
65
+ client.status # insert the status command into the list
66
+ client.command_list_end # result will be a Array with the results
67
+ ```
68
+
69
+ ### Binary responses
70
+
71
+ Some commands can return binary data.
72
+
73
+ ```ruby
74
+ require 'mpd_client'
75
+
76
+ client = MPD::Client.new
77
+ client.connect('localhost', 6600)
78
+
79
+ if (current_song = client.currentsong)
80
+ data, io = client.readpicture(current_song['file'])
81
+ io # StringIO
82
+ data # => {"size"=>"322860", "type"=>"image/jpeg", "binary"=>"3372"}
83
+ File.write('cover.jpg', io.string)
84
+ end
85
+ ```
86
+
87
+ The above will locate album art for the current song and save image to `cover.jpg` file.
88
+
89
+ ### Ranges
90
+
91
+ Some commands(e.g. `move`, `delete`, `load`, `shuffle`, `playlistinfo`) support integer ranges(`[START:END]`) as argument. This is done in `mpd_client` by using two element array:
92
+
93
+ ```ruby
94
+ # move the first three songs after the fifth number in the playlist
95
+ client.move([0, 3], 5)
96
+ ```
97
+
98
+ Second element can be omitted. MPD will assumes the biggest possible number then:
99
+
100
+ ```ruby
101
+ # delete all songs from the current playlist, except for the firts ten
102
+ client.delete([10,])
103
+ ```
104
+
105
+ ### Logging
106
+
107
+ Default logger for all MPD::Client instances:
108
+
109
+ ```ruby
110
+ require 'logger'
111
+ require 'mpd_client'
112
+
113
+ MPD::Client.log = Logger.new($stderr)
114
+
115
+ client = MPD::Client.new
116
+ ```
117
+
118
+ Sets the logger used by this instance of MPD::Client:
119
+
120
+ ```ruby
121
+ require 'logger'
122
+ require 'mpd_client'
123
+
124
+ client = MPD::Client.new
125
+ client.log = Logger.new($stderr)
126
+ ```
127
+
128
+ For more information about logging configuration, see [Logger](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html)
129
+
130
+ ## Development
131
+
132
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
133
+
134
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
135
+
136
+ ## Contributing
137
+
138
+ 1. Fork it
139
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
140
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
141
+ 4. Push to the branch (`git push origin my-new-feature`)
142
+ 5. Create new Pull Request
143
+
144
+ ## License and Author
145
+
146
+ Copyright (c) 2012-2022 by Anton Maminov
147
+
148
+ This library is distributed under the MIT license. Please see the LICENSE file.
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'mpd_client'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/examples/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'mpd_client', path: '../'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default
5
+
6
+ require 'logger'
7
+ require 'mpd_client'
8
+
9
+ # MPD::Client.log = Logger.new($stderr)
10
+
11
+ client = MPD::Client.new
12
+ client.connect('localhost', 6600)
13
+
14
+ if (current_song = client.currentsong)
15
+ data, io = client.readpicture(current_song['file'])
16
+ puts data
17
+ File.write('cover.jpg', io.string)
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default
5
+
6
+ require 'logger'
7
+ require 'mpd_client'
8
+
9
+ MPD::Client.log = Logger.new($stderr)
10
+
11
+ client = MPD::Client.new
12
+ client.connect('localhost', 6600)
13
+
14
+ puts client.stats
15
+ puts client.status
16
+ puts client.currentsong
17
+ puts client.playlistinfo
data/examples/idle.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default
5
+
6
+ require 'logger'
7
+ require 'mpd_client'
8
+
9
+ client = MPD::Client.new
10
+
11
+ client = MPD::Client.new
12
+ client.log = Logger.new($stderr)
13
+
14
+ client.connect('localhost', 6600)
15
+
16
+ # Lists all changed systems:
17
+ # database, update, stored_playlist, playlist, player, mixer, output, options, sticker, subscription, message
18
+ #
19
+ subsystems = %w[player playlist]
20
+
21
+ loop do
22
+ resp = client.idle(*subsystems)
23
+ puts resp
24
+ end
25
+
26
+ client.close
27
+ client.disconnect
data/examples/range.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default
5
+
6
+ require 'pp'
7
+ require 'logger'
8
+ require 'mpd_client'
9
+
10
+ MPD::Client.log = Logger.new($stderr)
11
+
12
+ client = MPD::Client.new
13
+ client.connect('localhost', 6600)
14
+
15
+ # delete all songs from the current playlist, except for the firts ten
16
+ client.delete([10])
17
+
18
+ # move the first three songs after the fifth number in the playlist
19
+ client.move([0, 3], 5)
20
+
21
+ # print songs form 5 to 10
22
+ client.playlistinfo([5, 10]).each { |s| puts "#{s['artist']} - #{s['title']}" }
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default
5
+
6
+ require 'pp'
7
+ require 'logger'
8
+ require 'mpd_client'
9
+
10
+ MPD::Client.log = Logger.new($stderr)
11
+
12
+ client = MPD::Client.new
13
+ client.connect('localhost', 6600)
14
+
15
+ # Get id of the first song in the playllist
16
+ song = client.playlistinfo(1).first
17
+ pp "#{song['artist']} - #{song['title']}"
18
+ song_id = song['id']
19
+
20
+ # Specifies the portion of the song that shall be played
21
+ client.rangeid(song_id, [60, 70])
22
+
23
+ # Play the playlist at song 1
24
+ client.play(1)
25
+
26
+ pp client.status
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default
5
+
6
+ require 'logger'
7
+ require 'mpd_client'
8
+
9
+ # MPD::Client.log = Logger.new($stderr)
10
+
11
+ client = MPD::Client.new
12
+
13
+ type = ARGV[0]
14
+ what = ARGV[1]
15
+
16
+ client = MPD::Client.new
17
+ client.log = Logger.new($stderr)
18
+
19
+ # Connecting to the server
20
+ client.connect('localhost', 6600)
21
+
22
+ puts "MPD version: #{client.mpd_version}"
23
+ puts "mpd_client version: #{MPD::Client::VERSION}"
24
+
25
+ client.stop
26
+ client.clear # clear the current playlist
27
+
28
+ # Finds songs in the db that are exactly `what`.
29
+ # `type` can be any tag supported by MPD
30
+ # or one of the two special parameters:
31
+ # * 'file' - to search by full path (relative to database root),
32
+ # * 'any' - to match against all available tags.
33
+ songs = client.search(type, what)
34
+
35
+ client.command_list_ok_begin # start a command list to speed up operations
36
+ songs.each do |song|
37
+ client.add(song['file']) if song.key?('file')
38
+ end
39
+ client.command_list_end
40
+
41
+ client.play
42
+
43
+ client.close
44
+ client.disconnect # disconnect from the server
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default
5
+
6
+ require 'logger'
7
+ require 'mpd_client'
8
+
9
+ MPD::Client.log = Logger.new($stderr)
10
+
11
+ # Stickers
12
+ # https://mpd.readthedocs.io/en/latest/protocol.html#stickers
13
+
14
+ client = MPD::Client.new
15
+
16
+ # Connecting to the server
17
+ client.connect('/run/mpd/socket')
18
+
19
+ puts "MPD version: #{client.mpd_version}"
20
+ puts "mpd_client version: #{MPD::Client::VERSION}"
21
+
22
+ uri = 'world/j/Jane Air/2012.Иллюзия полёта/12. Любить любовь.ogg'
23
+
24
+ # sticker set {TYPE} {URI} {NAME} {VALUE}
25
+ # Adds a sticker value to the specified object.
26
+ # If a sticker item with that name already exists, it is replaced.
27
+ #
28
+ client.sticker_set('song', uri, 'rating', '1')
29
+
30
+ # sticker get {TYPE} {URI} {NAME}
31
+ # Reads a sticker value for the specified object.
32
+ #
33
+ puts client.sticker_get('song', uri, 'rating')
34
+
35
+ # sticker list {TYPE} {URI}
36
+ # Lists the stickers for the specified object.
37
+ #
38
+ puts client.sticker_list('song', uri)
39
+
40
+ # sticker find {TYPE} {URI} {NAME}
41
+ # Searches the sticker database for stickers with the specified name, below the specified directory (URI).
42
+ # For each matching song, it prints the URI and that one sticker's value.
43
+ #
44
+ puts client.sticker_find('song', '/', 'rating')
45
+
46
+ # sticker delete {TYPE} {URI} [NAME]
47
+ # Deletes a sticker value from the specified object.
48
+ # If you do not specify a sticker name, all sticker values are deleted.
49
+ #
50
+ client.sticker_delete('song', uri, 'rating')
51
+
52
+ client.close
53
+ client.disconnect
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MPD
4
+ class Client
5
+ VERSION = '0.2.0.1'
6
+ end
7
+ end