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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5d4e5df146ca66edf6bf1cbe4f640dbfddd33f3
4
- data.tar.gz: d2e1ee38ab2c17b049fe58fbbfbfadb7fe271dbb
3
+ metadata.gz: b5e575043dff2dec033f7489c3597d55c299fd42
4
+ data.tar.gz: 35401e87c1ffb91bc1ae6b74e31d97757f76cf4f
5
5
  SHA512:
6
- metadata.gz: 4ec012cf7b2b9aafee03ebe394b4e2f901809fa023ac888ba0ddefd7b71a552e16bf0e989ee355fbb3a018578eca4e8dd8c37fb4df859ca42fd6bf9c4810ec96
7
- data.tar.gz: 0f8848137e743a15f8e6ccf97f77817d100af3bb658c168fcec74f0564d315743c87e837ed4ec2720668eafa5e4ce6c1327385f678f885f856d1d22724ad6c3a
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
- ## Example
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.1
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)
@@ -11,6 +11,10 @@ module Kagu
11
11
  @library = library
12
12
  end
13
13
 
14
+ def create(attributes = {})
15
+ Playlist.new(attributes).save
16
+ end
17
+
14
18
  def each(&block)
15
19
  return unless block_given?
16
20
  tracks = {}.tap do |tracks|
data/lib/kagu.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext'
2
+ require 'applescript'
2
3
  require 'byebug' if ENV['DEBUGGER']
3
4
  require 'htmlentities'
4
5
 
@@ -25,7 +25,7 @@ describe Kagu::Playlists do
25
25
  end
26
26
 
27
27
  it 'returns nil' do
28
- expect(playlists.each { break }).to be_nil
28
+ expect(playlists.each {}).to be_nil
29
29
  end
30
30
 
31
31
  end
@@ -34,7 +34,7 @@ describe Kagu::Tracks do
34
34
  end
35
35
 
36
36
  it 'returns nil' do
37
- expect(tracks.each { break }).to be_nil
37
+ expect(tracks.each {}).to be_nil
38
38
  end
39
39
 
40
40
  end
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.1.1
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-28 00:00:00.000000000 Z
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