1
0
Fork 0
oldhaven/app/controllers/artist_controller.rb

41 lines
945 B
Ruby
Raw Normal View History

2011-04-05 22:58:11 +00:00
# encoding: utf-8
2011-04-03 16:21:05 +00:00
class ArtistController < ApplicationController
2011-04-05 22:58:11 +00:00
require 'open-uri'
2011-04-03 16:21:05 +00:00
def view
if params[:name].nil?
name = ''
else
2011-04-12 02:46:07 +00:00
if request.request_method == 'POST'
2011-04-11 03:12:06 +00:00
redirect_to :action => 'view', :name => params[:name].gsub(' ', '+')
end
name = params[:name].gsub('+', ' ')
end
@artist = Artist.getByName(name)
2011-04-12 02:46:07 +00:00
@albums = []
@artist.albums.each do |album|
unless album.releases.empty?
tracks = album.tracksInDb()
@albums << {
:object => album,
:tracks => tracks
}
end
end
2011-04-03 16:21:05 +00:00
end
2011-04-10 06:17:06 +00:00
def autocomplete
autocomplete = Artist.getLastFmAutocomplete(params[:query])
return render :nothing => true if autocomplete.nil?
suggestions = []
autocomplete["response"]["docs"].each do |doc|
suggestions << doc["artist"] unless suggestions.include?(doc["artist"])
end
render :json => {
:query => params[:query],
:suggestions => suggestions
}
end
2011-04-03 16:21:05 +00:00
end