From 1d9f527f390b9fa52ea50f1e928934681baa90fe Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Tue, 21 Jun 2011 19:22:09 +0400 Subject: [PATCH] Search fixes --- app/controllers/artist_controller.rb | 2 +- app/controllers/import_controller.rb | 16 ++++++++-------- lib/tasks/db_import.rake | 2 +- public/javascripts/beathaven/search.js | 18 +++++++++++------- public/javascripts/beathaven/vkontakte.js | 5 +++-- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/controllers/artist_controller.rb b/app/controllers/artist_controller.rb index e772651..634590d 100644 --- a/app/controllers/artist_controller.rb +++ b/app/controllers/artist_controller.rb @@ -10,7 +10,7 @@ class ArtistController < ApplicationController pics << artist.pic_url unless artist.pic_url.nil? unless artist.albums.empty? artist.albums.each do |album| - pics << album.pic_url unless album.pic_url.nil? + pics << album.pic_url unless album.pic_url.nil? or album.pic_url.empty? end end render :json => {status: 'loading', pics: pics} diff --git a/app/controllers/import_controller.rb b/app/controllers/import_controller.rb index 371cdda..3b608f1 100644 --- a/app/controllers/import_controller.rb +++ b/app/controllers/import_controller.rb @@ -9,7 +9,7 @@ class ImportController < ApplicationController artist_lastfm_xml = open( 'http://ws.audioscrobbler.com/2.0/'+ '?method=artist.getinfo&api_key='+ @@lastfm_api_key + - '&artist='+ URI.escape(name).gsub(/\&/, '%26').gsub(/\?/, '%3F') + '&artist='+ URI.escape(name).gsub(/amp;/, '').gsub(/\&/, '%26').gsub(/\?/, '%3F') ).read artist_desc = artist_lastfm_xml.scan(/<\!\[CDATA\[?(.*)\]\]><\/summary>/m)[0][0] artist_pic = artist_lastfm_xml.scan(/?(.*)<\/image>/)[0][0] @@ -61,7 +61,7 @@ class ImportController < ApplicationController 'http://musicbrainz.org/ws/2/release/'+ main_release[0] +'/?inc=recordings', 'User-Agent' => @@user_agent ).read - mb_tracks = main_tracks_mb_xml.scan(/.*?(\d+?)<\/position>(.*?)<\/title><length>(.*?)<\/length>/m) + mb_tracks = main_tracks_mb_xml.scan(/<track>.*?<position>(\d+?)<\/position>.*?<recording\sid=\"([a-f0-9-]+?)\"><title>(.*?)<\/title>(<length>(.*?)<\/length>)?/m) mb_tracks.map! do |item| item << main_release[3] end @@ -73,8 +73,8 @@ class ImportController < ApplicationController album_lastm_xml = open( 'http://ws.audioscrobbler.com/2.0/'+ '?method=album.getinfo&api_key='+ @@lastfm_api_key + - '&artist='+ URI.escape(name).gsub(/\&/, '%26').gsub(/\?/, '%3F')+ - '&album='+ URI.escape(mb_album[2]).gsub(/\&/, '%26').gsub(/\?/, '%3F') + '&artist='+ URI.escape(name).gsub(/amp;/, '').gsub(/\&/, '%26').gsub(/\?/, '%3F')+ + '&album='+ URI.escape(mb_album[2]).gsub(/amp;/, '').gsub(/\&/, '%26').gsub(/\?/, '%3F') ).read album_image = album_lastm_xml.scan(/<image\ssize=\"extralarge\">?(.*)<\/image>/)[0][0] rescue @@ -105,7 +105,7 @@ class ImportController < ApplicationController 'http://musicbrainz.org/ws/2/release/'+ mb_release[0] +'/?inc=recordings', 'User-Agent' => @@user_agent ).read - mb_other_tracks = other_tracks_mb_xml.scan(/<track>.*?<position>(\d+?)<\/position><recording\sid=\"([a-f0-9-]+?)\"><title>(.*?)<\/title><length>(.*?)<\/length>/m) + mb_other_tracks = other_tracks_mb_xml.scan(/<track>.*?<position>(\d+?)<\/position>.*?<recording\sid=\"([a-f0-9-]+?)\"><title>(.*?)<\/title><length>(.*?)<\/length>/m) mb_other_tracks.each do |item| unless mb_main_tracks_hashed.include? item[2].downcase.scan(/[a-z0-9]*/).join item << mb_release[3] # Release country @@ -122,9 +122,9 @@ class ImportController < ApplicationController track.name = mb_track[2] track.album_id = album.id track.position = mb_track[0] - track.length = mb_track[3] - track.country = mb_track[4] - track.bonus = mb_track[5] + track.length = mb_track[4] + track.country = mb_track[5] + track.bonus = mb_track[6] track.live = mb_track[2].downcase.include? 'live' track.acoustic = mb_track[2].downcase.include? 'acoustic' track.save diff --git a/lib/tasks/db_import.rake b/lib/tasks/db_import.rake index 88afac9..748a5f8 100644 --- a/lib/tasks/db_import.rake +++ b/lib/tasks/db_import.rake @@ -3,7 +3,7 @@ require 'open-uri' namespace :db do desc 'Imports test data from MusicBrainz database' task :import => :environment do - ati = ['KISS'] + ati = ['The Killers'] ati.each do |name| ImportController.importArtist(name) #ap res = ArtistController.musicBrainzExactSearch(name) diff --git a/public/javascripts/beathaven/search.js b/public/javascripts/beathaven/search.js index d9bc832..0d4491b 100644 --- a/public/javascripts/beathaven/search.js +++ b/public/javascripts/beathaven/search.js @@ -1,5 +1,7 @@ var Search = { + pics: [], + showSpinner: function() { $('#search-container input').attr('disabled', 'disabled').blur(); $('#search-container img').show(); @@ -31,13 +33,15 @@ var Search = { showArtistPics: function(pics) { $('.artist_loading, .artist_pics').show(); - $('.artist_pics').html(''); - for (var i = 0; i < pics.length; i++) { - $('.artist_pics').append('\ - <div class="pic">\ - <img src="'+ pics[i] +'" alt=""/>\ - </div>\ - '); + for (var i = 0; i < pics.length; i++) {console.log(Search.pics.indexOf(pics[i])); + if (Search.pics.indexOf(pics[i]) === -1) { + Search.pics.push(pics[i]); + $('.artist_pics').append('\ + <div class="pic">\ + <img src="'+ pics[i] +'" alt=""/>\ + </div>\ + '); + } } } } diff --git a/public/javascripts/beathaven/vkontakte.js b/public/javascripts/beathaven/vkontakte.js index 89e8df1..e66d514 100644 --- a/public/javascripts/beathaven/vkontakte.js +++ b/public/javascripts/beathaven/vkontakte.js @@ -26,7 +26,7 @@ function authInfo(response) { $(function(){ VK.init({ apiId: (document.location.host == 'beathaven.org' ? 2335068 : 2383163), - nameTransportPath: "/demo/xd_receiver.html" + nameTransportPath: "/xd_receiver.html" }); VK.Auth.getLoginStatus(authInfo); $('#vk_login').click(function(){ @@ -38,7 +38,8 @@ $(function(){ }) function loadTracksData(artist, track, duration, callback) { - VK.Api.call('audio.search', {q: artist +' '+ track}, function(r){ + track_prepared = track.replace(/\(.*\)/i, ''); + VK.Api.call('audio.search', {q: artist +' '+ track_prepared}, function(r){ callback(matchPerfectResult(r.response, artist, track, duration)); }) }