music_sanitizer 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/lib/music_sanitizer.rb +9 -0
- data/lib/music_sanitizer/processor.rb +66 -0
- data/lib/music_sanitizer/version.rb +3 -0
- data/lists/exclude.yml +7 -0
- data/lists/ignore.yml +15 -0
- data/music_sanitizer.gemspec +23 -0
- data/spec/processor_spec.rb +141 -0
- data/spec/spec_helper.rb +6 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 371b270b34fc117eb79a812457ecfb9a3c8b6b14
|
4
|
+
data.tar.gz: e2d6a43e3956c92dc386dff5a8304dc1a88a7ff5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b51ea59ff10691ea6f5f03bf365b31fa6bdcc5ccc30b6380c1712da11fa49cb9a5d425f8d930a99a3bc41f3c6c29445b1497cfcb2bfce726477ddcf3d1f92588
|
7
|
+
data.tar.gz: 5f3e30e5fd35ff261507dcb58f39764ee69582dc51adb2759458b864dded809f601d6ea36223cd74b88ef59627805299fec92d317f8cfa69c9d131f218744783
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Linus Oleander
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# MusicSanitizer
|
2
|
+
|
3
|
+
Sanitizes music related data. Used internally @ [Radiofy](http://radiofy.se).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install music_sanitizer
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
MusicSanitizer::Processor.new("Will.I.Am Ft. Justin Bieber").process # => "will.i.am"
|
13
|
+
```
|
14
|
+
|
15
|
+
Take a look at the `spec/processor_spec.rb` file for more examples.
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
1. Fork it ( http://github.com/oleander/music_sanitizer-rb/fork )
|
20
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
21
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
22
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
23
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module MusicSanitizer
|
2
|
+
class Processor
|
3
|
+
IGNORE = YAML.load_file(File.join(MusicSanitizer.root, "lists/ignore.yml"))
|
4
|
+
EXCLUDE = YAML.load_file(File.join(MusicSanitizer.root, "lists/exclude.yml"))
|
5
|
+
|
6
|
+
def initialize(content)
|
7
|
+
@content = content
|
8
|
+
end
|
9
|
+
|
10
|
+
def process
|
11
|
+
string = @content.strip
|
12
|
+
|
13
|
+
EXCLUDE.each do |exclude|
|
14
|
+
string = string.gsub(/[^ ]*#{exclude}.*$/i, "")
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sub
|
18
|
+
string = string.gsub(/´/, "'").gsub(/`/, "'")
|
19
|
+
|
20
|
+
# Song - A "abc def" => Song - A
|
21
|
+
# Song - A [B + C] => Song - A
|
22
|
+
# Song A B.mp3 => Song A B
|
23
|
+
# 10. Song => Song
|
24
|
+
[
|
25
|
+
/\.mp3$/,
|
26
|
+
/\[[^\]]*\]/,
|
27
|
+
/".*"/,
|
28
|
+
/(\s+|^)'.*'(\s+|$)/
|
29
|
+
].each do |reg|
|
30
|
+
string = string.gsub(reg, " ").strip
|
31
|
+
end
|
32
|
+
|
33
|
+
[
|
34
|
+
/\(.+?(\)|$)/m,
|
35
|
+
/[^a-z0-9]feat(.*?)\s*[^\s]+/i,
|
36
|
+
/[-]+/,
|
37
|
+
/[\s]+/m,
|
38
|
+
/\_/
|
39
|
+
].each do |reg|
|
40
|
+
string = string.gsub(reg, " ").strip
|
41
|
+
end
|
42
|
+
|
43
|
+
# Split
|
44
|
+
# A ft. B => A
|
45
|
+
string = string.split(/ft\.\s+/i).first
|
46
|
+
# A + B => A
|
47
|
+
string = string.split(/\s+\+\s+/).first
|
48
|
+
|
49
|
+
EXCLUDE.each do |exclude|
|
50
|
+
string = string.gsub(/#{exclude}.*$/i, "")
|
51
|
+
end
|
52
|
+
|
53
|
+
string.gsub(/\A\s|\s\z/, "").gsub(/\s+/, " ").strip.downcase
|
54
|
+
rescue Encoding::CompatibilityError, Encoding::UndefinedConversionError, ArgumentError
|
55
|
+
return string
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.ignore?(this, compare = nil)
|
59
|
+
IGNORE.
|
60
|
+
reject{ |value| compare.to_s.match(/#{value}/i) }.
|
61
|
+
map{ |value| this.match(/#{value}/i) }.any?
|
62
|
+
rescue ArgumentError
|
63
|
+
return false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lists/exclude.yml
ADDED
data/lists/ignore.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'music_sanitizer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "music_sanitizer"
|
8
|
+
spec.version = MusicSanitizer::VERSION
|
9
|
+
spec.authors = ["Linus Oleander"]
|
10
|
+
spec.email = ["linus@oleander.nu"]
|
11
|
+
spec.summary = %q{Sanitizes music related data}
|
12
|
+
spec.homepage = "https://github.com/oleander/music_sanitizer-rb"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
describe MusicSanitizer::Processor do
|
2
|
+
context "processor" do
|
3
|
+
it "Song - Artist => Song Artist" do
|
4
|
+
MusicSanitizer::Processor.new("this is a string - this to").process.should eq("this is a string this to")
|
5
|
+
end
|
6
|
+
|
7
|
+
it "Song A \"abc def\" => Song - A" do
|
8
|
+
MusicSanitizer::Processor.new("Song A \"abc def\"").process.should eq("song a")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Sweet Child O' Mine by Guns N' Roses => sweet child o' mine by guns n' roses" do
|
12
|
+
MusicSanitizer::Processor.new("Sweet Child O' Mine by Guns N' Roses").process.should eq("sweet child o' mine by guns n' roses")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "'Get Lucky - Radio Edit' => 'get lucky'" do
|
16
|
+
MusicSanitizer::Processor.new("Get Lucky - Radio Edit").process.should eq("get lucky")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should handle 'Spelmannsvalsen (Remastered)'" do
|
20
|
+
MusicSanitizer::Processor.new("Spelmannsvalsen (Remastered)").process.should eq("spelmannsvalsen")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "Song - A [B + C] => Song - A" do
|
24
|
+
MusicSanitizer::Processor.new("Song - A [B + C]").process.should eq("song a")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "Song - A (Super Song) => Song - A" do
|
28
|
+
MusicSanitizer::Processor.new("Song - A (Super Song)").process.should eq("song a")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "Song A feat. (Super Song) => Song A" do
|
32
|
+
MusicSanitizer::Processor.new("Song A feat. (Super Song)").process.should eq("song a")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "Daft Punk => Daft Punk" do
|
36
|
+
MusicSanitizer::Processor.new("Daft Punk").process.should eq("daft punk")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "Song A feat.(Super Song) => Song A" do
|
40
|
+
MusicSanitizer::Processor.new("Song A feat.(Super Song)").process.should eq("song a")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "Song A feat.Super B C => Song A B C" do
|
44
|
+
MusicSanitizer::Processor.new("Song A feat.Super B C").process.should eq("song a")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "Song A feat Super B C => Song A B C" do
|
48
|
+
MusicSanitizer::Processor.new("Song A feat Super B C").process.should eq("song a b c")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "A -- B => A B" do
|
52
|
+
MusicSanitizer::Processor.new("A -- B").process.should eq("a b")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "A_B_C_D_E => A B C D E" do
|
56
|
+
MusicSanitizer::Processor.new("A_B_C_D_E").process.should eq("a b c d e")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "100_A=> A" do
|
60
|
+
MusicSanitizer::Processor.new("100_A").process.should eq("100 a")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "don't => don't (no change)" do
|
64
|
+
MusicSanitizer::Processor.new("don't").process.should eq("don't")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "A 'don' B => A B" do
|
68
|
+
MusicSanitizer::Processor.new("A 'don' B").process.should eq("a b")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "Video Games - Album Version Remastered => Video Games" do
|
72
|
+
MusicSanitizer::Processor.new("Video Games - Album Version Remastered").process.should eq("video games")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "r.e.m - Losing My Religion" do
|
76
|
+
MusicSanitizer::Processor.new("r.e.m").process.should eq("r.e.m")
|
77
|
+
MusicSanitizer::Processor.new("r.e.m.").process.should eq("r.e.m.")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "Knockin' On Heaven's Door" do
|
81
|
+
MusicSanitizer::Processor.new("Knockin' On Heaven's Door").process.should eq("knockin' on heaven's door")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "I Love Rock'n'roll => i love rock'n'roll" do
|
85
|
+
MusicSanitizer::Processor.new("I Love Rock'n'roll").process.should eq("i love rock'n'roll")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "Jason Derulo - Undefeated" do
|
89
|
+
MusicSanitizer::Processor.new("Undefeated").process.should eq("undefeated")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "Da Bop - Video Edit" do
|
93
|
+
MusicSanitizer::Processor.new("Da Bop - Video Edit").process.should eq("da bop")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "will.i.am - Scream & Shout" do
|
97
|
+
MusicSanitizer::Processor.new("Scream & Shout").process.should eq("scream & shout")
|
98
|
+
MusicSanitizer::Processor.new("will.i.am").process.should eq("will.i.am")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "handles 'I was made for loving you Official FULL HD'" do
|
102
|
+
MusicSanitizer::Processor.new("I was made for loving you Official FULL HD").process.should eq("i was made for loving you")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "handles 'Will.I.Am Ft. Justin Bieber'" do
|
106
|
+
MusicSanitizer::Processor.new("Will.I.Am Ft. Justin Bieber").process.should eq("will.i.am")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "handles `" do
|
110
|
+
MusicSanitizer::Processor.new("Feelin` Myself").process.should eq("feelin' myself")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "handles ´" do
|
114
|
+
MusicSanitizer::Processor.new("Feelin´ Myself").process.should eq("feelin' myself")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "handles 'S & M (Britney Version)'" do
|
118
|
+
MusicSanitizer::Processor.new("S & M (Britney Version)").process.should eq("s & m")
|
119
|
+
end
|
120
|
+
|
121
|
+
it "handles 'A + B" do
|
122
|
+
MusicSanitizer::Processor.new("A + B").process.should eq("a")
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should handle non ending (" do
|
126
|
+
MusicSanitizer::Processor.new("Can't Hold Us (Hook Up Front/Intro Radio Edit/Cc Cleane").
|
127
|
+
process.should eq("can't hold us")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should handle '2ne1'" do
|
131
|
+
MusicSanitizer::Processor.new("2ne1").process.should eq("2ne1")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "ignore?" do
|
136
|
+
# TODO: Add more specs
|
137
|
+
it "should work" do
|
138
|
+
MusicSanitizer::Processor.ignore?("club version").should be_true
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: music_sanitizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Linus Oleander
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- linus@oleander.nu
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/music_sanitizer.rb
|
69
|
+
- lib/music_sanitizer/processor.rb
|
70
|
+
- lib/music_sanitizer/version.rb
|
71
|
+
- lists/exclude.yml
|
72
|
+
- lists/ignore.yml
|
73
|
+
- music_sanitizer.gemspec
|
74
|
+
- spec/processor_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: https://github.com/oleander/music_sanitizer-rb
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.1.8
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Sanitizes music related data
|
100
|
+
test_files:
|
101
|
+
- spec/processor_spec.rb
|
102
|
+
- spec/spec_helper.rb
|