Skip to content
Browse files

encoder could work now, but needs intense refactoring

  • Loading branch information...
1 parent 36b7e62 commit 595bfb6a3b89dd35f86a66a8a4aabf30b12635a0 @dctanner dctanner committed Jun 11, 2008
Showing with 38 additions and 128 deletions.
  1. +12 −102 Rakefile
  2. +8 −8 app/models/video.rb
  3. +18 −18 lib/encoder.rb
View
114 Rakefile
@@ -7,115 +7,25 @@ require 'rake/rdoctask'
require 'rake/testtask'
require 'spec/rake/spectask'
require 'fileutils'
-
-require File.dirname(__FILE__)+'/config/boot.rb'
-require Merb::framework_root+'/tasks'
+require 'merb-core'
+require 'rubigen'
include FileUtils
-# Set these before any dependencies load
-# otherwise the ORM may connect to the wrong env
-Merb.root = File.dirname(__FILE__)
-Merb.environment = ENV['MERB_ENV'] if ENV['MERB_ENV']
-
+# Load the basic runtime dependencies; this will include
+# any plugins and therefore plugin rake tasks.
+init_env = ENV['MERB_ENV'] || 'rake'
+Merb.load_dependencies(:environment => init_env)
+
# Get Merb plugins and dependencies
-require File.dirname(__FILE__)+'/config/dependencies.rb'
-Merb::Plugins.rakefiles.each {|r| require r }
-
-#desc "Packages up Merb."
-#task :default => [:package]
-
-desc "load merb_init.rb"
-task :merb_init do
- # deprecated - here for BC
- Rake::Task['merb_env'].invoke
-end
-
-task :uninstall => [:clean] do
- sh %{sudo gem uninstall #{NAME}}
-end
-
-desc 'Run unit tests'
-Rake::TestTask.new('test_unit') do |t|
- t.libs << 'test'
- t.pattern = 'test/unit/*_test.rb'
- t.verbose = true
-end
-
-desc 'Run functional tests'
-Rake::TestTask.new('test_functional') do |t|
- t.libs << 'test'
- t.pattern = 'test/functional/*_test.rb'
- t.verbose = true
-end
-
-desc 'Run all tests'
-Rake::TestTask.new('test') do |t|
- t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
-
-desc "Run all specs"
-Spec::Rake::SpecTask.new('specs') do |t|
- t.spec_opts = ["--format", "specdoc", "--colour"]
- t.spec_files = Dir['spec/**/*_spec.rb'].sort
-end
-
-desc "Run all model specs"
-Spec::Rake::SpecTask.new('model_specs') do |t|
- t.spec_opts = ["--format", "specdoc", "--colour"]
- t.spec_files = Dir['spec/models/**/*_spec.rb'].sort
-end
-
-desc "Run all controller specs"
-Spec::Rake::SpecTask.new('controller_specs') do |t|
- t.spec_opts = ["--format", "specdoc", "--colour"]
- t.spec_files = Dir['spec/controllers/**/*_spec.rb'].sort
-end
-
-desc "Run a specific spec with TASK=xxxx"
-Spec::Rake::SpecTask.new('spec') do |t|
- t.spec_opts = ["--format", "specdoc", "--colour"]
- t.libs = ['lib', 'server/lib' ]
- t.spec_files = ["spec/merb/#{ENV['TASK']}_spec.rb"]
-end
-
-desc "Run all specs output html"
-Spec::Rake::SpecTask.new('specs_html') do |t|
- t.spec_opts = ["--format", "html"]
- t.libs = ['lib', 'server/lib' ]
- t.spec_files = Dir['spec/**/*_spec.rb'].sort
-end
-
-desc "RCov"
-Spec::Rake::SpecTask.new('rcov') do |t|
- t.spec_opts = ["--format", "specdoc", "--colour"]
- t.spec_files = Dir['spec/**/*_spec.rb'].sort
- t.libs = ['lib', 'server/lib' ]
- t.rcov = true
-end
-
-desc 'Run all tests, specs and finish with rcov'
-task :aok do
- sh %{rake rcov}
- sh %{rake spec}
-end
+Merb::Plugins.rakefiles.each { |r| require r }
-unless Gem.cache.search("haml").empty?
- namespace :haml do
- desc "Compiles all sass files into CSS"
- task :compile_sass do
- gem 'haml'
- require 'sass'
- puts "*** Updating stylesheets"
- Sass::Plugin.update_stylesheets
- puts "*** Done"
- end
- end
+desc "start runner environment"
+task :merb_env do
+ Merb.start_environment(:environment => init_env, :adapter => 'runner')
end
##############################################################################
-# SVN
+# ADD YOUR CUSTOM TASKS BELOW
##############################################################################
desc "Add new files to subversion"
View
16 app/models/video.rb
@@ -135,16 +135,16 @@ def add_to_queue
cur_video = Video.query("['parent' = '#{self.key}'] intersection ['profile' = '#{p.key}']")
unless cur_video
# TODO: move to a method like self.add_encoding
- video = Video.new
- video[:profile] = p.key
- video[:profile_title] = p.title
- video[:status] = 'queued'
- video[:parent] = self.key
+ encoding = Video.new
+ encoding[:profile] = p.key
+ encoding[:profile_title] = p.title
+ encoding[:status] = 'queued'
+ encoding[:parent] = self.key
[:original_filename, :duration, :container, :width, :height, :video_codec, :video_bitrate, :fps, :audio_codec, :audio_bitrate, :audio_sample_rate].each do |k|
- video.put(k, p.get(k))
+ encoding.put(k, p.get(k))
end
- video[:filename] = "#{self.key}.#{video.container}"
- video.save
+ encoding[:filename] = "#{encoding.key}.#{p.container}"
+ encoding.save
end
end
View
36 lib/encoder.rb
@@ -114,7 +114,7 @@ def encoding(key,log)
log.info recipe_options.to_yaml
- begin
+ # begin
case encoding.container
when "flv"
recipe = "ffmpeg -i $input_file$ -ar 22050 -ab $audio_bitrate$k -f flv -b $video_bitrate_in_bits$ -r 22 $resolution_and_padding$ -y $output_file$"
@@ -157,43 +157,43 @@ def encoding(key,log)
log.info Time.now
else
log.warn "Error: unknown encoding format given"
- Rog.log :error, "job##{job[:id]}: Couldn't encode #{encoding[:id]}. Unknown encoding format given."
+ Rog.log :error, "Couldn't encode #{encoding.key}. Unknown encoding format given."
end
log.info "Done encoding"
# Now upload it to S3
if File.exists?(enc_fn)
- Rog.log :info, "job##{job[:id]}: Success encoding #{encoding.filename}. Uploading to S3."
+ Rog.log :info, "Success encoding #{encoding.filename}. Uploading to S3."
log.info "Uploading #{encoding.filename}"
+
encoding.upload_to_s3
FileUtils.rm encoding.tmp_filepath
+
log.info "Done uploading"
# Update the encoding data which will be returned to the server
- encoding[:status] = "success"
+ encoding.status = "success"
else
- encoding[:status] = "error"
- Rog.log :info, "job##{job[:id]}: Couldn't upload #{encoding[:id]} to S3. To file #{enc_fn} doesn't exist."
+ encoding.status = "error"
+ Rog.log :info, "Couldn't upload #{encoding.key]} to S3 as #{enc_fn} doesn't exist."
log.warn "Error: Cannot upload as #{enc_fn} does not exist"
end
- # Seems like it was a success
- encoding[:status] = "success"
- encoding[:executed_commands] = transcoder.executed_commands
- rescue RVideo::TranscoderError => e
- encoding[:status] = "error"
- encoding[:executed_commands] = transcoder.executed_commands
- Rog.log :error, "job##{job[:id]}: Error transcoding #{encoding[:id]}: #{e.class} - #{e.message}"
- log.info "Unable to transcode file #{encoding[:id]}: #{e.class} - #{e.message}"
- end
+ # encoding[:executed_commands] = transcoder.executed_commands
+ # rescue RVideo::TranscoderError => e
+ # encoding.status = "error"
+ # # encoding[:executed_commands] = transcoder.executed_commands
+ # Rog.log :error, "Error transcoding #{encoding[:id]}: #{e.class} - #{e.message}"
+ # log.info "Unable to transcode file #{encoding[:id]}: #{e.class} - #{e.message}"
+ # end
end
log.info "All encodings complete!"
- Rog.log :info, "job##{job[:id]}: Complete!"
+ Rog.log :info, "Complete!"
FileUtils.rm raw_fn
- job[:encoding_time] = Time.now - begun_encoding
- return job
+ encoding.encoding_time = Time.now - begun_encoding
+ return true
end
loop do

0 comments on commit 595bfb6

Please sign in to comment.
Something went wrong with that request. Please try again.