anyplayer 1.1.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,66 +1,71 @@
1
1
  class Anyplayer::ItunesMac < Anyplayer::Player
2
2
  def play
3
- itunes 'play'
3
+ itunes "play"
4
4
  end
5
5
 
6
6
  def pause
7
- itunes 'pause'
7
+ itunes "pause"
8
8
  end
9
9
 
10
10
  def playpause
11
- itunes 'playpause'
11
+ itunes "playpause"
12
12
  end
13
13
 
14
14
  def prev
15
- itunes 'previous track'
15
+ itunes "previous track"
16
16
  super
17
17
  end
18
18
 
19
19
  def next
20
- itunes 'next track'
20
+ itunes "next track"
21
21
  super
22
22
  end
23
23
 
24
24
  def voldown
25
- itunes 'set sound volume to sound volume - 10'
25
+ itunes "set sound volume to sound volume - 10"
26
26
  end
27
27
 
28
28
  def volup
29
- itunes 'set sound volume to sound volume + 10'
29
+ itunes "set sound volume to sound volume + 10"
30
30
  end
31
31
 
32
32
  def volume
33
- itunes 'return sound volume'
33
+ itunes "return sound volume"
34
34
  end
35
35
 
36
36
  def track
37
- itunes 'return name of current track'
37
+ itunes "return name of current track"
38
38
  end
39
39
 
40
40
  def artist
41
- itunes 'return artist of current track'
41
+ itunes "return artist of current track"
42
42
  end
43
43
 
44
44
  def album
45
- itunes 'return album of current track'
45
+ itunes "return album of current track"
46
46
  end
47
47
 
48
48
  def playing?
49
- playing = itunes 'return player state is playing'
49
+ playing = itunes "return player state is playing"
50
50
  playing == "true"
51
51
  end
52
52
 
53
53
  def launched?
54
- nb = %x(osascript -e 'tell app "System Events" to count (every process whose name is "iTunes")' 2>/dev/null).rstrip
55
- nb.match(/^\d+/) and nb.to_i > 0 ? true : false
54
+ %x(osascript -e 'app "iTunes" is running').rstrip == "true"
56
55
  end
57
56
 
58
57
  def name
59
58
  "iTunes Mac"
60
59
  end
61
60
 
61
+ def platforms
62
+ [:mac]
63
+ end
64
+
65
+
62
66
  private
63
- def itunes(command)
64
- %x(osascript -e 'tell app "iTunes" to #{command}').rstrip
65
- end
67
+
68
+ def itunes(command)
69
+ %x(osascript -e 'tell app "iTunes" to #{command}').rstrip
70
+ end
66
71
  end
@@ -1,7 +1,7 @@
1
1
  begin
2
- require 'win32ole'
2
+ require "win32ole"
3
3
  rescue LoadError => e
4
- raise LoadError.new("#{e.message} -- You probably aren't on Windows")
4
+ raise LoadError.new("#{e.message} - You probably aren't on Windows")
5
5
  end
6
6
 
7
7
  class Anyplayer::ItunesWindows < Anyplayer::Player
@@ -59,10 +59,13 @@ class Anyplayer::ItunesWindows < Anyplayer::Player
59
59
  "iTunes Windows"
60
60
  end
61
61
 
62
+ def platforms
63
+ [:windows]
64
+ end
65
+
62
66
  private
63
67
 
64
- def itunes
65
- itunes ||= WIN32OLE.new("iTunes.Application")
66
- end
68
+ def itunes
69
+ itunes ||= WIN32OLE.new("iTunes.Application")
70
+ end
67
71
  end
68
-
@@ -1,11 +1,10 @@
1
1
  # encoding: utf-8
2
2
  begin
3
- require 'ruby-mpd'
3
+ require "ruby-mpd"
4
4
  rescue LoadError => e
5
- raise LoadError.new "#{e.message} — please install ruby-mpd gem"
5
+ raise LoadError.new "#{e.message} — Please install the ruby-mpd gem"
6
6
  end
7
7
 
8
-
9
8
  class Anyplayer::Mpd < Anyplayer::Player
10
9
  def initialize
11
10
  @mpc = false
