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

21 lines
752 B
Ruby

class TrackController < ApplicationController
require 'net/http'
require 'uri'
def listen
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
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
headers['Connection'] = 'close'
render :nothing => true
end
end