From 4ade7fa77fea1b59a7a9059c911831ccf06cfbd8 Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Sat, 26 Nov 2011 18:18:02 +0400 Subject: [PATCH] Top 50 playlists, last.fm and youtube links --- Gemfile.lock | 2 +- app/assets/images/services/youtube.ico | Bin 0 -> 1150 bytes app/controllers/artist_controller.rb | 2 +- app/controllers/last_fm_controller.rb | 8 ++++++++ app/models/beathaven/playlist.rb | 2 +- app/views/artist/_page.html.haml | 15 ++++++++++++--- 6 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 app/assets/images/services/youtube.ico diff --git a/Gemfile.lock b/Gemfile.lock index 99ba64d..5472697 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/assets/images/services/youtube.ico b/app/assets/images/services/youtube.ico new file mode 100644 index 0000000000000000000000000000000000000000..dc4ded6c4570b7bb18cef745a4cb0b0013b3dc5d GIT binary patch literal 1150 zcmbtTJx>Bb5FHXr3nGb?CPo^6hzW^}m4AU)UHk{y($XoRu@ea-bX;$ujYbm;M@xd8 z*k~g<&YN|(b-javx$Monc{6Wj`5-FDQ!J9acj$PHXp@Nc~E-#KqxX_rHHptL<|=AlwT&@YA=y{WcGLc+eZ>LW~+SpIfABbxD%y zXMM+3_s`26laWnb-Cw_au>3ap>vO1Lm3m+CZLO*}>JAjQtNWS5T9bF>zh^^kO`H}A zp^04Sq^TY_%a-+9pZQQD>OSkN@y(@Dm3plB?stFdGavSA{!0EAIs1k6K8`vAUOzb1 S6h0r@!LP}S&k8be1^WS1ociPd literal 0 HcmV?d00001 diff --git a/app/controllers/artist_controller.rb b/app/controllers/artist_controller.rb index 2686f81..5278f6b 100644 --- a/app/controllers/artist_controller.rb +++ b/app/controllers/artist_controller.rb @@ -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, diff --git a/app/controllers/last_fm_controller.rb b/app/controllers/last_fm_controller.rb index e84dff0..c3aaec7 100644 --- a/app/controllers/last_fm_controller.rb +++ b/app/controllers/last_fm_controller.rb @@ -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? diff --git a/app/models/beathaven/playlist.rb b/app/models/beathaven/playlist.rb index 3708723..36455d2 100644 --- a/app/models/beathaven/playlist.rb +++ b/app/models/beathaven/playlist.rb @@ -1,4 +1,4 @@ class Playlist < ActiveRecord::Base belongs_to :user - has_many :playlist_tracks + has_many :playlist_items end diff --git a/app/views/artist/_page.html.haml b/app/views/artist/_page.html.haml index 050be86..5e96c07 100644 --- a/app/views/artist/_page.html.haml +++ b/app/views/artist/_page.html.haml @@ -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 : ' '.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'