anyplayer 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7c0e8833c889429188b5c5ff92bd15ce9d97986
4
- data.tar.gz: 7db1340983fa012cb778bad3ccb86975d0be6ebb
3
+ metadata.gz: 7ce9982f42d4ae01c721cf82f4fc09a4fc61740c
4
+ data.tar.gz: ea519d8ba4bde8f84b3e2ad253ce6e276c98673e
5
5
  SHA512:
6
- metadata.gz: 0723be193d651281e960aa660bf0fa58a732470866225b5cccb578d9ef469549c2fc3d9ad4f1fc3eab50db825df9e08bb27efad5b89d98cdc6c03ae2d78f6cb9
7
- data.tar.gz: 72929df7fd5b6e422174a97377261531dd99a0f5ce65a595e08b5fedbc1f3b5d886fa98d63e9b4344798678e78a304bd331b6b016bc8cc222dbd01ec52e7c127
6
+ metadata.gz: e488e5dca3e611699ffea03d075cd25a6c5376325974e2be1eabdc714cdc4e18b77f612dcbb2e0465e1508498d83f9b9b3e06c35a8f38de40c7c5926e526f619
7
+ data.tar.gz: 73788384a220e2b6434c7f966f3475ac281408c054af4de10e13e98f96b98e547dbb4aebfbfbf1d4c03bcdc4e8d3b3b9e0ddc2e005829d7fabc71a71c9d7a227
@@ -3,6 +3,13 @@ Changelog
3
3
 
4
4
  Anyplayer tries its best to follow Semantic Versioning.
5
5
 
6
+ ## v1.1.5 (2014-07-07)
7
+
8
+ Bugfixes:
9
+
10
+ - Better platform detection by letting players list the platforms
11
+ they are intended to work on.
12
+
6
13
  ## v1.1.4 (2014-07-07)
7
14
 
8
15
  Bugfixes:
