Class: MusicMetadataScore::Score
- Inherits:
-
Object
- Object
- MusicMetadataScore::Score
- Defined in:
- lib/music_metadata_score/score.rb
Class Method Summary collapse
- .combine_arrays(first, second) ⇒ Object
-
.corrections(metadata) ⇒ Object
Corrections.
- .field_is_blank?(field) ⇒ Boolean
- .format_field_name(field) ⇒ Object
- .is_or_are(field) ⇒ Object
- .missing_or_corrected(field, original, corrected) ⇒ Object
- .object_is_blank?(value) ⇒ Boolean
- .product_corrections(metadata) ⇒ Object
- .product_fields_corrected(metadata) ⇒ Object
- .product_fields_exist(metadata) ⇒ Object
- .product_fields_quality(metadata) ⇒ Object
-
.product_score(metadata) ⇒ Object
Product level scores.
-
.total_product_score(metadata) ⇒ Object
Total Product Score.
- .track_corrections(metadata) ⇒ Object
- .track_fields_corrected(metadata) ⇒ Object
- .track_fields_exist(metadata) ⇒ Object
- .track_fields_quality(metadata) ⇒ Object
-
.track_score(metadata) ⇒ Object
Track level scores.
- .tracks_corrections(tracks) ⇒ Object
- .tracks_score(tracks) ⇒ Object
Class Method Details
.combine_arrays(first, second) ⇒ Object
253 254 255 256 257 258 |
# File 'lib/music_metadata_score/score.rb', line 253 def self.combine_arrays(first, second) second.each do |s| first << s end first end |
.corrections(metadata) ⇒ Object
Corrections
170 171 172 173 174 |
# File 'lib/music_metadata_score/score.rb', line 170 def self.corrections() array = [] array = MusicMetadataScore::Score.combine_arrays(array, MusicMetadataScore::Score.product_corrections([:product])) array = MusicMetadataScore::Score.combine_arrays(array, MusicMetadataScore::Score.tracks_corrections([:tracks])) end |
.field_is_blank?(field) ⇒ Boolean
229 230 231 232 233 234 235 |
# File 'lib/music_metadata_score/score.rb', line 229 def self.field_is_blank?(field) if field == nil || field == "" || field == [] true else false end end |
.format_field_name(field) ⇒ Object
245 246 247 248 249 250 251 |
# File 'lib/music_metadata_score/score.rb', line 245 def self.format_field_name(field) split = field.split('_') split.each do |s| s = MusicMetadataScore::TitleCase.titleize(s) end split.join(' ') end |
.is_or_are(field) ⇒ Object
237 238 239 240 241 242 243 |
# File 'lib/music_metadata_score/score.rb', line 237 def self.is_or_are(field) if field[field.length - 1].downcase == 's' 'are' else 'is' end end |
.missing_or_corrected(field, original, corrected) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/music_metadata_score/score.rb', line 207 def self.missing_or_corrected(field, original, corrected) field = MusicMetadataScore::Score.format_field_name(field) is_or_are = MusicMetadataScore::Score.is_or_are(field) if original && original != "" && original != [] || original == false if original == corrected || corrected == '' nil else "#{field} #{is_or_are} incorrect. It should be #{corrected}" end elsif MusicMetadataScore::Score.field_is_blank?(corrected) && field == 'Version' || field == 'Featuring Artists' nil elsif !MusicMetadataScore::Score.field_is_blank?(corrected) && field == 'Version' || field == 'Featuring Artists' if original == corrected nil else "#{field} #{is_or_are} incorrect. It should be #{corrected}" end else "#{field} #{is_or_are} missing" end end |
.object_is_blank?(value) ⇒ Boolean
143 144 145 146 147 148 149 |
# File 'lib/music_metadata_score/score.rb', line 143 def self.object_is_blank?(value) if value != nil && value != "" && value != [] && value != {} false else true end end |
.product_corrections(metadata) ⇒ Object
176 177 178 179 180 181 182 183 184 |
# File 'lib/music_metadata_score/score.rb', line 176 def self.product_corrections() array = [] = MusicMetadataScore::Score.product_fields_corrected() .each do |m| error = MusicMetadataScore::Score.missing_or_corrected(m[0].to_s, m[1], [m[0]]) array << "Product " + error if error end array end |
.product_fields_corrected(metadata) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/music_metadata_score/score.rb', line 49 def self.product_fields_corrected() titles = MusicMetadataScore::TitleCase.build_proper_title([:title], [:version], [:primary_artists], [:featuring_artists]) { :title => titles[:title], :version => titles[:version], :cat_no => [:cat_no].upcase, :barcode => MusicMetadataScore::Barcode.([:barcode]), :label => MusicMetadataScore::TitleCase.title_case([:label]), :primary_artists => MusicMetadataScore::Artist.format_artists([:primary_artists], false, :product), :featuring_artists => MusicMetadataScore::Artist.format_artists([:featuring_artists], false, :product), :release_date => [:release_date], :original_release_date => [:original_release_date], :p_year => [:p_year], :p_line => MusicMetadataScore::TitleCase.title_case([:p_line]), :c_year => [:c_year], :c_line => MusicMetadataScore::TitleCase.title_case([:c_line]), :parental_advisory => [:parental_advisory], :live => [:live], :remastered => [:remastered], :type => [:type], :media => [:media], :format => [:format], :primary_genre => MusicMetadataScore::TitleCase.title_case([:primary_genre]), :secondary_genre => MusicMetadataScore::TitleCase.title_case([:secondary_genre]), :description => [:description] } end |
.product_fields_exist(metadata) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/music_metadata_score/score.rb', line 11 def self.product_fields_exist() score = 0 score += 2 if !MusicMetadataScore::Score.object_is_blank?([:title]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:cat_no]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:barcode]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:label]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:primary_artists]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:release_date]) score += 1 if !MusicMetadataScore::Score.object_is_blank?([:original_release_date]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:p_year]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:p_line]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:c_year]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:c_line]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:parental_advisory]) score += 1 if !MusicMetadataScore::Score.object_is_blank?([:live]) score += 1 if !MusicMetadataScore::Score.object_is_blank?([:remastered]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:type]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:media]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:format]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:primary_genre]) score += 1 if !MusicMetadataScore::Score.object_is_blank?([:secondary_genre]) score += 1 if !MusicMetadataScore::Score.object_is_blank?([:description]) return score end |
.product_fields_quality(metadata) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/music_metadata_score/score.rb', line 36 def self.product_fields_quality() score = 0 score += 10 if MusicMetadataScore::TitleCase.is_proper_title_format?([:title], [:primary_artists], [:featuring_artists]) score += 10 if MusicMetadataScore.is_title_case?([:version]) score += 5 if MusicMetadataScore.([:barcode]) score += 2 if MusicMetadataScore.is_title_case?([:label]) score += 5 if MusicMetadataScore.is_title_case?([:p_line]) score += 5 if MusicMetadataScore.is_title_case?([:c_line]) score += 10 if MusicMetadataScore::Artist.are_proper_artist_format?([:primary_artists], false, :product) score += 5 if MusicMetadataScore::Artist.are_proper_artist_format?([:featuring_artists], false, :product) return score end |
.product_score(metadata) ⇒ Object
Product level scores
5 6 7 8 9 |
# File 'lib/music_metadata_score/score.rb', line 5 def self.product_score() score = MusicMetadataScore::Score.product_fields_exist() + MusicMetadataScore::Score.product_fields_quality() percent = score.to_f / 87 * 100 return percent.round(1) end |
.total_product_score(metadata) ⇒ Object
Total Product Score
152 153 154 155 156 157 |
# File 'lib/music_metadata_score/score.rb', line 152 def self.total_product_score() product_score = MusicMetadataScore::Score.product_score([:product]) tracks_score = MusicMetadataScore::Score.tracks_score([:tracks]) final_score = (product_score + tracks_score) / ([:tracks].count + 1) return final_score.round(1) end |
.track_corrections(metadata) ⇒ Object
197 198 199 200 201 202 203 204 205 |
# File 'lib/music_metadata_score/score.rb', line 197 def self.track_corrections() array = [] = MusicMetadataScore::Score.track_fields_corrected() .each do |m| error = MusicMetadataScore::Score.missing_or_corrected(m[0].to_s, m[1], [m[0]]) array << error if error end array end |
.track_fields_corrected(metadata) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/music_metadata_score/score.rb', line 119 def self.track_fields_corrected() titles = MusicMetadataScore::TitleCase.build_proper_title([:title], [:version], [:primary_artists], [:featuring_artists]) { :title => titles[:title], :version => titles[:version], :isrc => MusicMetadataScore::Isrc.valid_isrc_or_nil([:isrc]), :primary_artists => MusicMetadataScore::Artist.format_artists([:primary_artists], false, :track), :featuring_artists => MusicMetadataScore::Artist.format_artists([:featuring_artists], false, :track), :p_year => [:p_year], :p_line => MusicMetadataScore::TitleCase.title_case([:p_line]), :parental_advisory => [:parental_advisory], :primary_genre => MusicMetadataScore::TitleCase.title_case([:primary_genre]), :secondary_genre => MusicMetadataScore::TitleCase.title_case([:secondary_genre]), :recording_year => [:recording_year], :recording_country => [:recording_country], :recording_location => [:recording_location], :country_of_commission => [:country_of_commission], :rights_holder => [:rights_holder], :contributors => [:contributors], :composers => [:composers], :publishers => [:publishers] } end |
.track_fields_exist(metadata) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/music_metadata_score/score.rb', line 84 def self.track_fields_exist() score = 0 score += 2 if !MusicMetadataScore::Score.object_is_blank?([:title]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:isrc]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:primary_artists]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:p_year]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:p_line]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:parental_advisory]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:primary_genre]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:secondary_genre]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:recording_year]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:recording_country]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:recording_location]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:country_of_commission]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:rights_holder]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:contributors]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:composers]) score += 2 if !MusicMetadataScore::Score.object_is_blank?([:publishers]) return score end |
.track_fields_quality(metadata) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/music_metadata_score/score.rb', line 105 def self.track_fields_quality() score = 0 score += 10 if MusicMetadataScore::TitleCase.is_proper_title_format?([:title], [:primary_artists], [:featuring_artists]) score += 10 if MusicMetadataScore.is_title_case?([:version]) score += 5 if MusicMetadataScore.valid_isrc?([:isrc]) score += 5 if MusicMetadataScore.is_title_case?([:p_line]) score += 10 if MusicMetadataScore::Artist.are_proper_artist_format?([:primary_artists], false, :product) score += 5 if MusicMetadataScore::Artist.are_proper_artist_format?([:featuring_artists], false, :product) score += 10 if MusicMetadataScore::Contributor.are_proper_format?([:contributors]) score += 10 if MusicMetadataScore::Composer.are_proper_format?([:composers]) score += 10 if MusicMetadataScore::Publisher.are_proper_format?([:publishers]) return score end |
.track_score(metadata) ⇒ Object
Track level scores
78 79 80 81 82 |
# File 'lib/music_metadata_score/score.rb', line 78 def self.track_score() score = MusicMetadataScore::Score.track_fields_exist() + MusicMetadataScore::Score.track_fields_quality() percent = score.to_f / 107 * 100 return percent.round(1) end |
.tracks_corrections(tracks) ⇒ Object
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/music_metadata_score/score.rb', line 186 def self.tracks_corrections(tracks) array = [] tracks.each_with_index do |t, index| track_returned = MusicMetadataScore::Score.track_corrections(t) track_returned.each do |tr| array << "Track #{index + 1} #{tr}" end end array end |
.tracks_score(tracks) ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/music_metadata_score/score.rb', line 159 def self.tracks_score(tracks) tracks_score = 0 if tracks tracks.each do |t| tracks_score += MusicMetadataScore::Score.track_score(t) end end return tracks_score end |