Class: RJL::Itunes
- Inherits:
-
Object
- Object
- RJL::Itunes
- Defined in:
- lib/rjl/itunes.rb
Overview
RJL_itunes::Itunes contains the public api for Itunes.
Instance Attribute Summary collapse
-
#albums(album_artist: nil, title: nil) ⇒ List of Album, Album
readonly
The albums, or a single album.
-
#version ⇒ String
readonly
iTunes version number.
Instance Method Summary collapse
- #create_playlist(playlist_name: "Playlist", track_list: nil) ⇒ Object
- #create_playlist_folder(folder_name: "untitled folder", playlists: nil) ⇒ Object
- #destroy_playlist(playlist_name) ⇒ Object
- #destroy_playlist_folder(folder_name: nil) ⇒ Object
-
#initialize(playlist = nil) ⇒ Itunes
constructor
Create a new RJL_itunes::Itunes.
-
#playlist(playlist_name) ⇒ Playlist
Get a playlist of the specified name.
-
#playlists ⇒ List of Playlist
Return a list of the playlists.
Constructor Details
#initialize(playlist = nil) ⇒ Itunes
Create a new RJL_itunes::Itunes. Can be called with a Playlist name to only get the tracks in that Playlist - useful for testing, and may be deprecated
22 23 24 25 26 27 |
# File 'lib/rjl/itunes.rb', line 22 def initialize( playlist = nil ) @tracks = get_tracks( playlist ) @albums = get_albums( @tracks ) @playlists = fetch_playlists( kind: :none ) @playlist_folders = fetch_playlists( kind: :none ) end |
Instance Attribute Details
#albums(album_artist: nil, title: nil) ⇒ List of Album, Album (readonly)
The albums, or a single album
46 47 48 |
# File 'lib/rjl/itunes.rb', line 46 def albums @albums end |
#version ⇒ String (readonly)
iTunes version number
31 32 33 |
# File 'lib/rjl/itunes.rb', line 31 def version @version end |
Instance Method Details
#create_playlist(playlist_name: "Playlist", track_list: nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rjl/itunes.rb', line 79 def create_playlist( playlist_name: "Playlist", track_list: nil ) playlist_obj = app("iTunes").make( :new => :playlist, :with_properties => {:name => playlist_name} ) playlist = Playlist.new( playlist_obj ) playlist.tracks = track_list unless track_list.nil? @playlists << playlist return playlist end |
#create_playlist_folder(folder_name: "untitled folder", playlists: nil) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/rjl/itunes.rb', line 95 def create_playlist_folder( folder_name: "untitled folder", playlists: nil ) playlist_obj = app("iTunes").make( :new => :folder_playlist, :with_properties => {:name => folder_name} ) # TODO add playlists # TODO make and add to @playlist_folders end |
#destroy_playlist(playlist_name) ⇒ Object
90 91 92 93 |
# File 'lib/rjl/itunes.rb', line 90 def destroy_playlist( playlist_name ) app("iTunes").sources["Library"].user_playlists[playlist_name].delete # TODO remove from @playlists end |
#destroy_playlist_folder(folder_name: nil) ⇒ Object
104 105 106 |
# File 'lib/rjl/itunes.rb', line 104 def destroy_playlist_folder( folder_name: nil ) app("iTunes").sources["Library"].folder_playlists[folder_name].delete end |
#playlist(playlist_name) ⇒ Playlist
Get a playlist of the specified name. Raises error if more than one.
70 71 72 73 74 75 76 77 |
# File 'lib/rjl/itunes.rb', line 70 def playlist( playlist_name ) play_list = @playlists.select { |playlist| playlist.name == playlist_name } if play_list.count == 1 return play_list[0] else raise "ERROR: #{play_list.count} playlists with name #{playlist_name}" end end |
#playlists ⇒ List of Playlist
Return a list of the playlists.
63 64 65 |
# File 'lib/rjl/itunes.rb', line 63 def playlists return @playlists end |