kagu 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 +4 -4
- data/README.mdown +14 -1
- data/VERSION +1 -1
- data/kagu.gemspec +1 -0
- data/lib/kagu/playlist.rb +46 -0
- data/lib/kagu/playlists.rb +4 -0
- data/lib/kagu.rb +1 -0
- data/spec/kagu/playlists_spec.rb +1 -1
- data/spec/kagu/tracks_spec.rb +1 -1
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e575043dff2dec033f7489c3597d55c299fd42
|
4
|
+
data.tar.gz: 35401e87c1ffb91bc1ae6b74e31d97757f76cf4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a35eddae3a6f9716a9e9deb4f56554573da0b1ef945d53387d7dffc6d26383acd41cbcce2a4636a25647d313d79f891f44e9d2e17d217004e30331804f748b5
|
7
|
+
data.tar.gz: ff9d99d3298110c66afeaf4e6e4115414edf8410a8dbef6790523800c28c5f9356a31174f224961ebc1900042f65dbdee0b0d062b8520a0d4da9377c4d8adb83
|
data/README.mdown
CHANGED
@@ -10,7 +10,9 @@ Just add this into your `Gemfile`:
|
|
10
10
|
|
11
11
|
Then, just run `bundle install`.
|
12
12
|
|
13
|
-
##
|
13
|
+
## Examples
|
14
|
+
|
15
|
+
### Displaying all tracks artist
|
14
16
|
|
15
17
|
library = Kagu::Library.new
|
16
18
|
|
@@ -18,10 +20,21 @@ Then, just run `bundle install`.
|
|
18
20
|
puts track.artist
|
19
21
|
end
|
20
22
|
|
23
|
+
### Displaying all playlists and its tracks count
|
24
|
+
|
25
|
+
library = Kagu::Library.new
|
26
|
+
|
21
27
|
library.playlists.each do |playlist|
|
22
28
|
puts "#{playlist.name}: #{playlist.tracks.count}"
|
23
29
|
end
|
24
30
|
|
31
|
+
### Creating a playlist
|
32
|
+
|
33
|
+
library = Kagu::Library.new
|
34
|
+
|
35
|
+
tracks = library.tracks.select { |track| track.genre == 'Drum & Bass' && track.added_at > 1.week.ago }
|
36
|
+
library.playlists.create(name: 'Recent - D&B', tracks: tracks)
|
37
|
+
|
25
38
|
## Executing test suite
|
26
39
|
|
27
40
|
This project is fully tested with [Rspec 3](http://github.com/rspec/rspec).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/kagu.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.require_paths = ['lib']
|
18
18
|
|
19
19
|
s.add_dependency 'activesupport', '>= 4.1.0', '< 4.2.0'
|
20
|
+
s.add_dependency 'applescript', '>= 1.0', '< 2.0'
|
20
21
|
s.add_dependency 'htmlentities', '>= 4.3.0', '< 4.4.0'
|
21
22
|
|
22
23
|
s.add_development_dependency 'byebug', '>= 3.2.0', '< 3.3.0'
|
data/lib/kagu/playlist.rb
CHANGED
@@ -11,12 +11,58 @@ module Kagu
|
|
11
11
|
|
12
12
|
delegate :each, to: :tracks
|
13
13
|
|
14
|
+
def save
|
15
|
+
create
|
16
|
+
clear
|
17
|
+
add_tracks
|
18
|
+
end
|
19
|
+
|
14
20
|
def to_s
|
15
21
|
name
|
16
22
|
end
|
17
23
|
|
18
24
|
private
|
19
25
|
|
26
|
+
def add_tracks
|
27
|
+
ids = tracks.map(&:id)
|
28
|
+
AppleScript.execute(%Q{
|
29
|
+
tell application "iTunes"
|
30
|
+
set playlistToPush to user playlist #{name.inspect}
|
31
|
+
set idsToAdd to {#{ids.join(',')}}
|
32
|
+
repeat with idToAdd in idsToAdd
|
33
|
+
duplicate (tracks of library playlist 1 whose database ID is idToAdd) to playlistToPush
|
34
|
+
end repeat
|
35
|
+
end tell
|
36
|
+
})
|
37
|
+
nil
|
38
|
+
rescue => e
|
39
|
+
raise Error.new(e)
|
40
|
+
end
|
41
|
+
|
42
|
+
def clear
|
43
|
+
AppleScript.execute(%Q{
|
44
|
+
tell application "iTunes"
|
45
|
+
delete tracks of playlist #{name.inspect}
|
46
|
+
end tell
|
47
|
+
})
|
48
|
+
nil
|
49
|
+
rescue => e
|
50
|
+
raise Error.new(e)
|
51
|
+
end
|
52
|
+
|
53
|
+
def create
|
54
|
+
AppleScript.execute(%Q{
|
55
|
+
tell application "iTunes"
|
56
|
+
if not (exists user playlist #{name.inspect}) then
|
57
|
+
make new user playlist with properties { name: #{name.inspect} }
|
58
|
+
end if
|
59
|
+
end tell
|
60
|
+
})
|
61
|
+
nil
|
62
|
+
rescue => e
|
63
|
+
raise Error.new(e)
|
64
|
+
end
|
65
|
+
|
20
66
|
def itunes_name=(value)
|
21
67
|
@@html_entities ||= HTMLEntities.new
|
22
68
|
self.name = @@html_entities.decode(value)
|
data/lib/kagu/playlists.rb
CHANGED
data/lib/kagu.rb
CHANGED
data/spec/kagu/playlists_spec.rb
CHANGED
data/spec/kagu/tracks_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kagu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Toulotte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,6 +30,26 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 4.2.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: applescript
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.0'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.0'
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: htmlentities
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|