2011-04-07 04:02:49 +00:00
|
|
|
class TrackController < ApplicationController
|
2011-04-08 19:42:14 +00:00
|
|
|
require 'net/http'
|
|
|
|
require 'uri'
|
2011-04-07 04:02:49 +00:00
|
|
|
def listen
|
2011-04-10 03:17:34 +00:00
|
|
|
pp track = Track.where(:id => params[:id].to_i).first
|
|
|
|
pp release = Release.where(:id => track.release_id).first
|
|
|
|
pp album = Album.where(:id => release.album_id).first
|
|
|
|
pp artist = Artist.where(:id => album.artist_id).first
|
2011-04-08 19:42:14 +00:00
|
|
|
|
2011-04-11 08:19:47 +00:00
|
|
|
data = Vkontakte.get(artist.name, track.name, (track.length / 1000).round)
|
|
|
|
|
|
|
|
url = URI.parse(data['url'])
|
|
|
|
nginx_url = '/proxy-stream/no-token/' << data['remixsid'] << '/' << '5' << '/' << url.host << url.path
|
|
|
|
#render :inline => nginx_url
|
|
|
|
headers['Content-Type'] = 'audio/mpeg'
|
|
|
|
headers['X-Accel-Redirect'] = nginx_url
|
2011-04-11 16:49:25 +00:00
|
|
|
headers['Connection'] = 'close'
|
2011-04-11 08:19:47 +00:00
|
|
|
render :nothing => true
|
2011-04-07 04:02:49 +00:00
|
|
|
end
|
|
|
|
end
|