Class: AppleMusicLibrary::Library
- Inherits:
-
Object
- Object
- AppleMusicLibrary::Library
show all
- Includes:
- Utils
- Defined in:
- lib/apple_music_library/library.rb
Constant Summary
collapse
- MUSIC_FORMATS =
[
'AAC audio file',
'AIFF audio file',
'Matched AAC audio file',
'MPEG audio file',
'MPEG-4 audio file',
'Protected AAC audio file',
'Purchased AAC audio file'
]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#delimit, #dump, #heading, #message
Constructor Details
#initialize(music_library_file_path, verbose = false) ⇒ Library
Returns a new instance of Library.
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/apple_music_library/library.rb', line 21
def initialize(music_library_file_path, verbose = false)
@verbose = verbose
message("Initializing library with #{music_library_file_path}")
unless File.file?(music_library_file_path)
raise Error.new("Supplied library file path name does not exist: [#{music_library_file_path}]")
end
begin
@plist = Plist.parse_xml(music_library_file_path)
rescue => e
raise Error, "Failed to parse library xml file [#{e.message}]"
end
end
|
Instance Attribute Details
#plist ⇒ Object
Returns the value of attribute plist.
19
20
21
|
# File 'lib/apple_music_library/library.rb', line 19
def plist
@plist
end
|
Instance Method Details
#albums ⇒ Object
37
38
39
|
# File 'lib/apple_music_library/library.rb', line 37
def albums
@albums ||= Album.all
end
|
#artist(artist_name) ⇒ Object
45
46
47
|
# File 'lib/apple_music_library/library.rb', line 45
def artist(artist_name)
Artist.find_by_name(artist_name)
end
|
#artists(filter = nil, limit = nil) ⇒ Object
41
42
43
|
# File 'lib/apple_music_library/library.rb', line 41
def artists(filter = nil, limit = nil)
filter.present? ? Artist.send(filter, limit) : Artist.all
end
|
#centuries ⇒ Object
94
95
96
|
# File 'lib/apple_music_library/library.rb', line 94
def centuries
@centuries ||= Century.all
end
|
#centuries_report ⇒ Object
98
99
100
|
# File 'lib/apple_music_library/library.rb', line 98
def centuries_report
Century.report
end
|
#decades ⇒ Object
86
87
88
|
# File 'lib/apple_music_library/library.rb', line 86
def decades
@decades ||= Decade.all
end
|
#decades_report ⇒ Object
90
91
92
|
# File 'lib/apple_music_library/library.rb', line 90
def decades_report
Decade.report
end
|
#genre(genre_name) ⇒ Object
53
54
55
|
# File 'lib/apple_music_library/library.rb', line 53
def genre(genre_name)
Genre.find_by_name(genre_name)
end
|
#genres ⇒ Object
49
50
51
|
# File 'lib/apple_music_library/library.rb', line 49
def genres
@genres ||= Genre.all
end
|
#has_tracks? ⇒ Boolean
106
107
108
|
# File 'lib/apple_music_library/library.rb', line 106
def has_tracks?
tracks.any?
end
|
#playlist(playlist_name) ⇒ Object
62
63
64
|
# File 'lib/apple_music_library/library.rb', line 62
def playlist(playlist_name)
Playlist.find_by_name(playlist_name)
end
|
#playlist_folder(playlist_folder_name) ⇒ Object
70
71
72
|
# File 'lib/apple_music_library/library.rb', line 70
def playlist_folder(playlist_folder_name)
PlaylistFolder.find_by_name(playlist_folder_name)
end
|
#playlist_folders ⇒ Object
66
67
68
|
# File 'lib/apple_music_library/library.rb', line 66
def playlist_folders
@playlist_folders ||= PlaylistFolder.all
end
|
#playlists(filter = nil) ⇒ Object
57
58
59
60
|
# File 'lib/apple_music_library/library.rb', line 57
def playlists(filter = nil)
return Playlist.all unless filter
Playlist.send(filter)
end
|
#rated_tracks ⇒ Object
110
111
112
|
# File 'lib/apple_music_library/library.rb', line 110
def rated_tracks
tracks.select{|t| t.rated?}
end
|
#track(track_id) ⇒ Object
78
79
80
|
# File 'lib/apple_music_library/library.rb', line 78
def track(track_id)
Track.find(track_id)
end
|
#tracks(filter = nil) ⇒ Object
74
75
76
|
# File 'lib/apple_music_library/library.rb', line 74
def tracks(filter = nil)
filter.present? ? Track.send(filter) : Track.all
end
|
#valid? ⇒ Boolean
102
103
104
|
# File 'lib/apple_music_library/library.rb', line 102
def valid?
has_tracks?
end
|
#years ⇒ Object
82
83
84
|
# File 'lib/apple_music_library/library.rb', line 82
def years
@years ||= Year.all
end
|