Finally fixed lastfm post requests, couple of rake tasks
This commit is contained in:
parent
d9b75279f5
commit
e69a12ded5
2
Gemfile
2
Gemfile
|
@ -14,7 +14,7 @@ gem 'barista'
|
||||||
|
|
||||||
gem 'awesome_print', :require => 'ap'
|
gem 'awesome_print', :require => 'ap'
|
||||||
gem 'delayed_job'
|
gem 'delayed_job'
|
||||||
gem 'lastfm-client', '~> 0.0.2'#, :git => 'http://github.com/magnolia-fan/lastfm-client.git'
|
gem 'lastfm-client', :git => 'http://github.com/magnolia-fan/lastfm-client.git'
|
||||||
gem 'musicbrainz', '~> 0.4.3'
|
gem 'musicbrainz', '~> 0.4.3'
|
||||||
|
|
||||||
gem 'bitmask_attributes'
|
gem 'bitmask_attributes'
|
||||||
|
|
13
Gemfile.lock
13
Gemfile.lock
|
@ -1,3 +1,10 @@
|
||||||
|
GIT
|
||||||
|
remote: http://github.com/magnolia-fan/lastfm-client.git
|
||||||
|
revision: fe5614565eebb5b0b019c103211bba3698848daa
|
||||||
|
specs:
|
||||||
|
lastfm-client (0.0.2)
|
||||||
|
json (>= 1.4.6)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
@ -53,8 +60,6 @@ GEM
|
||||||
hike (1.2.1)
|
hike (1.2.1)
|
||||||
i18n (0.6.0)
|
i18n (0.6.0)
|
||||||
json (1.6.0)
|
json (1.6.0)
|
||||||
lastfm-client (0.0.2)
|
|
||||||
json (>= 1.4.6)
|
|
||||||
libv8 (3.3.10.2)
|
libv8 (3.3.10.2)
|
||||||
mail (2.3.0)
|
mail (2.3.0)
|
||||||
i18n (>= 0.4.0)
|
i18n (>= 0.4.0)
|
||||||
|
@ -62,7 +67,7 @@ GEM
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
mime-types (1.16)
|
mime-types (1.16)
|
||||||
multi_json (1.0.3)
|
multi_json (1.0.3)
|
||||||
musicbrainz (0.4.3)
|
musicbrainz (0.4.5)
|
||||||
nokogiri
|
nokogiri
|
||||||
nokogiri (1.5.0)
|
nokogiri (1.5.0)
|
||||||
pg (0.11.0)
|
pg (0.11.0)
|
||||||
|
@ -122,7 +127,7 @@ DEPENDENCIES
|
||||||
delayed_job
|
delayed_job
|
||||||
haml
|
haml
|
||||||
json
|
json
|
||||||
lastfm-client (~> 0.0.2)
|
lastfm-client!
|
||||||
musicbrainz (~> 0.4.3)
|
musicbrainz (~> 0.4.3)
|
||||||
nokogiri
|
nokogiri
|
||||||
pg
|
pg
|
||||||
|
|
|
@ -89,7 +89,7 @@ class ArtistController < ApplicationController
|
||||||
bonus_tracks = []
|
bonus_tracks = []
|
||||||
album.tracks.each do |track|
|
album.tracks.each do |track|
|
||||||
tmp_track = {id: track.id, name: track.name, live: track.live, acoustic: track.acoustic}
|
tmp_track = {id: track.id, name: track.name, live: track.live, acoustic: track.acoustic}
|
||||||
tmp_track[:length] = (track.length / 1000).round
|
tmp_track[:length] = (track.length / 1000).round unless track.length.nil?
|
||||||
tmp_track[:duration] = formatTrackDuration(track.length)
|
tmp_track[:duration] = formatTrackDuration(track.length)
|
||||||
tmp_track[:position] = track.position
|
tmp_track[:position] = track.position
|
||||||
tmp_track[:mbid] = track.mbid
|
tmp_track[:mbid] = track.mbid
|
||||||
|
|
|
@ -16,7 +16,7 @@ class ImportController < ApplicationController
|
||||||
rescue => e
|
rescue => e
|
||||||
lastfm_artist = { 'artist' => {
|
lastfm_artist = { 'artist' => {
|
||||||
'bio' => { 'summary' => '' },
|
'bio' => { 'summary' => '' },
|
||||||
'image' => [ nil, nil, nil, { 'content' => '' } ],
|
'image' => [ nil, nil, nil, { '#text' => '' } ],
|
||||||
'stats' => { 'listeners' => 0 }
|
'stats' => { 'listeners' => 0 }
|
||||||
} }
|
} }
|
||||||
ap e.message
|
ap e.message
|
||||||
|
@ -35,7 +35,7 @@ class ImportController < ApplicationController
|
||||||
brainz_artist.release_groups.each do |brainz_release_group|
|
brainz_artist.release_groups.each do |brainz_release_group|
|
||||||
# Saving album
|
# Saving album
|
||||||
begin
|
begin
|
||||||
album_lastfm = LastFM::Album.get_info( :artist => lastfm_artist['name'], :album => brainz_release_group.title )
|
album_lastfm = LastFM::Album.get_info( :artist => lastfm_artist['artist']['name'], :album => brainz_release_group.title )
|
||||||
album_image = album_lastfm['album']['image'][3]['#text']
|
album_image = album_lastfm['album']['image'][3]['#text']
|
||||||
rescue
|
rescue
|
||||||
album_image = ''
|
album_image = ''
|
||||||
|
|
|
@ -56,15 +56,13 @@ class LastFmController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
r = LastFM::Track.update_now_playing(
|
r = LastFM::Track.update_now_playing(
|
||||||
:track => params[:name].gsub(/\s/, '+').gsub(/\&/, '&'),
|
:track => params[:name],
|
||||||
:artist => params[:artist].gsub(/\s/, '+').gsub(/\&/, '&'),
|
:artist => params[:artist],
|
||||||
:album => params[:album].gsub(/\s/, '+').gsub(/\&/, '&'),
|
:album => params[:album],
|
||||||
:trackNumber => params[:position],
|
:trackNumber => params[:position],
|
||||||
:mbid => params[:mbid],
|
:mbid => params[:mbid],
|
||||||
:duration => params[:length],
|
:duration => params[:length],
|
||||||
|
:sk => user.lastfm_key # Auth session key
|
||||||
:api_sig => true,
|
|
||||||
:sk => user.lastfm_key
|
|
||||||
)
|
)
|
||||||
|
|
||||||
render :json => { :status => r['error'].nil? ? 'success' : 'failed' }
|
render :json => { :status => r['error'].nil? ? 'success' : 'failed' }
|
||||||
|
@ -86,16 +84,14 @@ class LastFmController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
r = LastFM::Track.scrobble(
|
r = LastFM::Track.scrobble(
|
||||||
:track => params[:name].gsub(/\s/, '+').gsub(/\&/, '&'),
|
:track => params[:name],
|
||||||
:timestamp => Time.now.utc.to_i,
|
:timestamp => Time.now.utc.to_i,
|
||||||
:artist => params[:artist].gsub(/\s/, '+').gsub(/\&/, '&'),
|
:artist => params[:artist],
|
||||||
:album => params[:album].gsub(/\s/, '+').gsub(/\&/, '&'),
|
:album => params[:album],
|
||||||
:trackNumber => params[:position],
|
:trackNumber => params[:position],
|
||||||
:mbid => params[:mbid],
|
:mbid => params[:mbid],
|
||||||
:duration => params[:length],
|
:duration => params[:length],
|
||||||
|
:sk => user.lastfm_key # Auth session key
|
||||||
:api_sig => true,
|
|
||||||
:sk => user.lastfm_key
|
|
||||||
)
|
)
|
||||||
|
|
||||||
render :json => { :status => r['error'].nil? ? 'success' : 'failed' }
|
render :json => { :status => r['error'].nil? ? 'success' : 'failed' }
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
namespace :db do
|
||||||
|
namespace :artist do
|
||||||
|
desc 'Fix broken imports'
|
||||||
|
task :fix => :environment do
|
||||||
|
Artist.where(:status => [0, 2]).each do |artist|
|
||||||
|
artist.albums.each do |album|
|
||||||
|
album.destroy
|
||||||
|
end
|
||||||
|
puts artist.name+(artist.mbid.nil? or artist.mbid.empty? ? '' : ' ('+artist.mbid+')')
|
||||||
|
res = ImportController.importArtist(artist.name)
|
||||||
|
if res == 1
|
||||||
|
puts 'OK'
|
||||||
|
elsif res == 2
|
||||||
|
puts 'FAIL'
|
||||||
|
elsif res == 3
|
||||||
|
puts 'SKIP'
|
||||||
|
end
|
||||||
|
puts ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,5 +18,22 @@ namespace :lastfm do
|
||||||
puts ''
|
puts ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
task :hyped => :environment do
|
||||||
|
ImportController.parseLastfmXML('tmp/data/hyped500.xml').each do |artist|
|
||||||
|
puts artist[:name] + (artist[:mbid].empty? ? '' : ' (' + artist[:mbid] + ')')
|
||||||
|
record = Artist.find_or_create_by_name(artist[:name])
|
||||||
|
record.mbid = artist[:mbid]
|
||||||
|
record.save
|
||||||
|
res = ImportController.importArtist(artist[:name])
|
||||||
|
if res == 1
|
||||||
|
puts 'OK'
|
||||||
|
elsif res == 2
|
||||||
|
puts 'FAIL'
|
||||||
|
elsif res == 3
|
||||||
|
puts 'SKIP'
|
||||||
|
end
|
||||||
|
puts ''
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue