Player library, unified renderer for artists and playlists
This commit is contained in:
@@ -16,7 +16,8 @@ class ApplicationController < ActionController::Base
|
||||
data: @data,
|
||||
html: render_compact_partial(params[:partial]),
|
||||
title: params[:title],
|
||||
status: (params[:status] unless params[:status].nil?)
|
||||
status: (params[:status] unless params[:status].nil?),
|
||||
callback: (params[:callback] unless params[:callback].nil?)
|
||||
}, include: (params[:include] unless params[:include].nil?)
|
||||
end
|
||||
|
||||
@@ -24,7 +25,7 @@ protected
|
||||
|
||||
def authorize
|
||||
unless Vkontakte.check(params)
|
||||
render :json => { :status => 'login failed' }
|
||||
render json: { status: 'login failed' }, status: 403
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -32,11 +32,14 @@ class ArtistController < ApplicationController
|
||||
return render json: { status: 'fail', html: render_compact_partial(:fail) }
|
||||
end
|
||||
|
||||
render json: {
|
||||
cache_for 1.week
|
||||
compile_page(
|
||||
data: @artist.serialize,
|
||||
partial: "artist/page",
|
||||
title: @artist.name,
|
||||
status: @artist.status_str,
|
||||
artist: @artist,
|
||||
html: render_compact_partial(:page)
|
||||
}, include: { albums: { include: { tracks: {}}}}
|
||||
callback: {object: :player, action: :updateLibrary}
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -14,10 +14,10 @@ class LastFmController < ApplicationController
|
||||
session.user.save
|
||||
render :text => '<script>window.close();</script>'
|
||||
else
|
||||
return render :text => 'You Don\'t Fool Me'
|
||||
return render :text => 'You Don\'t Fool Me', status: 403
|
||||
end
|
||||
else
|
||||
return render :text => 'So Much Trouble In The World'
|
||||
return render :text => 'So Much Trouble In The World', status: 403
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,7 +41,7 @@ class LastFmController < ApplicationController
|
||||
def listening
|
||||
@res = {}
|
||||
if params[:artist].nil? or params[:album].nil? or params[:name].nil?
|
||||
return render :json => { :status => 'bad params' }
|
||||
return render :json => { :status => 'bad params' }, status: 403
|
||||
end
|
||||
user = User.find_by_vkid(params[:mid])
|
||||
if user.lastfm_key.nil?
|
||||
@@ -51,17 +51,17 @@ class LastFmController < ApplicationController
|
||||
:track => params[:name],
|
||||
:artist => params[:artist],
|
||||
:album => params[:album],
|
||||
:trackNumber => params[:position].to_i,
|
||||
:trackNumber => params[:position].gsub(/[a-z]/, "").to_i,
|
||||
:duration => params[:length].to_i,
|
||||
:sk => user.lastfm_key # Auth session key
|
||||
)
|
||||
render :json => { :status => r['error'].nil? ? 'success' : r }
|
||||
render :json => { :status => r['error'].nil? ? 'success' : r }, :status => r['error'].nil? ? 200 : 403
|
||||
end
|
||||
|
||||
def scrobble
|
||||
@res = {}
|
||||
if params[:artist].nil? or params[:album].nil? or params[:name].nil?
|
||||
return render :json => { :status => 'bad params' }
|
||||
return render :json => { :status => 'bad params' }, status: 403
|
||||
end
|
||||
user = User.find_by_vkid(params[:mid])
|
||||
if user.lastfm_key.nil?
|
||||
@@ -72,11 +72,11 @@ class LastFmController < ApplicationController
|
||||
:timestamp => Time.now.utc.to_i,
|
||||
:artist => params[:artist],
|
||||
:album => params[:album],
|
||||
:trackNumber => params[:position].to_i,
|
||||
:trackNumber => params[:position].gsub(/[a-z]/, "").to_i,
|
||||
:duration => params[:length].to_i,
|
||||
:sk => user.lastfm_key # Auth session key
|
||||
)
|
||||
render :json => { :status => r['error'].nil? ? 'success' : r }
|
||||
render :json => { :status => r['error'].nil? ? 'success' : r }, :status => r['error'].nil? ? 200 : 403
|
||||
end
|
||||
|
||||
def self.top_playlist artist
|
||||
|
||||
@@ -8,13 +8,18 @@ class PlaylistController < ApplicationController
|
||||
artist = Artist.find_by_id(params[:id])
|
||||
return if artist.nil?
|
||||
|
||||
playlist = Playlist.new(name: "#{artist.name}: Last.fm TOP 50", artist: artist)
|
||||
playlist = Playlist.new(name: "#{artist.name}: Last.fm TOP 50", artist: artist, pic_url: artist.pic_url)
|
||||
LastFM::Artist.get_top_tracks(artist: artist.name)["toptracks"]["track"].each do |track|
|
||||
tracks = Track.joins(:album, :artists).where(name: track["name"], "track_artists.artist_id" => artist.id)
|
||||
playlist.playlist_items << PlaylistItem.new(track_id: tracks.first.id) unless tracks.empty?
|
||||
end
|
||||
|
||||
cache_for 1.week
|
||||
render json: playlist, include: { playlist_items: { include: { track: { include: { artists: {} }}}}}
|
||||
compile_page(
|
||||
data: playlist.serialize,
|
||||
partial: "playlist/tracks",
|
||||
title: playlist.name,
|
||||
callback: {object: :player, action: :updateLibrary}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user