spotify_osx_controller 1.0.0 → 2.0.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: 3a0952ea1a29701c386ce144c4f5913a9eccb455
4
- data.tar.gz: 4ab0338761fd7482aa23f06ebf371a4ed82e0ac4
3
+ metadata.gz: 5382df5adfa86b5ad63d2b7be7c8a5f677290ada
4
+ data.tar.gz: f7d85d51e1cc85b777502fc491e19655a4077444
5
5
  SHA512:
6
- metadata.gz: aa3f2947d98531495e70eee3c2cbd7e3c903c0b381ea38f92a4dd148788840a67b95e4d511c21e0647209f96bdb0f3c99b82959d97f834beb5686e7474861db0
7
- data.tar.gz: f7d8a6ae7668bf2a9b5e6ae0f89570231c0d4986ca221aa804c6691820cd77303e1f40c104738b7181822b8d3a7def19735b873d5027e24c8bba54b9c56c1b36
6
+ metadata.gz: 8b2c4eafede4cfa62eda1d0737f9a8eb8cf8cd64d22b0e7d629b58e464fe03c6b9845914c6c29e4972284c970c82b1c1c0c3a861b69ea6d9709ae987674144ed
7
+ data.tar.gz: 1551684368962b225448391397fecd70023e1ffb743e57945c8af68ac2d35bed05f6d3c8ec967fe263ac808b645ab56c39ebad3699280720c47f63ec87bbeef5
data/.gitignore CHANGED
@@ -7,4 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- *.gem
10
+ *.gem
11
+ .DS_Store
data/README.md CHANGED
@@ -7,19 +7,20 @@ Apple script forked from: [dronir/SpotifyControl](https://github.com/dronir/Spot
7
7
  ## Command-line options
8
8
 
9
9
  ```
10
- -p, --play <s>: Start playback of the given track, where <s> is the spotify URI
11
- -P, --play-pause: Play/pause playback
12
- -s, --stop: Stop playback
13
- -n, --next: Play next track
14
- -N, --previous: Play previous track
15
- -j, --jump <i>: Jump to position given position of the current track, where <i> is track position in
16
- seconds
17
- -f, --forward <i>: Jump <i> number of seconds ahead
18
- -r, --rewind <i>: Rewind <i> number of seconds backwards
19
- -v, --volume <i>: Set playback volume to <i>, where <i> is number between 0 and 100
20
- -S, --shuffle: Toggle shuffle
21
- -R, --repeat: Toggle repeat
22
- -i, --info: Display information about the current track
10
+ spotify_osx_controller [options] play [--track=<name>][--artist=<name>][--album=<name>] Start playback
11
+ spotify_osx_controller [options] play-pause Play/pause playback
12
+ spotify_osx_controller [options] stop Stop playback
13
+ spotify_osx_controller [options] next Play next track
14
+ spotify_osx_controller [options] previous Play previous track
15
+ spotify_osx_controller [options] jump [--seconds=<seconds>] Jump to <seconds> of current track
16
+ spotify_osx_controller [options] forward [--seconds=<seconds>] Jump <seconds> ahead
17
+ spotify_osx_controller [options] rewind [--seconds=<seconds>] Rewind <seconds> backwards
18
+
19
+ Where available [options] are the following:
20
+ -v, --volume=<i> Set playback volume to <i>, where <i> is number between 0 and 100
21
+ -S, --shuffle Toggle shuffle
22
+ -R, --repeat Toggle repeat
23
+ -i, --info Display information about the current track
23
24
  ```
24
25
 
25
26
  ## Installation
@@ -3,56 +3,94 @@ require "spotify_osx_controller"
3
3
  require "trollop"
4
4
 
5
5
 
6
+ SUB_COMMANDS = %w(play play-pause stop next previous jump forward rewind)
6
7
  opts = Trollop::options do
7
- banner <<-EOS
8
- OSX CLI for Spotify
8
+ banner <<-EOS
9
+ OSX CLI for Spotify
9
10
 
10
11
  Usage:
11
- spotify_osx_controller [command]
12
-
13
- Where [command] is one of the following:
14
-
15
- EOS
16
- opt :play, 'Start playback of the given track, where <s> is the spotify URI', type: :string, short: 'p', default: nil
17
- opt :play_pause, 'Play/pause playback', type: :boolean, short: 'P'
18
- opt :stop, 'Stop playback'
19
- opt :next, 'Play next track'
20
- opt :previous, 'Play previous track', short: 'N'
21
- opt :jump, 'Jump to position given position of the current track, where <i> is track position in seconds', type: :integer
22
- opt :forward, 'Jump <i> number of seconds ahead', type: :integer
23
- opt :rewind, 'Rewind <i> number of seconds backwards', type: :integer
12
+
13
+ spotify_osx_controller [options] play [--track=<name>] [--artist=<name>] [--album=<name>] Start playback
14
+ spotify_osx_controller [options] play-pause Play/pause playback
15
+ spotify_osx_controller [options] stop Stop playback
16
+ spotify_osx_controller [options] next Play next track
17
+ spotify_osx_controller [options] previous Play previous track
18
+ spotify_osx_controller [options] jump [--seconds=<seconds>] Jump to <seconds> of current track
19
+ spotify_osx_controller [options] forward [--seconds=<seconds>] Jump <seconds> ahead
20
+ spotify_osx_controller [options] rewind [--seconds=<seconds>] Rewind <seconds> backwards
21
+
22
+ Where available [options] are the following:
23
+
24
+ EOS
25
+
24
26
  opt :volume, 'Set playback volume to <i>, where <i> is number between 0 and 100', type: :integer
25
27
  opt :shuffle, 'Toggle shuffle', type: :boolean, short: 'S'
26
28
  opt :repeat, 'Toggle repeat', type: :boolean, short: 'R'
27
- opt :info, 'Display information about the current track'
28
- conflicts :play, :play_pause, :next, :previous, :jump, :forward, :rewind, :volume, :shuffle, :repeat, :info
29
+ opt :info, 'Display information about the current track', type: :boolean, short: 'i'
30
+ stop_on SUB_COMMANDS
29
31
  end
30
32
 
31
33
 
34
+ def global_cmds (opts)
35
+ if opts[:volume]
36
+ Trollop::die :volume, "must be between 0 and 100" if opts[:volume] < 0 or opts[:volume] > 100
37
+ SpotifyOsxController.volume opts[:volume]
38
+ end
39
+ if opts[:shuffle]
40
+ SpotifyOsxController.shuffle
41
+ end
42
+ if opts[:repeat]
43
+ SpotifyOsxController.repeat
44
+ end
45
+ if opts[:info]
46
+ SpotifyOsxController.info
47
+ end
48
+ end
49
+
32
50
 
33
- if opts[:play]
34
- SpotifyOsxController.play opts[:play]
35
- elsif opts[:play_pause]
51
+ cmd = ARGV.shift
52
+ case cmd
53
+ when "play"
54
+ cmd_opts = Trollop::options do
55
+ opt :track, "Track to play", type: :strings, short: 't', default: []
56
+ opt :artist, "Artist to play", type: :strings, short: 'a', default: []
57
+ opt :album, "Album to play", type: :strings, short: 'A', default: []
58
+ end
59
+ SpotifyOsxController.play track: cmd_opts[:track], artist: cmd_opts[:artist], album: cmd_opts[:album]
60
+ when "play-pause"
36
61
  SpotifyOsxController.play_pause
37
- elsif opts[:stop]
62
+ when "stop"
38
63
  SpotifyOsxController.pause
39
- elsif opts[:next]
64
+ when "next"
40
65
  SpotifyOsxController.next
41
- elsif opts[:previous]
66
+ when "previous"
42
67
  SpotifyOsxController.previous
43
- elsif opts[:jump]
44
- SpotifyOsxController.jump opts[:jump]
45
- elsif opts[:forward]
46
- SpotifyOsxController.forward opts[:forward]
47
- elsif opts[:rewind]
48
- SpotifyOsxController.rewind opts[:rewind]
49
- elsif opts[:volume]
50
- Trollop::die :volume, "must be between 0 and 100" if opts[:volume] < 0 or opts[:volume] > 100
51
- SpotifyOsxController.volume opts[:volume]
52
- elsif opts[:shuffle]
53
- SpotifyOsxController.shuffle
54
- elsif opts[:repeat]
55
- SpotifyOsxController.repeat
56
- elsif opts[:info]
57
- SpotifyOsxController.info
68
+ when "jump"
69
+ cmd_opts = Trollop::options do
70
+ opt :seconds, "Position in seconds to start play from", type: :integer, short: 's', required: true
71
+ end
72
+ Trollop::die :seconds, "must be greater that 0" if cmd_opts[:seconds] < 0
73
+ SpotifyOsxController.jump cmd_opts[:seconds]
74
+ when "forward"
75
+ cmd_opts = Trollop::options do
76
+ opt :seconds, "Number of seconds to jump ahead", type: :integer, short: 's', required: true
77
+ end
78
+
79
+ SpotifyOsxController.forward cmd_opts[:seconds]
80
+ when "rewind"
81
+ cmd_opts = Trollop::options do
82
+ opt :seconds, "Number of seconds to rewind", type: :integer, short: 's', required: true
83
+ end
84
+
85
+ SpotifyOsxController.rewind cmd_opts[:seconds]
86
+
87
+ when nil
88
+ global_cmds opts
89
+ run_global = true
90
+ else
91
+ Trollop::die "unknown subcommand #{cmd.inspect}"
58
92
  end
93
+
94
+ global_cmds opts if !run_global
95
+
96
+
@@ -0,0 +1,43 @@
1
+ require "rspotify"
2
+
3
+ module SpotifyOsxController
4
+
5
+ class Search
6
+
7
+ def initialize (parameters = {})
8
+ @track = parse parameters[:track]
9
+ @artist = parse parameters[:artist]
10
+ @album = parse parameters[:album]
11
+ @query = construct_query
12
+ @results = run_query
13
+ end
14
+
15
+ def any?
16
+ @results.any?
17
+ end
18
+
19
+ def first
20
+ @results.first
21
+ end
22
+
23
+ private
24
+
25
+ def run_query ()
26
+ RSpotify::Track.search @query
27
+ end
28
+
29
+ def parse (array)
30
+ array.join('+') if array
31
+ end
32
+
33
+ def construct_query
34
+ query = ""
35
+ query += "artist:#{@artist} " if !@artist.empty?
36
+ query += "track:#{@track} " if !@track.empty?
37
+ query += "album:#{@album}" if !@album.empty?
38
+ query
39
+ end
40
+ end
41
+
42
+
43
+ end
@@ -1,3 +1,3 @@
1
1
  module SpotifyOsxController
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,9 +1,18 @@
1
1
  require "spotify_osx_controller/version"
2
+ require "spotify_osx_controller/search.rb"
2
3
 
3
4
  module SpotifyOsxController
4
- def self.play(url)
5
- if url
6
- buildScript "tell application \"Spotify\" to play track \"#{url}\"\n"
5
+
6
+ def self.play(parameters = {})
7
+ if !parameters.values.all? &:empty?
8
+ search = Search.new(parameters)
9
+
10
+ if search.any?
11
+ uri = search.first.uri
12
+ buildScript "tell application \"Spotify\" to play track \"#{uri}\"\n"
13
+ else
14
+ puts "Error: no results"
15
+ end
7
16
  else
8
17
  buildScript "tell application \"Spotify\" to play\n"
9
18
  end
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_dependency "trollop"
26
+ spec.add_dependency "rspotify", "~> 1.0"
26
27
  spec.add_development_dependency "bundler", "~> 1.9"
27
28
  spec.add_development_dependency "rake", "~> 10.0"
28
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spotify_osx_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Swensson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-14 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspotify
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -68,6 +82,7 @@ files:
68
82
  - Rakefile
69
83
  - bin/spotify_osx_controller
70
84
  - lib/spotify_osx_controller.rb
85
+ - lib/spotify_osx_controller/search.rb
71
86
  - lib/spotify_osx_controller/version.rb
72
87
  - spotify_osx_controller.gemspec
73
88
  homepage: https://github.com/DanielSwensson/SpotifyControl