apple_music_library 0.6.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63c39fb0820781890a73912185de50cd207af719b59d25a022626374f1ab8eac
4
- data.tar.gz: 99d363ef519977c4b2786684e539289a58cf76503e397c34c7060f42a02c52aa
3
+ metadata.gz: be251230181d53ca2f311d1b3fe47f60773c16300f3c7c115761e98bfa8da47b
4
+ data.tar.gz: e0ebe21930daf26dacca4d16e4ff94f5fad36da8a2e07e06ae4fa8b94ef7d721
5
5
  SHA512:
6
- metadata.gz: e8f45294602867c1de2a10ad3dbe1d88ad02508dc6060712c0cdb436e032c93ea5eb35f69eb0a9e9f1c5dae98089666d8928919f140b668d1c8980b11a7ec517
7
- data.tar.gz: d0724a89d0d22c4be3a65550253284e176102e3c2c2f085ace60418516ba333ed7ebbdc25fda382ee18303d47bf29eeef256b533b231c733813f473c3c28a3a5
6
+ metadata.gz: a9ddddc083a2d4621110b304d32474fc1164471c67ec3c671a33ae5cbe40bc51ce6bb23b51c7a930d456fd9c8f33300dbd67b39e553ecf15558a3ae54515e774
7
+ data.tar.gz: 1b08775b63e98f7e1eae53c6caa2ec5f6dbed16ba4b2c97df5ee41dfa8b836116ef58cf370b3b689485bad38d31e151f8dae732b337798d74dd5b6c172b94f9c
data/CHANGELOG.md CHANGED
@@ -3,9 +3,13 @@
3
3
  ## [Unreleased]
4
4
  - Ability to print out playlist folder hierarchy
5
5
 
6
+ ## 0.7.0 - 2022-03-12
7
+ ### Added
8
+ - Average star ratings for track collectsion (albums, playlists, genres)
9
+
6
10
  ## 0.6.0 - 2022-03-11
7
11
  ### Added
8
- - Ability to sort list top artists by play count
12
+ - Ability to list top artists by play count
9
13
 
10
14
  ## 0.5.0 - 2022-03-11
11
15
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apple_music_library (0.6.0)
4
+ apple_music_library (0.7.0)
5
5
  facets (~> 3.1)
6
6
  plist (~> 3.6)
7
7
 
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:
@@ -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, :album_name, :tracks
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
- @tracks = []
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 add_track(track)
33
- @tracks << track
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
@@ -1,13 +1,13 @@
1
1
  module AppleMusicLibrary
2
- class Genre
2
+ class Genre < TrackCollection
3
3
 
4
- attr_reader :name, :tracks
4
+ attr_reader :name
5
5
 
6
6
  @@genres = {}
7
7
 
8
8
  def initialize(name)
9
9
  @name = name
10
- @tracks = []
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
@@ -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, :tracks
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
- @tracks = []
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,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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppleMusicLibrary
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  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.6.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 00:00:00.000000000 Z
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