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