anyplayer 1.1.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: db0d0a016e49bc83fdef8aa9aec374fc8c5c593569b3ff5d2d9270a05b493458
4
+ data.tar.gz: 28b16e0ffeb7d097da4432700ebccb2ce08bf682609695b64b7125b90450a6cb
5
+ SHA512:
6
+ metadata.gz: 86bc595bacbe1256a03503ece20a14ff368c82955ed8bd168d6b8d68c7c4616909086ec5549ae3c0915a4155392b6bb4223ef9c3c257aa20c421874fdb171ceb
7
+ data.tar.gz: f3ccc7caac60e7fec74a9bc3dcf3270ec3b6ffd89e0454130e914774c82306b5751c98dc95f1dca0fe3ec7ecb58ae1dbfb2b0f4364f858d2e093a07e9763a064
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  *.bundle
4
-
4
+ Gemfile.lock
@@ -0,0 +1 @@
1
+ 2.7.1
@@ -1,4 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
3
+ - 2.7.0
@@ -0,0 +1,82 @@
1
+ Changelog
2
+ ---------
3
+
4
+ Anyplayer tries its best to follow Semantic Versioning.
5
+
6
+ ## Unreleased
7
+
8
+ ## v1.2.1 (2020-12-19)
9
+
10
+ Fixes:
11
+
12
+ - Remove rake executable in gemspec.
13
+
14
+ ## v1.2.0 (2020-10-08)
15
+
16
+ Features:
17
+
18
+ - When using mpd, fallback to the file name if there is no track name.
19
+
20
+ Dependencies:
21
+
22
+ - Drop Ruby 1.9.3 and 2.0.0 support.
23
+
24
+ ## v1.1.5 (2014-07-07)
25
+
26
+ Bugfixes:
27
+
28
+ - Better platform detection by letting players list the platforms
29
+ they are intended to work on (thanks @inspire22)
30
+
31
+ ## v1.1.4 (2014-07-07)
32
+
33
+ Bugfixes:
34
+
35
+ - Fix iTunes Windows support by moving iTunes first
36
+ - New developement task "rake console"
37
+ - Refactorisations & tests
38
+
39
+ ## v1.1.3 (2014-01-27)
40
+
41
+ Bugfixes:
42
+
43
+ - xmms2.0.8 support (thanks @ofa-)
44
+
45
+ ## v1.1.2 (2013-12-18)
46
+
47
+ Bugfixes:
48
+
49
+ - MIT License
50
+
51
+ ## v1.1.1 (2013-12-18)
52
+
53
+ Bugfixes:
54
+
55
+ - Better MPD support (thanks @nkoehring)
56
+ - Encoding fixes
57
+
58
+ ## v1.1.0 (2013-10-27)
59
+
60
+ Features:
61
+
62
+ - Add Rdio Mac support (thanks @irosenb)
63
+
64
+ ## v1.0.0 (2013-07-26)
65
+
66
+ First major release.
67
+
68
+ ## v0.0.4
69
+
70
+ Unstable version.
71
+
72
+ ## v0.0.3
73
+
74
+ Unstable version.
75
+
76
+ ## v0.0.2
77
+
78
+ Unstable version.
79
+
80
+ ## v0.0.1
81
+
82
+ Unstable version.
@@ -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
 
data/README.md CHANGED
@@ -43,8 +43,17 @@ a player is running
43
43
  Or in Ruby
44
44
  ----------
45
45
 
46
+ In your Gemfile:
47
+
48
+ ```rb
49
+ # Interact with the current music player
50
+ gem "anyplayer"
51
+ ```
52
+
53
+ In your code:
54
+
46
55
  ```ruby
47
- require 'anyplayer'
56
+ require "anyplayer"
48
57
  player = Anyplayer::Selector.new.player
49
58
 
50
59
  player.launched? # => true
@@ -62,28 +71,20 @@ With the [So Nice](https://github.com/sunny/so-nice/) Web interface:
62
71
  ![So Nice Screenshot](https://github.com/sunny/so-nice/raw/gh-pages/screenshot.png)
63
72
 
64
73
 
65
- Development
74
+ Contribute!
66
75
  -----------
67
76
 
68
- Use the `anyplayer` binary from source:
69
-
70
- ```sh
71
- $ ruby -Ilib bin/anyplayer
72
- ```
73
-
74
- Launch tests:
75
-
76
- ```sh
77
- $ bundle exec rake test
78
- ```
77
+ 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`.
79
78
 
