anyplayer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/Gemfile.lock +3 -1
- data/Rakefile +1 -0
- data/Readme.markdown +17 -5
- data/anyplayer.gemspec +1 -0
- data/bin/anyplayer +13 -8
- data/lib/anyplayer.rb +17 -18
- data/lib/anyplayer/player.rb +45 -39
- data/lib/anyplayer/players/amarok.rb +43 -45
- data/lib/anyplayer/players/itunes_mac.rb +53 -0
- data/lib/anyplayer/players/itunes_windows.rb +68 -0
- data/lib/anyplayer/players/mpd.rb +45 -47
- data/lib/anyplayer/players/noplayer.rb +45 -0
- data/lib/anyplayer/players/rhythmbox.rb +41 -43
- data/lib/anyplayer/players/xmms2.rb +58 -60
- data/lib/anyplayer/selector.rb +66 -0
- data/lib/anyplayer/version.rb +1 -1
- data/test/anyplayer_test.rb +10 -69
- data/test/player_test.rb +53 -0
- data/test/selector_test.rb +26 -0
- data/test/test_helper.rb +9 -0
- metadata +34 -4
- data/lib/anyplayer/players/itunes.rb +0 -66
- data/lib/anyplayer/players/ituneswindows.rb +0 -66
@@ -1,65 +1,63 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
1
|
+
class Anyplayer::Mpd < Anyplayer::Player
|
2
|
+
def playpause
|
3
|
+
mpc 'toggle'
|
4
|
+
end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def play
|
7
|
+
mpc 'play'
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def pause
|
11
|
+
mpc 'pause'
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def prev
|
15
|
+
mpc 'prev'
|
16
|
+
super
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def next
|
20
|
+
mpc 'next'
|
21
|
+
super
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def voldown
|
25
|
+
mpc 'volume -10'
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def volup
|
29
|
+
mpc 'volume +10'
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def volume
|
33
|
+
mpc('volume').grep(/([0-9]+)/)
|
34
|
+
$1
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def track
|
38
|
+
mpc '-f "%title%" current'
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def artist
|
42
|
+
mpc '-f "%artist%" current'
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
def album
|
46
|
+
mpc '-f "%album%" current'
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
def launched?
|
50
|
+
%x(mpc 2> /dev/null)
|
51
|
+
$? == 0
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def host
|
55
|
+
ENV['MPD_HOST'] || super
|
56
|
+
end
|
58
57
|
|
59
|
-
|
58
|
+
private
|
60
59
|
def mpc(command)
|
61
60
|
%x(mpc #{command}).split("\n").first
|
62
61
|
end
|
63
|
-
end
|
64
62
|
end
|
65
63
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Anyplayer::Noplayer < Anyplayer::Player
|
2
|
+
def playpause
|
3
|
+
end
|
4
|
+
|
5
|
+
def play
|
6
|
+
end
|
7
|
+
|
8
|
+
def pause
|
9
|
+
end
|
10
|
+
|
11
|
+
def prev
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def next
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def voldown
|
20
|
+
end
|
21
|
+
|
22
|
+
def volup
|
23
|
+
end
|
24
|
+
|
25
|
+
def volume
|
26
|
+
100
|
27
|
+
end
|
28
|
+
|
29
|
+
def track
|
30
|
+
"Money"
|
31
|
+
end
|
32
|
+
|
33
|
+
def artist
|
34
|
+
"The Drums"
|
35
|
+
end
|
36
|
+
|
37
|
+
def album
|
38
|
+
"Money"
|
39
|
+
end
|
40
|
+
|
41
|
+
def launched?
|
42
|
+
true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -1,59 +1,57 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
1
|
+
class Anyplayer::Rhythmbox < Anyplayer::Player
|
2
|
+
def playpause
|
3
|
+
rhythmbox 'play-pause'
|
4
|
+
end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def play
|
7
|
+
rhythmbox 'play'
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def pause
|
11
|
+
rhythmbox 'pause'
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def prev
|
15
|
+
rhythmbox 'previous'
|
16
|
+
super
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def next
|
20
|
+
rhythmbox 'next'
|
21
|
+
super
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def voldown
|
25
|
+
rhythmbox 'volume-down'
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def volup
|
29
|
+
rhythmbox 'volume-up'
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def volume
|
33
|
+
rhythmbox 'print-volume'
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def track
|
37
|
+
rhythmbox 'print-playing-format=%tt'
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def artist
|
41
|
+
rhythmbox 'print-playing-format=%ta'
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
def album
|
45
|
+
rhythmbox 'print-playing-format=%at'
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
def launched?
|
49
|
+
%x(rhythmbox-client --no-start --print-playing 2>/dev/null).rstrip != ""
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
def
|
52
|
+
private
|
53
|
+
def rhythmbox(command)
|
55
54
|
%x(rhythmbox-client --no-start --#{command}).rstrip
|
56
55
|
end
|
57
|
-
end
|
58
56
|
end
|
59
57
|
|
@@ -1,79 +1,77 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
1
|
+
class Anyplayer::Xmms2 < Anyplayer::Player
|
2
|
+
def playpause
|
3
|
+
xmms2 'toggle'
|
4
|
+
end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def play
|
7
|
+
xmms2 'play'
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def pause
|
11
|
+
xmms2 'pause'
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def prev
|
15
|
+
xmms2 'prev'
|
16
|
+
super
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def next
|
20
|
+
xmms2 'next'
|
21
|
+
super
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
def voldown
|
25
|
+
current = volume.to_i
|
26
|
+
new_volume = (current < 11 ? 0 : current - 10)
|
27
|
+
xmms2 "server volume #{new_volume}"
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
def volup
|
31
|
+
current = volume.to_i
|
32
|
+
new_volume = (current > 89 ? 100 : current + 10)
|
33
|
+
xmms2 "server volume #{new_volume}"
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def volume
|
37
|
+
# currently just the first (left?) channel
|
38
|
+
xmms2('server volume').split("\n").first.sub(/([^0-9]*)/, '')
|
39
|
+
$1
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
def track
|
43
|
+
xmms2 "status -f '${title}'"
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
def artist
|
47
|
+
xmms2 "status -f '${artist}'"
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def album
|
51
|
+
xmms2 "status -f '${album}'"
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def playing?
|
55
|
+
xmms2("status -f '${playback_status}'") == "Playing"
|
56
|
+
end
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
def paused?
|
59
|
+
xmms2("status -f '${playback_status}'") == "Paused"
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
def launched?
|
63
|
+
# xmms2 autolaunches the daemon, so this should always be true
|
64
|
+
%x(xmms2 status 2> /dev/null)
|
65
|
+
$? == 0
|
66
|
+
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
def host
|
69
|
+
ENV['XMMS_PATH'] || super
|
70
|
+
end
|
72
71
|
|
73
|
-
|
72
|
+
private
|
74
73
|
def xmms2(command)
|
75
74
|
%x(xmms2 #{command}).split("\n").first.strip
|
76
75
|
end
|
77
|
-
end
|
78
|
-
|
79
76
|
end
|
77
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# The Selector is the tool that will find you the currently running player on your platform
|
2
|
+
#
|
3
|
+
# Example:
|
4
|
+
#
|
5
|
+
# selector = Anyplayer::Selector.new
|
6
|
+
# player = selector.player
|
7
|
+
#
|
8
|
+
# Needs the PLAYERS constant to contain a list of players.
|
9
|
+
class Anyplayer::Selector
|
10
|
+
attr_accessor :verbose
|
11
|
+
attr_reader :errors
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@verbose = false
|
15
|
+
@errors = []
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns an instance of the first music player that's launched
|
19
|
+
def player
|
20
|
+
players_for_this_platform.each { |player|
|
21
|
+
player_load(player) or next
|
22
|
+
instance = player_class(player).new
|
23
|
+
return instance if player_launched(instance)
|
24
|
+
}
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def players_for_this_platform
|
32
|
+
players = Anyplayer::PLAYERS
|
33
|
+
players.reject! { |player| player =~ /_mac$/ } if RUBY_PLATFORM !~ /darwin/
|
34
|
+
players.reject! { |player| player =~ /_windows$/ } if RUBY_PLATFORM !~ /cygwin|mswin|mingw|bccwin|wince|emx/
|
35
|
+
players
|
36
|
+
end
|
37
|
+
|
38
|
+
def player_load(player)
|
39
|
+
begin
|
40
|
+
require "anyplayer/players/#{player}"
|
41
|
+
$stderr.puts "Loaded #{player}" if verbose
|
42
|
+
true
|
43
|
+
rescue LoadError => e
|
44
|
+
$stderr.puts "Could not load #{player}" if verbose
|
45
|
+
@errors << "Error loading #{player}: #{e.message}"
|
46
|
+
false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def player_class(player)
|
51
|
+
camelized = player.to_s.split(/_/).map{ |word| word.capitalize }.join
|
52
|
+
Anyplayer::const_get(camelized)
|
53
|
+
end
|
54
|
+
|
55
|
+
def player_launched(player)
|
56
|
+
$stderr.puts "#{player.name} launched?" if verbose
|
57
|
+
|
58
|
+
seconds = 5
|
59
|
+
begin
|
60
|
+
Timeout::timeout(seconds) { player.launched? }
|
61
|
+
rescue Timeout::Error
|
62
|
+
$stderr.puts "Timed out after #{seconds} seconds" if verbose
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|