itunes-client 0.0.6 → 0.1.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: 73cbf11e4ffba3ff0928c8a872eb181e7ad6d941
4
- data.tar.gz: a7ee4be0ffb87dd6169c8a2c6291cf942d7d71d5
3
+ metadata.gz: 84cff6353f729ae6ed533ee0ea61f5ef4bc054f0
4
+ data.tar.gz: 69f8934039019946f497a38aaca502590948261c
5
5
  SHA512:
6
- metadata.gz: 63183e8d33a3c6237361293e7e0f77f72f52748199d5dd30e8a8598ff47217222a86924be98d426dd9d778adf0dc3fa044e742fa96fce5bcda0b16e97460659d
7
- data.tar.gz: 5e17dac860ead5cd8903a4879f2a7bb24cec14ea0760d1b86161e408274ece35e7919980da56259278d8972f2997ea664b15e11ae1611abe7d408b1ccdfa0a6d
6
+ metadata.gz: b65f4e065e816a8d61d8c04266d11a56e60cd60fd59c967648b1adb2ec335e53ffc4dc5a873a7aa1338b36b5f15489545ec146f8a1ddd5c5f0411805311aef0e
7
+ data.tar.gz: a4ef2807ecfca46366828afc7e2edf0551a178c9a73d9145ac7ff8ee1aee1f70669813adce4da7c12a12901a6a3eeed1c86c23caa320081a62c6c90a32dfc835
@@ -0,0 +1,55 @@
1
+ # coding: utf-8
2
+ require 'singleton'
3
+
4
+ require 'itunes/track'
5
+ require 'itunes/util'
6
+
7
+ module Itunes
8
+ class Player
9
+ extend Itunes::Util::Executor
10
+
11
+ class << self
12
+ def add(file_path)
13
+ persistent_id = execute_script("#{script_dir}/add.scpt", file_path)
14
+ Track.find_by(persistent_id: persistent_id).first
15
+ end
16
+
17
+ def stop
18
+ execute_script("#{script_dir}/stop.scpt")
19
+ self
20
+ end
21
+
22
+ def pause
23
+ execute_script("#{script_dir}/pause.scpt")
24
+ self
25
+ end
26
+
27
+ def playing?
28
+ execute_script("#{script_dir}/player_state.scpt") == 'playing'
29
+ end
30
+
31
+ def paused?
32
+ execute_script("#{script_dir}/player_state.scpt") == 'paused'
33
+ end
34
+
35
+ def stopped?
36
+ execute_script("#{script_dir}/player_state.scpt") == 'stopped'
37
+ end
38
+
39
+ def next_track
40
+ persistent_id = execute_script("#{script_dir}/next_track.scpt")
41
+ Track.find_by(persistent_id: persistent_id).first
42
+ end
43
+
44
+ def prev_track
45
+ persistent_id = execute_script("#{script_dir}/prev_track.scpt")
46
+ Track.find_by(persistent_id: persistent_id).first
47
+ end
48
+
49
+ private
50
+ def script_dir
51
+ 'player'
52
+ end
53
+ end
54
+ end
55
+ end
data/lib/itunes/track.rb CHANGED
@@ -49,12 +49,12 @@ module Itunes
49
49
  end
50
50
 
51
51
  def pause
52
- application.pause
52
+ Itunes.pause
53
53
  self
54
54
  end
55
55
 
56
56
  def stop
57
- application.stop
57
+ Itunes.stop
58
58
  self
59
59
  end
60
60
 
@@ -106,10 +106,6 @@ module Itunes
106
106
 
107
107
  private
108
108
 
109
- def application
110
- Application.instance
111
- end
112
-
113
109
  def update_attribute_records(args)
114
110
  records = []
115
111
  args.each do |key, val|
@@ -1,3 +1,3 @@
1
1
  module Itunes
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/itunes-client.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  require 'itunes/version'
3
- require 'itunes/application'
3
+ require 'itunes/player'
4
4
 
5
5
  module Itunes
6
6
  end
