Class: Apple::Music::Library::Library
- Inherits:
-
Object
- Object
- Apple::Music::Library::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.
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/apple/music/library/library.rb', line 29
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 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 due to invalid format'
end
@artists_hash = {}
@tracks_hash = {}
@playlists_hash = {}
@albums_hash = {}
@genres_hash = {}
@locations_hash = {}
@slugs_hash = {}
end
|
Instance Attribute Details
#plist ⇒ Object
Returns the value of attribute plist.
27
28
29
|
# File 'lib/apple/music/library/library.rb', line 27
def plist
@plist
end
|
Instance Method Details
#albums ⇒ Object
66
67
68
|
# File 'lib/apple/music/library/library.rb', line 66
def albums
@albums_hash.values
end
|
#artist(artist_name) ⇒ Object
62
63
64
|
# File 'lib/apple/music/library/library.rb', line 62
def artist(artist_name)
artists.find{|a| a.name == artist_name}
end
|
#artists ⇒ Object
58
59
60
|
# File 'lib/apple/music/library/library.rb', line 58
def artists
@artists_hash.values
end
|
#genre(genre_name) ⇒ Object
87
88
89
|
# File 'lib/apple/music/library/library.rb', line 87
def genre(genre_name)
genres.find{|g| g.name == genre_name}
end
|
#genres ⇒ Object
83
84
85
|
# File 'lib/apple/music/library/library.rb', line 83
def genres
@genres_hash.values.sort_by{|g| g.name}
end
|
#has_tracks? ⇒ Boolean
95
96
97
|
# File 'lib/apple/music/library/library.rb', line 95
def has_tracks?
tracks.any?
end
|
#playlist(playlist_name) ⇒ Object
74
75
76
|
# File 'lib/apple/music/library/library.rb', line 74
def playlist(playlist_name)
playlists.find{|p| p.name == playlist_name}
end
|
#playlists ⇒ Object
70
71
72
|
# File 'lib/apple/music/library/library.rb', line 70
def playlists
@playlists_hash.values
end
|
#track(track_id) ⇒ Object
99
100
101
102
103
104
105
106
|
# File 'lib/apple/music/library/library.rb', line 99
def track(track_id)
track = @tracks_hash[track_id.to_i]
if track.nil?
message("Cound not find track with ID [#{track_id}]")
message("Searched tracks: [#{@tracks_hash.keys.sort.join(', ')}]")
end
track
end
|
#tracks ⇒ Object
54
55
56
|
# File 'lib/apple/music/library/library.rb', line 54
def tracks
@tracks_hash.values
end
|
#valid? ⇒ Boolean
91
92
93
|
# File 'lib/apple/music/library/library.rb', line 91
def valid?
has_tracks?
end
|