apple_music_library 0.7.0 → 0.10.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 +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +24 -2
- data/lib/apple_music_library/album.rb +6 -6
- data/lib/apple_music_library/artist.rb +30 -5
- data/lib/apple_music_library/genre.rb +2 -22
- data/lib/apple_music_library/library.rb +5 -0
- data/lib/apple_music_library/playlist.rb +4 -0
- data/lib/apple_music_library/track.rb +9 -0
- data/lib/apple_music_library/track_collection.rb +35 -2
- data/lib/apple_music_library/version.rb +1 -1
- data/lib/apple_music_library/year.rb +20 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b67a41ade93ef2a93fb61db6496506bfd4bb57f6df952c7b3c57f91474116fdc
|
4
|
+
data.tar.gz: '068639ed7660feb425b667394861d5f295b0f4a211c6cb6c4c2bf4334357649e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62eaabf37c4288bf1dc65fd00ce39b7bd944882c647043cb79df6b5340461109e959e80016d98e74800d170e9f66bc15aa05c01cd887aba3d068366682f5b01f
|
7
|
+
data.tar.gz: d8b7ed8641d329c4f33d3aedd0fd2262d021e817ca02aa2bb2d2994c1e91993ab9d9210eb1fd7202dc3b1bd7d6716212daa3d63620b65ed7ed26d5fa865913b8
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,20 @@
|
|
3
3
|
## [Unreleased]
|
4
4
|
- Ability to print out playlist folder hierarchy
|
5
5
|
|
6
|
+
## 0.10.0 - 2022-03-15
|
7
|
+
### Fixed
|
8
|
+
- Fixed incorrect handling of tracks when added to track collections
|
9
|
+
### Added
|
10
|
+
- Added Year model to retrieve tracks and track counts per year of release
|
11
|
+
|
12
|
+
## 0.9.0 - 2022-03-15
|
13
|
+
### Added
|
14
|
+
- Ability to get genres associated with an artist
|
15
|
+
|
16
|
+
## 0.8.0 - 2022-03-13
|
17
|
+
### Added
|
18
|
+
- Ability to sort artists by track count and album count
|
19
|
+
|
6
20
|
## 0.7.0 - 2022-03-12
|
7
21
|
### Added
|
8
22
|
- Average star ratings for track collectsion (albums, playlists, genres)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -44,10 +44,15 @@ playlist.tracks.each do |track|
|
|
44
44
|
puts track.name
|
45
45
|
end
|
46
46
|
|
47
|
-
# Count tracks by artist
|
47
|
+
# Count tracks by an artist
|
48
48
|
artist = library.artist('XTC')
|
49
49
|
puts artist.tracks.count
|
50
50
|
|
51
|
+
# List genres associated with the artist
|
52
|
+
artist.genres.each do |genre|
|
53
|
+
puts genre.name
|
54
|
+
end
|
55
|
+
|
51
56
|
# Get favorite tracks by this artist
|
52
57
|
favorite_tracks = artist.tracks.select{|t| t.loved? || t.star_rating > 3}
|
53
58
|
|
@@ -56,10 +61,27 @@ library.artists(:most_played).each do |artist|
|
|
56
61
|
puts "#{artist.play_count} :: #{artist.name}"
|
57
62
|
end
|
58
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
|
+
|
59
74
|
# Display track counts per genre
|
60
75
|
library.genres.each do |genre|
|
61
|
-
puts "#{genre.
|
76
|
+
puts "#{genre.track_count} #{genre.name}"
|
77
|
+
end
|
78
|
+
|
79
|
+
# Display track counts per year
|
80
|
+
library.years.each do |year|
|
81
|
+
puts "#{year.track_count} #{year.name}"
|
62
82
|
end
|
83
|
+
|
84
|
+
|
63
85
|
```
|
64
86
|
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`.
|
65
87
|
|
@@ -4,14 +4,10 @@ module AppleMusicLibrary
|
|
4
4
|
class Album < TrackCollection
|
5
5
|
attr_reader :artist
|
6
6
|
|
7
|
-
|
8
|
-
attr_reader :artist
|
9
|
-
|
10
7
|
@@albums = {}
|
11
8
|
|
12
|
-
def initialize(
|
9
|
+
def initialize(album_name, artist)
|
13
10
|
@artist = artist
|
14
|
-
@album_name = album_name
|
15
11
|
super
|
16
12
|
end
|
17
13
|
|
@@ -24,7 +20,7 @@ module AppleMusicLibrary
|
|
24
20
|
if @@albums[key]
|
25
21
|
return @@albums[key]
|
26
22
|
end
|
27
|
-
@@albums[key] = self.new(
|
23
|
+
@@albums[key] = self.new(album_name, artist)
|
28
24
|
end
|
29
25
|
|
30
26
|
def id
|
@@ -46,5 +42,9 @@ module AppleMusicLibrary
|
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
45
|
+
def self.token
|
46
|
+
:album
|
47
|
+
end
|
48
|
+
|
49
49
|
end
|
50
50
|
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,28 +1,8 @@
|
|
1
1
|
module AppleMusicLibrary
|
2
2
|
class Genre < TrackCollection
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
@@genres = {}
|
7
|
-
|
8
|
-
def initialize(name)
|
9
|
-
@name = name
|
10
|
-
super
|
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]
|
4
|
+
def self.token
|
5
|
+
:genre
|
26
6
|
end
|
27
7
|
|
28
8
|
end
|
@@ -4,6 +4,7 @@ require_relative 'genre'
|
|
4
4
|
require_relative 'playlist'
|
5
5
|
require_relative 'playlist_folder'
|
6
6
|
require_relative 'track'
|
7
|
+
require_relative 'year'
|
7
8
|
require_relative "utils"
|
8
9
|
require 'plist'
|
9
10
|
|
@@ -84,6 +85,10 @@ module AppleMusicLibrary
|
|
84
85
|
Track.find(track_id)
|
85
86
|
end
|
86
87
|
|
88
|
+
def years
|
89
|
+
@years ||= Year.all
|
90
|
+
end
|
91
|
+
|
87
92
|
def valid?
|
88
93
|
has_tracks?
|
89
94
|
end
|
@@ -43,6 +43,11 @@ module AppleMusicLibrary
|
|
43
43
|
# end
|
44
44
|
@genre = Genre.find_or_create(genre_name)
|
45
45
|
|
46
|
+
if year_name.present?
|
47
|
+
@year = Year.find_or_create(year_name)
|
48
|
+
@year.add_track(self)
|
49
|
+
end
|
50
|
+
|
46
51
|
@artist.add_track(self)
|
47
52
|
@artist.add_album(@album)
|
48
53
|
@album.add_track(self)
|
@@ -79,6 +84,10 @@ module AppleMusicLibrary
|
|
79
84
|
@info['Genre']
|
80
85
|
end
|
81
86
|
|
87
|
+
def year_name
|
88
|
+
@info['Year']
|
89
|
+
end
|
90
|
+
|
82
91
|
def star_rating
|
83
92
|
rating / 20
|
84
93
|
end
|
@@ -1,16 +1,48 @@
|
|
1
1
|
module AppleMusicLibrary
|
2
2
|
class TrackCollection
|
3
3
|
|
4
|
-
attr_reader :tracks
|
4
|
+
attr_reader :name, :tracks
|
5
5
|
|
6
|
-
|
6
|
+
@@track_collections = {}
|
7
|
+
|
8
|
+
def initialize(name, *args)
|
7
9
|
@tracks = []
|
10
|
+
@name = name.present? ? name : 'Unknown'
|
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
|
+
if lookup_name.blank?
|
23
|
+
lookup_name = 'Unknown'
|
24
|
+
end
|
25
|
+
# puts "Finding or creating #{token}: #{lookup_name}"
|
26
|
+
unless @@track_collections[token]
|
27
|
+
@@track_collections[token] = {}
|
28
|
+
end
|
29
|
+
if @@track_collections[token][lookup_name]
|
30
|
+
# puts "FOUND"
|
31
|
+
return @@track_collections[token][lookup_name]
|
32
|
+
end
|
33
|
+
# puts "CREATING"
|
34
|
+
@@track_collections[token][lookup_name] = self.new(lookup_name)
|
8
35
|
end
|
9
36
|
|
10
37
|
def add_track(track)
|
38
|
+
# puts "Adding #{track.name} to #{self.class.token} #{name}"
|
11
39
|
@tracks << track
|
12
40
|
end
|
13
41
|
|
42
|
+
def track_count
|
43
|
+
@track_count ||= tracks.count
|
44
|
+
end
|
45
|
+
|
14
46
|
def star_rating
|
15
47
|
return nil if rated_tracks.empty?
|
16
48
|
rated_tracks.map(&:star_rating).sum / rated_tracks.size
|
@@ -22,5 +54,6 @@ module AppleMusicLibrary
|
|
22
54
|
@rated_tracks ||= tracks.select{|t| t.rated?}
|
23
55
|
end
|
24
56
|
|
57
|
+
|
25
58
|
end
|
26
59
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'track_collection'
|
2
|
+
|
3
|
+
module AppleMusicLibrary
|
4
|
+
class Year < TrackCollection
|
5
|
+
|
6
|
+
def self.dump
|
7
|
+
self.all.sort_by{|y| y.name}.each do |year|
|
8
|
+
puts "#{year.name} - #{year.track_count} tracks"
|
9
|
+
# year.tracks.each do |track|
|
10
|
+
# puts "\t#{track.name}"
|
11
|
+
# end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.token
|
16
|
+
:year
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
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.10.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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/apple_music_library/track_collection.rb
|
135
135
|
- lib/apple_music_library/utils.rb
|
136
136
|
- lib/apple_music_library/version.rb
|
137
|
+
- lib/apple_music_library/year.rb
|
137
138
|
- sig/apple_music_library.rbs
|
138
139
|
homepage: https://github.com/pugetive/apple_music_library
|
139
140
|
licenses:
|