Permalink
Browse files

Added more config options and dried up config code a bit.

  • Loading branch information...
1 parent bb2f02f commit 0d7be666ba32cb7bf9d04a04dd07f5987686ebd5 dave committed Oct 29, 2010
View
@@ -62,9 +62,12 @@ class EnigmaMachine < Sinatra::Base
unless File.exist? File.join(Dir.getwd, 'config.yml')
FileUtils.cp(File.dirname(__FILE__) + '/generators/config.yml', Dir.getwd)
end
- raw_config = File.read(Dir.getwd + "/config.yml")
- @@username = YAML.load(raw_config)['username']
- @@password = YAML.load(raw_config)['password']
+ config = YAML.load(File.read(Dir.getwd + "/config.yml"))
+ @@username = config['username']
+ @@password = config['password']
+ @@threads = config['threads']
+ @@enable_http_downloads = config['enable_http_downloads']
+ @@download_storage_path = config['download_storage_path']
end
# Set the views to the proper path inside the gem
@@ -115,6 +118,10 @@ class EnigmaMachine < Sinatra::Base
[username, password] == [@@username, @@password]
end
+ # Some accessors for config variables
+ #
+ cattr_accessor :download_storage_path, :enable_http_downloads, :threads
+
# Shows the enigma status page.
#
@@ -4,9 +4,11 @@ class DownloadQueue
# starts looking for videos to download.
#
def initialize
- EM.add_periodic_timer(5) {
- download_next_video
- }
+ if EnigmaMachine.enable_http_downloads
+ EM.add_periodic_timer(5) do
+ download_next_video
+ end
+ end
end
@@ -16,7 +16,7 @@ def initialize
# Gets the next unencoded Video from the database and starts encoding its file.
#
def encode_next_video
- if Video.unencoded.count > 0 && Video.encoding.count < @threads
+ if Video.unencoded.count > 0 && Video.encoding.count < EnigmaMachine.threads
video = Video.unencoded.first
begin
video.encode!
@@ -194,18 +194,20 @@ def do_encode
def ffmpeg(task)
current_task_index = encoder.encoding_tasks.index(task)
movie = FFMPEG::Movie.new(file_to_encode)
- encoding_operation = proc {
+ encoding_operation = proc do
movie.transcode(file_to_encode + task.output_file_suffix, task.command)
- }
- completion_callback = proc {|result|
+ end
+
+ completion_callback = proc do |result|
if task == encoder.encoding_tasks.last
self.complete!
else
next_task_index = current_task_index + 1
next_task = encoder.encoding_tasks[next_task_index]
ffmpeg(next_task)
end
- }
+ end
+
EventMachine.defer(encoding_operation, completion_callback)
end
@@ -247,14 +249,15 @@ def local?
end
# If the file is local, this just returns its location. If it's not local,
- # it builds a path to the file based on a standard location and returns that.
+ # it builds a path to the file based on your config.yml + the video's id and
+ # returns that.
#
def file_to_encode
if local?
return file
else
filename = File.basename(URI.parse(file).path)
- return File.join(Dir.pwd, "downloads", self.id.to_s, filename)
+ return File.join(EnigmaMachine.download_storage_path, self.id.to_s, filename)
end
end
@@ -1,3 +1,6 @@
username: admin
password: admin
threads: 1
+enable_http_downloads: false
+download_storage_path: /path/to/where/downloads/should/end/up
+

0 comments on commit 0d7be66

Please sign in to comment.