Built-in Last.fm TOP playlists
This commit is contained in:
parent
f3c178a092
commit
78be17fd58
|
@ -58,13 +58,13 @@ class window.Player
|
|||
s = len - Math.floor(len / 60) * 60
|
||||
duration = m + ':' + (if s < 10 then '0' else '') + s
|
||||
item_class = (if item.available == false then 'unavailable' else '')
|
||||
$('.playlist').append '
|
||||
<li id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'" class="'+item_class+'">
|
||||
<div class="song-duration">' +duration+ '</div>
|
||||
<div class="label important remove">remove</div>
|
||||
<div class="artist-name">' +item.artist+ '</div>
|
||||
<div class="song-title">' +item.name+ '</div>
|
||||
</li>'
|
||||
$('.playlist').append "
|
||||
<li id='i#{Math.round(Math.random() * 999999)}' data-id='#{item.id}' class='#{item_class}'>
|
||||
<div class='song-duration'>#{duration}</div>
|
||||
<div class='label important remove'>remove</div>
|
||||
<div class='artist-name'><a class='data artist'>#{item.artist}</a></div>
|
||||
<div class='song-title'>#{item.name}</div>
|
||||
</li>"
|
||||
_player.playlist.push item
|
||||
$('.playlist').sortable axis: 'y', cursor: 'move'
|
||||
if initial_count == 0 and not _player.hasTrack()
|
||||
|
@ -282,3 +282,11 @@ $('.set-playlist').live 'click', ->
|
|||
_search.hideSpinner()
|
||||
false
|
||||
false
|
||||
|
||||
$('.dynamic-playlist') .live 'click', ->
|
||||
_search.showSpinner()
|
||||
$.get "/playlist/#{$(this).data('playlist')}", (playlist) ->
|
||||
_player.setPlaylist playlist
|
||||
_search.hideSpinner()
|
||||
false
|
||||
false
|
||||
|
|
|
@ -14,7 +14,7 @@ class window.VkontakteMusic
|
|||
if @query_results[query]? and not return_all
|
||||
callback @query_results[query]
|
||||
that = this
|
||||
VK.Api.call 'audio.search', q: query, (r) ->
|
||||
VK.Api.call 'audio.search', q: query, count: 200, (r) ->
|
||||
results = that.range r.response, artist, track, duration
|
||||
top_result = null
|
||||
if results.length > 0
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
display: block;
|
||||
margin: 1px 0;
|
||||
}
|
||||
.set-playlist {
|
||||
.set-playlist, .dynamic-playlist {
|
||||
float: right;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
|
|
@ -28,4 +28,9 @@
|
|||
|
||||
table.stats {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.data.artist {
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
}
|
|
@ -23,6 +23,10 @@ class ApplicationController < ActionController::Base
|
|||
render partial: 'stat'
|
||||
end
|
||||
|
||||
def cache_for time
|
||||
response.headers['Cache-Control'] = 'public, max-age=' + time.seconds.to_s
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def authorize
|
||||
|
|
|
@ -32,7 +32,6 @@ 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
|
||||
render json: {
|
||||
status: @artist.status_str,
|
||||
artist: @artist,
|
||||
|
|
|
@ -80,7 +80,7 @@ class LastFmController < ApplicationController
|
|||
end
|
||||
|
||||
def self.top_playlist artist
|
||||
playlist = Playlist.create(name: "#{artist.name}: Last.fm TOP")
|
||||
playlist = Playlist.create(name: "#{artist.name}: Last.fm TOP", artist: artist)
|
||||
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?
|
||||
|
|
|
@ -3,4 +3,18 @@ class PlaylistController < ApplicationController
|
|||
@playlist = Playlist.find_by_id(params[:id])
|
||||
render json: @playlist, include: { playlist_items: { include: { track: { include: { artists: {} }}}}}
|
||||
end
|
||||
|
||||
def lastfm_top50
|
||||
artist = Artist.find_by_id(params[:id])
|
||||
return if artist.nil?
|
||||
|
||||
playlist = Playlist.new(name: "#{artist.name}: Last.fm TOP 50", artist: artist)
|
||||
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)
|
||||
playlist.playlist_items << PlaylistItem.new(track_id: tracks.first.id) unless tracks.empty?
|
||||
end
|
||||
|
||||
cache_for 1.week
|
||||
render json: playlist, include: { playlist_items: { include: { track: { include: { artists: {} }}}}}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Playlist < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :artist
|
||||
has_many :playlist_items
|
||||
has_many :playlist_items, dependent: :destroy
|
||||
end
|
||||
|
|
|
@ -18,11 +18,15 @@
|
|||
%a.foreign-link{ href: service.url, target: '_blank' }
|
||||
= image_tag 'services/'+service.service+(service.service == 'official_homepage' ? '.png' : '.ico')
|
||||
|
||||
- unless @artist.playlists.empty?
|
||||
.row
|
||||
.span7.offset4
|
||||
%h3= t('player.playlists')
|
||||
%table.zebra-striped
|
||||
.row
|
||||
.span7.offset4
|
||||
%h3= t('player.playlists')
|
||||
%table.zebra-striped
|
||||
%tr
|
||||
%td
|
||||
%span.label.success.dynamic-playlist{ href: "", 'data-playlist' => "lastfm-top50/#{@artist.id}" }= t('player.set_playlist')
|
||||
%a.playlist-name{ href: "", 'data-playlist' => "lastfm-top50/#{@artist.id}" }= "#{@artist.name}: Last.fm TOP"
|
||||
- @artist.playlists.each do |playlist|
|
||||
%tr
|
||||
- @artist.playlists.each do |playlist|
|
||||
%td
|
||||
|
|
|
@ -16,6 +16,7 @@ Beathaven::Application.routes.draw do
|
|||
match 'track/report' => 'track#report_unavailable'
|
||||
|
||||
match 'playlist/(:id)' => 'playlist#data'
|
||||
match 'playlist/lastfm-top50/(:id)' => 'playlist#lastfm_top50'
|
||||
|
||||
match 'settings' => 'user#settings'
|
||||
|
||||
|
|
Loading…
Reference in New Issue