spty 0.1.1 → 0.2.0

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: f4bf611a743556028e87e5ba12d0e78b0aef712d
4
- data.tar.gz: 760bc10b111841e78da8ec217c5a9b127aa3f5b0
3
+ metadata.gz: 522850d6e6a9a6eb5f13810aa5d6fd1a7b5b2c5e
4
+ data.tar.gz: a60e505c3c678e4192c59d5eb92ac31e55f1295d
5
5
  SHA512:
6
- metadata.gz: 0d592b930d6189b56cc71eb55496e4a982974b99356017b49e214c5bd98b1cae1a92b39b96f2e50499f0f5925b83393a1691a553240f44406d0bd3088ed5ed40
7
- data.tar.gz: e7a288529fed2c78e54a719cbaa05c7500fe86db048e6baaf7b0e8595bdc455c980702b3163f41e5a972fc3660bdae15efe754bbdadf16e6db07893b1af0ac50
6
+ metadata.gz: 71ce6cce28e3d61f19cf9eb95f9cc6e6b2103f2bf414536df847ab49d467959a983765f050fffb2ef8b117916cc3a66cf8ae4bb2185424ae2f903b978ebe28ef
7
+ data.tar.gz: 15f6143a5197f7f1f7c677518ac3c30bb5f9d9be62779508e0f1f2031a1e8a9ed2fd50e7949a7716709838812d6c57d305c8315ff8e1c8afc4f433ac257779bb
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Spty
2
2
 
3
3
  Spotify Player Terminal Utility. CLI that lets you control your
4
- (Spotify)[http://spotify.com] player from the terminal. Only works on MacOSX as
5
- it uses (AppleScript Spotify API)[https://developer.spotify.com/applescript-api/]
4
+ [Spotify](http://spotify.com) player from the terminal. Only works on MacOSX as
5
+ it uses [AppleScript API](https://developer.spotify.com/applescript-api/)
6
6
  to control the player.
7
7
 
8
8
  ## Installation
@@ -30,6 +30,21 @@ Toggle player play / pause
30
30
  $ spty player toggle
31
31
  ```
32
32
 
33
+ Get track title and artist
34
+ ```
35
+ $ spty track info
36
+ ```
37
+
38
+ Skip track and play the next track
39
+ ```
40
+ $ spty track skip
41
+ ```
42
+
43
+ Replay previous track
44
+ ```
45
+ $ spty track replay
46
+ ```
47
+
33
48
  ## Contributing
34
49
 
35
50
  Bug reports and pull requests are welcome on GitHub at
@@ -5,7 +5,7 @@ module Spty
5
5
 
6
6
  begin
7
7
  klass = Object.const_get("Spty::Command::#{command.capitalize}Command")
8
- klass.(args)
8
+ klass.(args, command)
9
9
  rescue NameError => _e
10
10
  puts "Do not understand command: #{command}"
11
11
  # [todo] display help menu with list of all valid commands
@@ -0,0 +1,13 @@
1
+ module Spty::Command
2
+ class BaseCommand
3
+ def self.call(options, command)
4
+ action = options.shift
5
+
6
+ begin
7
+ self.send(action.to_sym, options)
8
+ rescue NameError => _e
9
+ puts "Do not understand command: #{command} #{action}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,15 +1,5 @@
1
1
  module Spty::Command
2
- class PlayerCommand
3
- def self.call(options)
4
- action = options.shift
5
-
6
- begin
7
- self.send(action.to_sym, options)
8
- rescue NameError => _e
9
- puts "Do not understand command: player #{action}"
10
- end
11
- end
12
-
2
+ class PlayerCommand < BaseCommand
13
3
  # Check if the application is running
14
4
  ASCRIPT_PLAYER_DETECT = <<-EOL
15
5
  if application "Spotify" is running then
@@ -0,0 +1,48 @@
1
+ module Spty::Command
2
+ class TrackCommand < BaseCommand
3
+ ASCRIPT_TRACK_INFO = <<-EOL
4
+ tell application "Spotify"
5
+ set currentTrack to name of current track as string
6
+ set currentArtist to artist of current track as string
7
+
8
+ return currentTrack & " - " & currentArtist
9
+ end tell
10
+ EOL
11
+ def self.info(_)
12
+ if Spty::Command::PlayerCommand.running?
13
+ track_info = Spty::AppleScriptRunner.(ASCRIPT_TRACK_INFO)
14
+ player_state_script = Spty::Command::PlayerCommand::ASCRIPT_PLAYER_STATE
15
+ player_state = Spty::AppleScriptRunner.(player_state_script)
16
+
17
+ puts "=> #{track_info.strip} [#{player_state.strip}]"
18
+ end
19
+ end
20
+
21
+ ASCRIPT_TRACK_SKIP = <<-EOL
22
+ tell application "Spotify"
23
+ next track
24
+ end tell
25
+ EOL
26
+ def self.skip(_)
27
+ move_track(ASCRIPT_TRACK_SKIP)
28
+ end
29
+
30
+ ASCRIPT_TRACK_REPLAY = <<-EOL
31
+ tell application "Spotify"
32
+ previous track
33
+ end tell
34
+ EOL
35
+ def self.replay(_)
36
+ move_track(ASCRIPT_TRACK_REPLAY)
37
+ end
38
+
39
+ def self.move_track(ascript)
40
+ if Spty::Command::PlayerCommand.running?
41
+ Spty::AppleScriptRunner.(ascript)
42
+ Spty::Command::TrackCommand.info(nil)
43
+ end
44
+ end
45
+
46
+ private_class_method :move_track
47
+ end
48
+ end
@@ -1,6 +1,6 @@
1
1
  module Spty::Command
2
2
  class VersionCommand
3
- def self.call(options)
3
+ def self.call(_, _)
4
4
  puts "Version: #{Spty::VERSION}"
5
5
  end
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module Spty
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.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.1.1
4
+ version: 0.2.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-07-23 00:00:00.000000000 Z
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,7 +90,9 @@ files:
90
90
  - lib/spty.rb
91
91
  - lib/spty/apple_script_runner.rb
92
92
  - lib/spty/cli.rb
93
+ - lib/spty/commands/base_command.rb
93
94
  - lib/spty/commands/player_command.rb
95
+ - lib/spty/commands/track_command.rb
94
96
  - lib/spty/commands/version_command.rb
95
97
  - lib/spty/version.rb
96
98
  - spty.gemspec