cmus 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,123 @@
1
+ #! /usr/bin/env ruby
2
+ require 'cmus'
3
+ require 'optparse'
4
+
5
+ options = {}
6
+
7
+ OptionParser.new do |o|
8
+ o.on '--server SOCKET', 'connect using SOCKET instead of ~/.cmus/socket' do |value|
9
+ options[:server] = value
10
+ end
11
+
12
+ o.on '--version', 'display version information and exit' do
13
+ puts "cmus-remote.rb for #{Cmus.version}"
14
+ exit
15
+ end
16
+
17
+ o.on '-p', '--play', 'start playing' do
18
+ options[:player] = :play
19
+ end
20
+
21
+ o.on '-u', '--pause', 'toggle pause' do
22
+ options[:player] = :pause
23
+ end
24
+
25
+ o.on '-s', '--stop', 'stop playing' do
26
+ options[:player] = :stop
27
+ end
28
+
29
+ o.on '-n', '--next', 'skip forward in playlist' do
30
+ options[:player] = :next
31
+ end
32
+
33
+ o.on '-r', '--prev', 'skip backward in playlist' do
34
+ options[:player] = :prev
35
+ end
36
+
37
+ o.on '-v', '--volume VOL', 'changes volume' do |value|
38
+ options[:player] = :volume
39
+ options[:value] = value
40
+ end
41
+
42
+ o.on '-k', '--seek SEEK', 'seek' do |value|
43
+ options[:player] = :seek
44
+ options[:value] = value
45
+ end
46
+
47
+ o.on '-R', '--repeat', 'toggle repeat' do
48
+ options[:toggle] = :repeat
49
+ end
50
+
51
+ o.on '-S', '--shuffle', 'toggle shuffle' do
52
+ options[:toggle] = :shuffle
53
+ end
54
+
55
+ o.on '-Q', 'get player status information' do
56
+ options[:status] = true
57
+ end
58
+
59
+ o.on '-l', '--library', 'modify library instead of playlist' do
60
+ options[:library] = true
61
+ end
62
+
63
+ o.on '-P', '--playlist', 'modify playlist (default)' do
64
+ options[:playlist] = true
65
+ end
66
+
67
+ o.on '-q', '--queue', 'modify play queue instead of playlist' do
68
+ options[:queue] = true
69
+ end
70
+
71
+ o.on '-c', '--clear', 'clear playlist, library (-l) or play queue (-q)' do
72
+ options[:clear] = true
73
+ end
74
+
75
+ o.on '-C', '--raw', 'treat arguments (instead of stdin) as raw commands' do
76
+ options[:raw]
77
+ end
78
+ end.parse!
79
+
80
+ controller = options[:server] ? Cmus::Controller.new(options[:server]) : Cmus::Controller.new
81
+
82
+ if options[:clear]
83
+ controller.clear(options[:queue] ? :queue : options[:library] ? :library : :playlist)
84
+ end
85
+
86
+ if options[:player]
87
+ controller.player.__send__ *[options[:player], options[:value]].compact
88
+ end
89
+
90
+ if options[:toggle]
91
+ controller.toggle.__send__ options[:toggle]
92
+ end
93
+
94
+ if options[:status]
95
+ controller.status.tap {|status|
96
+ puts "status #{status.to_sym}"
97
+ puts "file #{status.path}" if status.path
98
+ puts "duration #{status.duration}" if status.duration
99
+ puts "position #{status.position}" if status.position
100
+
101
+ status.tags.marshal_dump.each {|name, value|
102
+ puts "tag #{name} #{value}"
103
+ }
104
+
105
+ status.settings.marshal_dump.each {|name, value|
106
+ puts "set #{name} #{value}"
107
+ }
108
+ }
109
+ end
110
+
111
+ if options[:raw]
112
+ ARGV.each {|command|
113
+ controller.puts command
114
+ }
115
+
116
+ while line = controller.readline
117
+ puts line
118
+ end
119
+ else
120
+ ARGV.each {|path|
121
+ controller.add(options[:queue] ? :queue : options[:library] ? :library : :playlist, path)
122
+ }
123
+ end
@@ -0,0 +1,16 @@
1
+ Kernel.load 'lib/cmus/version.rb'
2
+
3
+ Gem::Specification.new {|s|
4
+ s.name = 'cmus'
5
+ s.version = Cmus.version
6
+ s.author = 'meh.'
7
+ s.email = 'meh@paranoici.org'
8
+ s.homepage = 'http://github.com/meh/LOLastfm'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'cmus remote controller library.'
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.require_paths = ['lib']
16
+ }
@@ -0,0 +1,12 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ require 'cmus/controller'
12
+ require 'cmus/version'
@@ -0,0 +1,58 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ require 'socket'
12
+
13
+ require 'cmus/controller/toggle'
14
+ require 'cmus/controller/player'
15
+ require 'cmus/controller/status'
16
+
17
+ module Cmus
18
+
19
+ class Controller
20
+ attr_reader :path
21
+
22
+ def initialize (path = '~/.cmus/socket')
23
+ @path = File.expand_path(path)
24
+ @socket = UNIXSocket.new(@path)
25
+ end
26
+
27
+ def respond_to_missing? (id)
28
+ @socket.respond_to? id
29
+ end
30
+
31
+ def method_missing (id, *args, &block)
32
+ @socket.__send__ id, *args, &block
33
+ end
34
+
35
+ def clear (context = :playlist)
36
+ puts "clear -#{context.to_s[0]}"
37
+ end
38
+
39
+ def add (context = :playlist, *paths)
40
+ paths.flatten.compact.uniq.each {|path|
41
+ puts "clear -#{context.to_s[0]} #{path}"
42
+ }
43
+ end
44
+
45
+ def toggle
46
+ Toggle.new(self)
47
+ end
48
+
49
+ def player
50
+ Player.new(self)
51
+ end
52
+
53
+ def status
54
+ Status.new(self)
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,55 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ module Cmus; class Controller
12
+
13
+ class Player
14
+ attr_reader :controller
15
+
16
+ def initialize (controller)
17
+ @controller = controller
18
+ end
19
+
20
+ def play (file = nil)
21
+ if file
22
+ controller.puts "player-play #{File.real_path(File.expand_path(file))}"
23
+ else
24
+ controller.puts 'player-play'
25
+ end
26
+ end
27
+
28
+ def pause
29
+ return if controller.status == :paused
30
+
31
+ controller.puts 'player-pause'
32
+ end
33
+
34
+ def stop
35
+ controller.puts 'player-stop'
36
+ end
37
+
38
+ def next
39
+ controller.puts 'player-next'
40
+ end
41
+
42
+ def prev
43
+ controller.puts 'player-prev'
44
+ end
45
+
46
+ def volume (volume)
47
+ controller.puts "vol #{volume}"
48
+ end
49
+
50
+ def seek (second)
51
+ controller.puts "seek #{second}"
52
+ end
53
+ end
54
+
55
+ end; end
@@ -0,0 +1,72 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ require 'ostruct'
12
+
13
+ module Cmus; class Controller
14
+
15
+ class Status
16
+ attr_reader :controller, :path, :duration, :position, :tags, :settings
17
+
18
+ def initialize (controller)
19
+ @controller = controller
20
+
21
+ @tags = OpenStruct.new
22
+ @settings = OpenStruct.new
23
+
24
+ controller.puts 'status'
25
+
26
+ buffer = controller.read(1)
27
+
28
+ while tmp = (controller.read_nonblock(2048) rescue nil)
29
+ buffer << tmp
30
+ end
31
+
32
+ buffer.each_line {|line|
33
+ type, data = line.chomp.split ' ', 2
34
+
35
+ next unless type
36
+
37
+ case type.to_sym
38
+ when :status
39
+ @status = data.to_sym
40
+
41
+ when :file
42
+ @path = data
43
+
44
+ when :duration
45
+ @duration = data.to_i
46
+
47
+ when :position
48
+ @position = data.to_i
49
+
50
+ when :tag
51
+ name, data = data.split ' ', 2
52
+
53
+ @tags.send "#{name}=", data
54
+
55
+ when :set
56
+ name, data = data.split ' ', 2
57
+
58
+ @settings.send "#{name}=", data
59
+ end
60
+ }
61
+ end
62
+
63
+ def == (other)
64
+ super || to_sym == other
65
+ end
66
+
67
+ def to_sym
68
+ @status
69
+ end
70
+ end
71
+
72
+ end; end
@@ -0,0 +1,33 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ module Cmus; class Controller
12
+
13
+ class Toggle
14
+ attr_reader :controller
15
+
16
+ def initialize (controller)
17
+ @controller = controller
18
+ end
19
+
20
+ def repeat
21
+ controller.puts 'toggle repeat'
22
+ end
23
+
24
+ def shuffle
25
+ controller.puts 'toggle shuffle'
26
+ end
27
+
28
+ def pause
29
+ controller.puts 'player-pause'
30
+ end
31
+ end
32
+
33
+ end; end
@@ -0,0 +1,15 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ module Cmus
12
+ def self.version
13
+ '2.0.4'
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmus
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - meh.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-17 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: meh@paranoici.org
16
+ executables:
17
+ - cmus-remote.rb
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/cmus-remote.rb
22
+ - cmus.gemspec
23
+ - lib/cmus.rb
24
+ - lib/cmus/controller.rb
25
+ - lib/cmus/controller/player.rb
26
+ - lib/cmus/controller/status.rb
27
+ - lib/cmus/controller/toggle.rb
28
+ - lib/cmus/version.rb
29
+ homepage: http://github.com/meh/LOLastfm
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: cmus remote controller library.
53
+ test_files: []