apple_music_library 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/README.md +20 -1
- data/apple_music_library.gemspec +1 -1
- data/lib/apple_music_library/album.rb +15 -10
- data/lib/apple_music_library/artist.rb +33 -0
- data/lib/apple_music_library/genre.rb +1 -30
- data/lib/apple_music_library/library.rb +6 -2
- 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 +52 -0
- data/lib/apple_music_library/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c00fde335b53ca8bacdd13bdbce297b0bea1a7f5f4453f4c42bbe9c867b6c02
|
4
|
+
data.tar.gz: cec158953268525e8142c5a51960d0b79584e646c4e16def0fb2e71cd66b2b7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: debab2473712160521d5bc793b65e3febd984620f53d060e3864285bcb906119b074d645c678fcb4e865ea23ae90b6005eff4ccc89c26a3cfb0d91b556f26199
|
7
|
+
data.tar.gz: 47e7b6381f4d94afda90441cdd975fed9ba6afc6ff09de115e0cd0a1144b0bd9b3582cec0f5f736d394308d6537b5f3e31bba407cde5496b7ace6b5cc59ee6b6
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,18 @@
|
|
3
3
|
## [Unreleased]
|
4
4
|
- Ability to print out playlist folder hierarchy
|
5
5
|
|
6
|
+
## 0.8.0 - 2022-03-13
|
7
|
+
### Added
|
8
|
+
- Ability to sort artists by track count and album count
|
9
|
+
|
10
|
+
## 0.7.0 - 2022-03-12
|
11
|
+
### Added
|
12
|
+
- Average star ratings for track collectsion (albums, playlists, genres)
|
13
|
+
|
14
|
+
## 0.6.0 - 2022-03-11
|
15
|
+
### Added
|
16
|
+
- Ability to list top artists by play count
|
17
|
+
|
6
18
|
## 0.5.0 - 2022-03-11
|
7
19
|
### Added
|
8
20
|
- Basic functionality for track ratings via the #rating, #star_rating, and #loved
|
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
|
+
[](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:
|
@@ -44,9 +48,24 @@ end
|
|
44
48
|
artist = library.artist('XTC')
|
45
49
|
puts artist.tracks.count
|
46
50
|
|
47
|
-
# Get favorite tracks by this
|
51
|
+
# Get favorite tracks by this artist
|
48
52
|
favorite_tracks = artist.tracks.select{|t| t.loved? || t.star_rating > 3}
|
49
53
|
|
54
|
+
# List out the most played artists
|
55
|
+
library.artists(:most_played).each do |artist|
|
56
|
+
puts "#{artist.play_count} :: #{artist.name}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# List out artists with the most tracks
|
60
|
+
library.artists(:most_tracks).each do |artist|
|
61
|
+
puts "#{artist.track_count} :: #{artist.name}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# List out artists with the most albums
|
65
|
+
library.artists(:most_albums).each do |artist|
|
66
|
+
puts "#{artist.album_count} :: #{artist.name}"
|
67
|
+
end
|
68
|
+
|
50
69
|
# Display track counts per genre
|
51
70
|
library.genres.each do |genre|
|
52
71
|
puts "#{genre.tracks.count} #{genre.name}"
|
data/apple_music_library.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.metadata["homepage_uri"] = spec.homepage
|
20
20
|
spec.metadata["source_code_uri"] = "https://github.com/pugetive/apple_music_library"
|
21
|
-
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/pugetive/apple_music_library/blob/main/CHANGELOG.md"
|
22
22
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -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
|
@@ -15,6 +15,18 @@ module AppleMusicLibrary
|
|
15
15
|
@@artists.values
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.most_played(limit = 20)
|
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)
|
28
|
+
end
|
29
|
+
|
18
30
|
def self.find_or_create(name)
|
19
31
|
if @@artists[name]
|
20
32
|
return @@artists[name]
|
@@ -45,9 +57,30 @@ module AppleMusicLibrary
|
|
45
57
|
@albums.sort_by(&:year)
|
46
58
|
end
|
47
59
|
|
60
|
+
def album_count
|
61
|
+
@albums.size
|
62
|
+
end
|
63
|
+
|
48
64
|
def tracks
|
49
65
|
@tracks
|
50
66
|
end
|
51
67
|
|
68
|
+
def track_count
|
69
|
+
@tracks.size
|
70
|
+
end
|
71
|
+
|
72
|
+
def play_count
|
73
|
+
tracks.map(&:play_count).sum
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
def self.sorted_set(sort_by_method, limit)
|
79
|
+
if limit.nil?
|
80
|
+
self.all.sort_by{|a| a.send(sort_by_method)}.reverse
|
81
|
+
else
|
82
|
+
self.all.sort_by{|a| a.send(sort_by_method)}.reverse.take(limit)
|
83
|
+
end
|
84
|
+
end
|
52
85
|
end
|
53
86
|
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
|
@@ -44,8 +44,8 @@ module AppleMusicLibrary
|
|
44
44
|
@albums ||= Album.all
|
45
45
|
end
|
46
46
|
|
47
|
-
def artists
|
48
|
-
|
47
|
+
def artists(filter = nil, limit = nil)
|
48
|
+
filter.present? ? Artist.send(filter, limit) : Artist.all
|
49
49
|
end
|
50
50
|
|
51
51
|
def artist(artist_name)
|
@@ -92,6 +92,10 @@ module AppleMusicLibrary
|
|
92
92
|
tracks.any?
|
93
93
|
end
|
94
94
|
|
95
|
+
def rated_tracks
|
96
|
+
tracks.select{|t| t.rated?}
|
97
|
+
end
|
98
|
+
|
95
99
|
private
|
96
100
|
|
97
101
|
def extract_plist_info
|
@@ -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,52 @@
|
|
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 star_rating
|
33
|
+
return nil if rated_tracks.empty?
|
34
|
+
rated_tracks.map(&:star_rating).sum / rated_tracks.size
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def rated_tracks
|
40
|
+
@rated_tracks ||= tracks.select{|t| t.rated?}
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.token
|
44
|
+
self.class.name
|
45
|
+
end
|
46
|
+
|
47
|
+
def token
|
48
|
+
self.class.token
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
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.8.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-13 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
|
@@ -140,6 +141,7 @@ licenses:
|
|
140
141
|
metadata:
|
141
142
|
homepage_uri: https://github.com/pugetive/apple_music_library
|
142
143
|
source_code_uri: https://github.com/pugetive/apple_music_library
|
144
|
+
changelog_uri: https://github.com/pugetive/apple_music_library/blob/main/CHANGELOG.md
|
143
145
|
post_install_message:
|
144
146
|
rdoc_options: []
|
145
147
|
require_paths:
|