music_metadata_score 0.0.2 → 0.0.3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmI2MWM0YTY1ZGViNzc4ZmNhYTk0ZDYyYzNiM2JlYWVjNTlhOWE5ZA==
4
+ Nzc0OTQ4ZTE1MzA2YzQ0NDY0NGU2M2E0ODY1MzQwNTNjMDk4Nzk4Mw==
5
5
  data.tar.gz: !binary |-
6
- ZWZjMTM2OGFhMGRkMGNlMWQyMGQ4YjMyNjIzZDdjNTEyYjE5ZTFiNg==
6
+ MTU4ZjUwZGYxNmI2MTg3ZjVjYjExNTM4MzE3MGZlYzdiZTIwMTZjOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YmQ2Y2IzYWY0NjgyMjdiOTVkMjc5MGU1NTBkNGI5MGE0ZTc5NmM0YTg3MWI0
10
- NDhlMWQwZmVhYTAxNjNlMTI1MGNiYzNhOTljZjM2YzE3MjBkNWI3MTRiNzk4
11
- ZDAzOWNiYWU5MTllNmRiOGVhMGRkMDM5MWUzMDg3NDEzYWIxYWI=
9
+ MDE1N2U0NDE0YmU0NWE0NzQ5MWU4ZDQ4ZTgyODg2MzZiZDMxNzUyZTRjOTgz
10
+ NDIxMjliZjQ5NGRkZWEwNTEwZGZkNWU4N2VjNTgxYWEwODBlMmNiM2RhYTU3
11
+ YmRlMjQ4M2ZjZDhkNzY2NTkzNWQwOTE3OThlZThkNTAxMGZlMmY=
12
12
  data.tar.gz: !binary |-
13
- NzhiZGMyOWIwNDA1MTk5MWRjNGVhNGVmYWQxZjQyNTUxMmM0ZWI3MzkyYmY3
14
- MGU3NjUzMDViOWRmNTBiY2NkMjFhZTAwZGE5NTAxOWRlOTViOTRmMzliOWZi
15
- NjJmMzcwYmM0NGQ1YmMyZGVhMzEzZTA4ZDNiM2IxMGY1OTk2ZWI=
13
+ NWE5NGEwOGNiZmExZmZlMWYyNWI4NDg0OTk5MWQ2NzRkYWQ0MWVhZGRiOGM2
14
+ YTg4OGE5OTMzMzk2MWM1YTcyM2E4NmJkNTVkZDc5NmQxMzg5ZTQ1ZDYyMjk5
15
+ MWNkMjAwMTU4YWIyYTQ2Nzk4OTE1MDJhMTg1N2RjMWM4MDgzNzg=
@@ -1,123 +1,125 @@
1
- class Artist
2
-
3
- def self.are_proper_artist_format?(artists, override, level)
4
- if artists && artists != []
5
- Artist.loop_artists(artists, override, level)
6
- else
7
- false
1
+ module MusicMetadataScore
2
+ class Artist
3
+
4
+ def self.are_proper_artist_format?(artists, override, level)
5
+ if artists && artists != []
6
+ MusicMetadataScore::Artist.loop_artists(artists, override, level)
7
+ else
8
+ false
9
+ end
8
10
  end
9
- end
10
-
11
- def self.loop_artists(artists, override, level)
12
- value = true
13
- artists.each do |a|
14
- if !Artist.is_proper_artist_format?(a, override, level)
15
- value = false
16
- break
11
+
12
+ def self.loop_artists(artists, override, level)
13
+ value = true
14
+ artists.each do |a|
15
+ if !MusicMetadataScore::Artist.is_proper_artist_format?(a, override, level)
16
+ value = false
17
+ break
18
+ end
17
19
  end
20
+ value
18
21
  end
