-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on media controller and tests
- Loading branch information
Showing
7 changed files
with
96 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,104 @@ | ||
class MediaController < ApplicationController | ||
include Cache, Spectrogram, Audio | ||
|
||
respond_to :xml, :json, :html, :png | ||
respond_to :xml, :json, :html, :png, :ogg, :oga, :webm, :webma, :mp3 | ||
|
||
def index | ||
# index page for media files | ||
@testing = QubarSite::Application.config.media_file_config | ||
#@testing = QubarSite::Application.config.media_file_config | ||
end | ||
|
||
def item | ||
# page for an individual media file | ||
|
||
@requested_format1 = request.format | ||
@requested_format2 = params[:format] | ||
|
||
respond_to do |format| | ||
format.html { render 'item.html.erb'} | ||
format.json { render 'item.html.erb' } | ||
format.png { render 'item.html.erb' } | ||
format.mp3 { render 'item.html.erb' } | ||
format.oga { render 'item.html.erb' } | ||
format.ogg { render 'item.html.erb' } | ||
end | ||
|
||
|
||
=begin | ||
# determine the request format | ||
if request.format == :html | ||
elsif %w(png jpg).include? request.format | ||
file_name = Cache::cached_spectrogram_file(params) | ||
file_paths = Cache::existing_paths(Cache::cached_spectrogram_storage_paths,file_name) | ||
elsif %w(ogg oga webm webma mp3).include? request.format | ||
file_name = Cache::cached_audio_file(params) | ||
file_paths = Cache::existing_paths(Cache::cached_audio_storage_paths,file_name) | ||
else | ||
end | ||
# use the | ||
@requested_format = request.format | ||
return render | ||
# use params to get query string or parsed route parameters | ||
|
||
@avail_params = params | ||
|
||
# see if a file extension was specified. | ||
# if none was specified, default to html | ||
if !params.include? 'format' | ||
#@avail_params = params | ||
if params.include? :format | ||
else | ||
params[:format] = 'html' | ||
end | ||
|
||
if params[:format] == 'png' # if the extension is png, it is a spectrogram request | ||
# if an image format was specified, get spectrogram information, otherwise audio | ||
if %w(png jpg).include? params[:format] # if the extension is png or jpg, it is a spectrogram request | ||
file_name = Cache::cached_spectrogram_file(params) | ||
file_paths = Cache::possible_paths(Cache::cached_spectrogram_storage_paths,file_name) | ||
|
||
elsif ['mp3', 'webm', 'webma', 'ogg', 'oga'].include? params[:format] # if the extension is mp3, webma, ogg, it is an audio request | ||
file_name = Cache::cached_audio_file(params) | ||
file_paths = Cache::possible_paths(Cache::cached_audio_storage_paths,file_name) | ||
file_paths = Cache::existing_paths(Cache::cached_spectrogram_storage_paths,file_name) | ||
else | ||
# invalid request, what to do? | ||
file_name = Cache::cached_audio_file(params) | ||
file_paths = Cache::existing_paths(Cache::cached_audio_storage_paths,file_name) | ||
end | ||
|
||
@file_paths = file_paths | ||
|
||
mimeType = Mime::Type.lookup_by_extension(params[:format]) | ||
#=begin | ||
# construct a hash of information to be returned | ||
@file_info = params | ||
@file_info.delete 'controller' | ||
@file_info.delete 'action' | ||
@file_info.delete 'format' | ||
if file_paths.length > 0 && %w(html htm js json).include?(params[:format]) | ||
@file_info[:information] = Audio::info file_paths.first | ||
end | ||
mime_type = Mime::Type.lookup_by_extension(params[:format]) | ||
# respond to the request | ||
respond_with do |format| | ||
format.html { render } | ||
format.htm { render 'index.html.erb' } | ||
format.json { render json: params } | ||
format.js { render json: params } | ||
format.mp3 { send_file_response @file_paths, mimeType } | ||
format.webma { send_file_response @file_paths, mimeType } | ||
format.webm { send_file_response @file_paths, mimeType } | ||
format.oga { send_file_response @file_paths, mimeType } | ||
format.ogg { send_file_response @file_paths, mimeType } | ||
format.png { send_file_response @file_paths, mimeType } | ||
format.html { | ||
render | ||
} | ||
format.htm { | ||
render 'index.html.erb' | ||
} | ||
format.json { render json: @file_info } | ||
format.js { render json: @file_info } | ||
format.mp3 { send_file_response file_paths, file_name, mime_type } | ||
format.webma { send_file_response file_paths, file_name, mime_type } | ||
format.webm { send_file_response file_paths, file_name, mime_type } | ||
format.oga { send_file_response file_paths, file_name, mime_type } | ||
format.ogg { send_file_response file_paths, file_name, mime_type } | ||
format.png { send_file_response file_paths, file_name, mime_type } | ||
end | ||
#=end | ||
#render :formats => [:html] | ||
=end | ||
end | ||
|
||
private | ||
|
||
def send_file_response (file_paths, mime_type) | ||
send_file file_paths[0], :stream => true, :buffer_size => 4096, :disposition => 'inline', :type => mime_type | ||
end | ||
|
||
def info | ||
@input_path = './test/fixtures/' | ||
# not-an-audio-file.wav | ||
# TorresianCrow.wav | ||
# TestAudio1.wv | ||
# sites.yml | ||
# this file does not exist.nope | ||
@audio = 'TestAudio1.wv' | ||
@input_audio = @input_path + @audio | ||
@result = Audio::info(@input_audio) | ||
end | ||
def audio | ||
print params | ||
|
||
@input_path = './test/fixtures/' | ||
@output_path = './public/tests/' | ||
|
||
@audio = 'TestAudio1.wv' | ||
@modified_audio = 'TestAudio1.wav' | ||
|
||
@input_audio = @input_path + @audio | ||
@output_audio = @output_path + @modified_audio | ||
|
||
|
||
#@result = Audio::modify(@input_audio, @output_audio, []) | ||
end | ||
def spectrogram | ||
print params | ||
@input_path = './test/fixtures/' | ||
@output_path = './public/tests/' | ||
|
||
@audio = 'TorresianCrow.wav' | ||
@image = 'TorresianCrow.png' | ||
|
||
@input_audio = @input_path + @audio | ||
@output_image = @output_path + @image | ||
|
||
#@result = Spectrogram::generate(@input_audio, @output_image) | ||
def send_file_response (file_path, file_name, mime_type) | ||
#raise RuntimeError, "Can't find a source for file: #{file_name}" unless file_paths.length > 0 | ||
send_file file_path, :stream => true, :buffer_size => 4096, :disposition => 'inline', :type => mime_type, :content_type => mime_type | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
<h1>Media#index</h1> | ||
<p>Index page for media controller.</p> | ||
<p><%= @testing %></p> | ||
<p>Index page for media controller.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<h1>Media#item</h1> | ||
<p>Individual item page for media controller.</p> | ||
<p><%= @avail_params %></p> | ||
<p><%= @file_paths %></p> | ||
<h2>File Info</h2> | ||
<%= @requested_format1 %> | ||
<%= @requested_format2 %> | ||
<%= @file_info %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require 'audio_sox' | ||
|
||
module Audio | ||
include AudioSox, AudioMp3splt, AudioWavpack, AudioFfmpeg | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters