Class: Qtunes::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/qtunes/player.rb

Constant Summary collapse

INFO_KEYS =
%w(status file duration position)

Instance Method Summary collapse

Instance Method Details

#enqueue(file) ⇒ Object



85
86
87
# File 'lib/qtunes/player.rb', line 85

def enqueue(file)
  Cocaine::CommandLine.new('cmus-remote', "-q #{file.shellescape}").run
end

#execute(command) ⇒ Object



97
98
99
# File 'lib/qtunes/player.rb', line 97

def execute(command)
  Cocaine::CommandLine.new('cmus-remote', '-C :command', :command => command).run
end

#fileObject



45
46
47
# File 'lib/qtunes/player.rb', line 45

def file
  info['file']
end

#infoObject



12
13
14
15
16
17
18
# File 'lib/qtunes/player.rb', line 12

def info
  info_raw.inject({}) do |res,i|
    k,v = i.split(" ", 2)
    res[k] = v if INFO_KEYS.include?(k)
    res
  end
end

#info_rawObject



8
9
10
# File 'lib/qtunes/player.rb', line 8

def info_raw
  execute("status").split("\n")
end

#libraryObject



93
94
95
# File 'lib/qtunes/player.rb', line 93

def library
  execute('save -l -').split("\n")
end

#nextObject



77
78
79
# File 'lib/qtunes/player.rb', line 77

def next
  execute('player-next')
end

#pauseObject



73
74
75
# File 'lib/qtunes/player.rb', line 73

def pause
  execute('player-pause')
end

#paused?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/qtunes/player.rb', line 41

def paused?
  status == 'paused'
end

#playObject



65
66
67
# File 'lib/qtunes/player.rb', line 65

def play
  execute('player-play')
end

#playing?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/qtunes/player.rb', line 33

def playing?
  status == 'playing'
end

#prevObject



81
82
83
# File 'lib/qtunes/player.rb', line 81

def prev
  execute('player-prev')
end

#queueObject



89
90
91
# File 'lib/qtunes/player.rb', line 89

def queue
  execute('save -q -').split("\n")
end

#statusObject

The current state of the player.

Examples

player = Qtunes::Player.new
player.status
# => 'playing'

returns String, being one of: ‘playing’, ‘paused’, ‘stopped’.



29
30
31
# File 'lib/qtunes/player.rb', line 29

def status
  info['status']
end

#stopObject



69
70
71
# File 'lib/qtunes/player.rb', line 69

def stop
  execute('player-stop')
end

#stopped?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/qtunes/player.rb', line 37

def stopped?
  status == 'stopped'
end

#view_queueObject



49
50
51
# File 'lib/qtunes/player.rb', line 49

def view_queue
  execute('view queue')
end

#win_downObject



57
58
59
# File 'lib/qtunes/player.rb', line 57

def win_down
  execute('win-down')
end

#win_removeObject



61
62
63
# File 'lib/qtunes/player.rb', line 61

def win_remove
  execute('win-remove')
end

#win_topObject



53
54
55
# File 'lib/qtunes/player.rb', line 53

def win_top
  execute('win-top')
end