@@ -51,15 +50,18 @@ class Anyplayer::Mpd < Anyplayer::Player
51
50
  end
52
51
 
53
52
  def track
54
- mpc.current_song && mpc.current_song.title
53
+ song = current_song
54
+ return unless song
55
+
56
+ song.title || File.basename(song.file)
55
57
  end
56
58
 
57
59
  def artist
58
- mpc.current_song && mpc.current_song.artist
60
+ current_song&.artist
59
61
  end
60
62
 
61
63
  def album
62
- mpc.current_song && mpc.current_song.album
64
+ current_song&.album
63
65
  end
64
66
 
65
67
  def launched?
@@ -67,10 +69,15 @@ class Anyplayer::Mpd < Anyplayer::Player
67
69
  end
68
70
 
69
71
  def host
70
- ENV['MPD_HOST'] || super
72
+ ENV["MPD_HOST"] || super
71
73
  end
72
74
 
73
75
  private
76
+
77
+ def current_song
78
+ mpc.current_song
79
+ end
80
+
74
81
  def connect
75
82
  @mpc ||= MPD.new
76
83
  @mpc.connect
@@ -83,4 +90,3 @@ class Anyplayer::Mpd < Anyplayer::Player
83
90
  @mpc
84
91
  end
85
92
  end
86
-
@@ -1,5 +1,6 @@
1
1
  class Anyplayer::Noplayer < Anyplayer::Player
2
- def playpause
2
+ def playing?
3
+ true
3
4
  end
4
5
 
5
6
  def play
@@ -42,4 +43,3 @@ class Anyplayer::Noplayer < Anyplayer::Player
42
43
  true
43
44
  end
44
45
  end
45
-
@@ -1,66 +1,70 @@
1
1
  class Anyplayer::RdioMac < Anyplayer::Player
2
2
  def play
3
- rdio 'play'
3
+ rdio "play"
4
4
  end
5
5
 
6
6
  def pause
7
- rdio 'pause'
7
+ rdio "pause"
8
8
  end
9
9
 
10
10
  def playpause
11
- rdio 'playpause'
11
+ rdio "playpause"
12
12
  end
13
13
 
14
14
  def prev
15
- rdio 'previous track'
15
+ rdio "previous track"
16
16
  super
17
17
  end
18
18
 
19
19
  def next
20
- rdio 'next track'
20
+ rdio "next track"
21
21
  super
22
22
  end
23
23
 
24
24
  def voldown
25
- rdio 'set sound volume to sound volume - 10'
25
+ rdio "set sound volume to sound volume - 10"
26
26
  end
27
27
 
28
28
  def volup
29
- rdio 'set sound volume to sound volume + 10'
29
+ rdio "set sound volume to sound volume + 10"
30
30
  end
31
31
 
32
32
  def volume
33
- rdio 'return sound volume'
33
+ rdio "return sound volume"
34
34
  end
35
35
 
36
36
  def track
37
- rdio 'return name of current track'
37
+ rdio "return name of current track"
38
38
  end
39
39
 
40
40
  def artist
41
- rdio 'return artist of current track'
41
+ rdio "return artist of current track"
42
42
  end
43
43
 
44
44
  def album
45
- rdio 'return album of current track'
45
+ rdio "return album of current track"
46
46
  end
47
47
 
48
48
  def playing?
49
- playing = rdio 'return player state is playing'
49
+ playing = rdio "return player state is playing"
50
50
  playing == "true"
51
51
  end
52
52
 
53
53
  def launched?
54
- nb = %x(osascript -e 'tell app "System Events" to count (every process whose name is "rdio")' 2>/dev/null).rstrip
55
- nb.match(/^\d+/) and nb.to_i > 0 ? true : false
54
+ %x(osascript -e 'app "rdio" is running').rstrip == "true"
56
55
  end
57
56
 
58
57
  def name
59
58
  "Rdio Mac"
60
59
  end
61
60
 
61
+ def platforms
62
+ [:mac]
63
+ end
64
+
62
65
  private
63
- def rdio(command)
64
- %x(osascript -e 'tell app "rdio" to #{command}').rstrip
65
- end
66
- end
66
+
67
+ def rdio(command)
68
+ %x(osascript -e 'tell app "rdio" to #{command}').rstrip
69
+ end
70
+ end
@@ -1,48 +1,48 @@
1
1
  class Anyplayer::Rhythmbox < Anyplayer::Player