19
- value
20
- end
21
-
22
- def self.is_proper_artist_format?(artist, override, level)
23
- if Artist.is_title_case?(artist, override) && !Artist.is_compound_artist?(artist, override) && !Artist.is_bad_various_artists?(artist) && Artist.artist_fits_level?(artist, override, level)
24
- true
25
- else
26
- false
22
+
23
+ def self.is_proper_artist_format?(artist, override, level)
24
+ if MusicMetadataScore::Artist.is_title_case?(artist, override) && !MusicMetadataScore::Artist.is_compound_artist?(artist, override) && !MusicMetadataScore::Artist.is_bad_various_artists?(artist) && MusicMetadataScore::Artist.artist_fits_level?(artist, override, level)
25
+ true
26
+ else
27
+ false
28
+ end
27
29
  end
28
- end
29
-
30
- def self.is_title_case?(artist, override)
31
- if MusicMetadataScore.is_title_case?(artist) || override == true
32
- true
33
- else
34
- false
30
+
31
+ def self.is_title_case?(artist, override)
32
+ if MusicMetadataScore.is_title_case?(artist) || override == true
33
+ true
34
+ else
35
+ false
36
+ end
35
37
  end
36
- end
37
-
38
- def self.is_compound_artist?(artist, override)
39
- if override != true && (artist.downcase.include?('and') || artist.include?('&') || artist.downcase.include?('vs') || artist.downcase.include?('with') || artist.downcase.include?('feat') || artist.downcase.include?('present')) || artist.include?('/')
40
- true
41
- else
42
- false
38
+
39
+ def self.is_compound_artist?(artist, override)
40
+ if override != true && (artist.downcase.include?('and') || artist.include?('&') || artist.downcase.include?('vs') || artist.downcase.include?('with') || artist.downcase.include?('feat') || artist.downcase.include?('present')) || artist.include?('/')
41
+ true
42
+ else
43
+ false
44
+ end
43
45
  end
44
- end
45
-
46
- def self.is_bad_various_artists?(artist)
47
- # various, va, v/a
48
- if artist.downcase == 'various' || artist.downcase == 'va' || artist.downcase == 'v/a' || artist.downcase == 'various artist'
49
- true
50
- else
51
- false
46
+
47
+ def self.is_bad_various_artists?(artist)
48
+ # various, va, v/a
49
+ if artist.downcase == 'various' || artist.downcase == 'va' || artist.downcase == 'v/a' || artist.downcase == 'various artist'
50
+ true
51
+ else
52
+ false
53
+ end
52
54
  end
53
- end
54
-
55
- def self.artist_fits_level?(artist, override, level)
56
- if override == false && level == :track && (artist.downcase == 'various artists' || artist.downcase == 'various artist' || artist.downcase == 'v/a' || artist.downcase == 'various')
57
- false
58
- else
59
- true
55
+
56
+ def self.artist_fits_level?(artist, override, level)
57
+ if override == false && level == :track && (artist.downcase == 'various artists' || artist.downcase == 'various artist' || artist.downcase == 'v/a' || artist.downcase == 'various')
58
+ false
59
+ else
60
+ true
61
+ end
60
62
  end
61
- end
62
-
63
- def self.format_artists(artists, override, level)
64
- array = []
65
- artists.each do |a|
66
- new_artist = Artist.title_case(a)
67
- separated_artists = Artist.separate_compound_artists(new_artist)
68
- separated_artists.each do |sa|
69
- array << sa
63
+
64
+ def self.format_artists(artists, override, level)
65
+ array = []
66
+ artists.each do |a|
67
+ new_artist = MusicMetadataScore::Artist.title_case(a)
68
+ separated_artists = MusicMetadataScore::Artist.separate_compound_artists(new_artist)
69
+ separated_artists.each do |sa|
70
+ array << sa
71
+ end
70
72
  end
73
+ return array
71
74
  end
72
- return array
73
- end
74
-
75
- def self.title_case(artist)
76
- new_artist = MusicMetadataScore.title_case(artist)
77
- Artist.capitalize_the(new_artist)
78
- end
79
-
80
- def self.capitalize_the(string)
81
- split = string.split(' ')
82
- split.each_with_index do |s, i|
83
- if s == 'the'
84
- split[i] = 'The'
75
+
76
+ def self.title_case(artist)
77
+ new_artist = MusicMetadataScore.title_case(artist)
78
+ MusicMetadataScore::Artist.capitalize_the(new_artist)
79
+ end
80
+
81
+ def self.capitalize_the(string)
82
+ split = string.split(' ')
83
+ split.each_with_index do |s, i|
84
+ if s == 'the'
85
+ split[i] = 'The'
86
+ end
85
87
  end