File without changes
@@ -0,0 +1,5 @@
1
+ tell application "iTunes"
2
+ next track
3
+ play
4
+ return persistent ID of current track
5
+ end tell
File without changes
@@ -0,0 +1,3 @@
1
+ tell application "iTunes"
2
+ player state
3
+ end tell
@@ -0,0 +1,5 @@
1
+ tell application "iTunes"
2
+ previous track
3
+ play
4
+ return persistent ID of current track
5
+ end tell
File without changes
@@ -0,0 +1,115 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+ require 'itunes-client'
4
+
5
+ include Itunes
6
+
7
+ describe Player do
8
+ let(:player) { Itunes::Player }
9
+
10
+ describe '.add' do
11
+ subject(:add) { player.add(file_name) }
12
+
13
+ let(:file_name) { 'foo.wav' }
14
+ let(:new_persistent_id) { 'foo' }
15
+
16
+ before do
17
+ player.should_receive(:execute_script).
18
+ with('player/add.scpt', file_name).and_return(new_persistent_id)
19
+ Track.should_receive(:find_by).
20
+ with(persistent_id: new_persistent_id).
21
+ and_return([Track.new(persistent_id: new_persistent_id)])
22
+ end
23
+
24
+ it 'returns an array of track instance' do
25
+ expect(add).to be_a(Track)
26
+ expect(add.persistent_id).to eq(new_persistent_id)
27
+ end
28
+ end
29
+
30
+ describe '.pause' do
31
+ it 'calls pause.scpt' do
32
+ player.should_receive(:execute_script).with('player/pause.scpt')
33
+ player.pause
34
+ end
35
+ end
36
+
37
+ describe '.stop' do
38
+ it 'calls stop.scpt' do
39
+ player.should_receive(:execute_script).with('player/stop.scpt')
40
+ player.stop
41
+ end
42
+ end
43
+
44
+ describe '.playing?' do
45
+ subject { player.playing? }
46
+ context 'when iTunes plays a track' do
47
+ before { player.should_receive(:execute_script).with('player/player_state.scpt').and_return('playing') }
48
+ it { expect(subject).to be_true }
49
+ end
50
+
51
+ context 'when iTunes stops a track' do
52
+ before { player.should_receive(:execute_script).with('player/player_state.scpt').and_return('stopped') }
53
+ it { expect(subject).to be_false }
54
+ end
55
+ end
56
+
57
+ describe '.paused?' do
58
+ subject { player.paused? }
59
+ context 'when iTunes plays a track' do
60
+ before { player.should_receive(:execute_script).with('player/player_state.scpt').and_return('playing') }
61
+ it { expect(subject).to be_false }
62
+ end
63
+
64
+ context 'when iTunes pauses' do
65
+ before { player.should_receive(:execute_script).with('player/player_state.scpt').and_return('paused') }
66
+ it { expect(subject).to be_true }
67
+ end
68
+ end
69
+
70
+ describe '.stopped?' do
71
+ subject { player.stopped? }
72
+ context 'when iTunes plays a track' do
73
+ before { player.should_receive(:execute_script).with('player/player_state.scpt').and_return('playing') }
74
+ it { expect(subject).to be_false }
75
+ end
76
+
77
+ context 'when iTunes stops a track' do
78
+ before { player.should_receive(:execute_script).with('player/player_state.scpt').and_return('stopped') }
79
+ it { expect(subject).to be_true }
80
+ end
81
+ end
82
+
83
+ describe '.next_track' do
84
+ before do
85
+ player.should_receive(:execute_script).
86
+ with('player/next_track.scpt').and_return(new_persistent_id)
87
+ Track.should_receive(:find_by).
88
+ with(persistent_id: new_persistent_id).
89
+ and_return([Track.new(persistent_id: new_persistent_id)])
90
+ end
91
+ let(:new_persistent_id) { 'foo' }
92
+
93
+ it 'plays a next track' do
94
+ next_track = player.next_track
95
+ expect(next_track.persistent_id).to eq(new_persistent_id)
96
+ end
97
+ end
98
+
99
+ describe '.prev_track' do
100
+ before do
101
+ player.should_receive(:execute_script).
102
+ with('player/prev_track.scpt').and_return(new_persistent_id)
103
+ Track.should_receive(:find_by).
104
+ with(persistent_id: new_persistent_id).
105
+ and_return([Track.new(persistent_id: new_persistent_id)])
106
+ end
107
+ let(:new_persistent_id) { 'foo' }
108
+
109
+ it 'plays a previous track' do
110
+ next_track = player.prev_track
111
+ expect(next_track.persistent_id).to eq(new_persistent_id)
112
+ end
113
+ end
114
+
115
+ end
@@ -8,7 +8,7 @@ describe Track do
8
8
  let(:track) do
9
9
  Track.new(persistent_id: base_persistent_id, name: base_name, album: base_album)
10
10
  end
11
- let(:app) { Application.instance }
11
+ let(:app) { Itunes }
12
12
  let(:base_persistent_id) { 'foo' }
