Edit

thodg/mpd_client/examples/stickers.rb

Branch :

  • Show log

    Commit

  • Author : Anton Maminov
    Date : 2018-07-31 17:31:06
    Hash : 141cc085
    Message : Rename MPDClient to MPD::Client (#6) * Rename MPDClient to MPD::Client * remove redundants return * Avoid single-line method definitions * nothing special * update readme * add idle example * add rubocop * add .hound.yml * add travis config * add badges to readme * remove rakefile * add rake * revert rakefile * ichange gemspec * add rspec * change travis config * remove rakefile * remove rack-test * add spec * add test * fix rubocop * update badges

  • examples/stickers.rb
  • # frozen_string_literal: true
    
    require 'bundler'
    Bundler.setup :default
    
    require 'logger'
    require 'mpd_client'
    
    MPD::Client.log = Logger.new($stderr)
    
    # Stickers
    # http://www.musicpd.org/doc/protocol/ch03s07.html
    
    client = MPD::Client.new
    
    # Connecting to the server
    client.connect('/run/mpd/socket')
    
    puts "MPD version: #{client.mpd_version}"
    puts "mpd_client version: #{MPD::Client::VERSION}"
    
    uri = 'world/j/Jane Air/2012.Иллюзия полёта/12. Любить любовь.ogg'
    
    # sticker set {TYPE} {URI} {NAME} {VALUE}
    #   Adds a sticker value to the specified object.
    #   If a sticker item with that name already exists, it is replaced.
    #
    client.sticker_set('song', uri, 'rating', '1')
    
    # sticker get {TYPE} {URI} {NAME}
    #   Reads a sticker value for the specified object.
    #
    puts client.sticker_get('song', uri, 'rating')
    
    # sticker list {TYPE} {URI}
    #   Lists the stickers for the specified object.
    #
    puts client.sticker_list('song', uri)
    
    # sticker find {TYPE} {URI} {NAME}
    #   Searches the sticker database for stickers with the specified name, below the specified directory (URI).
    #   For each matching song, it prints the URI and that one sticker's value.
    #
    puts client.sticker_find('song', '/', 'rating')
    
    # sticker delete {TYPE} {URI} [NAME]
    #   Deletes a sticker value from the specified object.
    #   If you do not specify a sticker name, all sticker values are deleted.
    #
    client.sticker_delete('song', uri, 'rating')
    
    client.close
    client.disconnect