Kagu
Ruby API to manage macOS Music tracks and playlists.
Important note for macOS Catalina (10.15) users: Apple dropped automatic
XML library export you need to manually export your XML library to
$HOME/Music/iTunes/iTunes Music Library.xml
path to make kagu
work
properly.
Installation
Just add this into your Gemfile
:
gem 'kagu'
Then, just run bundle install
.
Examples
Displaying all tracks artist
library = Kagu::Library.new
library.tracks.each do |track|
puts track.artist
end
Displaying all playlists and its tracks count
library = Kagu::Library.new
library.playlists.each do |playlist|
puts "#{playlist.name}: #{playlist.tracks.count}"
end
Creating a playlist
library = Kagu::Library.new
tracks = library.tracks.select { |track| track.genre == 'Drum & Bass' && track.added_at > 1.week.ago }
library.playlists.create(name: 'Recent - D&B', tracks: tracks)
Finding some tracks
library = Kagu::Library.new
library.finder.find(artist: 'Serial Killaz', title: 'Walk and Skank').each do
puts track.id
end
Configuring logger
In order to have some debug informations about what kagu does, you could configure its logger:
Kagu.logger = Logger.new(STDERR)
Executing test suite
This project is fully tested with Rspec 3.
Just run bundle exec rake
(after a bundle install
).