spty 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36a4a7466d3e6d655f2738738476d2411d604e12
4
- data.tar.gz: f16da74414643bf5380ddd217e81975878cebbd5
3
+ metadata.gz: 6da1e8db64f316e104c98ae9254b694e2e983a4a
4
+ data.tar.gz: 5d9656b5fb1b560c96caf5a6e889f31262731b37
5
5
  SHA512:
6
- metadata.gz: 833a1aac1594c88ff35ea7ae3c7e08bf93244537975a1686f1b5473efc89f92cb8c642b7a654ce1b7281cebc017fccdbf1109d60b32bf18357792b04f4e60226
7
- data.tar.gz: 9410b8bcb475f9904c712e506df2bb39bd334d8c68ea2c37cf15b127dbbefd4b16b152ef3312d1d263ca98574b96ddc0fb5a3e96c7ce1163f081264332a60f03
6
+ metadata.gz: 6d729c7902bf5557b31deb17e3f0841ade66b69b35e955d6d937b91bb1077e170401bdf0ba704af8781597e0597aa20dbc0c95d0a5375fa4fc311e39effeb272
7
+ data.tar.gz: 30b5202ddbc8cc4e4c97eb3ea8573122f332a8167dac46efcba4f9dc7b7fa81dd1190ced548b801089e701a1d301756a4b217342a331c396f8f003253f8c0128
data/README.md CHANGED
@@ -45,6 +45,26 @@ Replay previous track
45
45
  $ spty track replay
