add example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/examples/Gemfile b/examples/Gemfile
new file mode 100644
index 0000000..fc20a81
--- /dev/null
+++ b/examples/Gemfile
@@ -0,0 +1,3 @@
+source :rubygems
+
+gem 'mpd_client', :path => '../'
diff --git a/examples/search_and_replace_playlist.rb b/examples/search_and_replace_playlist.rb
new file mode 100644
index 0000000..1a902b2
--- /dev/null
+++ b/examples/search_and_replace_playlist.rb
@@ -0,0 +1,38 @@
+# -*- encoding: utf-8 -*-
+
+require 'bundler'
+Bundler.setup :default
+
+require 'mpd_client'
+
+type = ARGV[0]
+what = ARGV[1]
+
+client = MPDClient.new
+
+# Connecting to the server
+client.connect('localhost', 6600)
+
+puts "MPD version: #{client.mpd_version}"
+puts "mpd_client version: #{MPDClient::VERSION}"
+
+client.stop
+client.clear # clear the current playlist
+
+# Finds songs in the db that are exactly `what`.
+# `type` can be any tag supported by MPD
+# or one of the two special parameters:
+# * 'file' - to search by full path (relative to database root),
+# * 'any' - to match against all available tags.
+songs = client.search(type, what)
+
+client.command_list_ok_begin # start a command list to speed up operations
+songs.each do |song|
+ client.add(song['file']) if song.has_key?('file')
+end
+client.command_list_end
+
+client.play
+
+client.close
+client.disconnect # disconnect from the server