spty 0.4.0 → 0.5.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: 6da1e8db64f316e104c98ae9254b694e2e983a4a
4
- data.tar.gz: 5d9656b5fb1b560c96caf5a6e889f31262731b37
3
+ metadata.gz: 03f320416e178aac141deb66fcb50a15c0855920
4
+ data.tar.gz: 612e24b134d748dfe3b1a96068dc10bdefcea377
5
5
  SHA512:
6
- metadata.gz: 6d729c7902bf5557b31deb17e3f0841ade66b69b35e955d6d937b91bb1077e170401bdf0ba704af8781597e0597aa20dbc0c95d0a5375fa4fc311e39effeb272
7
- data.tar.gz: 30b5202ddbc8cc4e4c97eb3ea8573122f332a8167dac46efcba4f9dc7b7fa81dd1190ced548b801089e701a1d301756a4b217342a331c396f8f003253f8c0128
6
+ metadata.gz: 03da0ee0f8774e25bc36fb6fb8a37bbff58c7ffa3a9f7c5c089f1a509088e4c3c67aa4432b596f2a697dbaf70e930ae21aac8075b7582b2e33f65be228cfd11c
7
+ data.tar.gz: cd384ef7c3c4612f87fdd0fce4dd4f4c73e58814ed8a743f7344f3f19cd58eaccea0d63a87a60b53829c37cb65cc6445c14d63cd8f785f496df9e8ee315054ad
data/README.md CHANGED
@@ -22,27 +22,27 @@ $ spty version
22
22
 
23
23
  Show current player state
24
24
  ```
25
- $ spty player state
25
+ $ spty state
26
26
  ```
27
27
 
28
28
  Toggle player play / pause
29
29
  ```
30
- $ spty player toggle
30
+ $ spty toggle
31
31
  ```
32
32
 
33
33
  Get track title and artist
34
34
  ```
35
- $ spty track info
35
+ $ spty info
36
36
  ```
37
37
 
38
38
  Skip track and play the next track
39
39
  ```
40
- $ spty track skip
40
+ $ spty skip
41
41
  ```
42
42
 
43
43
  Replay previous track
44
44
  ```
45
- $ spty track replay
45
+ $ spty replay
46
46
  ```
47
47
 
48
48
  Show current volume level
@@ -1,13 +1,25 @@
1
1
  module Spty::Command
2
2
  class BaseCommand
3
- def self.call(options, command)
4
- action = options.shift
3
+ # Check if the application is running
4
+ ASCRIPT_PLAYER_DETECT = <<-EOL
5
+ if application "Spotify" is running then
6
+ return "Running"
7
+ else
8
+ return "Not running"
9
+ end if
10
+ EOL
11
+ def self.running?(show_mesg: true)
12
+ player_running = Spty::AppleScriptRunner.(ASCRIPT_PLAYER_DETECT)
13
+ return true if player_running.strip == 'Running'
5
14
 
6
- begin
7
- self.send(action.to_sym, options)
8
- rescue NameError => _e
9
- puts "Do not understand command: #{command} #{action}"
15
+ if show_mesg
16
+ output = "player not running\n"\
17
+ "to launch Spotify player, use: spty launch"
18
+
19
+ puts output
10
20
  end
21
+
22
+ false
11
23
  end
12
24
  end
13
25
  end
@@ -1,6 +1,5 @@
1
1
  module Spty::Command
2
2
  class HelpCommand
3
-
4
3
  HELP_TEXT =
5
4
  "usage: spty <command> [<args>]\n"\
6
5
  "\n"\
@@ -9,10 +8,10 @@ module Spty::Command
9
8
  " toggle Toggle player play or pause\n"\
10
9
  " skip Skip the current track and play the next track\n"\
11
10
  " 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"\
11
+ " volume Shows the current volume level\n"\
12
+ " volume up Increase the volume level by 10\n"\
13
+ " volume down Decrease the volume level by 11\n"\
14
+ " volume [number] Set the volume level to number\n"\
16
15
  "\n"\
17
16
  "Track specific command\n"\
18
17
  " info Show information for the current track\n"\
@@ -1,5 +1,5 @@
1
1
  module Spty::Command