46
46
  ```
47
47
 
48
+ Show current volume level
49
+ ```
50
+ $ spty volume
51
+ ```
52
+
53
+ Increase the volume level by 10
54
+ ```
55
+ $ spty volume up
56
+ ```
57
+
58
+ Decrease the volume level by 10
59
+ ```
60
+ $ spty volume down
61
+ ```
62
+
63
+ Set the volume level with given number
64
+ ```
65
+ $ spty volume [number]
66
+ ```
67
+
48
68
  ## Contributing
49
69
 
50
70
  Bug reports and pull requests are welcome on GitHub at
@@ -7,8 +7,11 @@ module Spty
7
7
  klass = Object.const_get("Spty::Command::#{command.capitalize}Command")
8
8
  klass.(args, command)
9
9
  rescue NameError => _e
10
- puts "Do not understand command: #{command}"
11
- # [todo] display help menu with list of all valid commands
10
+ if !command.nil?
11
+ puts "Do not understand command: #{command}"
12
+ end
13
+
14
+ Spty::Command::HelpCommand.(args, command)
12
15
  end
13
16
  end
14
17
  end
@@ -0,0 +1,26 @@
1
+ module Spty::Command
2
+ class HelpCommand
3
+
4
+ HELP_TEXT =
5
+ "usage: spty <command> [<args>]\n"\
6
+ "\n"\
7
+ "Player specific command\n"\
8
+ " state Display teh current player state\n"\
9
+ " toggle Toggle player play or pause\n"\
10
+ " skip Skip the current track and play the next track\n"\
11
+ " replay Replay the current track\n"\
12
+ " volume Shows the current volume level"\
13
+ " volume up Increase the volume level by 10"\
14
+ " volume down Decrease the volume level by 11"\
15
+ " volume [number] Set the volume level to number"\
16
+ "\n"\
17
+ "Track specific command\n"\
18
+ " info Show information for the current track\n"\
19
+ "\n"\
20
+ "Version: #{Spty::VERSION}"
21
+
22
+ def self.call(_command, _)
23
+ puts HELP_TEXT
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ module Spty::Command
2
+ class LaunchCommand
3
+ ASCRIPT_PLAYER_LAUNCH = <<-EOL
4
+ tell application "Spotify" to activate
5
+ EOL
6
+
7
+ def self.call(_, _command = 'launch')
8
+ if Spty::Command::PlayerCommand.running?(show_mesg: false)
9
+ puts 'Spotify player is running'
10
+ return
11
+ end
12
+
13
+ Spty::AppleScriptRunner.(ASCRIPT_PLAYER_LAUNCH)
14
+ puts 'launching Spotify player'
15
+ end
16
+ end
17
+ end
@@ -8,11 +8,18 @@ module Spty::Command
8
8
  return "Not running"
9
9
  end if
10
10
  EOL
11
- def self.running?
11
+ def self.running?(show_mesg: true)
12
12
  player_running = Spty::AppleScriptRunner.(ASCRIPT_PLAYER_DETECT)
13
13
  return true if player_running.strip == 'Running'
14
14
 
15
- puts "=> player not running" and return false
15
+ if show_mesg
16
+ output = "player not running\n"\
17
+ "to launch Spotify player, use: spty launch"
18
+
19
+ puts output
20
+ end
21
+
22
+ false
16
23
  end
17
24
 
18
25
  # Method is depreciated. It calls the actuall method
@@ -0,0 +1,76 @@
1
+ module Spty::Command
2
+ class VolumeCommand
3
+ def self.call(options, _)
4
+ return unless Spty::Command::PlayerCommand.running?
5
+
6
+ action = options.shift
7
+
8
+ # call status if no sub command was called.
9
+ action = 'status' if action.nil?
10
+
11
+ # if sub command is number, trigger volume set with the number.
12
+ if action =~ /\A\d+\z/
13
+ options = action.to_i
14
+ action = 'level'
15
+ end
16
+
17
+ begin
18
+ send(action.to_sym, options)
19
+ rescue NameError => _e
20
+ puts "unknown volume command #{action}"
21
+ end
22
+ end
23
+
24
+ ASCRIPT_PLAYER_VOLUME_STATUS = <<-EOL
25
+ tell application "Spotify" to return sound volume
26
+ EOL
27
+ def self.status(_options = nil)
28
+ current_vol = Spty::AppleScriptRunner.call(ASCRIPT_PLAYER_VOLUME_STATUS)
29
+ puts "volume is at #{current_vol}"
30
+ end
31
+
32
+ ASCRIPT_PLAYER_VOLUME_UP = <<-EOL
33
+ tell application "Spotify"
34
+ set currentvol to get sound volume
35
+ if currentvol > 90 then
36
+ set sound volume to 100
37
+ else
38
+ set sound volume to currentvol + 10
39
+ end if
40
+ end tell
41
+ EOL
42
+ def self.up(_options)
43
+ Spty::AppleScriptRunner.call(ASCRIPT_PLAYER_VOLUME_UP)
44
+ status
45
+ end
46
+
47
+ ASCRIPT_PLAYER_VOLUME_DOWN = <<-EOL
48
+ tell application "Spotify"
49
+ set currentvol to get sound volume
50
+ if currentvol < 10 then
51
+ set sound volume to 0
52
+ else
53
+ set sound volume to currentvol - 10
54
+ end if
55
+ end tell
56
+ EOL
57
+ def self.down(_options)
58
+ Spty::AppleScriptRunner.call(ASCRIPT_PLAYER_VOLUME_DOWN)
59
+ status
60
+ end
61
+
62
+ ASCRIPT_PLAYER_VOLUME_SET = <<-EOL
63
+ tell application "Spotify" to set sound volume to %<level>s
64
+ EOL
65
+ def self.level(options)
66
+ if options < 0 || options > 100
67
+ puts 'volume level should be between 0 to 100'
68
+ return
69
+ end
70
+
71
+ script = format(ASCRIPT_PLAYER_VOLUME_SET, level: options)
72
+ Spty::AppleScriptRunner.call(script)
73
+ status
74
+ end
75
+ end
76
+ end
@@ -1,3 +1,3 @@
1
1
  module Spty
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
28
  spec.add_development_dependency "byebug", "~> 9.0"
29
+ spec.add_development_dependency "simplecov"
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - J Shamsul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-27 00:00:00.000000000 Z
11
+ date: 2017-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '9.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Control your Spotify player from the terminal. Currently only works for
70
84
  Mac OSX.
71
85
  email:
@@ -90,7 +104,9 @@ files:
90
104
  - lib/spty/apple_script_runner.rb
91
105
  - lib/spty/cli.rb
92
106
  - lib/spty/commands/base_command.rb
107
+ - lib/spty/commands/help_command.rb
93
108
  - lib/spty/commands/info_command.rb
109
+ - lib/spty/commands/launch_command.rb
94
110
  - lib/spty/commands/player_command.rb
95
111
  - lib/spty/commands/replay_command.rb
96
112
  - lib/spty/commands/skip_command.rb
@@ -98,6 +114,7 @@ files:
98
114
  - lib/spty/commands/toggle_command.rb
99
115
  - lib/spty/commands/track_command.rb
100
116
  - lib/spty/commands/version_command.rb
117
+ - lib/spty/commands/volume_command.rb
101
118
  - lib/spty/version.rb
102
119
  - spty.gemspec
103
120
  homepage: https://github.com/jibone/spty-rb