Search fixes
This commit is contained in:
		
							parent
							
								
									49f1fba33a
								
							
						
					
					
						commit
						1d9f527f39
					
				| @ -10,7 +10,7 @@ class ArtistController < ApplicationController | |||||||
|       pics << artist.pic_url unless artist.pic_url.nil? |       pics << artist.pic_url unless artist.pic_url.nil? | ||||||
|       unless artist.albums.empty? |       unless artist.albums.empty? | ||||||
|         artist.albums.each do |album| |         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 | ||||||
|       end |       end | ||||||
|       render :json => {status: 'loading', pics: pics} |       render :json => {status: 'loading', pics: pics} | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ class ImportController < ApplicationController | |||||||
|       artist_lastfm_xml = open( |       artist_lastfm_xml = open( | ||||||
|         'http://ws.audioscrobbler.com/2.0/'+ |         'http://ws.audioscrobbler.com/2.0/'+ | ||||||
|         '?method=artist.getinfo&api_key='+ @@lastfm_api_key + |         '?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 |       ).read | ||||||
|       artist_desc = artist_lastfm_xml.scan(/<summary><\!\[CDATA\[?(.*)\]\]><\/summary>/m)[0][0] |       artist_desc = artist_lastfm_xml.scan(/<summary><\!\[CDATA\[?(.*)\]\]><\/summary>/m)[0][0] | ||||||
|       artist_pic = artist_lastfm_xml.scan(/<image\ssize=\"extralarge\">?(.*)<\/image>/)[0][0] |       artist_pic = artist_lastfm_xml.scan(/<image\ssize=\"extralarge\">?(.*)<\/image>/)[0][0] | ||||||
| @ -61,7 +61,7 @@ class ImportController < ApplicationController | |||||||
|           'http://musicbrainz.org/ws/2/release/'+ main_release[0] +'/?inc=recordings', |           'http://musicbrainz.org/ws/2/release/'+ main_release[0] +'/?inc=recordings', | ||||||
|           'User-Agent' => @@user_agent |           'User-Agent' => @@user_agent | ||||||
|         ).read |         ).read | ||||||
|         mb_tracks = main_tracks_mb_xml.scan(/<track>.*?<position>(\d+?)<\/position><recording\sid=\"([a-f0-9-]+?)\"><title>(.*?)<\/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| |         mb_tracks.map! do |item| | ||||||
|           item << main_release[3] |           item << main_release[3] | ||||||
|         end |         end | ||||||
| @ -73,8 +73,8 @@ class ImportController < ApplicationController | |||||||
|             album_lastm_xml = open( |             album_lastm_xml = open( | ||||||
|               'http://ws.audioscrobbler.com/2.0/'+ |               'http://ws.audioscrobbler.com/2.0/'+ | ||||||
|               '?method=album.getinfo&api_key='+ @@lastfm_api_key + |               '?method=album.getinfo&api_key='+ @@lastfm_api_key + | ||||||
|               '&artist='+ URI.escape(name).gsub(/\&/, '%26').gsub(/\?/, '%3F')+ |               '&artist='+ URI.escape(name).gsub(/amp;/, '').gsub(/\&/, '%26').gsub(/\?/, '%3F')+ | ||||||
|               '&album='+ URI.escape(mb_album[2]).gsub(/\&/, '%26').gsub(/\?/, '%3F') |               '&album='+ URI.escape(mb_album[2]).gsub(/amp;/, '').gsub(/\&/, '%26').gsub(/\?/, '%3F') | ||||||
|             ).read |             ).read | ||||||
|             album_image = album_lastm_xml.scan(/<image\ssize=\"extralarge\">?(.*)<\/image>/)[0][0] |             album_image = album_lastm_xml.scan(/<image\ssize=\"extralarge\">?(.*)<\/image>/)[0][0] | ||||||
|           rescue |           rescue | ||||||
| @ -105,7 +105,7 @@ class ImportController < ApplicationController | |||||||
|               'http://musicbrainz.org/ws/2/release/'+ mb_release[0] +'/?inc=recordings', |               'http://musicbrainz.org/ws/2/release/'+ mb_release[0] +'/?inc=recordings', | ||||||
|               'User-Agent' => @@user_agent |               'User-Agent' => @@user_agent | ||||||
|             ).read |             ).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| |             mb_other_tracks.each do |item| | ||||||
|               unless mb_main_tracks_hashed.include? item[2].downcase.scan(/[a-z0-9]*/).join |               unless mb_main_tracks_hashed.include? item[2].downcase.scan(/[a-z0-9]*/).join | ||||||
|                 item << mb_release[3] # Release country |                 item << mb_release[3] # Release country | ||||||
| @ -122,9 +122,9 @@ class ImportController < ApplicationController | |||||||
|               track.name = mb_track[2] |               track.name = mb_track[2] | ||||||
|               track.album_id = album.id |               track.album_id = album.id | ||||||
|               track.position = mb_track[0] |               track.position = mb_track[0] | ||||||
|               track.length = mb_track[3] |               track.length = mb_track[4] | ||||||
|               track.country = mb_track[4] |               track.country = mb_track[5] | ||||||
|               track.bonus = mb_track[5] |               track.bonus = mb_track[6] | ||||||
|               track.live = mb_track[2].downcase.include? 'live' |               track.live = mb_track[2].downcase.include? 'live' | ||||||
|               track.acoustic = mb_track[2].downcase.include? 'acoustic' |               track.acoustic = mb_track[2].downcase.include? 'acoustic' | ||||||
|               track.save |               track.save | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ require 'open-uri' | |||||||
| namespace :db do | namespace :db do | ||||||
|   desc 'Imports test data from MusicBrainz database' |   desc 'Imports test data from MusicBrainz database' | ||||||
|   task :import => :environment do |   task :import => :environment do | ||||||
|     ati = ['KISS'] |     ati = ['The Killers'] | ||||||
|     ati.each do |name| |     ati.each do |name| | ||||||
|       ImportController.importArtist(name) |       ImportController.importArtist(name) | ||||||
|       #ap res = ArtistController.musicBrainzExactSearch(name) |       #ap res = ArtistController.musicBrainzExactSearch(name) | ||||||
|  | |||||||
| @ -1,5 +1,7 @@ | |||||||
| var Search = { | var Search = { | ||||||
| 	 | 	 | ||||||
|  | 	pics: [], | ||||||
|  | 	 | ||||||
| 	showSpinner: function() { | 	showSpinner: function() { | ||||||
| 		$('#search-container input').attr('disabled', 'disabled').blur(); | 		$('#search-container input').attr('disabled', 'disabled').blur(); | ||||||
| 		$('#search-container img').show(); | 		$('#search-container img').show(); | ||||||
| @ -31,13 +33,15 @@ var Search = { | |||||||
| 	 | 	 | ||||||
| 	showArtistPics: function(pics) { | 	showArtistPics: function(pics) { | ||||||
| 		$('.artist_loading, .artist_pics').show(); | 		$('.artist_loading, .artist_pics').show(); | ||||||
| 		$('.artist_pics').html(''); | 		for (var i = 0; i < pics.length; i++) {console.log(Search.pics.indexOf(pics[i])); | ||||||
| 		for (var i = 0; i < pics.length; i++) { | 			if (Search.pics.indexOf(pics[i]) === -1) { | ||||||
| 			$('.artist_pics').append('\ | 				Search.pics.push(pics[i]); | ||||||
| 				<div class="pic">\ | 				$('.artist_pics').append('\ | ||||||
| 					<img src="'+ pics[i] +'" alt=""/>\ | 					<div class="pic">\ | ||||||
| 				</div>\ | 						<img src="'+ pics[i] +'" alt=""/>\ | ||||||
| 			'); | 					</div>\ | ||||||
|  | 				'); | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ function authInfo(response) { | |||||||
| $(function(){ | $(function(){ | ||||||
| 	VK.init({ | 	VK.init({ | ||||||
| 		apiId: (document.location.host == 'beathaven.org' ? 2335068 : 2383163), | 		apiId: (document.location.host == 'beathaven.org' ? 2335068 : 2383163), | ||||||
| 		nameTransportPath: "/demo/xd_receiver.html" | 		nameTransportPath: "/xd_receiver.html" | ||||||
| 	}); | 	}); | ||||||
| 	VK.Auth.getLoginStatus(authInfo); | 	VK.Auth.getLoginStatus(authInfo); | ||||||
| 	$('#vk_login').click(function(){ | 	$('#vk_login').click(function(){ | ||||||
| @ -38,7 +38,8 @@ $(function(){ | |||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| function loadTracksData(artist, track, duration, callback) { | 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)); | 		callback(matchPerfectResult(r.response, artist, track, duration)); | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user