diff --git a/app/controllers/artist_controller.rb b/app/controllers/artist_controller.rb index 03c3fad..368b5cd 100644 --- a/app/controllers/artist_controller.rb +++ b/app/controllers/artist_controller.rb @@ -1,4 +1,3 @@ -require 'open-uri' require 'musicbrainz' class ArtistController < ApplicationController @@ -19,7 +18,7 @@ class ArtistController < ApplicationController return render json: { status: 'not_found' } end best_match = results[0][:name] - if best_match != artist_name and (best_match.downcase == artist_name.downcase or best_match.downcase == 'the '+ artist_name.downcase) + if best_match != artist_name and similar_names(artist_name, best_match) return render json: { status: 'corrected', correct_name: best_match } elsif results[0][:name] == artist_name queue_loading(artist_name, results[0][:mbid]) @@ -37,7 +36,11 @@ class ArtistController < ApplicationController return render json: { status: 'fail', html: render_compact_partial(:fail) } end - render json: { status: @artist.status_str, artist: @artist, html: render_compact_partial(:page) }, include: {albums: {include: {tracks: {}}}} + render json: { + status: @artist.status_str, + artist: @artist, + html: render_compact_partial(:page) }, include: {albums: {include: {tracks: {}}} + } end private @@ -50,4 +53,8 @@ private @artist = Artist.create( name: artist_name, mbid: mbid, status: 0 ) Delayed::Job.enqueue(LoadArtistJob.new(artist_name)) end + + def similar_names name1, name2 + (name2.downcase == name1.downcase or name2.downcase == 'the '+ name1.downcase) + end end