13
13
  let(:base_name) { 'base name' }
14
14
  let(:base_album) { 'base album' }
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  require 'spec_helper'
3
- require 'itunes-client'
3
+ require 'itunes/util'
4
4
 
5
5
  describe Itunes::Util::Executor do
6
6
  class DummyClass
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itunes-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryo katsuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-06 00:00:00.000000000 Z
11
+ date: 2013-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -169,21 +169,24 @@ files:
169
169
  - Rakefile
170
170
  - itunes-client.gemspec
171
171
  - lib/itunes-client.rb
172
- - lib/itunes/application.rb
172
+ - lib/itunes/player.rb
173
173
  - lib/itunes/track.rb
174
174
  - lib/itunes/util.rb
175
175
  - lib/itunes/util/executor.rb
176
176
  - lib/itunes/version.rb
177
- - scripts/application/add.scpt
178
- - scripts/application/pause.scpt
179
- - scripts/application/stop.scpt
177
+ - scripts/player/add.scpt
178
+ - scripts/player/next_track.scpt
179
+ - scripts/player/pause.scpt
180
+ - scripts/player/player_state.scpt
181
+ - scripts/player/prev_track.scpt
182
+ - scripts/player/stop.scpt
180
183
  - scripts/track/convert.scpt
181
184
  - scripts/track/current_track.scpt
182
185
  - scripts/track/delete.scpt
183
186
  - scripts/track/finder.tmpl.scpt
184
187
  - scripts/track/play.scpt
185
188
  - scripts/track/updater.tmpl.scpt
186
- - spec/itunes/application_spec.rb
189
+ - spec/itunes/player_spec.rb
187
190
  - spec/itunes/track_spec.rb
188
191
  - spec/itunes/util/executor_spec.rb
189
192
  - spec/spec_helper.rb
@@ -213,7 +216,7 @@ specification_version: 4
213
216
  summary: itunes-client provides a high level API like ActiveRecord style to control
214
217
  your iTunes.
215
218
  test_files:
216
- - spec/itunes/application_spec.rb
219
+ - spec/itunes/player_spec.rb
217
220
  - spec/itunes/track_spec.rb
218
221
  - spec/itunes/util/executor_spec.rb
219
222
  - spec/spec_helper.rb
@@ -1,34 +0,0 @@
1
- # coding: utf-8
2
- require 'singleton'
3
-
4
- require 'itunes/track'
5
- require 'itunes/util'
6
-
7
- module Itunes
8
- class Application
9
- include Singleton
10
- include Itunes::Util::Executor
11
-
12
- attr_accessor :tracks
13
-
14
- def add(file_path)
15
- persistent_id = execute_script("#{script_dir}/add.scpt", file_path)
16
- Track.find_by(persistent_id: persistent_id).first
17
- end
18
-
19
- def stop
20
- execute_script("#{script_dir}/stop.scpt")
21
- self
22
- end
23
-
24
- def pause
25
- execute_script("#{script_dir}/pause.scpt")
26
- self
27
- end
28
-
29
- private
30
- def script_dir
31
- 'application'
32
- end
33
- end
34
- end
@@ -1,49 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
- require 'itunes-client'
4
-
5
- include Itunes
6
-
7
- describe Application do
8
- let(:app) { described_class.instance }
9
-
10
- describe '#initialize' do
11
- it 'raises an Error' do
12
- expect { described_class.new }.to raise_error
13
- end
14
- end
15
-
16
- describe '#add' do
17
- subject(:add) { app.add(file_name) }
18
-
19
- let(:file_name) { 'foo.wav' }
20
- let(:new_persistent_id) { 'foo' }
21
-
22
- before do
23
- app.should_receive(:execute_script).
24
- with('application/add.scpt', file_name).and_return(new_persistent_id)
25
- Track.should_receive(:find_by).
26
- with(persistent_id: new_persistent_id).
27
- and_return([Track.new(persistent_id: new_persistent_id)])
28
- end
29
-
30
- it 'returns an array of track instance' do
31
- expect(add).to be_a(Track)
32
- expect(add.persistent_id).to eq(new_persistent_id)
33
- end
34
- end
35
-
36
- describe '#pause' do
37
- it 'calls pause.scpt' do
38
- app.should_receive(:execute_script).with('application/pause.scpt')
39
- app.pause
40
- end
41
- end
42
-
43
- describe '#stop' do
44
- it 'calls stop.scpt' do
45
- app.should_receive(:execute_script).with('application/stop.scpt')
46
- app.stop
47
- end
48
- end
49
- end