88
+ return split.join(' ')
86
89
  end
87
- return split.join(' ')
88
- end
89
-
90
- def self.separate_compound_artists(artist)
91
- if artist.downcase.include?('and')
92
- Artist.split_artists(artist, 'and')
93
- elsif artist.downcase.include?('&')
94
- Artist.split_artists(artist, '&')
95
- elsif artist.downcase.include?('vs.')
96
- Artist.split_artists(artist, 'vs.')
97
- elsif artist.downcase.include?('vs')
98
- Artist.split_artists(artist, 'vs')
99
- elsif artist.downcase.include?('with')
100
- Artist.split_artists(artist, 'with')
101
- elsif artist.downcase.include?('feat.')
102
- Artist.split_artists(artist, 'feat.')
103
- elsif artist.downcase.include?('featuring')
104
- Artist.split_artists(artist, 'featuring')
105
- elsif artist.downcase.include?('feat')
106
- Artist.split_artists(artist, 'feat')
107
- elsif artist.downcase.include?('presents')
108
- Artist.split_artists(artist, 'presents')
109
- else
110
- [artist]
90
+
91
+ def self.separate_compound_artists(artist)
92
+ if artist.downcase.include?('and')
93
+ MusicMetadataScore::Artist.split_artists(artist, 'and')
94
+ elsif artist.downcase.include?('&')
95
+ MusicMetadataScore::Artist.split_artists(artist, '&')
96
+ elsif artist.downcase.include?('vs.')
97
+ MusicMetadataScore::Artist.split_artists(artist, 'vs.')
98
+ elsif artist.downcase.include?('vs')
99
+ MusicMetadataScore::Artist.split_artists(artist, 'vs')
100
+ elsif artist.downcase.include?('with')
101
+ MusicMetadataScore::Artist.split_artists(artist, 'with')
102
+ elsif artist.downcase.include?('feat.')
103
+ MusicMetadataScore::Artist.split_artists(artist, 'feat.')
104
+ elsif artist.downcase.include?('featuring')
105
+ MusicMetadataScore::Artist.split_artists(artist, 'featuring')
106
+ elsif artist.downcase.include?('feat')
107
+ MusicMetadataScore::Artist.split_artists(artist, 'feat')
108
+ elsif artist.downcase.include?('presents')
109
+ MusicMetadataScore::Artist.split_artists(artist 'presents')
110
+ else
111
+ [artist]
112
+ end
111
113
  end
112
- end
113
-
114
- def self.split_artists(string, separator)
115
- array = string.split(separator)
116
- new_array = []
117
- array.each_with_index do |a, i|
118
- new_array << a.strip
114
+
115
+ def self.split_artists(string, separator)
116
+ array = string.split(separator)
117
+ new_array = []
118
+ array.each_with_index do |a, i|
119
+ new_array << a.strip
120
+ end
121
+ return new_array
119
122
  end
120
- return new_array
123
+
121
124
  end
122
-
123
125
  end
@@ -1,80 +1,82 @@
1
- class Barcode
2
- # Check length
3
- # Check checksum
4
-
5
- def self.is_valid?(barcode)
6
- if Barcode.valid_length?(barcode) && Barcode.valid_characters?(barcode) && Barcode.valid_checksum?(barcode)
7
- true
8
- else
9
- false
1
+ module MusicMetadataScore
2
+ class Barcode
3
+ # Check length
4
+ # Check checksum
5
+
6
+ def self.is_valid?(barcode)
7
+ if MusicMetadataScore::Barcode.valid_length?(barcode) && MusicMetadataScore::Barcode.valid_characters?(barcode) && MusicMetadataScore::Barcode.valid_checksum?(barcode)
8
+ true
9
+ else
10
+ false
11
+ end
10
12
  end
