itunes-client 0.0.1
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 +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Guardfile +45 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +19 -0
- data/itunes-client.gemspec +31 -0
- data/lib/itunes/application.rb +34 -0
- data/lib/itunes/track.rb +96 -0
- data/lib/itunes/util/executor.rb +45 -0
- data/lib/itunes/util.rb +10 -0
- data/lib/itunes/version.rb +3 -0
- data/lib/itunes-client.rb +6 -0
- data/scripts/application/add.scpt +7 -0
- data/scripts/application/pause.scpt +3 -0
- data/scripts/application/stop.scpt +3 -0
- data/scripts/track/convert.scpt +10 -0
- data/scripts/track/delete.scpt +13 -0
- data/scripts/track/finder.tmpl.scpt +15 -0
- data/scripts/track/play.scpt +8 -0
- data/spec/itunes/application_spec.rb +51 -0
- data/spec/itunes/track_spec.rb +119 -0
- data/spec/itunes/util/executor_spec.rb +48 -0
- data/spec/spec_helper.rb +23 -0
- metadata +217 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: acf0f6362da0cee6e1acd568af19372073f9ff1b
|
4
|
+
data.tar.gz: 819befcd3e4f4df0c3937d77d053e30350a88d4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71055a9bf65eef0718b2656e29ea2661f0505909750bb12494d993407f0cccfb4eaf22d0e5a96c4d2306d8c96cc09d2adf3224c75ef5011fb199b25d14636434
|
7
|
+
data.tar.gz: 55ca841cd771536984bb3750b9d1c1a57906540be6ff0842ebe49b89823f9d9dfa5dae479886a7c6de68a06042816040540413b8b0913a4052fce0c7bc70666a
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: LXbjHynXx7CMRWSuFTFOlbJeltdcFZJ5O
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara features specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
guard 'rspec' do
|
27
|
+
watch(%r{^spec/.+_spec\.rb$})
|
28
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
29
|
+
watch('spec/spec_helper.rb') { "spec" }
|
30
|
+
|
31
|
+
# Rails example
|
32
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
33
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
34
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
35
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
36
|
+
watch('config/routes.rb') { "spec/routing" }
|
37
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
38
|
+
|
39
|
+
# Capybara features specs
|
40
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
41
|
+
|
42
|
+
# Turnip features and steps
|
43
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
44
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
45
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 ryo katsuma
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# itunes-client [](https://travis-ci.org/katsuma/itunes-client) [](https://coveralls.io/r/katsuma/itunes-client)
|
2
|
+
|
3
|
+
`itunes-client` provides a high level API (like ActiveRecord style) to control your iTunes.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```sh
|
11
|
+
gem 'itunes-client'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```sh
|
17
|
+
$ bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
$ gem install itunes-client
|
24
|
+
```
|
25
|
+
|
26
|
+
## Supported OS
|
27
|
+
- OSX 10.8 (Mountain Lion)
|
28
|
+
|
29
|
+
|
30
|
+
## Supported Ruby
|
31
|
+
- 2.0.0
|
32
|
+
- 1.9.3
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'itunes-client'
|
38
|
+
include Itunes
|
39
|
+
|
40
|
+
# Add a track to player
|
41
|
+
application = Application.instance
|
42
|
+
track = application.add(path_to_your_sound_file)
|
43
|
+
|
44
|
+
# Convert by default encoder
|
45
|
+
encoded_track = track.convert
|
46
|
+
|
47
|
+
# Find a track
|
48
|
+
track = Track.find_by(name: "Hello, Goodbye")
|
49
|
+
# => #<Itunes::Track:0x007fdd38a1d430 @persistent_id="571B6412CDADBC93", @name="Hello, Goodbye", @album="1", @artist="The Beatles", @track_count="27", @track_number="19">
|
50
|
+
|
51
|
+
# Play track
|
52
|
+
track.play
|
53
|
+
|
54
|
+
# Stop track
|
55
|
+
track.stop
|
56
|
+
```
|
57
|
+
|
58
|
+
## License
|
59
|
+
`itunes-client` is released under the MIT License.
|
60
|
+
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
1. Fork it
|
65
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rspec/core'
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
|
16
|
+
RSpec::Core::RakeTask.new(:spec)
|
17
|
+
|
18
|
+
task :default => :spec
|
19
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'itunes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "itunes-client"
|
8
|
+
spec.version = Itunes::VERSION
|
9
|
+
spec.authors = ["ryo katsuma"]
|
10
|
+
spec.email = ["katsuma@gmail.com"]
|
11
|
+
spec.description = %q{iTunes client with high level API}
|
12
|
+
spec.summary = %q{itunes-client provides a high level API like ActiveRecord style to control your iTunes.}
|
13
|
+
spec.homepage = "https://github.com/katsuma/itunes-client"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0.3"
|
22
|
+
spec.add_development_dependency "rspec", "~> 2.13.0"
|
23
|
+
spec.add_development_dependency "rb-fsevent", "~> 0.3"
|
24
|
+
spec.add_development_dependency "guard", "~> 1.6.2"
|
25
|
+
spec.add_development_dependency "guard-rspec", "~> 2.4.1"
|
26
|
+
spec.add_development_dependency "growl", "~> 1.0.3"
|
27
|
+
spec.add_development_dependency "fakefs", "~> 0.4.2"
|
28
|
+
spec.add_development_dependency "simplecov", "~> 0.7.1"
|
29
|
+
spec.add_development_dependency "coveralls", "~> 0.6.6"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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)
|
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
|
data/lib/itunes/track.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'json'
|
3
|
+
require 'itunes/util'
|
4
|
+
|
5
|
+
module Itunes
|
6
|
+
class Track
|
7
|
+
include Itunes::Util::Executor
|
8
|
+
extend Itunes::Util::Executor
|
9
|
+
|
10
|
+
ATTRIBUTES = [
|
11
|
+
:persistent_id,
|
12
|
+
:name,
|
13
|
+
:album,
|
14
|
+
:artist,
|
15
|
+
:track_count,
|
16
|
+
:track_number
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
FINDER_ATTRIBUTES = [
|
20
|
+
:persistent_id,
|
21
|
+
:name,
|
22
|
+
:album,
|
23
|
+
:artist
|
24
|
+
].freeze
|
25
|
+
|
26
|
+
attr_accessor *ATTRIBUTES
|
27
|
+
|
28
|
+
def initialize(args=nil)
|
29
|
+
if args.is_a?(Hash)
|
30
|
+
args.each do |attr, val|
|
31
|
+
send("#{attr}=", val) if ATTRIBUTES.include?(attr)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def convert
|
37
|
+
converted_persistent_id = execute_script('track/convert.scpt', self.persistent_id)
|
38
|
+
Track.find_by(persistent_id: converted_persistent_id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete!
|
42
|
+
execute_script('track/delete.scpt', self.persistent_id)
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def play
|
47
|
+
execute_script('track/play.scpt', self.persistent_id)
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def pause
|
52
|
+
application.pause
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def stop
|
57
|
+
application.stop
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
def assign_attributes_by(itunes_response)
|
62
|
+
track_data = ::JSON.parse(itunes_response)
|
63
|
+
ATTRIBUTES.each { |attr| send("#{attr}=", track_data[attr.to_s]) }
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.find_by(arg)
|
67
|
+
raise ArgumentError.new('nil argument is given') if arg.nil?
|
68
|
+
|
69
|
+
conditions = find_conditions(arg)
|
70
|
+
script_name = generate_script_from_template('track/finder.tmpl.scpt', conditions: conditions)
|
71
|
+
track_response = execute_template_based_script(script_name)
|
72
|
+
|
73
|
+
Track.new.tap do |track|
|
74
|
+
track.assign_attributes_by(track_response)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.find_conditions(args)
|
79
|
+
conditions = []
|
80
|
+
args.each do |key, val|
|
81
|
+
if FINDER_ATTRIBUTES.include?(key)
|
82
|
+
conditions << "#{key.to_s.gsub('_', ' ')} is \"#{val}\""
|
83
|
+
end
|
84
|
+
end
|
85
|
+
conditions.join(' and ')
|
86
|
+
end
|
87
|
+
private_class_method :find_conditions
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def application
|
92
|
+
Application.instance
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Itunes
|
3
|
+
module Util
|
4
|
+
module Executor
|
5
|
+
def generate_script_from_template(template_path, args)
|
6
|
+
body = ''
|
7
|
+
script_name = "#{Time.now.to_i}.#{rand(1000)}.scpt"
|
8
|
+
script_path = "#{script_tmp_dir}/#{script_name}"
|
9
|
+
|
10
|
+
open("#{script_base_dir}/#{template_path}", 'r') do |f|
|
11
|
+
f.each { |line| body << line }
|
12
|
+
end
|
13
|
+
|
14
|
+
args.each do |key, val|
|
15
|
+
body.gsub!("#\{#{key}\}", val)
|
16
|
+
end
|
17
|
+
|
18
|
+
open(script_path, 'w') do |f|
|
19
|
+
f.write(body)
|
20
|
+
end
|
21
|
+
|
22
|
+
script_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute_script(script_path, args='')
|
26
|
+
execute_out, process_status = *Open3.capture2("osascript #{script_base_dir}/#{script_path} #{args}")
|
27
|
+
execute_out.chomp
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute_template_based_script(script_path)
|
31
|
+
execute_out, process_status = *Open3.capture2("osascript #{script_tmp_dir}/#{script_path}")
|
32
|
+
::FileUtils.rm "#{script_tmp_dir}/#{script_path}"
|
33
|
+
execute_out.chomp
|
34
|
+
end
|
35
|
+
|
36
|
+
def script_base_dir
|
37
|
+
File.expand_path("#{File.dirname(__FILE__)}/../../../scripts")
|
38
|
+
end
|
39
|
+
|
40
|
+
def script_tmp_dir
|
41
|
+
Dir.tmpdir
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/itunes/util.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
on run argv
|
2
|
+
tell application "iTunes"
|
3
|
+
set persistent_id to (item 1 of argv) as string
|
4
|
+
set specified_track to (some track whose persistent ID is persistent_id)
|
5
|
+
set loc to (get location of specified_track)
|
6
|
+
|
7
|
+
set converted_track to (convert specified_track)
|
8
|
+
return persistent ID of converted_track
|
9
|
+
end tell
|
10
|
+
end run
|
@@ -0,0 +1,13 @@
|
|
1
|
+
on run argv
|
2
|
+
tell application "iTunes"
|
3
|
+
set persistent_id to (item 1 of argv) as string
|
4
|
+
set specified_track to (some track whose persistent ID is persistent_id)
|
5
|
+
set loc to (get location of specified_track)
|
6
|
+
|
7
|
+
delete specified_track
|
8
|
+
|
9
|
+
tell application "Finder"
|
10
|
+
delete loc
|
11
|
+
end tell
|
12
|
+
end tell
|
13
|
+
end run
|
@@ -0,0 +1,15 @@
|
|
1
|
+
tell application "iTunes"
|
2
|
+
set specified_track to (some track whose #{conditions})
|
3
|
+
|
4
|
+
set props to {}
|
5
|
+
set end of props to "{"
|
6
|
+
set end of props to ("\"persistent_id\":\"" & persistent ID of specified_track & "\",")
|
7
|
+
set end of props to ("\"name\":\"" & name of specified_track & "\",")
|
8
|
+
set end of props to ("\"album\":\"" & album of specified_track & "\",")
|
9
|
+
set end of props to ("\"artist\":\"" & artist of specified_track & "\",")
|
10
|
+
set end of props to ("\"track_count\":\"" & track count of specified_track & "\",")
|
11
|
+
set end of props to ("\"track_number\":\"" & track number of specified_track & "\"")
|
12
|
+
set end of props to "}"
|
13
|
+
|
14
|
+
return props as string
|
15
|
+
end tell
|
@@ -0,0 +1,51 @@
|
|
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 a track instance' do
|
31
|
+
track = add
|
32
|
+
|
33
|
+
expect(track).to be_a(Track)
|
34
|
+
expect(track.persistent_id).to eq(new_persistent_id)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#pause' do
|
39
|
+
it 'calls pause.scpt' do
|
40
|
+
app.should_receive(:execute_script).with('application/pause.scpt')
|
41
|
+
app.pause
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#stop' do
|
46
|
+
it 'calls stop.scpt' do
|
47
|
+
app.should_receive(:execute_script).with('application/stop.scpt')
|
48
|
+
app.stop
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'itunes-client'
|
4
|
+
|
5
|
+
include Itunes
|
6
|
+
|
7
|
+
describe Track do
|
8
|
+
let(:track) { Track.new(persistent_id: base_persistent_id) }
|
9
|
+
let(:app) { Application.instance }
|
10
|
+
let(:base_persistent_id) { 'foo' }
|
11
|
+
|
12
|
+
describe '#initialize' do
|
13
|
+
subject(:init) { Track.new(args) }
|
14
|
+
|
15
|
+
context 'when nil is given' do
|
16
|
+
let(:args) { nil }
|
17
|
+
it { expect(init).to be_a(Track) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when some attributes are given' do
|
21
|
+
let(:args) { { persistent_id: '0123ABC', name: 'clammbon' } }
|
22
|
+
it { expect(init).to be_a(Track) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#convert' do
|
27
|
+
subject(:convert) { track.convert }
|
28
|
+
let(:new_persistent_id) { 'bar' }
|
29
|
+
|
30
|
+
before do
|
31
|
+
track.should_receive(:execute_script).
|
32
|
+
with('track/convert.scpt', base_persistent_id).
|
33
|
+
and_return(new_persistent_id)
|
34
|
+
Track.should_receive(:find_by).
|
35
|
+
with(persistent_id: new_persistent_id).
|
36
|
+
and_return(Track.new(persistent_id: new_persistent_id))
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns a new Track' do
|
40
|
+
converted_track = convert
|
41
|
+
expect(converted_track).to be_a(Track)
|
42
|
+
expect(converted_track.persistent_id).to eq(new_persistent_id)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#delete!' do
|
47
|
+
subject { track.delete! }
|
48
|
+
|
49
|
+
before do
|
50
|
+
track.should_receive(:execute_script).
|
51
|
+
with('track/delete.scpt', track.persistent_id)
|
52
|
+
end
|
53
|
+
|
54
|
+
it { expect(subject).to be_nil }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#play' do
|
58
|
+
subject { track.play }
|
59
|
+
|
60
|
+
before do
|
61
|
+
track.should_receive(:execute_script).
|
62
|
+
with('track/play.scpt', track.persistent_id)
|
63
|
+
end
|
64
|
+
|
65
|
+
it { expect(subject).to be_eql(track) }
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#pause' do
|
69
|
+
subject(:pause) { track.pause }
|
70
|
+
|
71
|
+
it 'calls application#pause' do
|
72
|
+
app.should_receive(:pause)
|
73
|
+
pause
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#stop' do
|
78
|
+
subject(:stop) { track.stop }
|
79
|
+
|
80
|
+
it 'calls application#stop' do
|
81
|
+
app.should_receive(:stop)
|
82
|
+
stop
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '.find_by' do
|
87
|
+
subject(:find) { Track.find_by(arg) }
|
88
|
+
let(:finder_scpt) { 'track/finder.tmpl.scpt' }
|
89
|
+
|
90
|
+
context 'when nil argument is given' do
|
91
|
+
let(:arg) { nil }
|
92
|
+
it 'raises an ArgumentError' do
|
93
|
+
expect { find }.to raise_error(ArgumentError)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when hash argument which has 1 key is given' do
|
98
|
+
let(:arg) { { name: name } }
|
99
|
+
let(:new_scpt) { 'new.scpt' }
|
100
|
+
let(:new_persistent_id) { 'bar' }
|
101
|
+
let(:name) { 'Hey Jude' }
|
102
|
+
|
103
|
+
before do
|
104
|
+
Track.stub(:generate_script_from_templae).
|
105
|
+
and_return(new_scpt)
|
106
|
+
|
107
|
+
Track.stub(:execute_template_based_script).
|
108
|
+
and_return({ persistent_id: new_persistent_id, name: name }.to_json)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns a track with specified name' do
|
112
|
+
track = find
|
113
|
+
expect(track).to be_a(Track)
|
114
|
+
expect(track.name).to eq(name)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'itunes-client'
|
4
|
+
|
5
|
+
describe Itunes::Util::Executor do
|
6
|
+
class DummyClass
|
7
|
+
include Itunes::Util::Executor
|
8
|
+
end
|
9
|
+
let!(:klass) { DummyClass.new }
|
10
|
+
|
11
|
+
describe '#execute_script' do
|
12
|
+
subject(:execute_script) { klass.execute_script(path, args) }
|
13
|
+
|
14
|
+
let(:path) { 'foo.scpt' }
|
15
|
+
let(:args) { 'bar' }
|
16
|
+
let(:result) { { status: 'ok' }.to_json }
|
17
|
+
|
18
|
+
it 'returns a script result' do
|
19
|
+
Open3.should_receive(:capture2).with("osascript #{klass.script_base_dir}/#{path} #{args}").and_return(result)
|
20
|
+
expect(execute_script).to eq(result)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#execute_template_based_script' do
|
25
|
+
subject(:execute_template_based_script) { klass.execute_template_based_script(path) }
|
26
|
+
|
27
|
+
let(:path) { 'foo.scpt' }
|
28
|
+
let(:script_full_path) { "#{klass.script_tmp_dir}/#{path}" }
|
29
|
+
let(:result) { { status: 'ok' }.to_json }
|
30
|
+
|
31
|
+
before do
|
32
|
+
Open3.should_receive(:capture2).with("osascript #{script_full_path}").and_return(result)
|
33
|
+
FileUtils.touch(script_full_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'retuens a script result' do
|
37
|
+
expect(execute_template_based_script).to eq(result)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'deletes a generated script' do
|
41
|
+
expect { execute_template_based_script }.to change {
|
42
|
+
File.exist?(script_full_path)
|
43
|
+
}.from(true).to(false)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
require 'fakefs/spec_helpers'
|
5
|
+
require 'simplecov'
|
6
|
+
require 'coveralls'
|
7
|
+
|
8
|
+
Bundler.setup(:default, :development)
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.color_enabled = true
|
12
|
+
config.tty = true
|
13
|
+
#config.formatter = :documentation
|
14
|
+
config.include FakeFS::SpecHelpers, fakefs: true
|
15
|
+
end
|
16
|
+
|
17
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
18
|
+
SimpleCov::Formatter::HTMLFormatter,
|
19
|
+
Coveralls::SimpleCov::Formatter
|
20
|
+
]
|
21
|
+
SimpleCov.start do
|
22
|
+
add_filter '/spec/'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: itunes-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ryo katsuma
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 10.0.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 10.0.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.13.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.13.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rb-fsevent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.6.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.4.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.4.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: growl
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fakefs
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.4.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.4.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.7.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.7.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: coveralls
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.6.6
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.6.6
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: iTunes client with high level API
|
154
|
+
email:
|
155
|
+
- katsuma@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- .coveralls.yml
|
161
|
+
- .gitignore
|
162
|
+
- .rspec
|
163
|
+
- .ruby-version
|
164
|
+
- .travis.yml
|
165
|
+
- Gemfile
|
166
|
+
- Guardfile
|
167
|
+
- LICENSE.txt
|
168
|
+
- README.md
|
169
|
+
- Rakefile
|
170
|
+
- itunes-client.gemspec
|
171
|
+
- lib/itunes-client.rb
|
172
|
+
- lib/itunes/application.rb
|
173
|
+
- lib/itunes/track.rb
|
174
|
+
- lib/itunes/util.rb
|
175
|
+
- lib/itunes/util/executor.rb
|
176
|
+
- lib/itunes/version.rb
|
177
|
+
- scripts/application/add.scpt
|
178
|
+
- scripts/application/pause.scpt
|
179
|
+
- scripts/application/stop.scpt
|
180
|
+
- scripts/track/convert.scpt
|
181
|
+
- scripts/track/delete.scpt
|
182
|
+
- scripts/track/finder.tmpl.scpt
|
183
|
+
- scripts/track/play.scpt
|
184
|
+
- spec/itunes/application_spec.rb
|
185
|
+
- spec/itunes/track_spec.rb
|
186
|
+
- spec/itunes/util/executor_spec.rb
|
187
|
+
- spec/spec_helper.rb
|
188
|
+
homepage: https://github.com/katsuma/itunes-client
|
189
|
+
licenses:
|
190
|
+
- MIT
|
191
|
+
metadata: {}
|
192
|
+
post_install_message:
|
193
|
+
rdoc_options: []
|
194
|
+
require_paths:
|
195
|
+
- lib
|
196
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - '>='
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
|
+
requirements:
|
203
|
+
- - '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
206
|
+
requirements: []
|
207
|
+
rubyforge_project:
|
208
|
+
rubygems_version: 2.0.0
|
209
|
+
signing_key:
|
210
|
+
specification_version: 4
|
211
|
+
summary: itunes-client provides a high level API like ActiveRecord style to control
|
212
|
+
your iTunes.
|
213
|
+
test_files:
|
214
|
+
- spec/itunes/application_spec.rb
|
215
|
+
- spec/itunes/track_spec.rb
|
216
|
+
- spec/itunes/util/executor_spec.rb
|
217
|
+
- spec/spec_helper.rb
|