apple_music_library 0.6.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/Gemfile.lock +1 -1
- data/README.md +22 -2
- data/lib/apple_music_library/album.rb +15 -10
- data/lib/apple_music_library/artist.rb +30 -5
- data/lib/apple_music_library/genre.rb +1 -30
- data/lib/apple_music_library/library.rb +4 -0
- data/lib/apple_music_library/playlist.rb +4 -3
- data/lib/apple_music_library/track.rb +7 -0
- data/lib/apple_music_library/track_collection.rb +56 -0
- data/lib/apple_music_library/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d57d33d85a24895e93ca386313d43fe9dd28c6a48bec21fbb4348ec3b168a177
|
4
|
+
data.tar.gz: d3d0b25dbd54fa23f03cea03b46729224d9b1054da276060a62cac40ab0016e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 319fb967951a32d12f0d871c32d40b56a2c4d674bbb8966de6bf6b592da5b5ed0af41f9443caf2b7b222345ded89264af85bdf75694856a8ed7e37162ab706f1
|
7
|
+
data.tar.gz: 148f0638affc3d19f1c96619e732280966574885fce0c66acc69e083d0cd569200e2a8535f75f96e8ef06b75fdee07b6f0ca82befd0ab8a4bcf914b86af2fff5
|
data/CHANGELOG.md
CHANGED
@@ -3,9 +3,21 @@
|
|
3
3
|
## [Unreleased]
|
4
4
|
- Ability to print out playlist folder hierarchy
|
5
5
|
|
6
|
+
## 0.9.0 - 2022-03-15
|
7
|
+
### Added
|
8
|
+
- Ability to get genres associated with an artist
|
9
|
+
|
10
|
+
## 0.8.0 - 2022-03-13
|
11
|
+
### Added
|
12
|
+
- Ability to sort artists by track count and album count
|
13
|
+
|
14
|
+
## 0.7.0 - 2022-03-12
|
15
|
+
### Added
|
16
|
+
- Average star ratings for track collectsion (albums, playlists, genres)
|
17
|
+
|
6
18
|
## 0.6.0 - 2022-03-11
|
7
19
|
### Added
|
8
|
-
- Ability to
|
20
|
+
- Ability to list top artists by play count
|
9
21
|
|
10
22
|
## 0.5.0 - 2022-03-11
|
11
23
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
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
4
|
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/86a57ad0904e4358dd02/maintainability)](https://codeclimate.com/github/pugetive/apple_music_library/maintainability)
|
6
|
+
|
7
|
+
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
@@ -40,10 +44,15 @@ playlist.tracks.each do |track|
|
|
40
44
|
puts track.name
|
41
45
|
end
|
42
46
|
|
43
|
-
# Count tracks by artist
|
47
|
+
# Count tracks by an artist
|
44
48
|
artist = library.artist('XTC')
|
45
49
|
puts artist.tracks.count
|
46
50
|
|
51
|
+
# List genres associated with the artist
|
52
|
+
artist.genres.each do |genre|
|
53
|
+
puts genre.name
|
54
|
+
end
|
55
|
+
|
47
56
|
# Get favorite tracks by this artist
|
48
57
|
favorite_tracks = artist.tracks.select{|t| t.loved? || t.star_rating > 3}
|
49
58
|
|
@@ -52,10 +61,21 @@ library.artists(:most_played).each do |artist|
|
|
52
61
|
puts "#{artist.play_count} :: #{artist.name}"
|
53
62
|
end
|
54
63
|
|
64
|
+
# List out artists with the most tracks
|
65
|
+
library.artists(:most_tracks).each do |artist|
|
66
|
+
puts "#{artist.track_count} :: #{artist.name}"
|
67
|
+
end
|
68
|
+
|
69
|
+
# List out artists with the most albums
|
70
|
+
library.artists(:most_albums).each do |artist|
|
71
|
+
puts "#{artist.album_count} :: #{artist.name}"
|
72
|
+
end
|
73
|
+
|
55
74
|
# Display track counts per genre
|
56
75
|
library.genres.each do |genre|
|
57
|
-
puts "#{genre.
|
76
|
+
puts "#{genre.track_count} #{genre.name}"
|
58
77
|
end
|
78
|
+
|
59
79
|
```
|
60
80
|
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`.
|
61
81
|
|
@@ -1,16 +1,14 @@
|
|
1
|
+
require_relative 'track_collection'
|
2
|
+
|
1
3
|
module AppleMusicLibrary
|
2
|
-
class Album
|
4
|
+
class Album < TrackCollection
|
3
5
|
attr_reader :artist
|
4
6
|
|
5
|
-
|
6
|
-
attr_reader :artist, :album_name, :tracks
|
7
|
-
|
8
7
|
@@albums = {}
|
9
8
|
|
10
|
-
def initialize(
|
9
|
+
def initialize(album_name, artist)
|
11
10
|
@artist = artist
|
12
|
-
|
13
|
-
@tracks = []
|
11
|
+
super
|
14
12
|
end
|
15
13
|
|
16
14
|
def self.all
|
@@ -22,20 +20,27 @@ module AppleMusicLibrary
|
|
22
20
|
if @@albums[key]
|
23
21
|
return @@albums[key]
|
24
22
|
end
|
25
|
-
@@albums[key] = self.new(
|
23
|
+
@@albums[key] = self.new(album_name, artist)
|
26
24
|
end
|
27
25
|
|
28
26
|
def id
|
29
27
|
"#{artist.name}-#{album_name}"
|
30
28
|
end
|
31
29
|
|
32
|
-
def
|
33
|
-
@
|
30
|
+
def name
|
31
|
+
@album_name
|
34
32
|
end
|
35
33
|
|
36
34
|
def year
|
37
35
|
@year ||= @tracks.sort_by(&:year).last.year
|
38
36
|
end
|
39
37
|
|
38
|
+
def dump
|
39
|
+
puts "#{artist.name} - #{name}"
|
40
|
+
tracks.each do |track|
|
41
|
+
puts "\t#{track.name}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
40
45
|
end
|
41
46
|
end
|
@@ -16,11 +16,15 @@ module AppleMusicLibrary
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.most_played(limit = 20)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
self.sorted_set(:play_count, limit)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.most_tracks(limit = 20)
|
23
|
+
self.sorted_set(:track_count, limit)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.most_albums(limit = 20)
|
27
|
+
self.sorted_set(:album_count, limit)
|
24
28
|
end
|
25
29
|
|
26
30
|
def self.find_or_create(name)
|
@@ -53,13 +57,34 @@ module AppleMusicLibrary
|
|
53
57
|
@albums.sort_by(&:year)
|
54
58
|
end
|
55
59
|
|
60
|
+
def album_count
|
61
|
+
@albums.size
|
62
|
+
end
|
63
|
+
|
56
64
|
def tracks
|
57
65
|
@tracks
|
58
66
|
end
|
59
67
|
|
68
|
+
def track_count
|
69
|
+
@tracks.size
|
70
|
+
end
|
71
|
+
|
60
72
|
def play_count
|
61
73
|
tracks.map(&:play_count).sum
|
62
74
|
end
|
63
75
|
|
76
|
+
def genres
|
77
|
+
@genres ||= tracks.map(&:genre).uniq
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
|
82
|
+
def self.sorted_set(sort_by_method, limit)
|
83
|
+
if limit.nil?
|
84
|
+
self.all.sort_by{|a| a.send(sort_by_method)}.reverse
|
85
|
+
else
|
86
|
+
self.all.sort_by{|a| a.send(sort_by_method)}.reverse.take(limit)
|
87
|
+
end
|
88
|
+
end
|
64
89
|
end
|
65
90
|
end
|
@@ -1,35 +1,6 @@
|
|
1
1
|
module AppleMusicLibrary
|
2
|
-
class Genre
|
2
|
+
class Genre < TrackCollection
|
3
3
|
|
4
|
-
attr_reader :name, :tracks
|
5
|
-
|
6
|
-
@@genres = {}
|
7
|
-
|
8
|
-
def initialize(name)
|
9
|
-
@name = name
|
10
|
-
@tracks = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.all
|
14
|
-
@@genres.values
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.find_or_create(name)
|
18
|
-
if @@genres[name]
|
19
|
-
return @@genres[name]
|
20
|
-
end
|
21
|
-
@@genres[name] = self.new(name)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.find_by_name(name)
|
25
|
-
@@genres[name]
|
26
|
-
end
|
27
|
-
|
28
|
-
def add_track(track)
|
29
|
-
unless tracks.include?(track)
|
30
|
-
@tracks << track
|
31
|
-
end
|
32
|
-
end
|
33
4
|
|
34
5
|
end
|
35
6
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'facets'
|
2
|
+
require_relative 'track_collection'
|
2
3
|
|
3
4
|
module AppleMusicLibrary
|
4
|
-
class Playlist
|
5
|
+
class Playlist < TrackCollection
|
5
6
|
|
6
|
-
attr_reader :info
|
7
|
+
attr_reader :info
|
7
8
|
|
8
9
|
@@playlists = {}
|
9
10
|
|
@@ -25,7 +26,7 @@ module AppleMusicLibrary
|
|
25
26
|
return PlaylistFolder.new(info)
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
+
super
|
29
30
|
|
30
31
|
load_tracks
|
31
32
|
|
@@ -38,6 +38,9 @@ module AppleMusicLibrary
|
|
38
38
|
@info = info
|
39
39
|
@artist = Artist.find_or_create(artist_name)
|
40
40
|
@album = Album.find_or_create(@artist, album_name)
|
41
|
+
# if name.match(/Humble.*demo/)
|
42
|
+
# puts "Adding track #{name} to album #{album_name}"
|
43
|
+
# end
|
41
44
|
@genre = Genre.find_or_create(genre_name)
|
42
45
|
|
43
46
|
@artist.add_track(self)
|
@@ -80,6 +83,10 @@ module AppleMusicLibrary
|
|
80
83
|
rating / 20
|
81
84
|
end
|
82
85
|
|
86
|
+
def rated?
|
87
|
+
rating > 0 and rating <= 100
|
88
|
+
end
|
89
|
+
|
83
90
|
def loved?
|
84
91
|
loved
|
85
92
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module AppleMusicLibrary
|
2
|
+
class TrackCollection
|
3
|
+
|
4
|
+
attr_reader :name, :tracks
|
5
|
+
|
6
|
+
@@track_collections = {}
|
7
|
+
|
8
|
+
def initialize(name, *args)
|
9
|
+
@tracks = []
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.all
|
14
|
+
@@track_collections[token].values
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find_by_name(lookup_name)
|
18
|
+
@@track_collections[token][lookup_name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.find_or_create(lookup_name)
|
22
|
+
unless @@track_collections[token]
|
23
|
+
@@track_collections[token] = {}
|
24
|
+
end
|
25
|
+
@@track_collections[token][lookup_name] = self.new(lookup_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_track(track)
|
29
|
+
@tracks << track
|
30
|
+
end
|
31
|
+
|
32
|
+
def track_count
|
33
|
+
@track_count ||= tracks.count
|
34
|
+
end
|
35
|
+
|
36
|
+
def star_rating
|
37
|
+
return nil if rated_tracks.empty?
|
38
|
+
rated_tracks.map(&:star_rating).sum / rated_tracks.size
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def rated_tracks
|
44
|
+
@rated_tracks ||= tracks.select{|t| t.rated?}
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.token
|
48
|
+
self.class.name
|
49
|
+
end
|
50
|
+
|
51
|
+
def token
|
52
|
+
self.class.token
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apple_music_library
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Gehman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/apple_music_library/playlist.rb
|
132
132
|
- lib/apple_music_library/playlist_folder.rb
|
133
133
|
- lib/apple_music_library/track.rb
|
134
|
+
- lib/apple_music_library/track_collection.rb
|
134
135
|
- lib/apple_music_library/utils.rb
|
135
136
|
- lib/apple_music_library/version.rb
|
136
137
|
- sig/apple_music_library.rbs
|
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
157
|
- !ruby/object:Gem::Version
|
157
158
|
version: '0'
|
158
159
|
requirements: []
|
159
|
-
rubygems_version: 3.3.
|
160
|
+
rubygems_version: 3.3.9
|
160
161
|
signing_key:
|
161
162
|
specification_version: 4
|
162
163
|
summary: Provides a Ruby interface to the information stored in an Apple Music (formerly
|