11
- end
12
-
13
- def self.valid_length?(barcode)
14
- if barcode.to_s.length == 12 || barcode.to_s.length == 13
15
- true
16
- else
17
- false
13
+
14
+ def self.valid_length?(barcode)
15
+ if barcode.to_s.length == 12 || barcode.to_s.length == 13
16
+ true
17
+ else
18
+ false
19
+ end
18
20
  end
19
- end
20
-
21
- def self.valid_characters?(barcode)
22
- number = Integer(barcode) rescue false
23
- if number != false
24
- true
25
- else
26
- false
21
+
22
+ def self.valid_characters?(barcode)
23
+ number = Integer(barcode) rescue false
24
+ if number != false
25
+ true
26
+ else
27
+ false
28
+ end
27
29
  end
28
- end
29
-
30
- def self.valid_checksum?(barcode)
31
- if barcode.to_s[barcode.to_s.length - 1].to_i == Barcode.get_checksum(barcode)
32
- true
33
- else
34
- false
30
+
31
+ def self.valid_checksum?(barcode)
32
+ if barcode.to_s[barcode.to_s.length - 1].to_i == MusicMetadataScore::Barcode.get_checksum(barcode)
33
+ true
34
+ else
35
+ false
36
+ end
35
37
  end
36
- end
37
-
38
- def self.get_checksum(barcode)
39
- barcode_sum = Barcode.calculate_barcode(Barcode.remove_checksum(barcode))
40
- if barcode_sum != nil
41
- Barcode.calculate_checksum(barcode_sum)
42
- else
43
- nil
38
+
39
+ def self.get_checksum(barcode)
40
+ barcode_sum = MusicMetadataScore::Barcode.calculate_barcode(MusicMetadataScore::Barcode.remove_checksum(barcode))
41
+ if barcode_sum != nil
42
+ MusicMetadataScore::Barcode.calculate_checksum(barcode_sum)
43
+ else
44
+ nil
45
+ end
44
46
  end
45
- end
46
-
47
- def self.remove_checksum(barcode)
48
- barcode = barcode.to_s
49
- return barcode[0..barcode.length - 2]
50
- end
51
-
52
- def self.calculate_barcode(barcode)
53
- barcode = barcode.to_s
54
- if barcode.length == 11
55
- (barcode[0].to_i * 3) + barcode[1].to_i + (barcode[2].to_i * 3) + barcode[3].to_i + (barcode[4].to_i * 3) + barcode[5].to_i + (barcode[6].to_i * 3) + barcode[7].to_i + (barcode[8].to_i * 3) + barcode[9].to_i + (barcode[10].to_i * 3)
56
- elsif barcode.length == 12
57
- barcode[0].to_i + (barcode[1].to_i * 3) + barcode[2].to_i + (barcode[3].to_i * 3) + barcode[4].to_i + (barcode[5].to_i * 3) + barcode[6].to_i + (barcode[7].to_i * 3) + barcode[8].to_i + (barcode[9].to_i * 3) + barcode[10].to_i + (barcode[11].to_i * 3)
58
- else
59
- nil
60
- end
61
- end
62
-
63
- def self.calculate_checksum(number)
64
- over = number % 10
65
- if over != 0
66
- 10 - over
67
- else
68
- 0
47
+
48
+ def self.remove_checksum(barcode)
49
+ barcode = barcode.to_s
50
+ return barcode[0..barcode.length - 2]
69
51
  end
70
- end
71
-
72
- def self.valid_barcode_or_nil(barcode)
73
- if Barcode.is_valid?(barcode)
74
- barcode
75
- else
76
- nil
52
+
53
+ def self.calculate_barcode(barcode)
54
+ barcode = barcode.to_s
55
+ if barcode.length == 11
56
+ (barcode[0].to_i * 3) + barcode[1].to_i + (barcode[2].to_i * 3) + barcode[3].to_i + (barcode[4].to_i * 3) + barcode[5].to_i + (barcode[6].to_i * 3) + barcode[7].to_i + (barcode[8].to_i * 3) + barcode[9].to_i + (barcode[10].to_i * 3)
57
+ elsif barcode.length == 12
58
+ barcode[0].to_i + (barcode[1].to_i * 3) + barcode[2].to_i + (barcode[3].to_i * 3) + barcode[4].to_i + (barcode[5].to_i * 3) + barcode[6].to_i + (barcode[7].to_i * 3) + barcode[8].to_i + (barcode[9].to_i * 3) + barcode[10].to_i + (barcode[11].to_i * 3)
59
+ else
60
+ nil
61
+ end
62
+ end
63
+
64
+ def self.calculate_checksum(number)
65
+ over = number % 10
66
+ if over != 0
67
+ 10 - over
68
+ else
69
+ 0
70
+ end
71
+ end
72
+
73
+ def self.valid_barcode_or_nil(barcode)
74
+ if MusicMetadataScore::Barcode.is_valid?(barcode)
75
+ barcode
76
+ else
77
+ nil
78
+ end
77
79
  end