2
2
  def playpause
3
- rhythmbox 'play-pause'
3
+ rhythmbox "play-pause"
4
4
  end
5
5
 
6
6
  def play
7
- rhythmbox 'play'
7
+ rhythmbox "play"
8
8
  end
9
9
 
10
10
  def pause
11
- rhythmbox 'pause'
11
+ rhythmbox "pause"
12
12
  end
13
13
 
14
14
  def prev
15
- rhythmbox 'previous'
15
+ rhythmbox "previous"
16
16
  super
17
17
  end
18
18
 
19
19
  def next
20
- rhythmbox 'next'
20
+ rhythmbox "next"
21
21
  super
22
22
  end
23
23
 
24
24
  def voldown
25
- rhythmbox 'volume-down'
25
+ rhythmbox "volume-down"
26
26
  end
27
27
 
28
28
  def volup
29
- rhythmbox 'volume-up'
29
+ rhythmbox "volume-up"
30
30
  end
31
31
 
32
32
  def volume
33
- rhythmbox 'print-volume'
33
+ rhythmbox "print-volume"
34
34
  end
35
35
 
36
36
  def track
37
- rhythmbox 'print-playing-format=%tt'
37
+ rhythmbox "print-playing-format=%tt"
38
38
  end
39
39
 
40
40
  def artist
41
- rhythmbox 'print-playing-format=%ta'
41
+ rhythmbox "print-playing-format=%ta"
42
42
  end
43
43
 
44
44
  def album
45
- rhythmbox 'print-playing-format=%at'
45
+ rhythmbox "print-playing-format=%at"
46
46
  end
47
47
 
48
48
  def launched?
@@ -50,8 +50,8 @@ class Anyplayer::Rhythmbox < Anyplayer::Player
50
50
  end
51
51
 
52
52
  private