80
- Install from source:
79
+ Here a few useful commands while developping:
81
80
 
82
81
  ```sh
83
- $ bundle exec rake install
82
+ $ ruby -Ilib bin/anyplayer # Use the anyplayer command-line from source
83
+ $ bin/rake test # Launch tests
84
+ $ bin/rake install # Install from source
85
+ $ bin/rake console # Launch console
84
86
  ```
85
87
 
86
- All contributions are welcome! Head to the [Github issues](https://github.com/sunny/anyplayer/issues) to report bugs, questions or code.
87
88
 
88
89
  License
89
90
  -------
data/Rakefile CHANGED
@@ -7,6 +7,16 @@ task :default => :test
7
7
 
8
8
  Rake::TestTask.new do |t|
9
9
  t.libs << "test"
10
+ t.libs << "lib"
10
11
  t.pattern = "test/**/*_test.rb"
11
12
  t.verbose = true
12
13
  end
14
+
15
+ # Via http://erniemiller.org/2014/02/05/7-lines-every-gems-rakefile-should-have/
16
+ task :console do
17
+ require 'irb'
18
+ require 'irb/completion'
19
+ require 'anyplayer'
20
+ ARGV.clear
21
+ IRB.start
22
+ end
@@ -15,10 +15,12 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.executables = ["anyplayer"]
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_runtime_dependency 'ruby-mpd', '~> 0.3.0'
22
+
22
23
  s.add_development_dependency 'minitest'
23
24
  s.add_development_dependency 'flexmock'
25
+ s.add_development_dependency 'rake'
24
26
  end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
@@ -1,13 +1,20 @@
1
1
  require "timeout"
2
2
 
3
3
  module Anyplayer
4
+ # Ordering of the players should put the most-used players and the fastest to
5
+ # test at the top.
6
+ #
7
+ # iTunes Windows has been placed at the top because of some linux false
8
+ # positives.
9
+ # https://github.com/sunny/anyplayer/issues/8
10
+
4
11
  PLAYERS = %w(
12
+ itunes_windows
5
13
  rhythmbox
6
14
  mpd
7
15
  xmms2
8
16
  amarok
9
17
  itunes_mac
10
- itunes_windows
11
18
  spotify_mac
12
19
  rdio_mac
13
20
  )
@@ -20,4 +27,3 @@ end
20
27
  require "anyplayer/player"
21
28
  require "anyplayer/selector"
22
29
  require "anyplayer/version"
23
-
@@ -4,12 +4,31 @@ require "anyplayer"
4
4
  module Anyplayer::CommandLine
5
5
  extend self
6
6
 
7
+ COMMANDS = %w(
8
+ playpause
9
+ play
10
+ pause
11
+ next
12
+ prev
13
+ voldown
14
+ volup
15
+ volume
16
+ track
17
+ artist
18
+ album
19
+ vote
20
+ name
21
+ launched
22
+ paused
23
+ playing
24
+ )
25
+
7
26
  def parse(argv)
8
27
  # Create a selector
9
28
  selector = Anyplayer::Selector.new
10
29
  if argv.first == "-v"
11
30
  selector.verbose = true
12
- argv.pop
31
+ argv.shift
13
32
 
14
33
  $stderr.puts "anyplayer v#{Anyplayer::VERSION}"
15
34
  end
@@ -18,36 +37,47 @@ module Anyplayer::CommandLine
18
37
  player = selector.player
19
38
  abort "Error: no player connected.\n" + selector.errors.join("\n") if !player
20
39
 
21
- # Call it
22
- case argv.first
23
- when "playpause" then player.playpause
24
- when "play" then player.play
25
- when "pause" then player.pause
26
- when "next" then player.next
27
- when "prev" then player.next
28
- when "voldown" then player.voldown
29
- when "volup" then player.volup
30
- when "volume" then puts player.volume
31
- when "track" then puts player.track
32
- when "artist" then puts player.artist
33
- when "album" then puts player.album
34
- when "vote" then player.vote
35
- when "name" then puts player.name
36
- when "launched" then exit(player.launched? ? 0 : 1)
37
- when "playing" then exit(player.playing? ? 0 : 1)
38
- when "paused" then exit(player.playing? ? 0 : 1)
40
+ # Call a command
41
+ if argv.empty?
42
+ usage(player)
39
43
  else
40
- puts <<USAGE
41
- Usage: anyplayer [-v] [command]
44
+ command(player, argv.first)
45
+ end
46
+ end
42
47
 
43
- Where command is one of: playpause, play, pause, next, prev, voldown, volup,
44
- volume, track, artist, album, vote, name, launched.
48
+ private
45
49
 
46
- Player connected: #{player.name}.
47
- USAGE
48
- exit(1)
50
+ # Call
51
+ def command(player, command)
52
+ response = call(player, command)
53
+
54
+ case response
55
+ when :undefined_command then usage(player)
56
+ when true then exit(0)
57
+ when false then exit(1)
58
+ when String, Numeric then puts response
59
+ end
60
+ end
61
+
62
+ # Call the method on the player
63
+ # Tries the boolean method as well
64
+ def call(player, command)
65
+ [command, "#{command}?"].each do |method|
66
+ method = method.to_sym
67
+ return player.send(method) if player.respond_to?(method)
49
68
  end
50
69
 
70
+ :undefined_command
51
71
  end
52
72
 
73
+ def usage(player)
74
+ $stderr.puts <<USAGE
75
+ Usage: anyplayer [-v] [command]
76
+
77
+ Where command is one of: #{COMMANDS.join(', ')}.
78
+
79
+ Player connected: #{player.name}.
80
+ USAGE
81
+ exit(1)
82
+ end
53
83
  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)
