From 4d2c32ec8e4059590073d0c286e1962afd3d02e4 Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Mon, 11 Apr 2011 12:19:47 +0400 Subject: [PATCH] Almost fixed streaming. The only thing left is to fix headers. --- app/controllers/track_controller.rb | 11 ++++++++--- app/helpers/vkontakte.rb | 9 +++++++-- nginx/proxy.conf | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index 5ab89cb..8586340 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -7,8 +7,13 @@ class TrackController < ApplicationController pp album = Album.where(:id => release.album_id).first pp artist = Artist.where(:id => album.artist_id).first - url = Vkontakte.get(artist.name, track.name, (track.length / 1000).round) - - redirect_to url + 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 + render :nothing => true end end diff --git a/app/helpers/vkontakte.rb b/app/helpers/vkontakte.rb index 7c151d6..a462a58 100644 --- a/app/helpers/vkontakte.rb +++ b/app/helpers/vkontakte.rb @@ -16,7 +16,12 @@ module Vkontakte files = self.parseHtml(html) files = self.calcWeight(files, artist, track, length) #self.stream files.first['url'] - files.first['url'] + + return { + 'url' => files.first['url'], + 'remixsid' => @@bot['remixsid'], + 'remixchk' => @@bot['remixchk'] + } end @@ -108,4 +113,4 @@ module Vkontakte data end -end \ No newline at end of file +end diff --git a/nginx/proxy.conf b/nginx/proxy.conf index d20e48d..ec6820c 100644 --- a/nginx/proxy.conf +++ b/nginx/proxy.conf @@ -32,13 +32,13 @@ location ~* ^/proxy-stream/(.*?)/(.*?)/(.*?)/(.*?)/(.*) { # when save content to the disk proxy_hide_header Content-Type; proxy_hide_header Content-Disposition; - add_header Content-Type 'audio/mpeg'; - add_header Content-Disposition 'inline'; + add_header Content-Disposition 'attachment; filename=audio.mp3'; # Do not touch local disks when proxying # content to clients proxy_max_temp_file_size 0; # Download the file and send it to client + resolver 192.168.0.1; proxy_pass $download_url; }