80
+
78
81
  end
79
-
80
82
  end
@@ -1,30 +1,32 @@
1
- class Composer
2
-
3
- def self.are_proper_format?(composers)
4
- if composers && composers != []
5
- Composer.loop_composers(composers)
6
- else
7
- false
8
- end
9
- end
1
+ module MusicMetadataScore
2
+ class Composer
10
3
 
11
- def self.loop_composers(composers)
12
- value = true
13
- composers.each do |c|
14
- if !Composer.is_proper_format?(c)
15
- value = false
16
- break
4
+ def self.are_proper_format?(composers)
5
+ if composers && composers != []
6
+ MusicMetadataScore::Composer.loop_composers(composers)
7
+ else
8
+ false
17
9
  end
18
10
  end
19
- value
20
- end
21
-
22
- def self.is_proper_format?(composer)
23
- if Contributor.is_human_name?(composer) && MusicMetadataScore.is_title_case?(composer) && !Artist.is_compound_artist?(composer, false)
24
- true
25
- else
26
- false
11
+
12
+ def self.loop_composers(composers)
13
+ value = true
14
+ composers.each do |c|
15
+ if !MusicMetadataScore::Composer.is_proper_format?(c)
16
+ value = false
17
+ break
18
+ end
19
+ end
20
+ value
21
+ end
22
+
23
+ def self.is_proper_format?(composer)
24
+ if MusicMetadataScore::Contributor.is_human_name?(composer) && MusicMetadataScore.is_title_case?(composer) && !MusicMetadataScore::Artist.is_compound_artist?(composer, false)
25
+ true
26
+ else
27
+ false
28
+ end
27
29
  end
30
+
28
31
  end
29
-
30
32
  end
@@ -1,46 +1,48 @@
1
- class Contributor
2
-
3
- def self.are_proper_format?(contributors)
4
- if contributors && contributors != []
5
- Contributor.loop_contributors(contributors)
6
- else
7
- false
1
+ module MusicMetadataScore
2
+ class Contributor
3
+
4
+ def self.are_proper_format?(contributors)
5
+ if contributors && contributors != []
6
+ MusicMetadataScore::Contributor.loop_contributors(contributors)
7
+ else
8
+ false
9
+ end
8
10
  end
9
- end
10
-
11
- def self.loop_contributors(contributors)
12
- value = true
13
- contributors.each do |c|
14
- if !Contributor.is_proper_format?(c)
15
- value = false
16
- break
11
+
12
+ def self.loop_contributors(contributors)
13
+ value = true
14
+ contributors.each do |c|
15
+ if !MusicMetadataScore::Contributor.is_proper_format?(c)
16
+ value = false
17
+ break
18
+ end
17
19
  end
20
+ value
18
21
  end
19
- value
20
- end
21
-
22
- def self.is_proper_format?(contributor)
23
- if Contributor.is_human_name?(contributor[:name]) && Contributor.has_role?(contributor[:role]) && !Artist.is_compound_artist?(contributor[:name], false) && MusicMetadataScore.is_title_case?(contributor[:name])
24
- true
25
- else
26
- false
22
+
23
+ def self.is_proper_format?(contributor)
24
+ if MusicMetadataScore::Contributor.is_human_name?(contributor[:name]) && MusicMetadataScore::Contributor.has_role?(contributor[:role]) && !MusicMetadataScore::Artist.is_compound_artist?(contributor[:name], false) && MusicMetadataScore.is_title_case?(contributor[:name])
25
+ true
26
+ else
27
+ false
28
+ end
27
29
  end