@@ -31,7 +31,12 @@ class Anyplayer::Player
31
31
  # Example:
32
32
  # player.name # => iTunes
33
33
  def name
34
- self.class.to_s.gsub(/^.*::/, '')
34
+ self.class.to_s.gsub(/^.*::/, "")
35
+ end
36
+
37
+ # Default paused is not playing
38
+ def paused?
39
+ !playing?
35
40
  end
36
41
 
37
42
  # Tells the player to toggle the pause state
@@ -65,11 +70,14 @@ class Anyplayer::Player
65
70
  reset_votes
66
71
  end
67
72
 
68
- private
73
+ # Operating systems where this player should work
74
+ def platforms
75
+ [:mac, :windows, :linux, :unix]
76
+ end
69
77
 
70
- def reset_votes
71
- @votes = 0
72
- end
78
+ private
73
79
 
80
+ def reset_votes
81
+ @votes = 0
82
+ end
74
83
  end
75
-
@@ -1,61 +1,67 @@
1
1
  class Anyplayer::Amarok < Anyplayer::Player
2
2
  def playpause
3
- amarok 'PlayPause'
3
+ amarok "PlayPause"
4
4
  end
5
5
 
6
6
  def play
7
- amarok 'Play'
7
+ amarok "Play"
8
8
  end
9
9
 
10
10
  def pause
11
- amarok 'Pause'
11
+ amarok "Pause"
12
12
  end
13
13
 
14
14
  def prev
15
- amarok 'Prev'
15
+ amarok "Prev"
16
16
  super
17
17
  end
18
18
 
19
19
  def next
20
- amarok 'Next'
20
+ amarok "Next"
21
21
  super
22
22
  end
23
23
 
24
24
  def voldown
25
- amarok 'VolumeDown 5'
25
+ amarok "VolumeDown 5"
26
26
  end
27
27
 
28
28
  def volup
29
- amarok 'VolumeUp 5'
29
+ amarok "VolumeUp 5"
30
30
  end
31
31
 
32
32
  def volume
33
- amarok 'VolumeGet'
33
+ amarok "VolumeGet"
34
34
  end
35
35
 
36
36
  def track
37
- amarok_get_meta 'title'
37
+ amarok_get_meta "title"
38
38
  end
39
39
 
40
40
  def artist
41
- amarok_get_meta 'artist'
41
+ amarok_get_meta "artist"
42
42
  end
43
43
 
44
44
  def album
45
- amarok_get_meta 'album'
45
+ amarok_get_meta "album"
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/)
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
  private
53
- def amarok(command)
54
- %x(qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.#{command}).rstrip
55
- end
56
59
 
57
- def amarok_get_meta(name)
58
- amarok('GetMetadata').match(/#{name}: (\S.*)/)[1] rescue nil
59
- end
60
- end
60
+ def amarok(command)
61
+ %x(qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.#{command}).rstrip
62
+ end
61
63
 
64
+ def amarok_get_meta(name)
65
+ amarok("GetMetadata").match(/#{name}: (\S.*)/)[1] rescue nil
66
+ end
67
+ end