Discogs artist search
This commit is contained in:
parent
d5992c31b4
commit
7bad8f16e0
@ -8,11 +8,11 @@ class ApplicationController < ActionController::Base
|
|||||||
def index; end
|
def index; end
|
||||||
|
|
||||||
def greetings
|
def greetings
|
||||||
render :partial => 'greetings'
|
render_compact_partial :greetings
|
||||||
end
|
end
|
||||||
|
|
||||||
def about
|
def about
|
||||||
render :partial => 'about'
|
render_compact_partial :about
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
@ -33,7 +33,7 @@ protected
|
|||||||
def session_key
|
def session_key
|
||||||
if cookies[:beathaven_sid].nil?
|
if cookies[:beathaven_sid].nil?
|
||||||
cookies[:beathaven_sid] = {
|
cookies[:beathaven_sid] = {
|
||||||
:value => Digest::SHA1.hexdigest(Beathaven::Application.config.secret_token+Time.now.to_f.to_s+Random.rand().to_s),
|
:value => Session.generate_key,
|
||||||
:expire => 42.years.from_now.utc
|
:expire => 42.years.from_now.utc
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
require 'musicbrainz'
|
|
||||||
|
|
||||||
class ArtistController < ApplicationController
|
class ArtistController < ApplicationController
|
||||||
def data
|
def data
|
||||||
# Bad params
|
# Bad params
|
||||||
@ -9,7 +7,7 @@ class ArtistController < ApplicationController
|
|||||||
|
|
||||||
# Searching for artist
|
# Searching for artist
|
||||||
artist_name = get_artist_name_from_query
|
artist_name = get_artist_name_from_query
|
||||||
@artist = Artist.find_by_name(artist_name, include: {artist_links: {}, albums: {tracks: {}}})
|
@artist = Artist.find_by_name(artist_name, include: { artist_links: {}, albums: { tracks: {}}})
|
||||||
|
|
||||||
# Artist not found in DB
|
# Artist not found in DB
|
||||||
unless @artist
|
unless @artist
|
||||||
@ -38,7 +36,7 @@ class ArtistController < ApplicationController
|
|||||||
status: @artist.status_str,
|
status: @artist.status_str,
|
||||||
artist: @artist,
|
artist: @artist,
|
||||||
html: render_compact_partial(:page)
|
html: render_compact_partial(:page)
|
||||||
}, include: {albums: {include: {tracks: {}}}}
|
}, include: { albums: { include: { tracks: {}}}}
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -49,6 +49,10 @@ class ImportController < ApplicationController
|
|||||||
).save
|
).save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if brainz_artist.urls[:discogs].nil?
|
||||||
|
brainz_artist.urls[:discogs] = Discogs.search_for_artist(artist.name)
|
||||||
|
end
|
||||||
|
|
||||||
unless brainz_artist.urls[:discogs].nil?
|
unless brainz_artist.urls[:discogs].nil?
|
||||||
Discogs.get_master_albums(brainz_artist.urls[:discogs]).each do |info|
|
Discogs.get_master_albums(brainz_artist.urls[:discogs]).each do |info|
|
||||||
begin
|
begin
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
class Session < ActiveRecord::Base
|
class Session < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
|
def self.generate_key
|
||||||
|
Digest::SHA1.hexdigest(Beathaven::Application.config.secret_token + Time.now.to_f.to_s + Random.rand().to_s)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
require 'zlib'
|
||||||
|
|
||||||
class Discogs
|
class Discogs
|
||||||
|
|
||||||
def self.artists
|
def self.artists
|
||||||
@ -148,7 +150,22 @@ class Discogs
|
|||||||
albums
|
albums
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def self.search_for_artist name
|
||||||
|
url = 'http://api.discogs.com/search?q=' << CGI::escape(name) << '&f=xml'
|
||||||
|
stream = open(url,
|
||||||
|
'User-Agent' => 'Haven Import Bot',
|
||||||
|
'Accept-Encoding' => 'gzip, deflate'
|
||||||
|
)
|
||||||
|
if (stream.content_encoding.empty?)
|
||||||
|
body = stream.read
|
||||||
|
else
|
||||||
|
body = Zlib::GzipReader.new(stream).read
|
||||||
|
end
|
||||||
|
x = Nokogiri::XML(body)
|
||||||
|
x.css('exactresults > result[type=artist] > uri, searchresults > result[type=artist] > uri').map{|n| n.text}.first
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def self.get_nodes filename, nodename, &block
|
def self.get_nodes filename, nodename, &block
|
||||||
File.open(filename) do |file|
|
File.open(filename) do |file|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user