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

55 lines
1.4 KiB
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
2011-04-13 13:40:24 +00:00
# Dirty auth block START
2011-04-13 05:04:13 +00:00
unless request.session['session_id'].nil? or MainController.logged_in request.session['session_id']
2011-04-13 04:42:44 +00:00
redirect_to '/login'
2011-04-13 13:40:24 +00:00
return
2011-04-13 05:04:13 +00:00
else
if request.session['session_id'].nil?
redirect_to '/login'
2011-04-13 13:40:24 +00:00
return
2011-04-13 05:04:13 +00:00
end
2011-04-13 04:42:44 +00:00
end
2011-04-13 13:40:24 +00:00
# Dirty auth block END
2011-04-13 04:42:44 +00:00
if params[:name].nil?
2011-04-13 13:40:24 +00:00
name = ''
else
if request.request_method == 'POST'
redirect_to :action => 'view', :name => params[:name].gsub(' ', '+')
end
name = params[:name].gsub('+', ' ')
end
@artist = Artist.getByName(name)
if @artist.nil?
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
else
@albums = []
@artist.albums.each do |album|
unless album.releases.empty?
tracks = album.tracksInDb()
@albums << {
:object => album,
:tracks => tracks
}
end
end
end
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