musicbrainz_ruby 0.0.5 → 0.1.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.
- data/.document +5 -0
- data/.gitignore +47 -15
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/codeStyleSettings.xml +13 -0
- data/.idea/dictionaries/j4k4x.xml +3 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +11 -0
- data/.idea/inspectionProfiles/profiles_settings.xml +7 -0
- data/.idea/misc.xml +8 -0
- data/.idea/modules.xml +9 -0
- data/.idea/musicbrainz_ruby.iml +67 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +8 -0
- data/.idea/workspace.xml +675 -0
- data/.rspec +1 -0
- data/Gemfile +26 -6
- data/Gemfile.lock +173 -0
- data/{LICENSE → LICENSE.txt} +1 -3
- data/README.rdoc +19 -0
- data/Rakefile +58 -2
- data/VERSION +1 -0
- data/database.yml +20 -0
- data/features/musicbrainz_ruby.feature +16 -0
- data/features/releases/release_query.feature +19 -0
- data/features/step_definitions/MB/rails_steps.rb +121 -0
- data/features/step_definitions/MB/release_steps.rb/release_steps.rb +0 -0
- data/features/support/cukigem.rb +26 -0
- data/features/support/env.rb +19 -0
- data/lib/generators/music_brainz/install/initializer_generator.rb +5 -0
- data/lib/generators/music_brainz/install/install_generator.rb +14 -0
- data/lib/generators/music_brainz/install/templates/config/initializers/musicbrainz.rb.erb +47 -0
- data/lib/musicbrainz/artist.rb +59 -0
- data/lib/musicbrainz/base.rb +30 -3
- data/lib/musicbrainz/label.rb +4 -0
- data/lib/musicbrainz/query.rb +83 -0
- data/lib/musicbrainz/recording.rb +4 -0
- data/lib/musicbrainz/release.rb +77 -8
- data/lib/musicbrainz/release_group.rb +4 -0
- data/lib/musicbrainz/string.rb +47 -0
- data/lib/musicbrainz/work.rb +4 -0
- data/lib/musicbrainz_ruby.rb +19 -0
- data/log/test.log +0 -0
- data/musicbrainz_ruby.gemspec +194 -0
- data/report.html +478 -0
- data/spec/factories.rb +9 -0
- data/spec/musicbrainz_ruby_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- data/tmp/rails_app/.gitignore +15 -0
- data/tmp/rails_app/Gemfile +21 -0
- data/tmp/rails_app/Gemfile.lock +183 -0
- data/tmp/rails_app/README.rdoc +261 -0
- data/tmp/rails_app/Rakefile +7 -0
- data/tmp/rails_app/app/assets/images/rails.png +0 -0
- data/tmp/rails_app/app/assets/javascripts/application.js +15 -0
- data/tmp/rails_app/app/assets/javascripts/mmbrains.js.coffee +3 -0
- data/tmp/rails_app/app/assets/stylesheets/application.css +13 -0
- data/tmp/rails_app/app/assets/stylesheets/mmbrains.css.scss +3 -0
- data/tmp/rails_app/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/tmp/rails_app/app/controllers/application_controller.rb +2 -0
- data/tmp/rails_app/app/controllers/mmbrains_controller.rb +7 -0
- data/tmp/rails_app/app/controllers/models_controller.rb +10 -0
- data/tmp/rails_app/app/helpers/application_helper.rb +2 -0
- data/tmp/rails_app/app/helpers/mmbrains_helper.rb +2 -0
- data/tmp/rails_app/app/mailers/.gitkeep +0 -0
- data/tmp/rails_app/app/models/.gitkeep +0 -0
- data/tmp/rails_app/app/models/mmbrain.rb +3 -0
- data/tmp/rails_app/app/views/layouts/application.html.erb +14 -0
- data/tmp/rails_app/app/views/mmbrains/_form.html.erb +21 -0
- data/tmp/rails_app/app/views/mmbrains/edit.html.erb +6 -0
- data/tmp/rails_app/app/views/mmbrains/index.html.erb +1 -0
- data/tmp/rails_app/app/views/mmbrains/new.html.erb +5 -0
- data/tmp/rails_app/app/views/mmbrains/show.html.erb +10 -0
- data/tmp/rails_app/app/views/models/show.html.erb +1 -0
- data/tmp/rails_app/config.ru +4 -0
- data/tmp/rails_app/config/application.rb +62 -0
- data/tmp/rails_app/config/boot.rb +6 -0
- data/tmp/rails_app/config/database.yml +28 -0
- data/tmp/rails_app/config/environment.rb +5 -0
- data/tmp/rails_app/config/environments/development.rb +37 -0
- data/tmp/rails_app/config/environments/production.rb +67 -0
- data/tmp/rails_app/config/environments/test.rb +37 -0
- data/tmp/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/tmp/rails_app/config/initializers/inflections.rb +15 -0
- data/tmp/rails_app/config/initializers/mime_types.rb +5 -0
- data/tmp/rails_app/config/initializers/secret_token.rb +7 -0
- data/tmp/rails_app/config/initializers/session_store.rb +8 -0
- data/tmp/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/tmp/rails_app/config/locales/en.yml +5 -0
- data/tmp/rails_app/config/routes.rb +3 -0
- data/tmp/rails_app/db/migrate/20120630070553_create_mmbrains.rb +9 -0
- data/tmp/rails_app/db/seeds.rb +7 -0
- data/tmp/rails_app/lib/assets/.gitkeep +0 -0
- data/tmp/rails_app/lib/tasks/.gitkeep +0 -0
- data/tmp/rails_app/log/.gitkeep +0 -0
- data/tmp/rails_app/public/404.html +26 -0
- data/tmp/rails_app/public/422.html +26 -0
- data/tmp/rails_app/public/500.html +25 -0
- data/tmp/rails_app/public/favicon.ico +0 -0
- data/tmp/rails_app/public/index.html +241 -0
- data/tmp/rails_app/public/robots.txt +5 -0
- data/tmp/rails_app/script/rails +6 -0
- data/tmp/rails_app/test/fixtures/.gitkeep +0 -0
- data/tmp/rails_app/test/fixtures/mmbrains.yml +7 -0
- data/tmp/rails_app/test/functional/.gitkeep +0 -0
- data/tmp/rails_app/test/functional/mmbrains_controller_test.rb +49 -0
- data/tmp/rails_app/test/integration/.gitkeep +0 -0
- data/tmp/rails_app/test/performance/browsing_test.rb +12 -0
- data/tmp/rails_app/test/test_helper.rb +13 -0
- data/tmp/rails_app/test/unit/.gitkeep +0 -0
- data/tmp/rails_app/test/unit/helpers/mmbrains_helper_test.rb +4 -0
- data/tmp/rails_app/test/unit/mmbrain_test.rb +7 -0
- data/tmp/rails_app/vendor/assets/javascripts/.gitkeep +0 -0
- data/tmp/rails_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/tmp/rails_app/vendor/plugins/.gitkeep +0 -0
- metadata +350 -11
- data/README.md +0 -29
- data/lib/music_brainz.rb +0 -17
- data/lib/musicbrainz/version.rb +0 -3
- data/musicbrainz.gemspec +0 -21
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class Cukigem
|
|
2
|
+
class << self
|
|
3
|
+
attr_accessor :project_root, :temp_root, :application_name, :paths_to_clear
|
|
4
|
+
|
|
5
|
+
def app_root
|
|
6
|
+
File.join(temp_root, application_name)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
self.project_root = File.expand_path(File.join(File.dirname(__FILE__), '..','..', '..')).freeze
|
|
11
|
+
#Now, below I'm referencing to a symbolic link, outside of the rails application.
|
|
12
|
+
self.temp_root = File.join(project_root, "/non_rails_tmp").freeze
|
|
13
|
+
self.application_name = "rails_app".freeze
|
|
14
|
+
|
|
15
|
+
self.paths_to_clear = %w[
|
|
16
|
+
"db/*.sqlite3",
|
|
17
|
+
"db/migrate/*.rb",
|
|
18
|
+
"app/views/**",
|
|
19
|
+
"app/controllers/**",
|
|
20
|
+
"app/helpers/**",
|
|
21
|
+
"app/models/**",
|
|
22
|
+
"vendor/plugins/**",
|
|
23
|
+
"public/images/**",
|
|
24
|
+
"public/stylesheets/**"
|
|
25
|
+
]
|
|
26
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module MusicBrainz
|
|
2
|
+
class InstallGenerator < ::Rails::Generators::Base
|
|
3
|
+
desc "Installs String Methods for Musicbrainz"
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.expand_path("../templates", __FILE__)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def create_initializer
|
|
10
|
+
template 'config/initializers/musicbrainz.rb.erb', 'config/initializers/musicbrainz.rb'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
class String
|
|
2
|
+
def is_mbid
|
|
3
|
+
if self.length==36
|
|
4
|
+
l=self.split("-")
|
|
5
|
+
if l[0].length==8 &&
|
|
6
|
+
l[1].length==4 &&
|
|
7
|
+
l[2].length==4 &&
|
|
8
|
+
l[3].length==4 &&
|
|
9
|
+
l[4].length==12
|
|
10
|
+
return true
|
|
11
|
+
else
|
|
12
|
+
return false
|
|
13
|
+
end
|
|
14
|
+
else
|
|
15
|
+
return false
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def titleize_proper
|
|
20
|
+
excluded_from_title=["a","an","the","and", "but", "or", "so",
|
|
21
|
+
"after", "before", "when", "while", "since",
|
|
22
|
+
"until", "although", "even if", "because",
|
|
23
|
+
"both", "either", "neither", "nor","as",
|
|
24
|
+
"at", "by", "for", "from", "in", "into",
|
|
25
|
+
"of", "off", "on", "onto", "than", "to",
|
|
26
|
+
"via", "with", "anti", "betwixt", "circa",
|
|
27
|
+
"per", "qua", "sans", "unto", "versus",
|
|
28
|
+
"vis-a-vis","ago", "hence", "through",
|
|
29
|
+
"withal"]
|
|
30
|
+
|
|
31
|
+
string_array=self.split(' ')
|
|
32
|
+
title=Array.new
|
|
33
|
+
string_array.each_with_index do |word,i|
|
|
34
|
+
|
|
35
|
+
if i==0
|
|
36
|
+
title<<word.capitalize
|
|
37
|
+
elsif excluded_from_title.include?(word)
|
|
38
|
+
title<<word
|
|
39
|
+
else
|
|
40
|
+
title<<word.capitalize
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
title.join(' ')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
data/lib/musicbrainz/artist.rb
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module MusicBrainz
|
|
2
|
+
class Artist < Base
|
|
3
|
+
attr_accessor :metadata
|
|
4
|
+
attr_accessor :name
|
|
5
|
+
attr_accessor :releases
|
|
6
|
+
attr_accessor :artist_info
|
|
7
|
+
attr_accessor :release_groups
|
|
8
|
+
attr_accessor :works
|
|
9
|
+
|
|
10
|
+
def initialize(mbid, query=[])
|
|
11
|
+
#Valid sub-queries: artists, labels, recordings, release-groups
|
|
12
|
+
@mbid=mbid.is_mbid ? mbid : false
|
|
13
|
+
if query.present? && query!=[]
|
|
14
|
+
@query=query.join("+")
|
|
15
|
+
else
|
|
16
|
+
@query='releases'
|
|
17
|
+
end
|
|
18
|
+
@method='artist'
|
|
19
|
+
get_request(@method, @mbid, @query)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def get_request(method, mbid, query=[])
|
|
23
|
+
@request=self.class.get(method, mbid, query)
|
|
24
|
+
@metadata=@request['metadata']
|
|
25
|
+
get_releases if query.include?('releases')
|
|
26
|
+
get_info if query.include?('info')
|
|
27
|
+
get_release_groups if query.include?('release-groups')
|
|
28
|
+
get_works if query.include?('works')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get_info
|
|
32
|
+
@artist_info={:type => @metadata['artist']['type'], :mbid => @metadata['artist']['id']}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def get_releases
|
|
36
|
+
releases=@metadata['artist']['release_list']['release']
|
|
37
|
+
@releases=Array.new
|
|
38
|
+
releases.each do |r|
|
|
39
|
+
@releases<<OpenStruct.new(r)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def get_release_groups
|
|
44
|
+
release_groups=@metadata['artist']['release_group_list']['release_group']
|
|
45
|
+
@release_groups=Array.new
|
|
46
|
+
release_groups.each do |r|
|
|
47
|
+
@release_groups<<OpenStruct.new(r)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def get_works
|
|
52
|
+
works=@metadata['artist']['work_list']['work']
|
|
53
|
+
@works=Array.new
|
|
54
|
+
works.each do |r|
|
|
55
|
+
@works<<OpenStruct.new(r)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
data/lib/musicbrainz/base.rb
CHANGED
|
@@ -2,9 +2,12 @@ module MusicBrainz
|
|
|
2
2
|
class Base
|
|
3
3
|
|
|
4
4
|
def self.get(method, mbid, query)
|
|
5
|
+
if method=='search'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
includes="?query=#{query}" unless query==[]
|
|
8
|
+
else
|
|
9
|
+
includes="?inc=#{query}" unless query==[]
|
|
10
|
+
end
|
|
8
11
|
path="/ws/2/#{method}/#{mbid}#{includes}"
|
|
9
12
|
uri_host="musicbrainz.org"
|
|
10
13
|
uri_port="80"
|
|
@@ -21,5 +24,29 @@ module MusicBrainz
|
|
|
21
24
|
|
|
22
25
|
|
|
23
26
|
end
|
|
27
|
+
|
|
28
|
+
def self.get_query_path(method, query)
|
|
29
|
+
|
|
30
|
+
inc="?query=#{query}"
|
|
31
|
+
path="/ws/2/#{method}#{inc}"
|
|
32
|
+
uri_host="musicbrainz.org"
|
|
33
|
+
uri_port="80"
|
|
34
|
+
puts path
|
|
35
|
+
http = Net::HTTP.new(uri_host, uri_port).get(path)
|
|
36
|
+
response = http.response.code
|
|
37
|
+
body = http.response.body
|
|
38
|
+
|
|
39
|
+
body=Hash.from_xml(body)
|
|
40
|
+
if response=="200"
|
|
41
|
+
return body
|
|
42
|
+
else
|
|
43
|
+
return false
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
24
48
|
end
|
|
25
|
-
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
end
|
data/lib/musicbrainz/label.rb
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module MusicBrainz
|
|
2
|
+
class Query < Base
|
|
3
|
+
attr_accessor :results
|
|
4
|
+
attr_accessor :original_query
|
|
5
|
+
attr_accessor :score
|
|
6
|
+
attr_accessor :top_match
|
|
7
|
+
attr_accessor :fetch
|
|
8
|
+
|
|
9
|
+
def initialize(query, method, fetch)
|
|
10
|
+
method=method[:entity]
|
|
11
|
+
fetch=fetch[:fetch]
|
|
12
|
+
@fetch=fetch if fetch.is_a?(Hash) && fetch.present? && fetch.has_key?(:fetch)
|
|
13
|
+
@fetch=fetch if fetch.is_a?(Array) && fetch.present?
|
|
14
|
+
@fetch=Array.new<<fetch if fetch.is_a?(String) && fetch.present?
|
|
15
|
+
available_methods=['artist', 'release', 'release-group', 'recording', 'work', 'label']
|
|
16
|
+
method= available_methods.include?(method) ? method : nil
|
|
17
|
+
if query.kind_of?(String)
|
|
18
|
+
@query= query.is_mbid ? [:mbid, query] : query
|
|
19
|
+
elsif query.kind_of?(Hash)
|
|
20
|
+
@query=Hash.new
|
|
21
|
+
query.each_pair do |k, v|
|
|
22
|
+
@query[k]=v
|
|
23
|
+
end
|
|
24
|
+
else
|
|
25
|
+
return false
|
|
26
|
+
end
|
|
27
|
+
#Now, transferring to query format.
|
|
28
|
+
query_a=Array.new
|
|
29
|
+
@query.each_pair do |k, v|
|
|
30
|
+
if k==:date
|
|
31
|
+
v=v.to_date
|
|
32
|
+
v="#{v-7.days} TO #{v}"
|
|
33
|
+
end
|
|
34
|
+
query_a<<"#{k}:#{v}"
|
|
35
|
+
end
|
|
36
|
+
@original_query=query_a
|
|
37
|
+
query_s=String.new
|
|
38
|
+
query_s=URI.encode(query_a.join("AND"))
|
|
39
|
+
#Dealing with non-mbid...
|
|
40
|
+
get_query(method, query_s,fetch)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def inspect
|
|
44
|
+
"#{@method} ,#{@query} : #{@results}, #{@score}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def get_query(method, query,fetch=[])
|
|
48
|
+
puts method
|
|
49
|
+
puts query
|
|
50
|
+
puts fetch
|
|
51
|
+
@request=self.class.get_query_path(method, query)
|
|
52
|
+
#Find the highest score.
|
|
53
|
+
@results=@request
|
|
54
|
+
list="#{method}_list"
|
|
55
|
+
case method
|
|
56
|
+
when 'release'
|
|
57
|
+
@results=@request['metadata'][list][method]
|
|
58
|
+
@score=@results[0]['ext:score']
|
|
59
|
+
if @score=='100'
|
|
60
|
+
puts @results[0]['id']
|
|
61
|
+
@top_match=MusicBrainz::Release.new(@results[0]['id'], fetch)
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
when 'artist'
|
|
65
|
+
@results=@request['metadata'][list][method]
|
|
66
|
+
@score=@results[0]['ext:score']
|
|
67
|
+
if @score=='100'
|
|
68
|
+
@top_match=MusicBrainz::Artist.new(@results['id'], fetch)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
when 'release-group'
|
|
72
|
+
when 'recording'
|
|
73
|
+
when 'work'
|
|
74
|
+
when 'label'
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
data/lib/musicbrainz/release.rb
CHANGED
|
@@ -1,19 +1,88 @@
|
|
|
1
1
|
module MusicBrainz
|
|
2
|
-
class Release
|
|
3
|
-
|
|
2
|
+
class Release < Base
|
|
3
|
+
|
|
4
|
+
attr_accessor :title
|
|
5
|
+
attr_accessor :raw
|
|
6
|
+
attr_accessor :artists
|
|
7
|
+
attr_accessor :labels
|
|
8
|
+
attr_accessor :recordings
|
|
9
|
+
attr_accessor :release_groups
|
|
10
|
+
@@class_name=self.name.gsub('MusicBrainz::', "").downcase
|
|
11
|
+
|
|
12
|
+
def initialize(mbid, query=[])
|
|
13
|
+
acceptable_subqueries=['artists', 'labels', 'recordings', 'release-groups']
|
|
14
|
+
if query.kind_of?(Array)
|
|
15
|
+
|
|
16
|
+
query.each do |query|
|
|
17
|
+
unless acceptable_subqueries.include?(query)
|
|
18
|
+
raise "#{query} is an unacceptable Sub-query for #{@@class_name.pluralize.upcase}. Please use one of the following:\n#{acceptable_subqueries}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
else
|
|
22
|
+
unless acceptable_subqueries.include?(query)
|
|
23
|
+
raise "#{query} is an unacceptable Sub-query for #{@@class_name.pluralize.upcase}. Please use one of the following:\n#{acceptable_subqueries}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
unless mbid.is_mbid
|
|
29
|
+
raise "Unacceptable MBID for #{@@class_name.pluralize.upcase}. Check to make sure you have the correct mbid."
|
|
30
|
+
end
|
|
31
|
+
|
|
4
32
|
@mbid=mbid
|
|
5
33
|
if query.present? && query!=[]
|
|
6
|
-
@query=query.join("+")
|
|
34
|
+
@query=query.join("+") if query.kind_of?(Array)
|
|
35
|
+
@query=query if query.kind_of?(String)
|
|
7
36
|
else
|
|
8
|
-
|
|
37
|
+
return false
|
|
9
38
|
end
|
|
10
|
-
|
|
39
|
+
@method='release'
|
|
40
|
+
get_release(@method, @mbid, @query)
|
|
11
41
|
end
|
|
12
42
|
|
|
13
|
-
def
|
|
14
|
-
|
|
15
|
-
end
|
|
43
|
+
def get_release(method, mbid, query)
|
|
44
|
+
@raw=self.class.get(method, mbid, query)
|
|
16
45
|
|
|
46
|
+
subquery=query.split("+")
|
|
47
|
+
if subquery.kind_of?(Array)
|
|
48
|
+
subquery.each do |q|
|
|
49
|
+
get_subquery(q)
|
|
50
|
+
end
|
|
51
|
+
else
|
|
52
|
+
get_subquery(subquery)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
#TODO Move to Base class, and use it in each subclass. Expand for each usage as needed
|
|
57
|
+
def get_subquery(subquery)
|
|
58
|
+
subquery=subquery.gsub("-", "_")
|
|
59
|
+
subquery_s=subquery.singularize
|
|
60
|
+
if subquery_s=='artist'
|
|
61
|
+
list_array=@raw['metadata']["#{@@class_name}"]["#{subquery_s}_credit"]['name_credit']["#{subquery_s}"]
|
|
62
|
+
elsif subquery_s=='label'
|
|
63
|
+
list_array=@raw['metadata']["#{@@class_name}"]["#{subquery_s}_info_list"]["#{subquery_s}_info"]["#{subquery_s}"]
|
|
64
|
+
elsif subquery_s=='release_group'
|
|
65
|
+
list_array=@raw['metadata']["#{@@class_name}"]["#{subquery_s}"]
|
|
66
|
+
elsif subquery_s=='recording'
|
|
67
|
+
list_array=@raw['metadata']["#{@@class_name}"]['medium_list']['medium']['track_list']['track']
|
|
68
|
+
end
|
|
69
|
+
if list_array.kind_of?(Array)
|
|
70
|
+
sub=Array.new
|
|
71
|
+
list_array.each do |r|
|
|
72
|
+
sub<<OpenStruct.new(r)
|
|
73
|
+
end
|
|
74
|
+
else
|
|
75
|
+
sub=OpenStruct.new(list_array)
|
|
76
|
+
end
|
|
17
77
|
|
|
78
|
+
@artists=sub if subquery=='artists'
|
|
79
|
+
@labels=sub if subquery=='labels'
|
|
80
|
+
@recordings=sub if subquery=='recordings'
|
|
81
|
+
@release_groups=sub if subquery=='release_groups'
|
|
82
|
+
end
|
|
83
|
+
#TODO Expand the inspection, and add to base
|
|
84
|
+
def inspect
|
|
85
|
+
"#{@@class_name.upcase} identified by:#{@mbid}, Title:#{@title} }"
|
|
86
|
+
end
|
|
18
87
|
end
|
|
19
88
|
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#this file belongs in config/initializers
|
|
2
|
+
|
|
3
|
+
class String
|
|
4
|
+
def is_mbid
|
|
5
|
+
if self.length==36
|
|
6
|
+
l=self.split("-")
|
|
7
|
+
if l[0].length==8 &&
|
|
8
|
+
l[1].length==4 &&
|
|
9
|
+
l[2].length==4 &&
|
|
10
|
+
l[3].length==4 &&
|
|
11
|
+
l[4].length==12
|
|
12
|
+
return true
|
|
13
|
+
else
|
|
14
|
+
return false
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def titleize_proper
|
|
20
|
+
excluded_from_title=["a","an","the","and", "but", "or", "so",
|
|
21
|
+
"after", "before", "when", "while", "since",
|
|
22
|
+
"until", "although", "even if", "because",
|
|
23
|
+
"both", "either", "neither", "nor","as",
|
|
24
|
+
"at", "by", "for", "from", "in", "into",
|
|
25
|
+
"of", "off", "on", "onto", "than", "to",
|
|
26
|
+
"via", "with", "anti", "betwixt", "circa",
|
|
27
|
+
"per", "qua", "sans", "unto", "versus",
|
|
28
|
+
"vis-a-vis","ago", "hence", "through",
|
|
29
|
+
"withal"]
|
|
30
|
+
|
|
31
|
+
string_array=self.split(' ')
|
|
32
|
+
title=Array.new
|
|
33
|
+
string_array.each_with_index do |word,i|
|
|
34
|
+
|
|
35
|
+
if i==0
|
|
36
|
+
title<<word.capitalize
|
|
37
|
+
elsif excluded_from_title.include?(word)
|
|
38
|
+
title<<word
|
|
39
|
+
else
|
|
40
|
+
title<<word.capitalize
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
title.join(' ')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|