itunes-client 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +5 -3
- data/lib/itunes/track.rb +7 -5
- data/lib/itunes/version.rb +1 -1
- data/scripts/track/finder.tmpl.scpt +21 -13
- data/spec/itunes/application_spec.rb +6 -5
- data/spec/itunes/track_spec.rb +12 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5645b5129783ab41989f48719cc052f25a5f835b
|
4
|
+
data.tar.gz: 7253a509ac6e66791d49dc71dca6acad9a7f4dd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a57212b58a551bbc99ca4d70027ad5ffa308cbae0f121932c3e8e0e2b04a672fab0ed95f0a54762192b6d06df31301a2c4144cfee2fbcdfa067ed89695d463c
|
7
|
+
data.tar.gz: a89c43842d98e6f0a22d06348907c1ea9ae78be9c7579b6a3272489863c870d1d0f57da57ea60c8f211d9fde9b8e104c10a13b183b49cdd09cd58e6a6fa51054
|
data/README.md
CHANGED
@@ -44,9 +44,11 @@ track = application.add(path_to_your_sound_file)
|
|
44
44
|
# Convert by default encoder
|
45
45
|
encoded_track = track.convert
|
46
46
|
|
47
|
-
# Find
|
48
|
-
|
49
|
-
# => #<Itunes::Track:0x007fdd38a1d430 @persistent_id="571B6412CDADBC93", @name="Hello, Goodbye", @album="1", @artist="The Beatles", @track_count="27", @track_number="19">
|
47
|
+
# Find all tracks
|
48
|
+
tracks = 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
|
+
track = tracks.first
|
50
52
|
|
51
53
|
# Play track
|
52
54
|
track.play
|
data/lib/itunes/track.rb
CHANGED
@@ -58,9 +58,8 @@ module Itunes
|
|
58
58
|
self
|
59
59
|
end
|
60
60
|
|
61
|
-
def assign_attributes_by(
|
62
|
-
|
63
|
-
ATTRIBUTES.each { |attr| send("#{attr}=", track_data[attr.to_s]) }
|
61
|
+
def assign_attributes_by(track_attributes)
|
62
|
+
ATTRIBUTES.each { |attr| send("#{attr}=", track_attributes[attr.to_s]) }
|
64
63
|
end
|
65
64
|
|
66
65
|
def self.find_by(arg)
|
@@ -70,8 +69,11 @@ module Itunes
|
|
70
69
|
script_name = generate_script_from_template('track/finder.tmpl.scpt', conditions: conditions)
|
71
70
|
track_response = execute_template_based_script(script_name)
|
72
71
|
|
73
|
-
|
74
|
-
|
72
|
+
tracks_attributes = ::JSON.parse(track_response)
|
73
|
+
tracks_attributes.compact.map do |track_attributes|
|
74
|
+
Track.new.tap do |track|
|
75
|
+
track.assign_attributes_by(track_attributes)
|
76
|
+
end
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
data/lib/itunes/version.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
tell application "iTunes"
|
2
|
-
set
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
2
|
+
set specified_tracks to (every track whose #{conditions})
|
3
|
+
|
4
|
+
set json to "["
|
5
|
+
|
6
|
+
repeat with specified_track in specified_tracks
|
7
|
+
set props to {}
|
8
|
+
set end of props to "{"
|
9
|
+
set end of props to ("\"persistent_id\":\"" & persistent ID of specified_track & "\",")
|
10
|
+
set end of props to ("\"name\":\"" & name of specified_track & "\",")
|
11
|
+
set end of props to ("\"album\":\"" & album of specified_track & "\",")
|
12
|
+
set end of props to ("\"artist\":\"" & artist of specified_track & "\",")
|
13
|
+
set end of props to ("\"track_count\":\"" & track count of specified_track & "\",")
|
14
|
+
set end of props to ("\"track_number\":\"" & track number of specified_track & "\"")
|
15
|
+
set end of props to "}"
|
16
|
+
|
17
|
+
set json to json & props as string & ","
|
18
|
+
end repeat
|
19
|
+
|
20
|
+
set json to json & "null]"
|
21
|
+
return json
|
22
|
+
|
15
23
|
end tell
|
@@ -24,14 +24,15 @@ describe Application do
|
|
24
24
|
with('application/add.scpt', file_name).and_return(new_persistent_id)
|
25
25
|
Track.should_receive(:find_by).
|
26
26
|
with(persistent_id: new_persistent_id).
|
27
|
-
and_return(Track.new(persistent_id: new_persistent_id))
|
27
|
+
and_return([Track.new(persistent_id: new_persistent_id)])
|
28
28
|
end
|
29
29
|
|
30
|
-
it 'returns
|
31
|
-
|
30
|
+
it 'returns an array of track instance' do
|
31
|
+
tracks = add
|
32
32
|
|
33
|
-
expect(
|
34
|
-
expect(
|
33
|
+
expect(tracks).to be_an(Array)
|
34
|
+
expect(tracks.size).to eq(1)
|
35
|
+
expect(tracks.first.persistent_id).to eq(new_persistent_id)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
data/spec/itunes/track_spec.rb
CHANGED
@@ -33,13 +33,14 @@ describe Track do
|
|
33
33
|
and_return(new_persistent_id)
|
34
34
|
Track.should_receive(:find_by).
|
35
35
|
with(persistent_id: new_persistent_id).
|
36
|
-
and_return(Track.new(persistent_id: new_persistent_id))
|
36
|
+
and_return([Track.new(persistent_id: new_persistent_id)])
|
37
37
|
end
|
38
38
|
|
39
|
-
it 'returns
|
40
|
-
|
41
|
-
expect(
|
42
|
-
expect(
|
39
|
+
it 'returns an array of new Track' do
|
40
|
+
converted_tracks = convert
|
41
|
+
expect(converted_tracks).to be_an(Array)
|
42
|
+
expect(converted_tracks.size).to eq(1)
|
43
|
+
expect(converted_tracks.first.persistent_id).to eq(new_persistent_id)
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -94,7 +95,7 @@ describe Track do
|
|
94
95
|
end
|
95
96
|
end
|
96
97
|
|
97
|
-
context 'when hash argument
|
98
|
+
context 'when hash argument is given' do
|
98
99
|
let(:arg) { { name: name } }
|
99
100
|
let(:new_scpt) { 'new.scpt' }
|
100
101
|
let(:new_persistent_id) { 'bar' }
|
@@ -105,15 +106,14 @@ describe Track do
|
|
105
106
|
and_return(new_scpt)
|
106
107
|
|
107
108
|
Track.stub(:execute_template_based_script).
|
108
|
-
and_return({ persistent_id: new_persistent_id, name: name }.to_json)
|
109
|
+
and_return([{ persistent_id: new_persistent_id, name: name }].to_json)
|
109
110
|
end
|
110
111
|
|
111
|
-
it 'returns
|
112
|
-
|
113
|
-
expect(
|
114
|
-
expect(
|
112
|
+
it 'returns an array of track with specified name' do
|
113
|
+
tracks = find
|
114
|
+
expect(tracks.size).to eq(1)
|
115
|
+
expect(tracks.first.name).to eq(name)
|
115
116
|
end
|
116
117
|
end
|
117
|
-
|
118
118
|
end
|
119
119
|
end
|