2
- class InfoCommand
2
+ class InfoCommand < BaseCommand
3
3
  ASCRIPT_TRACK_INFO = <<-EOL
4
4
  tell application "Spotify"
5
5
  set currentTrack to name of current track as string
@@ -9,13 +9,13 @@ module Spty::Command
9
9
  end tell
10
10
  EOL
11
11
  def self.call(_, _command = 'info')
12
- if Spty::Command::PlayerCommand.running?
13
- track_info = Spty::AppleScriptRunner.(ASCRIPT_TRACK_INFO)
14
- player_state_script = Spty::Command::StateCommand::ASCRIPT_PLAYER_STATE
15
- player_state = Spty::AppleScriptRunner.(player_state_script)
12
+ return unless running?
16
13
 
17
- puts "=> #{track_info.strip} [#{player_state.strip}]"
18
- end
14
+ track_info = Spty::AppleScriptRunner.(ASCRIPT_TRACK_INFO)
15
+ player_state_script = Spty::Command::StateCommand::ASCRIPT_PLAYER_STATE
16
+ player_state = Spty::AppleScriptRunner.(player_state_script)
17
+
18
+ puts "=> #{track_info.strip} [#{player_state.strip}]"
19
19
  end
20
20
  end
21
21
  end
@@ -1,11 +1,11 @@
1
1
  module Spty::Command
2
- class LaunchCommand
2
+ class LaunchCommand < BaseCommand
3
3
  ASCRIPT_PLAYER_LAUNCH = <<-EOL
4
4
  tell application "Spotify" to activate
5
5
  EOL
6
6
 
7
7
  def self.call(_, _command = 'launch')
8
- if Spty::Command::PlayerCommand.running?(show_mesg: false)
8
+ if running?(show_mesg: false)
9
9
  puts 'Spotify player is running'
10
10
  return
11
11
  end
@@ -7,10 +7,10 @@ module Spty::Command
7
7
  end tell
8
8
  EOL
9
9
  def self.call(_, command = 'replay')
10
- if Spty::Command::PlayerCommand.running?
11
- Spty::AppleScriptRunner.(ASCRIPT_TRACK_REPLAY)
12
- Spty::Command::InfoCommand.(nil, command)
13
- end
10
+ return unless running?
11
+
12
+ Spty::AppleScriptRunner.(ASCRIPT_TRACK_REPLAY)
13
+ Spty::Command::InfoCommand.(nil, command)
14
14
  end
15
15
 
16
16
  end
@@ -1,16 +1,15 @@
1
1
  module Spty::Command
2
- class SkipCommand
3
-
2
+ class SkipCommand < BaseCommand
4
3
  ASCRIPT_TRACK_SKIP = <<-EOL
5
4
  tell application "Spotify"
6
5
  next track
7
6
  end tell
8
7
  EOL
9
8
  def self.call(_, command = 'skip')
10
- if Spty::Command::PlayerCommand.running?
11
- Spty::AppleScriptRunner.(ASCRIPT_TRACK_SKIP)
12
- Spty::Command::InfoCommand.(nil, command)
13
- end
9
+ return unless running?
10
+
11
+ Spty::AppleScriptRunner.(ASCRIPT_TRACK_SKIP)
12
+ Spty::Command::InfoCommand.(nil, command)
14
13
  end
15
14
 
16
15
  end
@@ -1,14 +1,14 @@
1
1
  module Spty::Command
2
- class StateCommand
2
+ class StateCommand < BaseCommand
3
3
  # Display the current state of the player.
4
4
  ASCRIPT_PLAYER_STATE = <<-EOL
5
5
  tell application "Spotify" to return player state
6
6
  EOL
7
7
  def self.call(_, _command = nil)
8
- if Spty::Command::PlayerCommand.running?
9
- player_state = Spty::AppleScriptRunner.(ASCRIPT_PLAYER_STATE)
10
- puts "=> player #{player_state}"
11
- end
8
+ return unless running?
9
+
10
+ player_state = Spty::AppleScriptRunner.(ASCRIPT_PLAYER_STATE)
11
+ puts "=> player #{player_state}"
12
12
  end
13
13
  end
14
14
  end
@@ -1,14 +1,14 @@
1
1
  module Spty::Command