@@ -0,0 +1,22 @@
1
+ Contributing
2
+ ============
3
+
4
+ All contributions are welcome! Head to the [Github issues](https://github.com/sunny/anyplayer/issues) to report bugs, questions or code.
5
+
6
+
7
+ Submit code
8
+ -----------
9
+
10
+ 1. Fork the repository on Github
11
+ 1. Create a topic branch
12
+ 1. Implement your feature and the accompanying tests
13
+ 1. Run `rake test` to make sure the tests are passing
14
+ 1. Add documentation for your feature or bug fix
15
+ 1. Add, commit, and push your changes
16
+ 1. Submit a pull request
17
+
18
+
19
+ Versionning
20
+ -----------
21
+
22
+ This library aims to adhere to [Semantic Versioning 2.0](http://semver.org/).
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "rake"
4
-
5
3
  # Gem dependencies in anyplayer.gemspec
6
4
  gemspec
7
5
 
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- anyplayer (1.1.3)
4
+ anyplayer (1.1.5)
5
5
  ruby-mpd (~> 0.3.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  flexmock (1.3.3)
11
- minitest (5.3.1)
12
- rake (0.9.2.2)
13
- ruby-mpd (0.3.1)
11
+ minitest (5.4.1)
12
+ rake (10.3.2)
13
+ ruby-mpd (0.3.2)
14
14
 
15
15
  PLATFORMS
16
16
  ruby
data/README.md CHANGED
@@ -62,9 +62,13 @@ With the [So Nice](https://github.com/sunny/so-nice/) Web interface:
62
62
  ![So Nice Screenshot](https://github.com/sunny/so-nice/raw/gh-pages/screenshot.png)
63
63
 
64
64
 
65
- Development
65
+ Contribute!
66
66
  -----------
67
67
 
68
+ All contributions are welcome! Head to the [Github issues](https://github.com/sunny/anyplayer/issues) to report bugs, questions or code. Also, check out `CONTRIBUTING.md`.
69
+
70
+ Here a few useful commands while developping:
71
+
68
72
  ```sh
69
73
  $ ruby -Ilib bin/anyplayer # Use the anyplayer command-line from source
70
74
  $ bundle exec rake test # Launch tests
@@ -72,7 +76,6 @@ $ bundle exec rake install # Install from source
72
76
  $ bundle exec rake console # Launch console
73
77
  ```
74
78
 
75
- All contributions are welcome! Head to the [Github issues](https://github.com/sunny/anyplayer/issues) to report bugs, questions or code.
76
79
 
77
80
  License
78
81
  -------
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.add_runtime_dependency 'ruby-mpd', '~> 0.3.0'
22
22
  s.add_development_dependency 'minitest'
23
23
  s.add_development_dependency 'flexmock'
24
+ s.add_development_dependency 'rake'
24
25
  end
@@ -1,4 +1,4 @@
1
- # Default Player class that is inherrited by all players.
1
+ # Default Player class that is inherited by all players.
2
2
  #
3
3
  # All players should override these methods:
4
4
  # launched? (return bool)
@@ -70,6 +70,11 @@ class Anyplayer::Player
70
70
  reset_votes
71
71
  end
72
72
 
73
+ # Operating systems where this player should work
74
+ def platforms
75
+ [:mac, :windows, :linux, :unix]
76
+ end
77
+
73
78
 
74
79
  private
75
80
 
@@ -46,7 +46,13 @@ class Anyplayer::Amarok < Anyplayer::Player
46
46
  end
47
47
 
48
48
  def launched?
49
- not %x(qdbus org.kde.amarok 2>&1).match(/does not exist|command not found|cannot find the path specified/)
49
+ not %x(qdbus org.kde.amarok 2>&1).match(
50
+ /does not exist|not found|cannot find the path specified/
51
+ )
52
+ end
53
+
54
+ def platforms
55
+ [:unix, :linux]
50
56
  end
51
57
 
52
58
 
@@ -51,14 +51,18 @@ class Anyplayer::ItunesMac < Anyplayer::Player
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
67
 
64
68
  def itunes(command)
@@ -1,7 +1,7 @@
1
1
  begin
2
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,6 +59,10 @@ class Anyplayer::ItunesWindows < Anyplayer::Player
59
59
  "iTunes Windows"
60
60
  end
61
61
 
62
+ def platforms
63
+ [:windows]
64
+ end
65
+
62
66
 
63
67
  private
64
68
 
@@ -2,10 +2,9 @@
2
2
  begin
3
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,14 +51,17 @@ class Anyplayer::RdioMac < Anyplayer::Player
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
 
63
66
  private
64
67
 
@@ -49,6 +49,7 @@ class Anyplayer::Rhythmbox < Anyplayer::Player
49
49
  %x(rhythmbox-client --no-start --print-playing 2>/dev/null).rstrip != ""
50
50
  end
51
51
 
52
+
52
53
  private
53
54
 
54
55
  def rhythmbox(command)
@@ -51,18 +51,21 @@ class Anyplayer::SpotifyMac < Anyplayer::Player
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
 
63
66
  private
64
67
 
65
68
  def spotify(command)
66
- %x(osascript -e 'tell app "spotify" to #{command}').rstrip
69
+ %x(osascript -e 'tell app "Spotify" to #{command}').rstrip
67
70
  end
68
71
  end
@@ -64,6 +64,10 @@ class Anyplayer::Xmms2 < Anyplayer::Player
64
64
  ENV['XMMS_PATH'] || super
65
65
  end
66
66
 
67
+ def platforms
68
+ [:unix, :linux]
69
+ end
70
+
67
71
 
68
72
  private
69
73
 
@@ -1,3 +1,5 @@
1
+ require "rbconfig"
2
+
1
3
  # The Selector is the tool that will find you the currently running player on your platform
2
4
  #
3
5
  # Example:
@@ -7,62 +9,93 @@
7
9
  # player = selector.player
8
10
  #
9
11
  # Needs the PLAYERS constant to contain a list of players.
12
+ module Anyplayer
13
+ class Selector
14
+ attr_accessor :verbose
15
+ attr_reader :errors
10
16
 
11
- class Anyplayer::Selector
12
- attr_accessor :verbose
13
- attr_reader :errors
17
+ def initialize
18
+ @verbose = false
19
+ @errors = []
20
+ end
14
21
 
15
- def initialize
16
- @verbose = false
17
- @errors = []
18
- end
22
+ # Returns an instance of the first music player that's launched
23
+ def player
24
+ PLAYERS.each do |player|
25
+ player_load(player) or next
19
26
 
20
- # Returns an instance of the first music player that's launched
21
- def player
22
- players_for_this_platform.each { |player|
23
- player_load(player) or next
24
- instance = player_class(player).new
25
- return instance if player_launched(instance)
26
- }
27
- nil
28
- end
27
+ instance = player_class(player).new
28
+ player_on_platform?(instance) or next
29
29
 
30
+ if player_launched?(instance)
31
+ return instance
32
+ end
33
+ end
34
+ nil
35
+ end
30
36
 
31
- private
32
37
 
33
- def players_for_this_platform
34
- players = Anyplayer::PLAYERS
35
- players.reject! { |player| player =~ /_mac$/ } if RUBY_PLATFORM !~ /darwin/
36
- players.reject! { |player| player =~ /_windows$/ } if RUBY_PLATFORM !~ /cygwin|mswin|mingw|bccwin|wince|emx/
37
- players
38
- end
38
+ private
39
39
 
40
- def player_load(player)
41
- begin
42
- require "anyplayer/players/#{player}"
43
- $stderr.puts "Loaded #{player}" if verbose
44
- true
45
- rescue LoadError => e
46
- $stderr.puts "Could not load #{player}" if verbose
47
- @errors << "Error loading #{player}: #{e.message}"
48
- false
40
+ def platform
41
+ @platform ||= begin
42
+ host_os = RbConfig::CONFIG["host_os"]
43
+ case host_os
44
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
45
+ :windows
46
+ when /darwin|mac os/
47
+ :mac
48
+ when /linux/
49
+ :linux
50
+ when /solaris|bsd/
51
+ :unix
52
+ else
53
+ @errors << "Unknown operating system #{host_os.inspect}"
54
+ nil
55
+ end
56
+ end
49
57
  end
50
- end
51
58
 
52
- def player_class(player)
53
- camelized = player.to_s.split(/_/).map{ |word| word.capitalize }.join
54
- Anyplayer::const_get(camelized)
55
- end
59
+ def player_load(player)
60
+ log "#{player}:"
61
+ begin
62
+ require "anyplayer/players/#{player}"
63
+ log " loaded"
64
+ true
65
+ rescue LoadError => e
66
+ log " #{e.message}"
67
+ @errors << "Error loading #{player}: #{e.message}"
68
+ false
69
+ end
70
+ end
71
+
72
+ def player_on_platform?(player)
73
+ result = player.platforms.include?(platform)
74
+ log " not on platform" if !result
75
+ result
76
+ end
56
77
 
57
- def player_launched(player)
58
- $stderr.puts "#{player.name} launched?" if verbose
78
+ def player_class(player)
79
+ camelized = player.to_s.split(/_/).map{ |word| word.capitalize }.join
80
+ Anyplayer::const_get(camelized)
81
+ end
82
+
83
+ def player_launched?(player)
84
+ seconds = 5
85
+ begin
86
+ Timeout::timeout(seconds) do
87
+ launched = player.launched?
88
+ log launched ? " launched" : " not launched"
89
+ launched
90
+ end
91
+ rescue Timeout::Error
92
+ log " timed out after #{seconds} seconds"
93
+ false
94
+ end
95
+ end
59
96
 
60
- seconds = 5
61
- begin
62
- Timeout::timeout(seconds) { player.launched? }
63
- rescue Timeout::Error
64
- $stderr.puts "Timed out after #{seconds} seconds" if verbose
65
- false
97
+ def log(text)
98
+ $stderr.puts text if verbose
66
99
  end
67
100
  end
68
101
  end
@@ -1,3 +1,3 @@
1
1
  module Anyplayer
2
- VERSION = "1.1.4"
2
+ VERSION = "1.1.5"
3
3
  end
@@ -19,7 +19,7 @@ class AnyplayerTest < Minitest::Test
19
19
  selector = Selector.new
20
20
  selector.verbose = true
21
21
 
22
- assert_output nil, "Loaded noplayer\nNoplayer launched?\n" do
22
+ assert_output nil, "noplayer:\n loaded\n launched\n" do
23
23
  selector.player
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anyplayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunny Ripert
@@ -9,48 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-07 00:00:00.000000000 Z
12
+ date: 2015-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-mpd
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
20
  version: 0.3.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: 0.3.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: minitest
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: flexmock
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
54
68
  - !ruby/object:Gem::Version
55
69
  version: '0'
56
70
  description: Play/pause/skip songs in iTunes Mac, iTunes Windows, Spotify Mac, Rdio
@@ -63,10 +77,11 @@ executables:
63
77
  extensions: []
64
78
  extra_rdoc_files: []
65
79
  files:
66
- - ".envrc"
67
- - ".gitignore"
68
- - ".travis.yml"
80
+ - .envrc
81
+ - .gitignore
82
+ - .travis.yml
69
83
  - CHANGELOG.md
84
+ - CONTRIBUTING.md
70
85
  - Gemfile
71
86
  - Gemfile.lock
72
87
  - MIT-LICENSE
@@ -104,17 +119,17 @@ require_paths:
104
119
  - lib
105
120
  required_ruby_version: !ruby/object:Gem::Requirement
106
121
  requirements:
107
- - - ">="
122
+ - - '>='
108
123
  - !ruby/object:Gem::Version
109
124
  version: '0'
110
125
  required_rubygems_version: !ruby/object:Gem::Requirement
111
126
  requirements:
112
- - - ">="
127
+ - - '>='
113
128
  - !ruby/object:Gem::Version
114
129
  version: '0'
115
130
  requirements: []
116
131
  rubyforge_project:
117
- rubygems_version: 2.1.11
132
+ rubygems_version: 2.4.5
118
133
  signing_key:
119
134
  specification_version: 4
120
135
  summary: Interact with the running music player