apple_music_library 0.4.0 → 0.7.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 +12 -0
- data/apple_music_library.gemspec +1 -1
- data/lib/apple_music_library/album.rb +14 -5
- data/lib/apple_music_library/artist.rb +12 -0
- data/lib/apple_music_library/genre.rb +3 -9
- data/lib/apple_music_library/library.rb +8 -4
- data/lib/apple_music_library/playlist.rb +4 -3
- data/lib/apple_music_library/track.rb +20 -0
- data/lib/apple_music_library/track_collection.rb +26 -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: be251230181d53ca2f311d1b3fe47f60773c16300f3c7c115761e98bfa8da47b
|
4
|
+
data.tar.gz: e0ebe21930daf26dacca4d16e4ff94f5fad36da8a2e07e06ae4fa8b94ef7d721
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9ddddc083a2d4621110b304d32474fc1164471c67ec3c671a33ae5cbe40bc51ce6bb23b51c7a930d456fd9c8f33300dbd67b39e553ecf15558a3ae54515e774
|
7
|
+
data.tar.gz: 1b08775b63e98f7e1eae53c6caa2ec5f6dbed16ba4b2c97df5ee41dfa8b836116ef58cf370b3b689485bad38d31e151f8dae732b337798d74dd5b6c172b94f9c
|
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,19 @@
|
|
3
3
|
## [Unreleased]
|
4
4
|
- Ability to print out playlist folder hierarchy
|
5
5
|
|
6
|
-
## 0.
|
6
|
+
## 0.7.0 - 2022-03-12
|
7
|
+
### Added
|
8
|
+
- Average star ratings for track collectsion (albums, playlists, genres)
|
9
|
+
|
10
|
+
## 0.6.0 - 2022-03-11
|
11
|
+
### Added
|
12
|
+
- Ability to list top artists by play count
|
13
|
+
|
14
|
+
## 0.5.0 - 2022-03-11
|
15
|
+
### Added
|
16
|
+
- Basic functionality for track ratings via the #rating, #star_rating, and #loved
|
17
|
+
|
18
|
+
## 0.4.0 - 2022-03-11
|
7
19
|
### Added
|
8
20
|
- Basic functionality for Playlist Folders
|
9
21
|
### Fixed
|
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:
|
@@ -44,6 +48,14 @@ end
|
|
44
48
|
artist = library.artist('XTC')
|
45
49
|
puts artist.tracks.count
|
46
50
|
|
51
|
+
# Get favorite tracks by this artist
|
52
|
+
favorite_tracks = artist.tracks.select{|t| t.loved? || t.star_rating > 3}
|
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
|
+
|
47
59
|
# Display track counts per genre
|
48
60
|
library.genres.each do |genre|
|
49
61
|
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,18 @@
|
|
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
7
|
|
6
|
-
attr_reader :artist
|
8
|
+
attr_reader :artist
|
7
9
|
|
8
10
|
@@albums = {}
|
9
11
|
|
10
12
|
def initialize(artist, album_name)
|
11
13
|
@artist = artist
|
12
14
|
@album_name = album_name
|
13
|
-
|
15
|
+
super
|
14
16
|
end
|
15
17
|
|
16
18
|
def self.all
|
@@ -29,13 +31,20 @@ module AppleMusicLibrary
|
|
29
31
|
"#{artist.name}-#{album_name}"
|
30
32
|
end
|
31
33
|
|
32
|
-
def
|
33
|
-
@
|
34
|
+
def name
|
35
|
+
@album_name
|
34
36
|
end
|
35
37
|
|
36
38
|
def year
|
37
39
|
@year ||= @tracks.sort_by(&:year).last.year
|
38
40
|
end
|
39
41
|
|
42
|
+
def dump
|
43
|
+
puts "#{artist.name} - #{name}"
|
44
|
+
tracks.each do |track|
|
45
|
+
puts "\t#{track.name}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
40
49
|
end
|
41
50
|
end
|
@@ -15,6 +15,14 @@ module AppleMusicLibrary
|
|
15
15
|
@@artists.values
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.most_played(limit = 20)
|
19
|
+
if limit.nil?
|
20
|
+
self.all.sort_by(&:play_count).reverse
|
21
|
+
else
|
22
|
+
self.all.sort_by(&:play_count).reverse.take(limit)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
18
26
|
def self.find_or_create(name)
|
19
27
|
if @@artists[name]
|
20
28
|
return @@artists[name]
|
@@ -49,5 +57,9 @@ module AppleMusicLibrary
|
|
49
57
|
@tracks
|
50
58
|
end
|
51
59
|
|
60
|
+
def play_count
|
61
|
+
tracks.map(&:play_count).sum
|
62
|
+
end
|
63
|
+
|
52
64
|
end
|
53
65
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module AppleMusicLibrary
|
2
|
-
class Genre
|
2
|
+
class Genre < TrackCollection
|
3
3
|
|
4
|
-
attr_reader :name
|
4
|
+
attr_reader :name
|
5
5
|
|
6
6
|
@@genres = {}
|
7
7
|
|
8
8
|
def initialize(name)
|
9
9
|
@name = name
|
10
|
-
|
10
|
+
super
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.all
|
@@ -25,11 +25,5 @@ module AppleMusicLibrary
|
|
25
25
|
@@genres[name]
|
26
26
|
end
|
27
27
|
|
28
|
-
def add_track(track)
|
29
|
-
unless tracks.include?(track)
|
30
|
-
@tracks << track
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
28
|
end
|
35
29
|
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)
|
@@ -76,8 +76,8 @@ module AppleMusicLibrary
|
|
76
76
|
PlaylistFolder.find_by_name(playlist_folder_name)
|
77
77
|
end
|
78
78
|
|
79
|
-
def tracks
|
80
|
-
|
79
|
+
def tracks(filter = nil)
|
80
|
+
filter.present? ? Track.send(filter) : Track.all
|
81
81
|
end
|
82
82
|
|
83
83
|
def track(track_id)
|
@@ -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
|
|
@@ -24,6 +24,7 @@ module AppleMusicLibrary
|
|
24
24
|
'Rating',
|
25
25
|
'Album Rating',
|
26
26
|
'Album Rating Computed',
|
27
|
+
'Loved',
|
27
28
|
'Normalization',
|
28
29
|
'Persistent ID',
|
29
30
|
'Track Type',
|
@@ -37,6 +38,9 @@ module AppleMusicLibrary
|
|
37
38
|
@info = info
|
38
39
|
@artist = Artist.find_or_create(artist_name)
|
39
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
|
40
44
|
@genre = Genre.find_or_create(genre_name)
|
41
45
|
|
42
46
|
@artist.add_track(self)
|
@@ -55,6 +59,10 @@ module AppleMusicLibrary
|
|
55
59
|
@@tracks.values
|
56
60
|
end
|
57
61
|
|
62
|
+
def self.loved
|
63
|
+
@loved ||= self.all.select{|t| t.loved?}
|
64
|
+
end
|
65
|
+
|
58
66
|
def id
|
59
67
|
track_id
|
60
68
|
end
|
@@ -71,6 +79,18 @@ module AppleMusicLibrary
|
|
71
79
|
@info['Genre']
|
72
80
|
end
|
73
81
|
|
82
|
+
def star_rating
|
83
|
+
rating / 20
|
84
|
+
end
|
85
|
+
|
86
|
+
def rated?
|
87
|
+
rating > 0 and rating <= 100
|
88
|
+
end
|
89
|
+
|
90
|
+
def loved?
|
91
|
+
loved
|
92
|
+
end
|
93
|
+
|
74
94
|
ATTRIBUTES.each do |track_attribute|
|
75
95
|
define_method(track_attribute.to_s.snakecase) do
|
76
96
|
@info[track_attribute]
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AppleMusicLibrary
|
2
|
+
class TrackCollection
|
3
|
+
|
4
|
+
attr_reader :tracks
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
@tracks = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_track(track)
|
11
|
+
@tracks << track
|
12
|
+
end
|
13
|
+
|
14
|
+
def star_rating
|
15
|
+
return nil if rated_tracks.empty?
|
16
|
+
rated_tracks.map(&:star_rating).sum / rated_tracks.size
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def rated_tracks
|
22
|
+
@rated_tracks ||= tracks.select{|t| t.rated?}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
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.7.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-12 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:
|