28
- end
29
-
30
- def self.is_human_name?(contributor)
31
- if contributor.downcase.include?('the ') || contributor.split(' ').count < 2
32
- false
33
- else
34
- true
30
+
31
+ def self.is_human_name?(contributor)
32
+ if contributor.downcase.include?('the ') || contributor.split(' ').count < 2
33
+ false
34
+ else
35
+ true
36
+ end
35
37
  end
36
- end
37
-
38
- def self.has_role?(role)
39
- if role && role != ""
40
- true
41
- else
42
- false
38
+
39
+ def self.has_role?(role)
40
+ if role && role != ""
41
+ true
42
+ else
43
+ false
44
+ end
43
45
  end
46
+
44
47
  end
45
-
46
48
  end
@@ -1,55 +1,57 @@
1
- class Isrc
2
-
3
- def self.is_valid?(isrc)
4
- isrc = Isrc.strip_isrc(isrc)
5
- if Isrc.valid_length?(isrc) && Isrc.valid_country_code?(isrc[0..1]) && Isrc.valid_numbers?(isrc[5..11])
6
- true
7
- else
8
- false
1
+ module MusicMetadataScore
2
+ class Isrc
3
+
4
+ def self.is_valid?(isrc)
5
+ isrc = MusicMetadataScore::Isrc.strip_isrc(isrc)
6
+ if MusicMetadataScore::Isrc.valid_length?(isrc) && MusicMetadataScore::Isrc.valid_country_code?(isrc[0..1]) && MusicMetadataScore::Isrc.valid_numbers?(isrc[5..11])
7
+ true
8
+ else
9
+ false
10
+ end
9
11
  end
10
- end
11
-
12
- def self.valid_length?(isrc)
13
- length = Isrc.strip_isrc(isrc).length rescue 0
14
- if length != 12
15
- false
16
- else
17
- true
12
+
13
+ def self.valid_length?(isrc)
14
+ length = MusicMetadataScore::Isrc.strip_isrc(isrc).length rescue 0
15
+ if length != 12
16
+ false
17
+ else
18
+ true
19
+ end
18
20
  end
19
- end
20
-
21
- def self.strip_isrc(isrc)
22
- if isrc
23
- isrc.strip!
24
- isrc.tr!('^A-Za-z0-9', '')
25
- isrc.upcase!
26
- end
27
- return isrc
28
- end
29
-
30
- def self.valid_country_code?(code)
31
- if code.length == 2 && code[/[a-zA-Z]+/] == code
32
- true
33
- else
34
- false
35
- end
36
- end
37
-
38
- def self.valid_numbers?(numbers)
39
- number = Integer(numbers) rescue false
40
- if numbers.to_s.length == 7 && number
41
- true
42
- else
43
- false
44
- end
45
- end
46
-
47
- def self.valid_isrc_or_nil(isrc)
48
- if Isrc.is_valid?(isrc)
49
- Isrc.strip_isrc(isrc)
50
- else
51
- nil
21
+
22
+ def self.strip_isrc(isrc)
23
+ if isrc
24
+ isrc.strip!
25
+ isrc.tr!('^A-Za-z0-9', '')
26
+ isrc.upcase!
27
+ end
28
+ return isrc
29
+ end
30
+
31
+ def self.valid_country_code?(code)
32
+ if code.length == 2 && code[/[a-zA-Z]+/] == code
33
+ true
34
+ else
35
+ false
36
+ end
37
+ end
38
+
39
+ def self.valid_numbers?(numbers)
40
+ number = Integer(numbers) rescue false
41
+ if numbers.to_s.length == 7 && number
42
+ true
43
+ else
44
+ false
45
+ end
46
+ end
47
+
48
+ def self.valid_isrc_or_nil(isrc)
49
+ if MusicMetadataScore::Isrc.is_valid?(isrc)
50
+ MusicMetadataScore::Isrc.strip_isrc(isrc)
51
+ else
52
+ nil
53
+ end
52
54
  end
55
+
53
56
  end
54
-
55
57
  end