1
0
Fork 0

Cleaning up

This commit is contained in:
magnolia-fan 2011-10-20 20:42:38 +04:00
parent bff4107ec9
commit 92e925e1ee
3 changed files with 35 additions and 104 deletions

View File

@ -15,7 +15,7 @@ class window.Vkontakte
_vkontakte.authInfo(response)
setTimeout ->
$('#vk_api_transport').append('<script async="async" type="text/javascript" src="http://vkontakte.ru/js/api/openapi.js"></script>')
$('#vk_api_transport').append($('<script async="async" type="text/javascript" src="http://vkontakte.ru/js/api/openapi.js">'))
, 0
authInfo: (response) ->

View File

@ -9,7 +9,7 @@ class ImportController < ApplicationController
return 3 if artist.status == 1
begin
lastfm_artist = LastFM::Artist.get_info( :artist => name )
lastfm_artist = LastFM::Artist.get_info( artist: name )
unless artist.mbid.nil? or artist.mbid.empty?
brainz_artist = MusicBrainz::Artist.find(artist.mbid)
else
@ -43,9 +43,9 @@ class ImportController < ApplicationController
brainz_artist.urls.each do |service, url|
ArtistLink.new(
:artist_id => artist.id,
:service => service.to_s,
:url => url
artist_id: artist.id,
service: service.to_s,
url: url
).save
end
@ -64,14 +64,14 @@ class ImportController < ApplicationController
end
# Creating album
album = Album.new(
:name => info[:title],
:artist_id => artist.id,
:year => info[:year],
:status => 1,
:master => true
name: info[:title],
artist_id: artist.id,
year: info[:year],
status: 1,
master: true
)
begin
album_lastfm = LastFM::Album.get_info( :artist => lastfm_artist['artist']['name'], :album => info[:title] )
album_lastfm = LastFM::Album.get_info( artist: lastfm_artist['artist']['name'], album: info[:title] )
album_image = album_lastfm['album']['image'][3]['#text']
rescue
album_image = ''
@ -84,70 +84,7 @@ class ImportController < ApplicationController
sleep 1
end
end
# brainz_artist.release_groups.each do |brainz_release_group|
# # Saving album
# begin
# album_lastfm = LastFM::Album.get_info( :artist => lastfm_artist['artist']['name'], :album => '' )
# album_image = album_lastfm['album']['image'][3]['#text']
# rescue
# album_image = ''
# end
# album = Album.new
# album.name = brainz_release_group.title
# album.year = brainz_release_group.first_release_date.year
# album.artist_id = artist.id
# album.mbid = brainz_release_group.id
# album.album_type = brainz_release_group.type
# album.pic_url = album_image
# album.has_pic = (album_image != '' and not album_image.nil?)
# album.status = 0
# album.save
# # Tracks from the first release
# tracks_hashed = []
# brainz_release_group.releases.each_with_index do |brainz_release, i|
# local_brainz_release = LocalBrainz::Release.new(
# :mbid => brainz_release.id,
# :title => brainz_release.title,
# :status => brainz_release.status,
# :date => brainz_release.date,
# :country => brainz_release.country,
# :format => brainz_release.format,
# :album_id => album.id
# )
# local_brainz_release.save
# # Processing tracks
# brainz_release.tracks.each do |brainz_track|
# local_brainz_track = LocalBrainz::Track.new(
# :position => brainz_track.position,
# :recording_id => brainz_track.recording_id,
# :title => brainz_track.title,
# :length => brainz_track.length,
# :release_id => local_brainz_release.id
# )
# local_brainz_track.save
# track_title = brainz_track.title.gsub(/\s\/\s\[.*?\]/, '')
# if tracks_hashed.include? track_title.downcase.scan(/[a-z0-9]*/).join
# next
# end
# tracks_hashed << track_title.downcase.scan(/[a-z0-9]*/).join
# track = Track.new
# track.name = track_title
# track.album_id = album.id
# track.position = brainz_track.position
# track.length = brainz_track.length
# track.country = brainz_release.country
# track.bonus = (i == 0 ? 0 : 1)
# track.live = track_title.downcase.include? 'live'
# track.acoustic = track_title.downcase.include? 'acoustic'
# track.mbid = brainz_track.recording_id
# track.save
# end
# end
# album.status = 1
# album.save unless dry_run
# end
artist.status = 1
rescue => e
ap e.message

View File

@ -2,10 +2,10 @@ class UserController < ApplicationController
before_filter :authorize
def auth
@res = {:status => 'hello', :newbie => false}
@res = {status: 'hello', newbie: false}
user = User.find_by_vkid(params[:mid])
if user.nil?
user = User.new(:vkid => params[:mid], :lang => 'ru').save
user = User.new(vkid: params[:mid], lang: 'ru').save
@res[:newbie] = true
end
@ -14,31 +14,21 @@ class UserController < ApplicationController
session.key = session_key
session.save
@res[:ok_reload] = true
return render :json => @res
return render json: @res
end
@res[:user] = {
:id => user.id,
:name => user.name,
:email => user.email,
:vkid => user.vkid,
:lang => user.lang,
:lastfm_username => user.lastfm_username,
:lastfm_login_url => 'http://www.last.fm/api/auth?api_key=' << LastFM.api_key <<
'&cb=http://' << request.host << ':' << request.port.to_s << '/lastfm/connect/?sid=' << user.session.key
}
@res[:user] = build_user_info(user)
render :json => @res
render json: @res
end
def settings
@user = User.find_by_vkid(params[:mid])
render :partial => 'settings'
render partial: 'settings'
end
def update
allowed_params = [:name, :email, :lang, :show]
@res = {}
user = User.find_by_vkid(params[:mid])
unless params[:params].nil?
@ -55,18 +45,7 @@ class UserController < ApplicationController
end
end
@res[:user] = {
:id => user.id,
:name => user.name,
:email => user.email,
:vkid => user.vkid,
:lang => user.lang,
:lastfm_username => user.lastfm_username,
:lastfm_login_url => 'http://www.last.fm/api/auth?api_key=' << LastFM.api_key <<
'&cb=http://' << request.host << ':' << request.port.to_s << '/lastfm/connect/?sid=' << user.session.key
}
render :json => @res
render json: {user: build_user_info(user)}
end
def fav
@ -93,7 +72,22 @@ class UserController < ApplicationController
end
end
render :json => @res
render json: @res
end
private
def build_user_info user
{
id: user.id,
name: user.name,
email: user.email,
vkid: user.vkid,
lang: user.lang,
lastfm_username: user.lastfm_username,
lastfm_login_url: ('http://www.last.fm/api/auth?api_key=' << LastFM.api_key <<
'&cb=http://' << request.host << ':' << request.port.to_s << '/lastfm/connect/?sid=' <<
user.session.key if user.lastfm_username.nil?)
}
end
end