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

21 lines
683 B
Ruby

class TrackController < ApplicationController
require 'net/http'
require 'uri'
@@token_salt = '8FW*W#dWOH*FHW4j:Q@RQ{Qo[qF;fw0`0w4fkl'
def listen
pp track = Track.where(:id => params[:id].to_i).first
data = Vkontakte.get(track.artist_name, track.name, (track.length / 1000).round)
# data = Vkontakte.get(1, 1, 1)
url = URI.parse(data['url'])
token = Digest::SHA256.hexdigest(params[:id] << @@token_salt)
nginx_url = '/proxy-stream/' << token << '/' << data['remixsid'] << '/' << '5' << '/' << url.host << url.path
headers['Content-Type'] = 'audio/mpeg'
headers['X-Accel-Redirect'] = nginx_url
render :nothing => true
end
end