1
0
Fork 0

Top 50 playlists, last.fm and youtube links

This commit is contained in:
magnolia-fan 2011-11-26 18:18:02 +04:00
parent 705b4cfbc2
commit 4ade7fa77f
6 changed files with 23 additions and 6 deletions

View File

@ -63,7 +63,7 @@ GEM
haml (3.1.3)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.18)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.1)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -32,7 +32,7 @@ class ArtistController < ApplicationController
return render json: { status: 'fail', html: render_compact_partial(:fail) }
end
response.headers['Cache-Control'] = 'public, max-age='+1.week.seconds.to_s
# response.headers['Cache-Control'] = 'public, max-age='+1.week.seconds.to_s
render json: {
status: @artist.status_str,
artist: @artist,

View File

@ -79,6 +79,14 @@ class LastFmController < ApplicationController
render :json => { :status => r['error'].nil? ? 'success' : r }
end
def self.top_playlist artist
playlist = Playlist.create(name: "#{artist.name}: Last.fm TOP")
LastFM::Artist.get_top_tracks(artist: artist.name)["toptracks"]["track"].each do |track|
tracks = Track.joins(:album, :artists).where(name: track["name"], "track_artists.artist_id" => artist.id)
PlaylistItem.create(playlist_id: playlist.id, track_id: tracks.first.id) unless tracks.empty?
end
end
def autocomplete
autocomplete = getSuggestions(params[:query])
return render :nothing => true if autocomplete.nil?

View File

@ -1,4 +1,4 @@
class Playlist < ActiveRecord::Base
belongs_to :user
has_many :playlist_tracks
has_many :playlist_items
end

View File

@ -8,14 +8,23 @@
%h2
=@artist.name
%small= " "+@artist.original_name.to_s
= @artist.desc.html_safe unless @artist.desc.nil?
%p= @artist.desc.html_safe unless @artist.desc.nil?
- unless @artist.artist_links.empty?
.service-icons
%a.foreign-link{ :href => "http://last.fm/artist/#{@artist.name.gsub(" ", "+")}", :target => '_blank' }
= image_tag 'services/lastfm.ico'
- @artist.artist_links.each do |service|
- if ['wikipedia', 'microblog', 'official_homepage', 'social_network'].include?service.service
- if ['wikipedia', 'microblog', 'official_homepage', 'social_network', 'youtube'].include?(service.service)
%a.foreign-link{ :href => service.url, :target => '_blank' }
= image_tag 'services/'+service.service+(service.service == 'official_homepage' ? '.png' : '.ico')
.row
.span7.offset4
%h3 Playlists
%table.zebra-striped
%tr
%td
%a{ href: "" } Last.fm TOP
- @artist.albums.each do |album|
.row.album
@ -33,4 +42,4 @@
%td.song-title= track.name
%td.song-duration
.s-duration= (track.duration != '0:00' ? track.duration : '&nbsp;'.html_safe)
.s-add{ :'data-album-id' => album.id, :'data-id' => track.id }= I18n.t 'player.add_one'
%span.label.success.s-add{ :'data-album-id' => album.id, :'data-id' => track.id }= I18n.t 'player.add_one'