1
0
Fork 0
oldhaven/app/controllers/playlist_controller.rb

26 lines
967 B
Ruby
Raw Normal View History

2011-11-26 15:03:33 +00:00
class PlaylistController < ApplicationController
def data
@playlist = Playlist.find_by_id(params[:id])
render json: @playlist, include: { playlist_items: { include: { track: { include: { artists: {} }}}}}
end
2011-11-26 20:56:09 +00:00
def lastfm_top50
artist = Artist.find_by_name(get_artist_name_from_query)
2011-11-26 20:56:09 +00:00
return if artist.nil?
playlist = Playlist.new(name: "#{artist.name}: Last.fm TOP 50", artist: artist, pic_url: artist.pic_url)
2011-11-26 20:56:09 +00:00
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
compile_page(
data: playlist.serialize,
partial: "playlist/tracks",
title: playlist.name,
callback: {object: :player, action: :updateLibrary}
)
2011-11-26 20:56:09 +00:00
end
2011-11-26 15:03:33 +00:00
end