2
- class ToggleCommand
2
+ class ToggleCommand < BaseCommand
3
3
  # Toggle player play / pause
4
4
  ASCRIPT_PLAYER_TOGGLE = <<-EOL
5
5
  tell application "Spotify" to playpause
6
6
  EOL
7
7
  def self.call(_, command = 'toggle')
8
- if Spty::Command::PlayerCommand.running?
9
- Spty::AppleScriptRunner.(ASCRIPT_PLAYER_TOGGLE)
10
- Spty::Command::StateCommand.(nil, command)
11
- end
8
+ return unless running?
9
+
10
+ Spty::AppleScriptRunner.(ASCRIPT_PLAYER_TOGGLE)
11
+ Spty::Command::StateCommand.(nil, command)
12
12
  end
13
13
  end
14
14
  end
@@ -1,7 +1,7 @@
1
1
  module Spty::Command
2
- class VolumeCommand
2
+ class VolumeCommand < BaseCommand
3
3
  def self.call(options, _)
4
- return unless Spty::Command::PlayerCommand.running?
4
+ return unless running?
5
5
 
6
6
  action = options.shift
7
7
 
@@ -1,3 +1,3 @@
1
1
  module Spty
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  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.4.0
4
+ version: 0.5.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-09-10 00:00:00.000000000 Z
11
+ date: 2017-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,12 +107,10 @@ files:
107
107
  - lib/spty/commands/help_command.rb
108
108
  - lib/spty/commands/info_command.rb
109
109
  - lib/spty/commands/launch_command.rb
110
- - lib/spty/commands/player_command.rb
111
110
  - lib/spty/commands/replay_command.rb
112
111
  - lib/spty/commands/skip_command.rb
113
112
  - lib/spty/commands/state_command.rb
114
113
  - lib/spty/commands/toggle_command.rb
115
- - lib/spty/commands/track_command.rb
116
114
  - lib/spty/commands/version_command.rb
117
115
  - lib/spty/commands/volume_command.rb
118
116
  - lib/spty/version.rb
@@ -1,43 +0,0 @@
1
- module Spty::Command
2
- class PlayerCommand < BaseCommand
3
- # Check if the application is running
4
- ASCRIPT_PLAYER_DETECT = <<-EOL
5
- if application "Spotify" is running then
6
- return "Running"
7
- else
8
- return "Not running"
9
- end if
10
- EOL
11
- def self.running?(show_mesg: true)
12
- player_running = Spty::AppleScriptRunner.(ASCRIPT_PLAYER_DETECT)
13
- return true if player_running.strip == 'Running'
14
-
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
23
- end
24
-
25
- # Method is depreciated. It calls the actuall method
26
- # This method should be removed on next release
27
- def self.state(_, command = 'state')
28
- if running?
29
- Spty::Command::StateCommand.('state')
30
- puts "Command is deprecated. Use \"spty #{command}\"."
31
- end
32
- end
33
-
34
- # Method is depreciated. It calls the actuall method
35
- # This method should be removed on next release
36
- def self.toggle(_, command = 'toggle')
37
- if running?
38
- Spty::Command::ToggleCommand.(nil, 'toggle')
39
- puts "Command is deprecated. Use \"spty #{command}\"."
40
- end
41
- end
42
- end
43
- end
@@ -1,26 +0,0 @@
1
- module Spty::Command
2
- class TrackCommand < BaseCommand
3
-
4
- # This command is deprecated.
5
- def self.info(_, command = 'info')
6
- if Spty::Command::PlayerCommand.running?
7
- Spty::Command::InfoCommand.(nil, 'info')
8
- puts "Command is deprecated. Use \"spty #{command}\"."
9
- end
10
- end
11
-
12
- # This command is deprecated.
13
- def self.skip(_)
14
- Spty::Command::SkipCommand.call(nil)
15
- puts 'Command is deprecated. Use "spty skip".'
16
- end
17
-
18
- # This command is deprecared.
19
- def self.replay(_)
20
- #move_track(ASCRIPT_TRACK_REPLAY, 'replay')
21
- Spty::Command::ReplayCommand.call(nil)
22
- puts 'Command is deprecated. Use "spty replay".'
23
- end
24
-
25
- end
26
- end