apple_music_library 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +8 -0
- data/apple_music_library.gemspec +49 -0
- data/lib/apple_music_library/album.rb +27 -0
- data/lib/apple_music_library/artist.rb +27 -0
- data/lib/apple_music_library/genre.rb +18 -0
- data/lib/apple_music_library/library.rb +176 -0
- data/lib/apple_music_library/playlist.rb +68 -0
- data/lib/apple_music_library/track.rb +69 -0
- data/lib/apple_music_library/utils.rb +28 -0
- data/lib/apple_music_library/version.rb +5 -0
- data/lib/apple_music_library.rb +13 -0
- data/sig/apple_music_library.rbs +4 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d1148dd5f546044638ace3b635c61799d36f427cdf380e19d146be4ab55a0128
|
4
|
+
data.tar.gz: ceeafe5ace4e3ac2d76aa34bb2695592584799755b9318ce99b055bdfc971f83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 289f57dc10c8ec89d0ddf9506fbea8083ab8c6d07d0bfc1b060d481434e47e375e73bb8e6b5518570babd5add4f24bb3817a2bf6dce5108f173edbe43ed5b506
|
7
|
+
data.tar.gz: 0276d14ab7d07c5b2aaf1c56c95494ddb81680a2d6811ce3c5a0254e3f93a18fbbf8c8d85223de7b6ea0ec110a00748cc9727d936c46c98c5fd87ab4f0d98aa6
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
apple_music_library (0.2.0)
|
5
|
+
facets (~> 3.1)
|
6
|
+
plist (~> 3.6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
awesome_print (1.9.2)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
docile (1.4.0)
|
14
|
+
facets (3.1.0)
|
15
|
+
plist (3.6.0)
|
16
|
+
rake (13.0.6)
|
17
|
+
rspec (3.11.0)
|
18
|
+
rspec-core (~> 3.11.0)
|
19
|
+
rspec-expectations (~> 3.11.0)
|
20
|
+
rspec-mocks (~> 3.11.0)
|
21
|
+
rspec-core (3.11.0)
|
22
|
+
rspec-support (~> 3.11.0)
|
23
|
+
rspec-expectations (3.11.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.11.0)
|
26
|
+
rspec-mocks (3.11.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.11.0)
|
29
|
+
rspec-support (3.11.0)
|
30
|
+
simplecov (0.21.2)
|
31
|
+
docile (~> 1.1)
|
32
|
+
simplecov-html (~> 0.11)
|
33
|
+
simplecov_json_formatter (~> 0.1)
|
34
|
+
simplecov-html (0.12.3)
|
35
|
+
simplecov_json_formatter (0.1.4)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
arm64-darwin-21
|
39
|
+
x86_64-linux
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
apple_music_library!
|
43
|
+
awesome_print (~> 1.9)
|
44
|
+
bundler (~> 2.0)
|
45
|
+
rake (~> 13.0)
|
46
|
+
rspec (~> 3.0)
|
47
|
+
simplecov (~> 0.21)
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
2.3.9
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Todd Gehman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# AppleMusicLibrary
|
2
|
+
|
3
|
+
The `apple_music_library` gem offeres a ruby interface to the information stored in an iTunes / Apple Muisic `Library.xml` file, as can be generated with the app's menu option `File > Library > Export Library...`
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'apple_music_library'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install apple_music_library
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
|
25
|
+
# Create library
|
26
|
+
library = AppleMusicLibrary.new('path/to/Library.xml')
|
27
|
+
|
28
|
+
# Count albums
|
29
|
+
puts library.albums.count
|
30
|
+
|
31
|
+
# Show tracks in a specific playlist
|
32
|
+
playlist = library.playlist('XTC Favorites')
|
33
|
+
playlist.tracks.each do |track|
|
34
|
+
puts track.name
|
35
|
+
end
|
36
|
+
|
37
|
+
# Count tracks by artist
|
38
|
+
artist = library.artist('XTC')
|
39
|
+
puts artist.tracks.count
|
40
|
+
|
41
|
+
# Display track counts per genre
|
42
|
+
library.genres.each do |genre|
|
43
|
+
puts "#{genre.tracks.count} #{genre.name}"
|
44
|
+
end
|
45
|
+
```
|
46
|
+
All stored attributes are available via snake_cased methods on `Track` and `Playlist`. However, note that `#artist`, `#album`, and `#genre` are special cases, returning Ruby objects rather than their associated string values. Methods to return the string versions of these track attributes are provided as `track.artist_name`, `track.album_name`, and `track.genre_name`.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pugetive/apple-music-library.
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
55
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/apple_music_library/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "apple_music_library"
|
7
|
+
spec.version = AppleMusicLibrary::VERSION
|
8
|
+
spec.authors = ["Todd Gehman"]
|
9
|
+
spec.email = ["github@pugetive.com"]
|
10
|
+
|
11
|
+
spec.summary = "Provides a ruby OO interface to the information stored in an Apple Music (formerly iTunes) Library xml file."
|
12
|
+
# spec.description = "TODO: Write a longer description or delete this line."
|
13
|
+
spec.homepage = "https://github.com/pugetive/apple_music_library"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/pugetive/apple_music_library"
|
21
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
|
40
|
+
spec.add_development_dependency "awesome_print", "~> 1.9"
|
41
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
42
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
43
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
44
|
+
spec.add_development_dependency "simplecov", "~> 0.21"
|
45
|
+
|
46
|
+
spec.add_runtime_dependency "plist", "~> 3.6"
|
47
|
+
spec.add_runtime_dependency "facets", "~> 3.1"
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AppleMusicLibrary
|
2
|
+
class Album
|
3
|
+
attr_reader :artist
|
4
|
+
|
5
|
+
|
6
|
+
attr_reader :artist, :album_name, :tracks
|
7
|
+
|
8
|
+
def initialize(artist, album_name)
|
9
|
+
@artist = artist
|
10
|
+
@album_name = album_name
|
11
|
+
@tracks = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
"#{artist.name}-#{album_name}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_track(track)
|
19
|
+
@tracks << track
|
20
|
+
end
|
21
|
+
|
22
|
+
def year
|
23
|
+
@year ||= tracks.sort(&:year).last.year
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AppleMusicLibrary
|
2
|
+
class Artist
|
3
|
+
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
@albums = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_album(album)
|
12
|
+
unless albums.include?(album)
|
13
|
+
@albums << album
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def albums
|
19
|
+
@albums.sort(&:year)
|
20
|
+
end
|
21
|
+
|
22
|
+
def tracks
|
23
|
+
@tracks ||= @albums.map(&:tracks).flatten
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require_relative 'album'
|
2
|
+
require_relative 'artist'
|
3
|
+
require_relative 'genre'
|
4
|
+
require_relative 'playlist'
|
5
|
+
require_relative 'track'
|
6
|
+
require_relative "utils"
|
7
|
+
require 'plist'
|
8
|
+
|
9
|
+
module AppleMusicLibrary
|
10
|
+
class Library
|
11
|
+
|
12
|
+
include Utils
|
13
|
+
|
14
|
+
MUSIC_FORMATS = [
|
15
|
+
'AAC audio file',
|
16
|
+
'AIFF audio file',
|
17
|
+
'Matched AAC audio file',
|
18
|
+
'MPEG audio file',
|
19
|
+
'MPEG-4 audio file',
|
20
|
+
'Protected AAC audio file',
|
21
|
+
'Purchased AAC audio file'
|
22
|
+
]
|
23
|
+
|
24
|
+
attr_reader :plist
|
25
|
+
|
26
|
+
def initialize(music_library_file_path, verbose = false)
|
27
|
+
@verbose = verbose
|
28
|
+
message("Initializing library with #{music_library_file_path}")
|
29
|
+
|
30
|
+
unless File.file?(music_library_file_path)
|
31
|
+
raise Error.new("Supplied library file path name does not exist: [#{music_library_file_path}]")
|
32
|
+
end
|
33
|
+
begin
|
34
|
+
@plist = Plist.parse_xml(music_library_file_path)
|
35
|
+
rescue => e
|
36
|
+
raise Error, "Failed to parse library xml file [#{e.message}]"
|
37
|
+
end
|
38
|
+
|
39
|
+
@artists_hash = {}
|
40
|
+
@tracks_hash = {}
|
41
|
+
@playlists_hash = {}
|
42
|
+
@albums_hash = {}
|
43
|
+
@genres_hash = {}
|
44
|
+
|
45
|
+
@locations_hash = {}
|
46
|
+
@slugs_hash = {}
|
47
|
+
|
48
|
+
extract_plist_info
|
49
|
+
end
|
50
|
+
|
51
|
+
def tracks
|
52
|
+
@tracks_hash.values
|
53
|
+
end
|
54
|
+
|
55
|
+
def artists
|
56
|
+
@artists_hash.values
|
57
|
+
end
|
58
|
+
|
59
|
+
def artist(artist_name)
|
60
|
+
artists.find{|a| a.name == artist_name}
|
61
|
+
end
|
62
|
+
|
63
|
+
def albums
|
64
|
+
@albums_hash.values
|
65
|
+
end
|
66
|
+
|
67
|
+
def playlists
|
68
|
+
@playlists_hash.values
|
69
|
+
end
|
70
|
+
|
71
|
+
def playlist(playlist_name)
|
72
|
+
playlists.find{|p| p.name == playlist_name}
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def albums
|
77
|
+
@albums_hash.values
|
78
|
+
end
|
79
|
+
|
80
|
+
def genres
|
81
|
+
@genres_hash.values.sort_by{|g| g.name}
|
82
|
+
end
|
83
|
+
|
84
|
+
def genre(genre_name)
|
85
|
+
genres.find{|g| g.name == genre_name}
|
86
|
+
end
|
87
|
+
|
88
|
+
def valid?
|
89
|
+
has_tracks?
|
90
|
+
end
|
91
|
+
|
92
|
+
def has_tracks?
|
93
|
+
tracks.any?
|
94
|
+
end
|
95
|
+
|
96
|
+
def track(track_id)
|
97
|
+
track = @tracks_hash[track_id.to_i]
|
98
|
+
if track.nil?
|
99
|
+
message("Cound not find track with ID [#{track_id}]")
|
100
|
+
message("Searched tracks: [#{@tracks_hash.keys.sort.join(', ')}]")
|
101
|
+
end
|
102
|
+
track
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def extract_plist_info
|
108
|
+
non_music_formats = {}
|
109
|
+
plist['Tracks'].each do |track|
|
110
|
+
if MUSIC_FORMATS.include?(track[1]['Kind'])
|
111
|
+
track = Track.new(track[1])
|
112
|
+
# next if track.artist.name == 'NPR'
|
113
|
+
@tracks_hash[track.id] = track
|
114
|
+
# @locations_hash[track.location] = track
|
115
|
+
|
116
|
+
artist = add_artist(track.artist)
|
117
|
+
album = add_track_to_album(track, track.album)
|
118
|
+
artist.add_album(album)
|
119
|
+
|
120
|
+
if track.genre_name.present?
|
121
|
+
genre = add_track_to_genre(track)
|
122
|
+
end
|
123
|
+
else
|
124
|
+
non_music_formats[track[1]['Kind']] = true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
plist['Playlists'].each do |playlist_info|
|
129
|
+
playlist = Playlist.new(playlist_info, self)
|
130
|
+
next if playlist.folder?
|
131
|
+
@playlists_hash[playlist.id] = playlist
|
132
|
+
end
|
133
|
+
|
134
|
+
if non_music_formats.any?
|
135
|
+
message("Skipped the following non-music formats:\n#{non_music_formats.keys.join(', ')}")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
def add_artist(artist)
|
141
|
+
unless @artists_hash[artist.name]
|
142
|
+
@artists_hash[artist.name] = artist
|
143
|
+
end
|
144
|
+
artist
|
145
|
+
end
|
146
|
+
|
147
|
+
def add_track_to_album(track, album)
|
148
|
+
return if @albums_hash[album.id]
|
149
|
+
# message("Creating new artist #{artist.name}")
|
150
|
+
@albums_hash[album.id] = album
|
151
|
+
album.add_track(track)
|
152
|
+
album
|
153
|
+
end
|
154
|
+
|
155
|
+
def find_or_create_album(album)
|
156
|
+
unless @albums_hash[album.id]
|
157
|
+
@albums_hash[album.id] = album
|
158
|
+
end
|
159
|
+
album.artist.add_album(album)
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
def add_track_to_genre(track)
|
164
|
+
if @genres_hash[track.genre_name]
|
165
|
+
return @genres_hash[track.genre_name]
|
166
|
+
end
|
167
|
+
# message("Creating new artist #{artist.name}")
|
168
|
+
genre = AppleMusicLibrary::Genre.new(track.genre_name)
|
169
|
+
@genres_hash[track.genre_name] = genre
|
170
|
+
genre.add_track(track)
|
171
|
+
genre
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# <key>Name</key><string>Non-XTC</string>
|
2
|
+
# <key>Description</key><string></string>
|
3
|
+
# <key>Playlist ID</key><integer>79359</integer>
|
4
|
+
# <key>Playlist Persistent ID</key><string>59C95825DF1F0DCC</string>
|
5
|
+
# <key>All Items</key><true/>
|
6
|
+
# <key>Smart Info</key>
|
7
|
+
# <data>
|
8
|
+
# AQEAAwAAAAIAAAAZAAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
9
|
+
# AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
10
|
+
# AAAAAA==
|
11
|
+
# </data>
|
12
|
+
# <key>Smart Criteria</key>
|
13
|
+
# <data>
|
14
|
+
|
15
|
+
require 'facets'
|
16
|
+
|
17
|
+
module AppleMusicLibrary
|
18
|
+
class Playlist
|
19
|
+
|
20
|
+
attr_reader :info, :tracks
|
21
|
+
|
22
|
+
ATTRIBUTES = ['Name',
|
23
|
+
'Description',
|
24
|
+
'Playlist ID',
|
25
|
+
'Playlist Persistent ID',
|
26
|
+
'All Items',
|
27
|
+
'Smart Info',
|
28
|
+
'Smart Criteria',
|
29
|
+
'Playlist Items',
|
30
|
+
'Folder']
|
31
|
+
|
32
|
+
def initialize(info, library)
|
33
|
+
@info = info
|
34
|
+
@library = library
|
35
|
+
@tracks = []
|
36
|
+
|
37
|
+
load_tracks
|
38
|
+
end
|
39
|
+
|
40
|
+
def id
|
41
|
+
playlist_id
|
42
|
+
end
|
43
|
+
|
44
|
+
ATTRIBUTES.each do |attribute|
|
45
|
+
define_method(attribute.to_s.snakecase) do
|
46
|
+
info[attribute]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def folder?
|
51
|
+
folder.present?
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def load_tracks
|
57
|
+
if playlist_items and playlist_items.any?
|
58
|
+
playlist_items.each do |playlist_item|
|
59
|
+
track_id = playlist_item['Track ID']
|
60
|
+
track = @library.track(track_id)
|
61
|
+
@tracks << track
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'facets'
|
2
|
+
|
3
|
+
module AppleMusicLibrary
|
4
|
+
class Track
|
5
|
+
attr_reader :info, :artist, :album
|
6
|
+
|
7
|
+
ATTRIBUTES = ['Track ID',
|
8
|
+
'Name',
|
9
|
+
# 'Artist', The #artist, #album, and #genre methods return objects rather than strings and have methods like #artist_name to retrieve the strings.
|
10
|
+
# 'Album',
|
11
|
+
# 'Genre',
|
12
|
+
'Kind',
|
13
|
+
'Size',
|
14
|
+
'Total Time',
|
15
|
+
'Track Number',
|
16
|
+
'Year',
|
17
|
+
'Date Modified',
|
18
|
+
'Date Added',
|
19
|
+
'Bit Rate',
|
20
|
+
'Sample Rate',
|
21
|
+
'Play Count',
|
22
|
+
'Play Date',
|
23
|
+
'Play Date UTC',
|
24
|
+
'Rating',
|
25
|
+
'Album Rating',
|
26
|
+
'Album Rating Computed',
|
27
|
+
'Normalization',
|
28
|
+
'Persistent ID',
|
29
|
+
'Track Type',
|
30
|
+
'Location',
|
31
|
+
'File Folder Count',
|
32
|
+
'Library Folder Count']
|
33
|
+
|
34
|
+
def initialize(info)
|
35
|
+
@info = info
|
36
|
+
@artist = Artist.new(artist_name)
|
37
|
+
@album = Album.new(@artist, album_name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def id
|
41
|
+
track_id
|
42
|
+
end
|
43
|
+
|
44
|
+
def artist_name
|
45
|
+
info['Artist']
|
46
|
+
end
|
47
|
+
|
48
|
+
def album_name
|
49
|
+
info['Album']
|
50
|
+
end
|
51
|
+
|
52
|
+
def genre_name
|
53
|
+
info['Genre']
|
54
|
+
end
|
55
|
+
|
56
|
+
ATTRIBUTES.each do |attribute|
|
57
|
+
define_method(attribute.to_s.snakecase) do
|
58
|
+
info[attribute]
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
# def slug
|
64
|
+
# "#{name}::#{artist.name}::#{album}::#{disc_number}::#{track_number}"
|
65
|
+
# end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'awesome_print'
|
2
|
+
|
3
|
+
module AppleMusicLibrary
|
4
|
+
module Utils
|
5
|
+
|
6
|
+
def message(text)
|
7
|
+
return unless @verbose
|
8
|
+
puts "---------------------------------------------------------------------------"
|
9
|
+
puts "DEV MESSAGE @ #{Time.now.strftime('%H:%M:%S')} ::: #{text}"
|
10
|
+
puts "---------------------------------------------------------------------------"
|
11
|
+
end
|
12
|
+
|
13
|
+
def heading(text)
|
14
|
+
puts
|
15
|
+
puts "---------------------------------------------------------------------------"
|
16
|
+
puts "#{text} [#{delimit(songs.size)} songs]"
|
17
|
+
puts "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
18
|
+
end
|
19
|
+
|
20
|
+
def delimit(number)
|
21
|
+
number.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
|
22
|
+
end
|
23
|
+
|
24
|
+
def dump
|
25
|
+
ap plist
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "apple_music_library/library"
|
4
|
+
require_relative "apple_music_library/version"
|
5
|
+
|
6
|
+
module AppleMusicLibrary
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
def self.new(music_library_file_path, verbose = false)
|
10
|
+
AppleMusicLibrary::Library.new(music_library_file_path, verbose)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apple_music_library
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Todd Gehman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: awesome_print
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.21'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.21'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: plist
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.6'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: facets
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.1'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.1'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- github@pugetive.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".rspec"
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- apple_music_library.gemspec
|
125
|
+
- lib/apple_music_library.rb
|
126
|
+
- lib/apple_music_library/album.rb
|
127
|
+
- lib/apple_music_library/artist.rb
|
128
|
+
- lib/apple_music_library/genre.rb
|
129
|
+
- lib/apple_music_library/library.rb
|
130
|
+
- lib/apple_music_library/playlist.rb
|
131
|
+
- lib/apple_music_library/track.rb
|
132
|
+
- lib/apple_music_library/utils.rb
|
133
|
+
- lib/apple_music_library/version.rb
|
134
|
+
- sig/apple_music_library.rbs
|
135
|
+
homepage: https://github.com/pugetive/apple_music_library
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata:
|
139
|
+
homepage_uri: https://github.com/pugetive/apple_music_library
|
140
|
+
source_code_uri: https://github.com/pugetive/apple_music_library
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 2.6.0
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubygems_version: 3.3.3
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Provides a ruby OO interface to the information stored in an Apple Music
|
160
|
+
(formerly iTunes) Library xml file.
|
161
|
+
test_files: []
|