Edit

thodg/mpd_client/examples/search_and_replace_playlist.rb

Branch :

  • Show log

    Commit

  • Author : Anton Maminov
    Date : 2012-04-23 16:38:48
    Hash : ca7786cb
    Message : add example

  • examples/search_and_replace_playlist.rb
  • # -*- 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