53
- def rhythmbox(command)
54
- %x(rhythmbox-client --no-start --#{command}).rstrip
55
- end
56
- end
57
53
 
54
+ def rhythmbox(command)
55
+ %x(rhythmbox-client --no-start --#{command}).rstrip
56
+ end
57
+ end
@@ -1,66 +1,70 @@
1
1
  class Anyplayer::SpotifyMac < Anyplayer::Player
2
2
  def play
3
- spotify 'play'
3
+ spotify "play"
4
4
  end
5
5
 
6
6
  def pause
7
- spotify 'pause'
7
+ spotify "pause"
8
8
  end
9
9
 
10
10
  def playpause
11
- spotify 'playpause'
11
+ spotify "playpause"
12
12
  end
13
13
 
14
14
  def prev
15
- spotify 'previous track'
15
+ spotify "previous track"
16
16
  super
17
17
  end
18
18
 
19
19
  def next
20
- spotify 'next track'
20
+ spotify "next track"
21
21
  super
22
22
  end
23
23
 
24
24
  def voldown
25
- spotify 'set sound volume to sound volume - 10'
25
+ spotify "set sound volume to sound volume - 10"
26
26
  end
27
27
 
28
28
  def volup
29
- spotify 'set sound volume to sound volume + 10'
29
+ spotify "set sound volume to sound volume + 10"
30
30
  end
31
31
 
32
32
  def volume
33
- spotify 'return sound volume'
33
+ spotify "return sound volume"
34
34
  end
35
35
 
36
36
  def track
37
- spotify 'return name of current track'
37
+ spotify "return name of current track"
38
38
  end
39
39
 
40
40
  def artist
41
- spotify 'return artist of current track'
41
+ spotify "return artist of current track"
42
42
  end
43
43
 
44
44
  def album
45
- spotify 'return album of current track'
45
+ spotify "return album of current track"
46
46
  end
47
47
 
48
48
  def playing?
49
- playing = spotify 'return player state is playing'
49
+ playing = spotify "return player state is playing"
50
50
  playing == "true"
51
51
  end
52
52
 
53
53
  def launched?
54
- nb = %x(osascript -e 'tell app "System Events" to count (every process whose name is "Spotify")' 2>/dev/null).rstrip
55
- nb.match(/^\d+/) and nb.to_i > 0 ? true : false
54
+ %x(osascript -e 'app "Spotify" is running').rstrip == "true"
56
55
  end
57
56
 
58
57
  def name
59
58
  "Spotify Mac"
60
59
  end
61
60
 
61
+ def platforms
62
+ [:mac]
63
+ end
64
+
62
65
  private
63
- def spotify(command)
64
- %x(osascript -e 'tell app "spotify" to #{command}').rstrip
65
- end
66
+
67
+ def spotify(command)
68
+ %x(osascript -e 'tell app "Spotify" to #{command}').rstrip
69
+ end
66
70
  end
@@ -1,77 +1,87 @@
1
1
  class Anyplayer::Xmms2 < Anyplayer::Player
2
2
  def playpause
3
- xmms2 'toggle'
3
+ xmms2 "toggle"
4
4
  end
5
5
 
6
6
  def play
7
- xmms2 'play'
7
+ xmms2 "play"
8
8
  end
9
9
 
10
10
  def pause
11
- xmms2 'pause'
11
+ xmms2 "pause"
12
12
  end
13
13
 
14
14
  def prev
15
- xmms2 'prev'
15
+ xmms2 "prev"
16
16
  super
17
17
  end
18
18
 
19
19
  def next
20
- xmms2 'next'
20
+ xmms2 "next"
21
21
  super
22
22
  end
23
23
 
24
24
  def voldown
25
- current = volume.to_i
26
- new_volume = (current < 11 ? 0 : current - 10)
27
- xmms2 "server volume #{new_volume}"
25
+ set_volume volume - 10
28
26
  end
29
27
 
30
28
  def volup
31
- current = volume.to_i
32
- new_volume = (current > 89 ? 100 : current + 10)
33
- xmms2 "server volume #{new_volume}"
29
+ set_volume volume + 10
34
30
  end
35
31
 
36
32
  def volume
37
33
  # currently just the first (left?) channel
38
- xmms2('server volume').split("\n").first.sub(/([^0-9]*)/, '')
39
- $1
34
+ xmms2("server volume").split("\n").first.sub(/([^0-9]*)/, "").to_i
40
35
  end
41
36
 
42
37
  def track
43
- xmms2 "status -f '${title}'"
38
+ xmms2 "current -f '${title}'"
44
39
  end
45
40
 
46
41
  def artist
47
- xmms2 "status -f '${artist}'"
42
+ xmms2 "current -f '${artist}'"
48
43
  end
49
44
 
50
45
  def album
51
- xmms2 "status -f '${album}'"
46
+ xmms2 "current -f '${album}'"
52
47
  end
53
48
 
54
49
  def playing?
55
- xmms2("status -f '${playback_status}'") == "Playing"
50
+ xmms2("current -f '${playback_status}'") == "Playing"
56
51
  end
57
52
 
58
53
  def paused?
59
- xmms2("status -f '${playback_status}'") == "Paused"
54
+ xmms2("current -f '${playback_status}'") == "Paused"
60
55
  end
61
56
 
62
57
  def launched?
63
58
  # xmms2 autolaunches the daemon, so this should always be true
64
- %x(xmms2 status 2> /dev/null)
59
+ %x(xmms2 current 2> /dev/null)
65
60
  $? == 0
66
61
  end
67
62
 
68
63
  def host
69
- ENV['XMMS_PATH'] || super
64
+ ENV["XMMS_PATH"] || super
65
+ end
66
+
67
+ def platforms
68
+ [:unix, :linux]
70
69
  end
71
70
 
72
71
  private
73
- def xmms2(command)
74
- %x(xmms2 #{command}).split("\n").first.strip
75
- end
76
- end
77
72
 
73
+ def xmms2(command)
74
+ ret = %x(xmms2 #{command}).split("\n").first
75
+ ret ? ret.strip : ""
76
+ end
77
+
78
+ def set_volume(num)
79
+ num = if num < 0
80
+ 0
81
+ elsif num > 100
82
+ 100
83
+ end
84
+
85
+ xmms2 "server volume #{num}"
86
+ end
87
+ end